<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Pearl Tech &#187; HassanW</title>
	<atom:link href="http://blog.pearltechnology.com/author/hassanw/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.pearltechnology.com</link>
	<description></description>
	<lastBuildDate>Fri, 17 Feb 2012 17:35:27 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Creating a custom pipeline component for Biztalk 2010 server (Part 1)</title>
		<link>http://blog.pearltechnology.com/creating-a-custom-pipeline-component-for-biztalk-2010-server-part-1/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed</link>
		<comments>http://blog.pearltechnology.com/creating-a-custom-pipeline-component-for-biztalk-2010-server-part-1/#comments</comments>
		<pubDate>Fri, 22 Apr 2011 13:34:35 +0000</pubDate>
		<dc:creator>HassanW</dc:creator>
				<category><![CDATA[Application Development]]></category>
		<category><![CDATA[Miscellaneous]]></category>

		<guid isPermaLink="false">http://blog.pearltechnology.com/?p=1190</guid>
		<description><![CDATA[This tutorial will show how to create a custom pipeline component for Biztalk server 2010. The pipeline component will be called "PeopleReader". The pipeline task is simple; it is going to consume an xml file on the receive port from a specified location, and then write a modified file to another location.The tutorial is going to cover all aspects of the custom pipeline coding, adding to orchestration, setting up ports, and debugging.]]></description>
			<content:encoded><![CDATA[<p><span style="color: black; font-size: 14pt; text-decoration: underline;"><strong>Custom Pipeline Component in C#:<br />
</strong></span></p>
<p><span style="color:black">Introduction<br />
</span></p>
<p><span style="color:black">This tutorial will show how to create a custom pipeline component for Biztalk server 2010. The pipeline component will be called &#8220;PeopleReader&#8221;. The pipeline task is simple; it is going to consume an xml file on the receive port from a specified location, and then write a modified file to another location.<br />
</span></p>
<p><span style="color:black">The xml content before passing through BizTalk:<br />
</span></p>
<p><span style="font-family:Courier New">&lt;?xml version=&#8221;1.0&#8243; encoding=&#8221;ISO-8859-1&#8243;?&gt;<br />
</span></p>
<p><span style="font-family:Courier New">&lt;People&gt;<br />
</span></p>
<p style="margin-left: 36pt"><span style="font-family:Courier New">&lt;FirstName&gt;Peter&lt;/FirstName&gt;<br />
</span></p>
<p style="margin-left: 36pt"><span style="font-family:Courier New">&lt;LastName&gt;Decosta&lt;/LastName&gt;<br />
</span></p>
<p><span style="font-family:Courier New">&lt;/People&gt;<br />
</span></p>
<p><span style="color:black; font-size:12pt">The final xml file after passing through Biztalk :<br />
</span></p>
<p><span style="font-family:Courier New">&lt;?xml version=&#8221;1.0&#8243; encoding=&#8221;ISO-8859-1&#8243;?&gt;<br />
</span></p>
<p><span style="font-family:Courier New">&lt;People&gt;<br />
</span></p>
<p style="margin-left: 36pt"><span style="font-family:Courier New">&lt;FirstName&gt;your_First_Name&lt;/FirstName&gt;<br />
</span></p>
<p style="margin-left: 36pt"><span style="font-family:Courier New">&lt;LastName&gt;your_Last_Name&lt;/LastName&gt;<br />
</span></p>
<p><span style="font-family:Courier New">&lt;/People&gt;<br />
</span></p>
<p><span style="color:black">The tutorial is going to cover all aspects of the custom pipeline coding, adding to orchestration, setting up ports, and debugging.<br />
</span></p>
<ol>
<li><span style="color:black">Creating C# project:<br />
</span></li>
</ol>
<p><span style="color:black">Open VS 2010 as administrator then go to &#8220;<strong>New Project</strong>&#8220;, then under Visual C# select Windows then class library, and name it People Reader (fig.1).<br />
</span></p>
<p><img src="http://blog.pearltechnology.com/wp-content/uploads/2011/04/042211_1324_Creatingacu11.png" alt="" /><span style="color:black; font-size:12pt"><br />
</span></p>
<p style="text-align: justify"><span style="color:black; font-size:12pt"><strong>Fig. 1</strong> creating the PeopleReader Class for the Custom Pipeline component<br />
</span></p>
<p style="text-align: justify">1.2 Adding references</p>
<p style="text-align: justify">The first step after the project is created is to add a reference to the BizTalk pipeline. In order to accomplish that, go to solution explorer; right click <strong>&#8220;references &#8220;</strong>then select <strong>&#8220;Add&#8221;</strong>.  On the Add Reference Dialog box select the <strong>&#8220;Browse&#8221;</strong> tab then go to your Biztalk server 2010  installation directory, in the case of this tutorial it&#8217;s <strong>&#8220;C:\Program Files (x86)\Microsoft BizTalk Server 2010&#8243;</strong> then select the reference <strong>&#8220;Microsoft.BizTalk.Pipeline.dll&#8221; </strong>then hit the &#8220;OK&#8221; button (fig2). Then right Click on <strong>&#8220;Class1.cs&#8221;</strong> then <strong>&#8220;rename&#8221;</strong>. Call the file &#8220;<strong>PeopleReader.cs&#8221;. </strong>Next Step is to add the namespaces necessary for this project and these are the following:</p>
<p><span style="font-family:Consolas; font-size:9pt"><span style="color:blue">using</span> System;<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"><span style="color:blue">using</span> System.Xml;<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"><span style="color:blue">using</span> System.IO;<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"><span style="color:blue">using</span> System.Collections;<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"><span style="color:blue">using</span> System.Text;<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"><span style="color:green">//Biztalk stuff</span><br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"><span style="color:blue">using</span> Microsoft.BizTalk.Message.Interop;<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"><span style="color:blue">using</span> Microsoft.BizTalk.Component.Interop;<br />
</span></p>
<p><img src="http://blog.pearltechnology.com/wp-content/uploads/2011/04/042211_1324_Creatingacu21.png" alt="" />Fig.2 Adding a reference to <strong>&#8220;Microsoft.BizTalk.Pipeline.dll&#8221;.<br />
</strong></p>
<p style="text-align: justify">In order to build a custom Pipeline class, our Peoplereader class need to inherit from four interfaces which are in no specific order: IComponent, IcomponentUI,IpersistPropertyBag and IbaseComponent.</p>
<p><span style="font-family:Consolas; font-size:9pt"><br />
<span style="color:blue">Public</span><br />
<span style="color:blue">class</span><br />
<span style="color:#2b91af">PeopleReader</span>: <span style="color:#2b91af">IbaseComponent</span><br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> ,<span style="color:#2b91af">IcomponentUI</span><br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> ,<span style="color:#2b91af">IpersistPropertyBag</span><br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> ,<span style="color:#2b91af">IcomponentUI</span><br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> {<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> }<br />
</span></p>
<p style="text-align: justify">Since this is a small project all the code can be in one file, however, in case the pipeline required heavy coding, I would recommend declaring the people reader class as partial, then separating the code to different files each inheriting from a different Interface, that will greatly facilitate readability, and scalability since multiple developer could be working on different parts of the Custom Pipeline.</p>
<p style="text-align: justify">Our next step is to declare that this class is going to a Pipeline component we do that by adding the following:[<span style="color:#2b91af">ComponentCategory</span>(<span style="color:#2b91af">CategoryTypes</span>.CATID_PipelineComponent)]  above the class declaration. Then we define where in the pipeline this component will go, by adding [<span style="color:#2b91af">ComponentCategory</span>(<span style="color:#2b91af">CategoryTypes</span>.CATID_Decoder)] which means that the component can only be added in the decoder stage of a receive pipeline. Last we need to create a &#8220;GUID&#8221; since it&#8217;s required for use in COM interop. To generate a new &#8220;GUID&#8221; go to the Tools Menu, then select the &#8220;Create GUID&#8221; Option, select GUID format 6 then hit copy (fig. 3). Paste the new GUID in [System.Runtime.InteropServices.<span style="color:#2b91af">Guid</span>(<span style="color:#a31515">"0D212B7D-F3E9-418B-92BA-9FBC36CF2948"</span>)] right above the class declaration.</p>
<p style="text-align: justify">
<p style="text-align: justify"><img src="http://blog.pearltechnology.com/wp-content/uploads/2011/04/042211_1324_Creatingacu31.png" alt="" /><span style="font-family:Consolas; font-size:9pt"><br />
</span></p>
<p>Fig.3 Creating a new GUID</p>
<ol>
<li>
<div style="text-align: justify">Defining public properties</div>
<p style="text-align: justify">
</li>
</ol>
<p style="text-align: justify">After adding the GUID, we declare two private member strings (m_FirstName, m_LastName) along with their (get, set) properties.  Those properties will allow the user to modify the content of &lt;FirstName&gt; and &lt;LastName&gt; Tags by exposing the properties to the pipeline designer at design time.</p>
<p style="text-align: justify">Your code should look like this at this point</p>
<p style="text-align: justify">
<p><span style="font-family:Consolas; font-size:9pt"> [<span style="color:#2b91af">ComponentCategory</span>(<span style="color:#2b91af">CategoryTypes</span>.CATID_PipelineComponent)]<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> [<span style="color:#2b91af">ComponentCategory</span>(<span style="color:#2b91af">CategoryTypes</span>.CATID_Decoder)]<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> [System.Runtime.InteropServices.<span style="color:#2b91af">Guid</span>(<span style="color:#a31515">"0D212B7D-F3E9-418B-92BA-9FBC36CF2948"</span>)]<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"><br />
<span style="color:blue">public</span><br />
<span style="color:blue">partial</span><br />
<span style="color:blue">class</span><br />
<span style="color:#2b91af">PeopleReader</span>: <span style="color:#2b91af">IBaseComponent</span><br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> ,<span style="color:#2b91af">IcomponentUI</span><br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> ,<span style="color:#2b91af">IpersistPropertyBag</span><br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> ,<span style="color:#2b91af">IcomponentUI</span><br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> {<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"><br />
<span style="color:blue">private</span><br />
<span style="color:blue">string</span> m_FirstName;<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"><br />
<span style="color:blue">private</span><br />
<span style="color:blue">string</span> m_LastName;<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"><br />
<span style="color:blue">public</span><br />
<span style="color:blue">string</span> FirstName<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> {<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"><br />
<span style="color:blue">get</span><br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> {<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"><br />
<span style="color:blue">return</span> m_FirstName;<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> }<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"><br />
<span style="color:blue">set</span><br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> {<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> m_FirstName = <span style="color:blue">value</span>;<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> }<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> }<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"><br />
<span style="color:blue">public</span><br />
<span style="color:blue">string</span> LastName<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> {<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"><br />
<span style="color:blue">get</span><br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> {<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"><br />
<span style="color:blue">return</span> m_LastName;<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> }<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"><br />
<span style="color:blue">set</span><br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> {<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> m_LastName = <span style="color:blue">value</span>;<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> }<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> }<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> }<br />
</span></p>
<p>1.4 Defining the IBaseComponent Members</p>
<p style="text-align: justify">Next we will define the IBaseComponent members. For ease of readability we create a new region then define the properties Description, Name, and version which represent the description for the Pipeline component we are creating, the Name as it will be seen in the BizTalk project and the version number.</p>
<p><span style="font-family:Consolas; font-size:9pt"><span style="color:blue"> #region</span> IBaseComponent members<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"><br />
<span style="color:blue">public</span><br />
<span style="color:blue">string</span> Description<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> {<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"><br />
<span style="color:blue">get</span><br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> {<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"><br />
<span style="color:blue">return</span><br />
<span style="color:#a31515">&#8220;Pipeline component to Read XML with Peoples Name&#8221;</span>;<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> }<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> }<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"><br />
<span style="color:blue">public</span><br />
<span style="color:blue">string</span> Name<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> {<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"><br />
<span style="color:blue">get</span><br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> {<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"><br />
<span style="color:blue">return</span><br />
<span style="color:#a31515">&#8220;PeopleReader Test Pipeline&#8221;</span>;<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> }<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> }<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"><br />
<span style="color:blue">public</span><br />
<span style="color:blue">string</span> Version<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> {<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"><br />
<span style="color:blue">get</span><br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> {<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"><br />
<span style="color:blue">return</span><br />
<span style="color:#a31515">&#8220;1.0.0.0&#8243;</span>;<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> }<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> }<br />
</span></p>
<p><span style="color:blue; font-family:Consolas; font-size:9pt"> #endregion<br />
</span></p>
<ol>
<li>Defining the IComponentUI Members</li>
</ol>
<p style="text-align: justify">Next up is the IcomponentUI interface members, which contains the icon that will show up in Biztalk toolbox for pipeline and a validate method. We are going to define the icon to be the default system icon, and as far as validation we are not going to add any validation at this stage.</p>
<p><span style="font-family:Consolas; font-size:9pt"><span style="color:blue">#region</span> IcomponentUI members<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"><br />
<span style="color:blue">public</span><br />
<span style="color:#2b91af">IntPtr</span> Icon<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> {<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"><br />
<span style="color:blue">get</span><br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> {<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"><br />
<span style="color:blue">return</span><br />
<span style="color:blue">new</span> System.<span style="color:#2b91af">IntPtr</span>();<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> }<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> }<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"><br />
<span style="color:blue">public</span><br />
<span style="color:#2b91af">Ienumerator</span> Validate(<span style="color:blue">object</span> projectSystem)<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> {<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"><br />
<span style="color:blue">return</span><br />
<span style="color:blue">null</span>;<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> }<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"><span style="color:blue"> #endregion</span><br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> }<br />
</span></p>
<p>1.6 Defining the IPersistPropertyBag Members</p>
<p>IPersistPropertyBag Has 4 methods: GetClassID, InitNew, Load and Save</p>
<p>GetClassID: return a unique ID (the GUID we defined earlier) that represents the component</p>
<p>InitNew: used to establish structures (data, caching..) used by other IPersistPropertyBag methods, we are going to leave it blank for this tutorial</p>
<p>Load: used to load the properties values (in this case the value the user enters at design time)</p>
<p>Save: same as load but used to save the values.</p>
<p>In the code below I used two helper functions ReadPropertyBag and WritePropertyBag that are called from within the Load and Save methods.</p>
<p><span style="font-family:Consolas; font-size:9pt"><span style="color:blue"> #region</span> IPersistPropertyBag members<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"><br />
<span style="color:blue">public</span><br />
<span style="color:blue">void</span> GetClassID(<span style="color:blue">out</span><br />
<span style="color:#2b91af">Guid</span> classID)<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> {<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> classID = <span style="color:blue">new</span><br />
<span style="color:#2b91af">Guid</span>(<span style="color:#a31515">&#8220;0D212B7D-F3E9-418B-92BA-9FBC36CF2948&#8243;</span>);<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> }<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"><br />
<span style="color:blue">public</span><br />
<span style="color:blue">void</span> InitNew()<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> {<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> }<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"><br />
<span style="color:blue">public</span><br />
<span style="color:blue">void</span> Load(<span style="color:#2b91af">IPropertyBag</span> propertyBag, <span style="color:#2b91af">Int32</span> errorLog)<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> {<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"><br />
<span style="color:blue">string</span> val = (<span style="color:blue">string</span>)ReadPropertyBag(propertyBag, <span style="color:#a31515">&#8220;FirstName&#8221;</span>);<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"><br />
<span style="color:blue">if</span> (val != <span style="color:blue">null</span>)<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> m_FirstName = val;<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"><br />
<span style="color:blue">else</span><br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> m_FirstName = <span style="color:#a31515">&#8220;N/A&#8221;</span>;<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> val = (<span style="color:blue">string</span>)ReadPropertyBag(propertyBag, <span style="color:#a31515">&#8220;LastName&#8221;</span>);<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"><br />
<span style="color:blue">if</span> (val != <span style="color:blue">null</span>)<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> m_LastName = val;<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"><br />
<span style="color:blue">else</span><br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> m_LastName = <span style="color:#a31515">&#8220;N/A&#8221;</span>;<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> }<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"><br />
<span style="color:blue">public</span><br />
<span style="color:blue">void</span> Save(<span style="color:#2b91af">IPropertyBag</span> propertyBag, <span style="color:blue">bool</span> clearDirty, <span style="color:blue">bool</span> saveAllProperties)<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> {<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"><br />
<span style="color:blue">object</span> val = (<span style="color:blue">object</span>)m_FirstName;<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> WritePropertyBag(propertyBag,<span style="color:#a31515">&#8220;FirstName&#8221;</span>,val);<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> val=(<span style="color:blue">object</span>)m_LastName;<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> WritePropertyBag(propertyBag,<span style="color:#a31515">&#8220;LastName&#8221;</span>,val);<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> }<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"><br />
<span style="color:blue">private</span><br />
<span style="color:blue">static</span><br />
<span style="color:blue">object</span> ReadPropertyBag(<span style="color:#2b91af">IPropertyBag</span> propertyBag, <span style="color:blue">string</span> propertyName)<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> {<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"><br />
<span style="color:blue">object</span> val = <span style="color:blue">null</span>;<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"><br />
<span style="color:blue">try</span><br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> {<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> propertyBag.Read(propertyName, <span style="color:blue">out</span> val, 0);<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> }<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"><br />
<span style="color:blue">catch</span> (<span style="color:#2b91af">ArgumentException</span>)<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> {<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"><br />
<span style="color:blue">return</span> val;<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> }<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"><br />
<span style="color:blue">catch</span> (<span style="color:#2b91af">Exception</span> ex)<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> {<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"><br />
<span style="color:blue">throw</span><br />
<span style="color:blue">new</span><br />
<span style="color:#2b91af">ApplicationException</span>(<span style="color:#a31515">&#8220;Error reading propertybag: &#8220;</span> + ex.Message);<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> }<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"><br />
<span style="color:blue">return</span> val;<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> }<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"><span style="color:blue">private</span><br />
<span style="color:blue">static</span><br />
<span style="color:blue">void</span> WritePropertyBag(<span style="color:#2b91af">IPropertyBag</span> propertyBag, <span style="color:blue">string</span> propertyName, <span style="color:blue">object</span> val)<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> {<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"><br />
<span style="color:blue">try</span><br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> {<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> propertyBag.Write(propertyName, <span style="color:blue">ref</span> val);<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> }<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"><br />
<span style="color:blue">catch</span> (<span style="color:#2b91af">Exception</span> ex)<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> {<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"><br />
<span style="color:blue">throw</span><br />
<span style="color:blue">new</span><br />
<span style="color:#2b91af">ApplicationException</span>(<span style="color:#a31515">&#8220;Error Writing propertybag: &#8220;</span> + ex.Message);<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> }<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> }<br />
</span></p>
<p><span style="color:blue; font-family:Consolas; font-size:9pt"> #endregion<br />
</span></p>
<p style="text-align: justify">1.7 Defining IComponent Members</p>
<p style="text-align: justify">Finally the most important Interface of the custom pipeline Icomponent which has one method Execute. BizTalk calls the execute method to process the message, and then passes the context of the message and the message.</p>
<p><span style="font-family:Consolas; font-size:9pt"><span style="color:blue">#region</span> Icomponent members<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"><br />
<span style="color:blue">public</span><br />
<span style="color:#2b91af">IbaseMessage</span> Execute(<span style="color:#2b91af">IpipelineContext</span> pContext, <span style="color:#2b91af">IbaseMessage</span> pInMsg)<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> {<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"><br />
<span style="color:#2b91af">IbaseMessagePart</span> bodyPart = pInMsg.BodyPart;<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"><br />
<span style="color:#2b91af">StringBuilder</span> outputMessageText = <span style="color:blue">null</span>;<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"><br />
<span style="color:blue">if</span> (bodyPart != <span style="color:blue">null</span>)<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> {<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"><br />
<span style="color:#2b91af">Stream</span> originalStream = bodyPart.GetOriginalDataStream();<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"><br />
<span style="color:blue">if</span> (originalStream != <span style="color:blue">null</span>)<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> {<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"><br />
<span style="color:#2b91af">XmlDocument</span> xdoc = <span style="color:blue">new</span><br />
<span style="color:#2b91af">XmlDocument</span>();<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> xdoc.Load(originalStream);<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"><br />
<span style="color:#2b91af">XmlElement</span> root = xdoc.DocumentElement;<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"><br />
<span style="color:#2b91af">XmlNodeList</span> firstName = xdoc.GetElementsByTagName(<span style="color:#a31515">&#8220;FirstName&#8221;</span>);<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"><br />
<span style="color:#2b91af">XmlNodeList</span> lastName = xdoc.GetElementsByTagName(<span style="color:#a31515">&#8220;LastName&#8221;</span>);<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> outputMessageText = <span style="color:blue">new</span><br />
<span style="color:#2b91af">StringBuilder</span>();<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> outputMessageText.Append(<span style="color:#a31515">&#8220;&lt;?xml version=\&#8221;1.0\&#8221;<br />
</span></span></p>
<p style="margin-left: 72pt"><span style="font-family:Consolas; font-size:9pt"><span style="color:#a31515">encoding=\&#8221;ISO-8859-1\&#8221;?&gt;&#8221;</span>);<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> outputMessageText.Append(<span style="color:#a31515">&#8220;&lt;&#8221;</span> + root.Name + <span style="color:#a31515">&#8220;&gt;&#8221;</span>);<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> outputMessageText.Append(<span style="color:#a31515">&#8220;&lt;&#8221;</span> + firstName[0].Name + <span style="color:#a31515">&#8220;&gt;&#8221;</span><br />
</span></p>
<p style="margin-left: 72pt"><span style="font-family:Consolas; font-size:9pt"> + <span style="color:blue">this</span>.m_FirstName + <span style="color:#a31515">&#8220;&lt;/&#8221;</span> + firstName[0].Name + <span style="color:#a31515">&#8220;&gt;&#8221;</span>);<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> outputMessageText.Append(<span style="color:#a31515">&#8220;&lt;&#8221;</span> + lastName[0].Name + <span style="color:#a31515">&#8220;&gt;&#8221;</span><br />
</span></p>
<p style="margin-left: 36pt"><span style="font-family:Consolas; font-size:9pt"> + <span style="color:blue">this</span>.m_LastName  + <span style="color:#a31515">&#8220;&lt;/&#8221;</span> + lastName[0].Name + <span style="color:#a31515">&#8220;&gt;&#8221;</span>);<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> outputMessageText.Append(<span style="color:#a31515">&#8220;&lt;/&#8221;</span> + root.Name + <span style="color:#a31515">&#8220;&gt;&#8221;</span>);<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"><br />
<span style="color:blue">byte</span>[] outBytes =<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> System.Text.<span style="color:#2b91af">Encoding</span>.ASCII.GetBytes(outputMessageText.ToString());<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"><br />
<span style="color:#2b91af">MemoryStream</span> memStream = <span style="color:blue">new</span><br />
<span style="color:#2b91af">MemoryStream</span>();<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> memStream.Write(outBytes, 0, outBytes.Length);<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> memStream.Position = 0;<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> bodyPart.Data = memStream;<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> pContext.ResourceTracker.AddResource(memStream);<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> }<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> }<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"><br />
<span style="color:blue">return</span> pInMsg;<br />
</span></p>
<p><span style="font-family:Consolas; font-size:9pt"> }<br />
</span></p>
<p><span style="color:blue; font-family:Consolas; font-size:9pt"> #endregion<br />
</span></p>
<p style="text-align: justify">
<p style="text-align: justify">1.8 Compilation and strong key creation for Assembly</p>
<p style="text-align: justify">Finally we can compile the code and check that the solution build succeeded. Next step though is to assign a key to the assembly.</p>
<p style="text-align: justify">Start the &#8220;Visual Studio&#8221; command prompt (fig 1.4). Make sure it&#8217;s not the windows command prompt!!!</p>
<p style="text-align: justify"><img src="http://blog.pearltechnology.com/wp-content/uploads/2011/04/042211_1324_Creatingacu41.png" alt="" /><span style="font-size:12pt"><br />
</span></p>
<p style="text-align: justify">Fig.1.4 starting the VS command Prompt</p>
<p style="text-align: justify">Go to the directory where your solution is, to do that type CD\ + whatever_your_directory_is  in our case it&#8217;s CD\ Users\yourusername\Documents\Visual Studio 2010\Projects then hit enter. For the simplicity I am going to create a key under C:\temp (fig. 5)</p>
<p style="text-align: justify"><img src="http://blog.pearltechnology.com/wp-content/uploads/2011/04/042211_1324_Creatingacu51.png" alt="" /><span style="font-size:12pt"><br />
</span></p>
<p style="text-align: justify">Fig. 5 creating a strong key</p>
<p style="text-align: justify">After the key is created go to solution explorer, then right click on your project and select properties. Select the signing tab then check the &#8220;sign assembly&#8221; check box, and from the drop down menu select browse, then navigate to where you create your strong key (fig. 6).</p>
<p style="text-align: justify"><img src="http://blog.pearltechnology.com/wp-content/uploads/2011/04/042211_1324_Creatingacu61.png" alt="" /><span style="font-size:12pt"><br />
</span></p>
<p style="text-align: justify">Fig. 6 attaching the strong key to the assembly</p>
<p style="text-align: justify">
<p style="text-align: justify">Then compile again!</p>
<p style="text-align: justify"><span style="font-size:12pt"><br />
</span></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.pearltechnology.com/creating-a-custom-pipeline-component-for-biztalk-2010-server-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

