Excel pipeline component decode or disassemble?

Home Page Forums BizTalk 2004 – BizTalk 2010 Excel pipeline component decode or disassemble?

Viewing 1 reply thread
  • Author
    Posts
    • #25616

      Hi Guys

      I am busy writing a custom pipeline component which reads a excel file and then convert the data into xml so that I can do some mapping and processing on it in a orchestration.

      I have successfully done it in a Disassembler component but was thinking is this the right place for it?  Cause I am only creating one message out of data that I read in the excel file?

      Here is my code for the Disassembler (which works)

          public void Disassemble(IPipelineContext pContext, IBaseMessage pInMsg)

              {

                  System.Diagnostics.Trace.WriteLine(“Pipeline Disassemble Stage Enter”);

                  //load up the Excel reader:

                  Stream originalStream = pInMsg.BodyPart.GetOriginalDataStream();

                  string fileName = (string) pInMsg.Context.Read(“ReceivedFileName”, “http://schemas.microsoft.com/BizTalk/2003/file-properties”);

       

                  Customers customers = GetCustomers(fileName, originalStream);

       

                  //store the incoming context properties to write out again:

                  _contextProperties = new List<ContextProperty>();

                  for (int i = 0; i < pInMsg.Context.CountProperties; i++)

                  {

                      ContextProperty property = new ContextProperty();

                      property.Value = pInMsg.Context.ReadAt(i, out property.Name, out property.Namespace);

                      property.IsPromoted = pInMsg.Context.IsPromoted(property.Name, property.Namespace);

                      _contextProperties.Add(property);

                  }

                  MemoryStream memoryStream = new MemoryStream();

                  XmlSerializer xs = new XmlSerializer(typeof(Customers));

                  XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8);

                  xs.Serialize(xmlTextWriter, customers);

                  memoryStream = (MemoryStream)xmlTextWriter.BaseStream;

       

                  byte[] data = memoryStream.ToArray();

       

                  MemoryStream memStream = new MemoryStream(data);

       

                  IBaseMessagePart messagePart = pContext.GetMessageFactory().CreateMessagePart();

                  messagePart.Data = memStream;

                  messagePart.ContentType = “text/xml”;

                  messagePart.Charset = “utf-8”;

       

                  IBaseMessage outMsg = pContext.GetMessageFactory().CreateMessage();

                  outMsg.AddPart(“Body”, messagePart, true);

       

                  foreach (ContextProperty property in _contextProperties)

                  {

                      if (property.IsPromoted)

                          outMsg.Context.Promote(property.Name, property.Namespace, property.Value);

                      else

                          outMsg.Context.Write(property.Name, property.Namespace, property.Value);

                  }

       

                  outMsg.Context.Promote(“MessageType”, 

                      “http://schemas.microsoft.com/BizTalk/2003/system-properties&#8221;,

                      “http://AklAirports.ADE.Integration.Customer_EXCEL#Customers&#8221;);

       

                 /* outMsg.Context.Promote(“SchemaStrongName”, 

                      “http://schemas.microsoft.com/BizTalk/2003/system-properties&#8221;,

                      “SchemaAssebly full name”);*/

       

                  outputMsgs.Enqueue(outMsg);

       

                  System.Diagnostics.Trace.WriteLine(“Pipeline Disassemble Stage Exit”);

              }

       

              public IBaseMessage GetNext(IPipelineContext pContext)

              {

                  if (outputMsgs.Count > 0)

                  {

                      IBaseMessage msg = (IBaseMessage)outputMsgs.Dequeue();

                      return msg;

                  }

                  else

                      return null;

              }

      But for some reason I am struggling to implement the same logic into a Decode component, for some reason my Disassemble code wont work in the Execute method of the Decode.

      Any advice guys?

       

      Cheers
       Jamie

    • #25618

      In the Execute method you do not have to create a new message. You can just modify the data stream:

      public IBaseMessage Execute(IPipelineContext Context, IBaseMessage inMsg)
      {
         Stream originalStream = inMsg.BodyPart.GetOriginalDataStream();
         Customers customers = GetCustomers(fileName, originalStream);
          MemoryStream memoryStream = new MemoryStream();
          XmlSerializer xs = new XmlSerializer(typeof(Customers));
          XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8);
          xs.Serialize(xmlTextWriter, customers);
          memoryStream.Seek(0, SeekOrigin.Begin);     return InMsg;
      }

      • #25619

        Hi Greg

        Thanks for the reply will go test it out now.

        But what is the correct way in doing it in the Decode or Disassemble?

        • #25620

          There is no right answer here.
          I would tend to reserve the disassembler for a more generic purpose e.g. parsing any Excel file, possibly generating a separate message for each page?

          In your instance you are pretty much hardcoding the conversion for a single document format so I would use the decode stage.

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