Error in Custom Pipeline Component

1.3k views Asked by At

A .txt file which is in the similar format as below

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

The first 3 lines are body elements but the number of lines in the body part will be unknown(may occur from 1 to unbounded). There is no tag identifier in body part. The last line in the file is always a trailer.The trailer from the file is to be removed prior to parsing so that only the records need parsed.Created a Custom Pipeline Component to add tag to the body part. But shows error when I add the component from the tool box to the Receive Piepline "Pipeline Component Load() failed on IPersistPropertyBag implementation"

Code of the Pipeline Component is,

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

}

}

1

There are 1 answers

0
Zee On

Looks the propertyBag.Read throw an exception then you catch it and throw an applicationException.

Refer to this article, same issue as yours. and the suggested approach is

 propertyBag.Read("System", strValue, errorLog)