Tallan's Technology Blog

Tallan's Top Technologists Share Their Thoughts on Today's Technology Challenges

Custom Pipeline Components – part 2: Archive component continued…

In the previous post we started creating the c# class that implements the interfaces needed to develop a custom BizTalk pipeline component. In this post, we continue with this sample…

The next interface we will implement is the IPersistPropertyBag interface. Before we do that, we need to add two generic utility methods to read to & write from property bags. A property bag is an object which can persistently save its properties. MSDN provides more info on the Microsoft.BizTalk.Adapter.Framework.PropertyBag class.

        #region utility functions

        /// <summary>

        /// Reads property value from property bag

        /// </summary>

        /// <param name=”pb”>Property bag</param>

        /// <param name=”propName”>Name of property</param>

        /// <returns>Value of the property</returns>

        private object ReadPropertyBag(

                  Microsoft.BizTalk.Component.Interop.IPropertyBag pb, string propName)

        {

            object val = null;

            try

            {

                pb.Read(propName, out val, 0);

            }

            catch (System.ArgumentException)

            {

                return val;

            }

            catch (System.Exception e)

            {

                throw new System.ApplicationException(e.Message);

            }

            return val;

        }

        /// <summary>

        /// Writes property values into a property bag.

        /// </summary>

        /// <param name=”pb”>Property bag.</param>

        /// <param name=”propName”>Name of property.</param>

        /// <param name=”val”>Value of property.</param>

        private void WritePropertyBag(

                             Microsoft.BizTalk.Component.Interop.IPropertyBag pb,

                             string propName, object val)

        {

            try

            {

                pb.Write(propName, ref val);

            }

            catch (System.Exception e)

            {

                throw new System.ApplicationException(e.Message);

            }

    &nb
sp;   }

        #endregion

 

      Now we can implement the

IPersistPropertyBag

    interface which only requires the following four methods:

  • GetClassID – Gets the class ID of the object to persist.
  • InitNew – Initializes a new class.
  • Load – Loads data from the persisted object into the new object.
  • Save – Saves the new object. Notice that the Save and Load methods persist the custom properties (path, IsActive) we created in the first post.

        #region IPersistPropertyBag members

        /// <summary>

        /// Gets class ID of component for usage from unmanaged code.

        /// </summary>

        /// <param name=”classid”>

        /// Class ID of the component

        /// </param>

        public void GetClassID(out System.Guid classid)

        {

            classid = new System.Guid(“f5f5337f-593f-4618-8e35-dff308dbb6f5″);

        }

        /// <summary>

        /// not implemented

        /// </summary>

        public void InitNew()

        {

        }

        /// <summary>

        /// Loads configuration properties for the component

        /// </summary>

        /// <param name=”pb”>Configuration property bag</param>

        /// <param name=”errlog”>Error status</param>

        public virtual void Load(

                     Microsoft.BizTalk.Component.Interop.IPropertyBag pb, int errlog)

        {

            object val = null;

            val = this.ReadPropertyBag(pb, “path”);

            if ((val != null))

            {

                this._path = ((string)(val));

            }

            val = this.ReadPropertyBag(pb, “IsActive”);

            if ((val != null))

            {

                this._IsActive = ((bool)(val));

            }

        }

        /// <summary>

        /// Saves the current component configuration into the property bag

        /// </summary>

        /// <param name=”pb”>Configuration property bag</param>

        /// <param name=”fClearDirty”>not used</param>

        /// <param name=”fSaveAllProperties”>not used</param>

        public virtual void Save(Microsoft.BizTalk.Component.Interop.IPropertyBag pb,

                                 bool fClearDirty, bool fSaveAllProperties)

        {

            this.WritePropertyBag(pb, “path”, this.path);

            this.WritePropertyBag(pb, “IsActive”, this.IsActive);

        }

        #endregion

      Note: the guid in this example should be replaced by your custom derived value (see the

first post

    of this series)

The last part of the interface we need to implement is the Microsoft.BizTalk.Component.Interop.IComponent interface. We just need to define one method – Execute – which is called by the pipeline to process the input message and get the resulting message. The method accepts the current pipeline context and the message to process, and it returns the modified (or not) message.

        #region IComponent members

        /// <summary>

        /// Implements IComponent.Execute method.

        /// </summary>

        /// <param name=”pc”>Pipeline context</param>

        /// <param name=”inmsg”>Input message</param>

        /// <returns>Original input message</returns>

        /// <remarks>

        /// IComponent.Execute method is used to initiate

        /// the processing of the message in this pipeline component.

        /// </remarks>

        public Microsoft.BizTalk.Message.Interop.IBaseMessage Execute(

                             Microsoft.BizTalk.Component.Interop.IPipelineContext pc,

                             Microsoft.BizTalk.Message.Interop.IBaseMessage inmsg)

        {

            //

            // TODO: implement component logic

            //

            // this way, it’s a passthrough pipeline component

            return inmsg;

        }

        #endregion

For now, we will not add the actual “archive” code – that comes in the next post. We will just return the same message passed in. The reader should be able to compile this class and generate a DLL.

Tags: BizTalk,

3 Comments. Leave new

[…] Just a quick one today.  I’ve been working on several BizTalk pipeline components lately, and had been using some code that’s been floating around here for a while – I’ve found them posted on other blogs/message boards as well, but the earliest posting I’ve found of it is from another Tallan blog post from 2006: http://blog.tallan.com/2006/11/22/custom-pipeline-components-part-2-archive-same-continued/. […]

Hi can you provide me the link for archive component part 3

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

\\\