xyz
xyz

Reputation: 549

Issue with Custom Pipeline component

The Custom Pipeline component developed reads the incoming stream to a folder and pass only some meta data through the MessageBox.I am using the one already availaible in Code Project

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
}
}

The issue here is the LargeFileLocation is configurable in the receive pipeline. If I give a location for the first time for example E:\ABC\ the files are sent to the location.

But if I change the location to E:\DEF\ the files are still being sent to the previous location E:\ABC. I tried to create a new biztalk application deleting the old one but still I get the files dropped in to the old location E:\ABC\ not sure why.

Upvotes: 0

Views: 1481

Answers (2)

Vikas Bhardwaj
Vikas Bhardwaj

Reputation: 1510

Most likely the issue is with respect to Property definition of LargeFileLocation and its implementation and usage in IPersistPropertyBag interfaces. You can try following things:

  1. Check if you have added E:\ABC path in Pipeline at design time. If yes remove it from there and set in Admin console for first time also and see how it behaves, my feeling is it will take temp path location.
  2. Change the Properties and IPersistPropertyBag implementation to use property with declaration such as public string LargeFileName {get;set;} i.e. no local variables _largeFileName.

Upvotes: 1

Zee
Zee

Reputation: 840

Have you deleted the dll in %BizTalkFolder%\Pipeline Components\ ?

To refresh the pipeline component, you need delete the old dll file/remove the item in VS toolbox. then restart the VS, deploy it again.

and for this LargeFileLocation , I suggest you make it as a property so you can config it.

Upvotes: 0

Related Questions