Testing Custom Pipeline Component

Home Page Forums BizTalk 2004 – BizTalk 2010 Testing Custom Pipeline Component

Viewing 1 reply thread
  • Author
    Posts
    • #26444

      Hello,

      Created a Custom Pipeline Component to remove the Trailer of the the
      received .txt file. How to check if the output is correct. Can anybody
      check if the coding(below) is correct and let me know how do I test.
      Because I have to use the output of the component
      to Flat File Disassembler and Parse using the Flat File Schema wizard.
      When I did I am getting error like,

      Reason: Unexpected end of stream while looking for:
      Positional data (length is 10)
      The current definition being parsed is Root_Child1. The stream offset
      where the error occured is 245. The line number where the error occured
      is 5. The column where the error occured is 0.

      So I have to check if the Pipeline Component is working correct. I am
      struggling since I am new, it would be great if somebody help me to get
      through it.

      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 RemoveTrailerPL
      {   [ComponentCategory(CategoryTypes.CATID_PipelineComponent)]
          [ComponentCategory(CategoryTypes.CATID_Any)]
          [System.Runtime.InteropServices.Guid(“9d0e4103-4cce-4536-83fa-4a5040674ad6”)]
          public class RemoveTrailer : IBaseComponent,
                                              IComponentUI,
                                              IComponent,
                                              IPersistPropertyBag

             {
          
              #region IBaseComponent Members

              public string Description
              {
                  get
                  {
                      return “Pipeline component used to remove Trailer and Body Tag”;
                  }
              }
              public string Name
              {
                  get
                  {
                      return “RemoveTrailerPL”;
                  }
              }
              public string Version
              {
                  get
                  {
                      return “3.0.1.0”;
                  }
              }
              #endregion

              #region IComponentUI Members

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

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

              #endregion

              #region IPersistPropertyBag Members

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

              public void GetClassID(out Guid classID)
              {
                  classID = new Guid(“A0AED10E-5E04-4ECE-8EEB-C990C31E8989”);
              }

              public void InitNew()
              {

              }

              public void Load(IPropertyBag propertyBag, int errorLog)
              {
                  object val = null;
                  try
                  {
                      propertyBag.Read(“RemoveTrailerPL”, out val, 0);
                  }
                  catch (System.ArgumentException)
                  {
                      //val = null;
                  }
                  catch (Exception ex)
                  {
                      throw new ApplicationException(“Error reading propertybag: ” + ex.Message);
                  }

                  if (val != null)
                      _NewNameSpace = (string)val;
                  else
                      _NewNameSpace = “http://RemoveTrailerPL”;

              }

              public void Save(IPropertyBag propertyBag, bool clearDirty, bool saveAllProperties)
              {
                  object val = (object)_NewNameSpace;
                  propertyBag.Write(“RemoveTrailerPL”, ref val);
              }

              #endregion

              #region IComponent Member
              public IBaseMessage Execute(IPipelineContext pContext, IBaseMessage pInMsg)
              {
                  //Validate parameters
                  if (pContext == null) throw new ArgumentNullException(“pContext”);
                  if (pInMsg == null) throw new ArgumentNullException(“pInMsg”);

                  IPipelineContext pipelineContext = pContext;
                  IBaseMessage baseMessage = pInMsg;
                  
                  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))
                          {
                              strArrayNo =  strArrayNo;
                          }
                          //Add the line break back.
                          writer.Write(strArrayNo + “\r\n”);
                      }
                      writer.Flush();
                      outStream.Seek(0, SeekOrigin.Begin);
                     
                      part.Data = outStream;
                  }
                  return baseMessage;
              }
              #endregion
          }}

    • #26445

      Hi,

        See the following articles on how to set up debugging for your custom pipeline components:

      msdn.microsoft.com/…/aa559290.aspx

      geekswithblogs.net/…/120852.aspx

        Good luck.

Viewing 1 reply thread
  • The forum ‘BizTalk 2004 – BizTalk 2010’ is closed to new topics and replies.