BizTalk自定义管道组件不会加载重写的属性

时间:2017-03-10 14:15:16

标签: biztalk custom-pipeline-component

我有一个自定义的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);
        }
    }

0 个答案:

没有答案