我创建了一个动态 GP 扩展方法来规范遵循 MSDN 指南动态 GP 扩展程序集
这是我的自定义扩展程序集的代码:
namespace MyGPService
{
public static class GPExtensions
{
public static void OnRecordCreated(object sender, BusinessObjectEventArgs e)
{
try
{
Customer customer;
Extension CustomerEmailExtension = new Extension();
//get current cust connection
//connection = Connection.GetInstance();
if (e.BusinessObject.GetType() == typeof(Customer))
{
customer = (Customer)e.BusinessObject;
// Look at the Extension list passed along
foreach (Extension ext in customer.Extensions)
{
Logger.LogExtention(ext);
}
}
else
{
Logger.LogExtentionType(e.GetType().ToString());
}
}
catch (Exception ex)
{
Logger.LogException(ex.Message);
}
}
}
}
此代码包含一些日志记录机制,可将任何传入数据记录到本地驱动器(让我进一步了解测试期间通过的内容)。
下面是我的 BusinessObjectsFile.config 文件条目(进一步解释了业务对象配置文件
<DictionaryEntry>
<Key xsi:type="xsd:string">Microsoft.Dynamics.GP.Customer</Key>
<Value xsi:type="BusinessObjectConfiguration">
<Event>
<EventName>Created</EventName>
<EventHandlerType>
<Type>Microsoft.Dynamics.Common.BusinessObjectEventHandler</Type>
<Assembly>Microsoft.Dynamics.Common</Assembly>
</EventHandlerType>
EventHandler>
<SoftwareVendor>XYZ</SoftwareVendor>
<Type>MyGPService.GPExtentions</Type>
<StaticMethod>OnRecordCreated</StaticMethod>
<Assembly>MyGPExtensionMethods</Assembly>
<Execute>true</Execute>
</EventHandler>
</Event>
</Value>
</DictionaryEntry>
在我配置了适当的更改后(将新的扩展程序集放在 C:\Program Files\Microsoft Dynamics\GPWebServices 中,配置了 BusinessObjectFile.config,然后重新启动Microsoft Dynamics GP Service Host。然后我创建了一个新客户,创建了一个 PO 和所以对于那个客户,什么都没有记录???
记录方法:
public static void LogException(string error)
{
try
{
string path = Path.Combine(Utilities.SystemDirectory, "GPExtentionMethod\\Errors\\ExtErrorLog.txt");
if(!Directory.Exists(Path.GetDirectoryName(path)))
Directory.CreateDirectory(Path.GetDirectoryName(path));
if (!File.Exists(path))
{
// Create a file to write to.
using (StreamWriter sw = File.CreateText(path))
{
sw.WriteLine("GP Extention Error Log");
sw.WriteLine("");
}
}
using (StreamWriter sw = File.AppendText(path))
{
sw.WriteLine(Environment.NewLine);
sw.WriteLine("Error");
sw.WriteLine(DateTime.Now.ToString() + ": " + error);
}
}
catch { }
}
我已经跟进了所有部署,但我无法弄清楚为什么这个扩展方法永远不会从 GP 调用?我错过了(或者我应该说微软)这个难题的一部分吗?