0

一个 .txt 文件,格式如下

1115151651515950000055 00012913702613000000000003000 139C0000007000000 1215151651121510000054 00022913803603000000000009000 000279A0000009000 1315115950000065516515 00032813104643000000000007000 000399B0000003000 121515160003290003290000010000000003000

前 3 行是正文元素,但正文部分的行数未知(可能从 1 到无界)。正文部分没有标签标识符。文件中的最后一行始终是预告片。文件中的预告片将在解析之前删除,以便只解析记录。创建自定义管道组件以将标签添加到正文部分。但是当我将工具箱中的组件添加到接收 Piepline 时显示错误“IPersistPropertyBag 实现上的管道组件加载​​()失败”

管道组件的代码是,

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.IO;
using Microsoft.BizTalk.Message.Interop;
using Microsoft.BizTalk.Component.Interop;
namespace PipelinezTrailerPrj
{
    [ComponentCategory(CategoryTypes.CATID_PipelineComponent)]

    [ComponentCategory(CategoryTypes.CATID_DisassemblingParser)]

    [System.Runtime.InteropServices.Guid("6118B8F0-8684-4ba2-87B4-8336D70BD4F7")]
    public class CRemoveTrailer : IBaseComponent, IComponentUI, IComponent, IPersistPropertyBag
    {
        #region IBaseComponent
        public string Description
        {
            get
            {
                return "Pipeline component used to delete the Trailer in The Incoming messages";
            }
        }
        public string Name
        {
            get
            {
                return "CRemoveTrailer";
            }
        }
        public string Version
        {
            get
            {
                return "1.0.0.0";
            }
        }
        #endregion

        #region IComponentUI
        public IntPtr Icon
        {
            get
            {
                return new System.IntPtr();
            }
        }

        public System.Collections.IEnumerator Validate(object projectSystem)
        {
            return null;
        }
        #endregion

        #region IPersistPropertyBag
        private string _NewNameSpace;
        public string NewNameSpace
        {
            get { return _NewNameSpace; }
            set { _NewNameSpace = value; }
        }

        public void GetClassID(out Guid classID)
        {
            classID = new Guid("ACC3F15A-C389-4a5d-8F8E-2A951CDC4C19");
        }

        public void InitNew()
        {

        }

        public void Load(IPropertyBag propertyBag, int errorLog)
        {
            object val = null;
            try
            {
                propertyBag.Read("PipelinezTrailerPrj", out val, 0);
            }
            catch (Exception ex)
            {
                throw new ApplicationException("Error reading propertybag: " + ex.Message);
            }
            if (val != null)
                _NewNameSpace = (string)val;
            else
                _NewNameSpace = "http://PipelinezTrailerPrj";
        }

        public void Save(IPropertyBag propertyBag, bool clearDirty, bool saveAllProperties)
        {
            object val = (object)_NewNameSpace;
            propertyBag.Write("PipelinezTrailerPrj", ref val);
        }
        #endregion
        #region IComponent
        public IBaseMessage Execute(IPipelineContext pContext, IBaseMessage pInMsg)
        {
            if (pContext == null) throw new ArgumentNullException("pContext");

            if (pInMsg == null) throw new ArgumentNullException("pInMsg");

            IPipelineContext pipelineContext = pContext;
            IBaseMessage baseMessage = pInMsg;
            //Validate parameters

            string partName;

            for (int i = 0; i < baseMessage.PartCount; i++)

            {
                MemoryStream outStream = new MemoryStream();

                partName = null;

                IBaseMessagePart part = baseMessage.GetPartByIndex(i, out partName);

                StreamReader reader = new StreamReader(part.GetOriginalDataStream());

                string partBody = reader.ReadToEnd();

                StreamWriter writer = new StreamWriter(outStream, new UTF8Encoding());               


                string[] separator = new string[] {"\r\n"};

                string[] strArray = partBody.Split(separator, StringSplitOptions.None);



                for (int n = 0; n < strArray.Length; n++)

                {

                    //There will be a blank string in the last line of the array. So we don't need to add tag to the last 2 lines.

                    if (n < (strArray.Length - 2))     

                    {

                        strArray[n] = "BODY" + strArray[n];

                    }


                    //Add the line break back.

                    writer.Write(strArray[n] + "\r\n");

                }                             

                writer.Flush();

                outStream.Seek(0, SeekOrigin.Begin);

                part.Data = outStream;

            }

            return baseMessage;

        }

        #endregion

}

}

4

1 回答 1

0

看起来 propertyBag.Read 抛出一个异常,然后你捕获它并抛出一个 applicationException。

参考这篇文章,和你的问题一样。建议的方法是

 propertyBag.Read("System", strValue, errorLog)
于 2014-08-21T18:06:41.353 回答