首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >与自定义管道组件一起发布

与自定义管道组件一起发布
EN

Stack Overflow用户
提问于 2015-03-24 14:56:54
回答 2查看 1.2K关注 0票数 0

开发的自定义管道组件将传入的流读取到文件夹中,并仅通过MessageBox.I传递一些元数据。

代码语言:javascript
复制
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.BizTalk.Message.Interop;
using Microsoft.BizTalk.Component.Interop;
using System.IO;

  namespace SendLargeFilesDecoder
   {
     [ComponentCategory(CategoryTypes.CATID_PipelineComponent)]
     [ComponentCategory(CategoryTypes.CATID_Decoder)]
     [System.Runtime.InteropServices.Guid("53fd04d5-8337-42c2-99eb-32ac96d1105a")]
     public class SendLargeFileDecoder :   IBaseComponent,
                                           IComponentUI,
                                           IComponent,
                                           IPersistPropertyBag
   {
    #region IBaseComponent
    private const string _description = "Pipeline component used to save large files to disk";
    private const string _name = "SendLargeFileDecoded";
    private const string _version = "1.0.0.0";

    public string Description
    {
        get { return _description; }
    }
    public string Name
    {
        get { return _name; }
    }
    public string Version
    {
        get { return _version; }
    }
    #endregion

    #region IComponentUI
    private IntPtr _icon = new IntPtr();
    public IntPtr Icon
    {
        get { return _icon; }
    }
    public System.Collections.IEnumerator Validate(object projectSystem)
    {
        return null;
    }
    #endregion

    #region IComponent
    public IBaseMessage Execute(IPipelineContext pContext, IBaseMessage pInMsg)
    {
        if (_largeFileLocation == null || _largeFileLocation.Length == 0)
            _largeFileLocation = Path.GetTempPath();

        if (_thresholdSize == null || _thresholdSize == 0)
            _thresholdSize = 4096;

        if (pInMsg.BodyPart.GetOriginalDataStream().Length > _thresholdSize)
        {
            Stream originalStream = pInMsg.BodyPart.GetOriginalDataStream();

            string srcFileName = pInMsg.Context.Read("ReceivedFileName", "http://schemas.microsoft.com/BizTalk/2003/file-properties").ToString();
            string largeFilePath = _largeFileLocation + System.IO.Path.GetFileName(srcFileName);

            FileStream fs = new FileStream(largeFilePath, FileMode.Create);

            // Write message to disk
            byte[] buffer = new byte[1];
            int bytesRead = originalStream.Read(buffer, 0, buffer.Length);
            while (bytesRead != 0)
            {
                fs.Flush();
                fs.Write(buffer, 0, buffer.Length);
                bytesRead = originalStream.Read(buffer, 0, buffer.Length);
            }
            fs.Flush();
            fs.Close();

            // Create a small xml file
            string xmlInfo = "<MsgInfo xmlns='http://SendLargeFiles'><LargeFilePath>" + largeFilePath + "</LargeFilePath></MsgInfo>";
            byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(xmlInfo);
            MemoryStream ms = new MemoryStream(byteArray);
            pInMsg.BodyPart.Data = ms;
        }
        return pInMsg;
    }

    #endregion

    #region IPersistPropertyBag
    private string _largeFileLocation;
    private int _thresholdSize;

    public string LargeFileLocation
    {
        get { return _largeFileLocation; }
        set { _largeFileLocation = value; }
    }

    public int ThresholdSize
    {
        get { return _thresholdSize; }
        set { _thresholdSize = value; }
    }

    public void GetClassID(out Guid classID)
    {
        classID = new Guid("CA47347C-010C-4B21-BFCB-22F153FA141F");
    }
    public void InitNew()
    {
    }
    public void Load(IPropertyBag propertyBag, int errorLog)
    {
        object val1 = null;
        object val2 = null;
        try
        {
            propertyBag.Read("LargeFileLocation", out val1, 0);
            propertyBag.Read("ThresholdSize", out val2, 0);
        }
        catch (ArgumentException)
        {
        }
        catch (Exception ex)
        {
            throw new ApplicationException("Error reading PropertyBag: " + ex.Message);
        }
        if (val1 != null)
            _largeFileLocation = (string)val1;

        if (val2 != null)
            _thresholdSize = (int)val2;

    }
    public void Save(IPropertyBag propertyBag, bool clearDirty, bool saveAllProperties)
    {
        object val1 = (object)_largeFileLocation;
        propertyBag.Write("LargeFileLocation", ref val1);

        object val2 = (object)_thresholdSize;
        propertyBag.Write("ThresholdSize", ref val2);
    }
    #endregion
}
}

这里的问题是LargeFileLocation在接收管道中是可配置的。如果我第一次给出一个位置,例如E:\ABC\,文件将被发送到该位置。

但是,如果我将位置更改为E:\DEF\,则仍将文件发送到前面的位置E:\ABC。我尝试创建一个新的biztalk应用程序,删除旧的biztalk应用程序,但我仍然将文件放到旧位置E:\ABC\不确定原因。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-03-24 16:14:36

最有可能的问题是LargeFileLocation的属性定义及其在IPersistPropertyBag接口中的实现和使用。你可以尝试以下几点:

  1. 检查是否在设计时在管道中添加了E:\ABC路径。如果是的,从那里删除它,并设置在管理控制台第一次,看看它的行为,我的感觉是,它将采取临时路径定位。
  2. 将属性和IPersistPropertyBag实现更改为使用带有声明的属性,例如public string LargeFileName {get;set;},即没有局部变量_largeFileName。
票数 1
EN

Stack Overflow用户

发布于 2015-03-24 16:06:40

您是否删除了%BizTalkFolder%\管道组件中的dll?

若要刷新管道组件,需要删除VS工具箱中的旧dll文件/删除项。然后重新启动VS,再次部署它。

对于这个LargeFileLocation,我建议您将它作为一个属性来配置它。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29235864

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档