3

我有一个自定义 BizTalk 2013 R2 管道组件,它定义了几个设计时属性。出于某种原因,BizTalk 将加载在 VS 管道设计器中设置的设计时属性值,但它会忽略在 BizTalk 管理控制台中设置的运行时值。我的组件实现了 IPersistPropertyBag 并且我已经验证它没有抛出任何异常。

在调试管道(附加到独立主机实例)时,我注意到 BizTalk 仅在管道实例化时调用 Load 方法。这只会加载 VS 设计器值,并且 BizTalk 应该在调用 Execute 之前再次调用 Load 方法。不幸的是,这并没有发生。

[编辑]我做了更多调试,发现这似乎只发生在双向接收端口的发送管道上。接收管道按预期加载设计时和运行时属性。

这是我的代码示例:

[ComponentCategory(CategoryTypes.CATID_PipelineComponent)]
[ComponentCategory(CategoryTypes.CATID_Encoder)]
[System.Runtime.InteropServices.Guid(COMPONENT_GUID)]
public class RhapsodyMessageEncoder : BasePipelineComponent, IBaseComponent, IComponentUI, 
    IPersistPropertyBag, Microsoft.BizTalk.Component.Interop.IComponent
{
...
    public void Load(IPropertyBag propertyBag, int errorLog)
    {
        try
        {
            this.Enabled = Convert.ToBoolean(this.ReadPropertyBag(propertyBag, "Enabled"));
            this.UsernameSSOKey = this.ReadPropertyBag(propertyBag, "UsernameSSOKey") as string;
            this.PasswordSsoKey = this.ReadPropertyBag(propertyBag, "PasswordSsoKey") as string;
            this.AffiliateAppName = this.ReadPropertyBag(propertyBag, "AffiliateAppName") as string;
        }
        catch (Exception e) { this.WriteErrorLog(e); }
    }

    public void Save(IPropertyBag propertyBag, bool clearDirty, bool saveAllProperties)
    {
        try
        {
            this.WritePropertyBag(propertyBag, "Enabled", this.Enabled);
            this.WritePropertyBag(propertyBag, "UsernameSSOKey", this.UsernameSSOKey);
            this.WritePropertyBag(propertyBag, "PasswordSsoKey", this.PasswordSsoKey);
            this.WritePropertyBag(propertyBag, "AffiliateAppName", this.AffiliateAppName);
        }
        catch (Exception e) { this.WriteErrorLog(e); }
    }
...
}

读/写属性包辅助方法:

    protected virtual object ReadPropertyBag(IPropertyBag pb, string propName)
    {
        PropertyInfo pInfo = this.GetType().GetProperty(propName);
        object currentValue = null;
        object val = null;

        if (pInfo != null)
            currentValue = pInfo.GetValue(this, null);

        try
        {
            pb.Read(propName, out val, 0);
        }
        catch (System.ArgumentException e)
        {
            System.Diagnostics.Trace.WriteLine(
                "Argument Exception encountered: " + e.Message,
                this.Name
            );
        }
        catch (System.Exception e)
        {
            throw new System.ApplicationException("Can't read design time Properties", e);
        }

        return val ?? currentValue;
    }

    protected virtual void WritePropertyBag(IPropertyBag pb, string propName, object val)
    {
        try
        {
            object obj = val;
            pb.Write(propName, ref obj);
        }
        catch (System.Exception e)
        {
            throw new System.ApplicationException("Can't write design time properties", e);
        }
    }
4

0 回答 0