<?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; Application Development</title>
	<atom:link href="http://blog.pearltechnology.com/category/application-development/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.pearltechnology.com</link>
	<description></description>
	<lastBuildDate>Thu, 05 Jan 2012 14:47:55 +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>JQGrid and Jquery &#8211; Move toolbar below pager</title>
		<link>http://blog.pearltechnology.com/jqgrid-and-jquery-move-toolbar-below-pager/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed</link>
		<comments>http://blog.pearltechnology.com/jqgrid-and-jquery-move-toolbar-below-pager/#comments</comments>
		<pubDate>Thu, 05 Jan 2012 14:47:55 +0000</pubDate>
		<dc:creator>Chad Ferguson</dc:creator>
				<category><![CDATA[Application Development]]></category>
		<category><![CDATA[JQGrid]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://blog.pearltechnology.com/?p=1288</guid>
		<description><![CDATA[For a current client it was requested that I move the JQGrid toolbar below the pager if a pager exists. The Toolbar is a nice feature of the JQGrid which can be used for pratically anything. Unfortunately the way the toolbar is set up can be hard to work with. The toolbar can be set [...]]]></description>
			<content:encoded><![CDATA[<p>For a current client it was requested that I move the JQGrid toolbar below the pager if a pager exists. The Toolbar is a nice feature of the JQGrid which can be used for pratically anything. Unfortunately the way the toolbar is set up can be hard to work with. The toolbar can be set into one of 3 positions: Above the header row (Top), below the footer row (Bottom), and both (Both). When the either the top or bottom option is selected a toolbar with id t_<your gridid> is created. If the Both option is selected the Top toolbar will have an id of t_<your gridid> and the bottom will have an id of tb_<your gridid>. This complicates things since I only want to move the bottom toolbar. Thankefully Jquery has a method, <a href="http://api.jquery.com/last/">Last</a>, that will solve the problem. Last does what we need which is grab the last child of a selector. The grid&#8217;s sections are divided up into divs under a parent div with the id of gview_<your gridid>. If a bottom toolbar exists, it will always be the last div under that parent. So first we check if a pager exists, then get the last child of the gview div, and if that child has a class of ui-userdata, which indicates that it is a toolbar, we can detach it and insert it after the pager as seen below.</p>
<p><code><br />
function moveLowerJQGridToolbar(gridid) {<br />
    var pager = $('#' + gridid + '_pager');<br />
    if ($(pager).exists()) {<br />
        var lastChild = $('#gview_' + gridid).children().last();<br />
        if (lastChild.hasClass('ui-userdata')) {<br />
            var toolbar = $(lastChild).detach();<br />
            $(toolbar).insertAfter(pager);<br />
        }<br />
    }<br />
}</code></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.pearltechnology.com/jqgrid-and-jquery-move-toolbar-below-pager/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>XNA Tutorial Series 1: Golf (Patience) Solitaire Part II – Deck Class</title>
		<link>http://blog.pearltechnology.com/xna-tutorial-series-1-golf-patience-solitaire-part-ii-%e2%80%93-deck-class/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed</link>
		<comments>http://blog.pearltechnology.com/xna-tutorial-series-1-golf-patience-solitaire-part-ii-%e2%80%93-deck-class/#comments</comments>
		<pubDate>Mon, 19 Dec 2011 19:46:32 +0000</pubDate>
		<dc:creator>Chad Ferguson</dc:creator>
				<category><![CDATA[Application Development]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Game Programming]]></category>
		<category><![CDATA[XNA; Solitaire]]></category>

		<guid isPermaLink="false">http://blog.pearltechnology.com/?p=1283</guid>
		<description><![CDATA[Golf Solitaire as described by wikipedia:
Golf is a Patience game where players try to earn the lowest number of points (as in golf, the sport) over the course of nine deals (or &#8220;holes&#8221; to further use golfing teminology). It has a tableau of 35 face-up cards and a higher ratio of skill to luck than [...]]]></description>
			<content:encoded><![CDATA[<p>Golf Solitaire as described by wikipedia:</p>
<p>Golf is a Patience game where players try to earn the lowest number of points (as in golf, the sport) over the course of nine deals (or &#8220;holes&#8221; to further use golfing teminology). It has a tableau of 35 face-up cards and a higher ratio of skill to luck than most other solitaire card games.</p>
<p>My attempts in this tutorial series will be able to keep the code reusable and hopefully build onto this series with other Card/Solitaire games. </p>
<p><strong>XNA Tutorial Series 1: Golf (Patience) Solitaire Part III &#8211; Deck Class</strong><br />
For this tutorial we will focus on the class that will handle the logic for a group of cards. Start by right clicking on your classes folder and adding a new class called Deck.cs. The first thing we will need to do is setup are using&#8217;s as follows:<br />
<code><br />
        using System;<br />
        using System.Collections.Generic;<br />
        using System.Linq;<br />
        using Microsoft.Xna.Framework;<br />
        using Microsoft.Xna.Framework.Content;<br />
        using Microsoft.Xna.Framework.Graphics;<br />
        using Microsoft.Xna.Framework.Input;<br />
</code></p>
<p>Next set your class to be public.</p>
<p>Now we can begin by adding a Enum to our class to represent a deck type:<br />
<code><br />
        public enum DeckType<br />
        {<br />
            User = 1,<br />
            Source,<br />
            Waste,<br />
            Target<br />
        };<br />
</code></p>
<p>Now we can setup the individual properties that a Card will have, I will show the code first and then proceed to explain what each property is for:<br />
<code><br />
        protected List cards = new List();<br />
        protected Point pos;<br />
        protected int deckID;<br />
        protected DeckType deckType;<br />
        Texture2D background;</p>
<p>        public virtual Point Position<br />
        {<br />
            get<br />
            {<br />
                return pos;<br />
            }<br />
            set<br />
            {<br />
                pos = value;<br />
            }<br />
        }</p>
<p>        public DeckType Type<br />
        {<br />
            get<br />
            {<br />
                return deckType;<br />
            }<br />
        }<br />
</code><br />
cards will be a list of the cards in the deck, pos is a point that is used for offsetting a card image so you can have one card on top of another and see the values for both. deckID is an ID for keeping track of the decks. DeckType to indicate the enum for which type of deck it is, and a texture to store the decks background.</p>
<p>Next we have our constructors:<br />
<code><br />
        public Deck()<br />
        {<br />
            deckType = DeckType.User;<br />
        }</p>
<p>        public Deck(int id)<br />
        {<br />
            deckID = id;<br />
            deckType = DeckType.User;<br />
        }<br />
</code></p>
<p>Since this deck class is going to be a base type it will default to being a user deck, other deck types (waste, source, etc..) will implement the desk class. Next we will need some basic methods for maintaining the list of cards that are in the deck.</p>
<p>First we will need to be able to retrieve the number of cards in the deck:<br />
<code><br />
        public virtual int CardCount()<br />
        {<br />
            return cards.Count();<br />
        }</p>
<p>Get the last card(top) of the deck<br />
        public virtual Card GetLast()<br />
        {<br />
            return cards.Last();<br />
        }</p>
<p>Remove the last card<br />
        public virtual Card RemoveLast()<br />
        {<br />
            Card card = cards.Last();<br />
            cards.Remove(card);<br />
            return card;<br />
        }</p>
<p>And finally get a card<br />
        public virtual Card GetCard(int index)<br />
        {<br />
            return cards[index];<br />
        }<br />
</code></p>
<p>In the second part of the deck class we will look at Adding cards, handling input, and drawing the cards.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.pearltechnology.com/xna-tutorial-series-1-golf-patience-solitaire-part-ii-%e2%80%93-deck-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>XNA Tutorial Series 1: Golf (Patience) Solitaire Part I &#8211; Card Class</title>
		<link>http://blog.pearltechnology.com/xna-tutorial-series-1-golf-patience-solitaire-part-i-card-class/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed</link>
		<comments>http://blog.pearltechnology.com/xna-tutorial-series-1-golf-patience-solitaire-part-i-card-class/#comments</comments>
		<pubDate>Tue, 22 Nov 2011 13:24:26 +0000</pubDate>
		<dc:creator>Chad Ferguson</dc:creator>
				<category><![CDATA[Application Development]]></category>

		<guid isPermaLink="false">http://blog.pearltechnology.com/?p=1237</guid>
		<description><![CDATA[Golf Solitaire as described by wikipedia:
Golf is a Patience game where players try to earn the lowest number of points (as in golf, the sport) over the course of nine deals (or &#8220;holes&#8221; to further use golfing teminology). It has a tableau of 35 face-up cards and a higher ratio of skill to luck than [...]]]></description>
			<content:encoded><![CDATA[<p><em>Golf Solitaire as described by wikipedia:<br />
Golf is a Patience game where players try to earn the lowest number of points (as in golf, the sport) over the course of nine deals (or &#8220;holes&#8221; to further use golfing teminology). It has a tableau of 35 face-up cards and a higher ratio of skill to luck than most other solitaire card games.</em></p>
<p>My attempts in this tutorial series will be able to keep the code reusable and hopefully build onto this series with other Card/Solitaire games. Also this tutorial assumes that you have basic XNA knowledge. </p>
<p><u><strong>XNA Tutorial Series 1: Golf (Patience) Solitaire Part I &#8211; Project Setup</strong></u></p>
<p>Start by creating a new XNA 4.0 Windows game project. In my sample I named the project &#8220;Patience&#8221; but you are free to name it whatever you like. Then in the main project right click the project and add a new folder called classes. This will be where we define our game logic.</p>
<p><img src="http://blog.pearltechnology.com/wp-content/uploads/2011/07/project.JPG" alt="project" title="project" width="212" height="305" class="aligncenter size-full wp-image-1240" /></p>
<p>Also in your Content Project right click and add  &#8220;Cards&#8221; and &#8220;Fonts&#8221; Directories. Where the actual game art will be stored. Right now that gives us the basis for starting our game. In the next tutorial we will focus on creating the Card class.</p>
<p>For this tutorial we will focus on the class that will handle the logic for one individual card. Start by right clicking on your classes folder and adding a new class called Card.cs. The first thing we will need to do is setup are using&#8217;s as follows:<br />
<code><br />
using System;<br />
using Microsoft.Xna.Framework;<br />
using Microsoft.Xna.Framework.Content;<br />
using Microsoft.Xna.Framework.Graphics;<br />
using Microsoft.Xna.Framework.Input;<br />
</code></p>
<p>Next set your class to be public.</p>
<p>Now we can begin by adding some Enums to our class. The first enum will deal with the suit of the cards:<br />
<code><br />
public enum CardSuit<br />
{<br />
             Clubs = 1,<br />
             Diamonds,<br />
             Hearts,<br />
             Spades<br />
}<br />
</code><br />
The next enum will be for the value of the cards:<br />
<code><br />
 public enum CardValue<br />
        {<br />
             Ace = 1,<br />
             Two,<br />
             Three,<br />
             Four,<br />
             Five,<br />
             Six,<br />
             Seven,<br />
             Eight,<br />
             Nine,<br />
             Ten,<br />
             Jack,<br />
             Queen,<br />
             King<br />
        }<br />
</code><br />
The final enum will be for indicating what color the card is:<br />
<code><br />
public enum CardColor<br />
        {<br />
             Black = 1,<br />
             Red<br />
        }<br />
</code></p>
<p>Now we can setup the individual properties that a Card will have, I will show the code first and then proceed to explain what each property is for:<br />
<code></p>
<p>public CardSuit Suit { get; set; }<br />
        public CardValue Value { get; set; }<br />
        public CardColor TheColor { get; set; }<br />
        public Boolean IsTurned { get; set; }<br />
        public Card ParentCard { get; set; }<br />
        public Card ChildCard { get; set; }<br />
        public int ZOrder { get; set; }<br />
        public String CardName { get; set; }<br />
        public Deck OwnerDeck { get; set; }<br />
        public Rectangle OriginRect { get; set; }<br />
        public static int CARD_WIDTH = 80;<br />
        public static int CARD_HEIGHT = 110;<br />
        Texture2D card = null;<br />
        Texture2D cardBack = null;<br />
        Rectangle rect;</p>
<p>        public Rectangle CardRectangle<br />
        {<br />
            get<br />
            {<br />
                return rect;<br />
            }<br />
            set<br />
            {<br />
                rect = value;<br />
            }<br />
        }<br />
</code></p>
<p>The first three will be used to set the enums(Suit, value, and color) for the specific card. IsTurned will be used to determine if the front or the back of the card should be drawn. ParentCard and ChildCard will be used for indicating what card is above and below the card on the screen. ZOrder is similar to the css property z-index and will be used for card drag and drop. Though this game does not have drag and drop capability we are adding the ZOrder property for future use. CardName will be a string that will indicate which artwork to use, it will be made up of concatenating the cards suit with a &#8220;-&#8221; and the cards value. If you choose to use cards other than the ones I provide, please be sure they follow this naming convention. OwnerDeck will refer to which deck the card is currently in (draw pile, plateau, waste, etc&#8230;) this refers to a class that we will develop in part 3 of this series. Teh we have the OriginRect this is a placeholder value so that we always know where the card came from, in case we ever need to return it to that spot. Then we have two static variables for storing the size of the card. Next we have two XNA textures that will store the card image and the back of the card image. Finally we have the rectangle where those card images will be drawn.</p>
<p>Next up is the constructor followed by a description:<br />
<code><br />
public Card(CardSuit suit, CardValue value, int z, ContentManager contentManager)<br />
        {<br />
            ZOrder = z;<br />
            ParentCard = null;<br />
            ChildCard = null;<br />
            OwnerDeck = null;</p>
<p>            LoadCard(suit, value, contentManager);<br />
        }<br />
</code></p>
<p>Since we are just declaring the card and not yet putting it in a deck we will be setting several of the properties to null, and then lastly we call another method to load the cards content based on the suit and value that we passed in.</p>
<p>The cards Load method is detailed next:<br />
<code><br />
 public void LoadCard(CardSuit suit, CardValue value, ContentManager contentManager)<br />
        {<br />
            if (suit == CardSuit.Clubs || suit == CardSuit.Spades)<br />
                TheColor = CardColor.Black;<br />
            else<br />
                TheColor = CardColor.Red;</p>
<p>            Suit = suit;<br />
            Value = value;</p>
<p>            //Set default pos and size<br />
            CardRectangle = new Rectangle(0, 0, CARD_WIDTH, CARD_HEIGHT);</p>
<p>            // Card background<br />
            cardBack = contentManager.Load("Cards/card_background");</p>
<p>            CardName = suit.ToString() + "_" + value.ToString();</p>
<p>            card = contentManager.Load("Cards/" + CardName);<br />
        }<br />
</code></p>
<p>Based on the suit we first determine the cards color, Clubs/Spades are black and Hearts/Diamonds are red. We set the cards suit and value from the passed in parameters and then we create the rectangle that will hold the card texture. Next we load the cards background picture into its texture, and then after determine the cards name we load the card image into its texture.</p>
<p>Finally we have the method that will draw the card to the screen:<br />
<code><br />
public void Draw(SpriteBatch theSpriteBatch)<br />
        {<br />
            if (IsTurned)<br />
            {<br />
                if (card != null)<br />
                    theSpriteBatch.Draw(card, CardRectangle, Color.White);<br />
            }<br />
            else<br />
            {<br />
                if (cardBack != null)<br />
                    theSpriteBatch.Draw(cardBack, CardRectangle, Color.White);<br />
            }<br />
        }<br />
</code><br />
Here we are determining if the card is face up or face down and drawing that particular image to the screen.</p>
<p>That is it right now for our card class. In the future it will be expanded more to handle different input types like drag and drop but for now clicking on the card is all that is necessary.  Also not the reason the card has no coordinates is because it&#8217;s draw location will be based on the location of it&#8217;s stack/deck. Stay tuned for the next part in the series where we will make a deck class.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.pearltechnology.com/xna-tutorial-series-1-golf-patience-solitaire-part-i-card-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Lessons Learned: XSS Security Scan</title>
		<link>http://blog.pearltechnology.com/lessons-learned-xss-security-scan/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed</link>
		<comments>http://blog.pearltechnology.com/lessons-learned-xss-security-scan/#comments</comments>
		<pubDate>Mon, 25 Apr 2011 18:25:53 +0000</pubDate>
		<dc:creator>Geer</dc:creator>
				<category><![CDATA[Application Development]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Security Scan]]></category>
		<category><![CDATA[XSS]]></category>

		<guid isPermaLink="false">http://blog.pearltechnology.com/?p=1212</guid>
		<description><![CDATA[Lessons learned during cross-site scripting security scan...]]></description>
			<content:encoded><![CDATA[<p>During the code review process for an ASP.NET web application that we built for a client, a cross-site scripting (XSS) security scanner was used to check whether the application was secure enough to survive during XSS attacks.  Fortunately, the application was well designed and coded leaving no chance for the scanner to inject even a single line of script for XSS attack.  Alright, I will be honest with you &#8211; we did found a couple issues during the scan, but we were able to fix them before the application was delivered to our customer.  So, here are the two notes I would like to share:</p>
<ol>
<li><strong>Watch out for those non-ASP.NET components</strong>.  Actually, all ASP.NET components were designed very well and the scanner was not able to inject any script on any page.  The only problem we found was on the error page which accepts some parameters in the query string and displays part of the information on the error page which is a fairly common implementation.  Because it is simply an HTML page and does not contain server-side code, it was overlooked for XSS attack.  The scanner was able to embed scripts in the query string, and had them executed when the error page tried to render them on the page.  Although the error page cannot post any data back to the ASP.NET application itself or insert any data to the database, it is still a security risk.  You never know what hackers can do with this small hole in your site.</li>
<li><strong>DO NOT perform the scan on production database</strong>.  We performed the scan on our QA environment assuming it would not do any harm to our database because it was only for XSS scan.  However, we have found that it entered thousands of records in a table in our database through a page which only requires one field for data entering.  As a result, the scanner tried all possible injection scripts on that page, and entered them all into the table in the database.  Now, we have a list of scripts we can try on other sites to have some fun. : )  So, I guess we shouldn&#8217;t have done this in the QA environment which points to our production database.  Even if we had to do so for whatever reason, we probably should have pointed the application to a test database for the duration of the scan.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://blog.pearltechnology.com/lessons-learned-xss-security-scan/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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>
		<item>
		<title>Getting out of a bind &#8212; with bindings</title>
		<link>http://blog.pearltechnology.com/getting-out-of-a-bind-with-bindings/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed</link>
		<comments>http://blog.pearltechnology.com/getting-out-of-a-bind-with-bindings/#comments</comments>
		<pubDate>Tue, 12 Apr 2011 12:12:52 +0000</pubDate>
		<dc:creator>RobB</dc:creator>
				<category><![CDATA[Application Development]]></category>
		<category><![CDATA[Miscellaneous]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Bindings]]></category>
		<category><![CDATA[Converters]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[XAML]]></category>

		<guid isPermaLink="false">http://blog.pearltechnology.com/?p=1152</guid>
		<description><![CDATA[Converters in WPF are quite possibly the most useful tool that I&#8217;ve used in the relatively short time I&#8217;ve spent developing WPF applications.  They give the ability to format data, style controls, and more, based on the value supplied from a binding.  And it doesn&#8217;t even have to be a binding to a data source.  [...]]]></description>
			<content:encoded><![CDATA[<p>Converters in WPF are quite possibly the most useful tool that I&#8217;ve used in the relatively short time I&#8217;ve spent developing WPF applications.  They give the ability to format data, style controls, and more, based on the value supplied from a binding.  And it doesn&#8217;t even have to be a binding to a data source.  You can bind to a property of another control on the page.  Lets take a look at a couple of examples.</p>
<p><span style="text-decoration: underline;">Setting a property based on a data value:</span></p>
<p>In this example, we have a label on a form that will display a dollar amount from our data source.  If the dollar amount is negative we want the label&#8217;s background to be red, and green if the value is positive.  To do this, we simply create a converter class in our code behind page.  This will use the numeric value and return a Brush object which we will use in our label&#8217;s Background property.  Here&#8217;s the code for the converter:</p>
<p style="text-align: center;"><img class="size-large wp-image-1153 aligncenter" title="cellbackgroundconverter" src="http://blog.pearltechnology.com/wp-content/uploads/2011/04/cellbackgroundconverter-1024x312.jpg" alt="cellbackgroundconverter" width="1024" height="312" /></p>
<p>We then have to create a simple reference to our converter class in our ResourceDictionary in the Window.Resources section of our XAML:</p>
<p><img class="alignnone size-full wp-image-1154" title="converterdefinition" src="http://blog.pearltechnology.com/wp-content/uploads/2011/04/converterdefinition.JPG" alt="converterdefinition" width="397" height="30" /></p>
<p>So far so good.  Now all we have to do is bind the label&#8217;s background property to the converter and data value.  Notice that we have to bind both the label&#8217;s content (text) and background to the Amount value from our data context.  We also can set the ContentStringFormat property to automatically format the value as currency:</p>
<p style="text-align: center;"><img class="size-full wp-image-1155 aligncenter" title="labelwithconverterbinding" src="http://blog.pearltechnology.com/wp-content/uploads/2011/04/labelwithconverterbinding.JPG" alt="labelwithconverterbinding" width="709" height="39" /></p>
<p><span style="text-decoration: underline;">Setting a property based on another control&#8217;s property:</span></p>
<p>This method is useful when there isn&#8217;t a data field to bind to, but there is a need to conditionally set a control&#8217;s property.  Let&#8217;s assume we need to set a button control&#8217;s IsEnabled property based on a check box&#8217;s IsChecked property:</p>
<p style="text-align: center;"><img class="size-full wp-image-1158 aligncenter" title="bindingtocontrolproperties" src="http://blog.pearltechnology.com/wp-content/uploads/2011/04/bindingtocontrolproperties1.JPG" alt="bindingtocontrolproperties" width="754" height="144" /></p>
<p>As you can see, we&#8217;ve bound the IsEnabled property of the buttons to the IsChecked property of  the check box by specifying the ElementName (control&#8217;s name) and Path (control&#8217;s property).  We also bound the Content property of the button to the same IsChecked property using the same method, to show the current state of the button (which the framework automatically converts from a boolean to a string).  The best part about this method?  No code behind!  Here&#8217;s the result:</p>
<p style="text-align: center;"><img class="size-full wp-image-1159 aligncenter" title="bindingtocontrolpropertiesresult" src="http://blog.pearltechnology.com/wp-content/uploads/2011/04/bindingtocontrolpropertiesresult.JPG" alt="bindingtocontrolpropertiesresult" width="115" height="101" /></p>
<p style="text-align: left;">This is a very simple overview of the power of converters and bindings, and how they can be used to help you do more than just display the data on your page.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.pearltechnology.com/getting-out-of-a-bind-with-bindings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Chrome Extensions</title>
		<link>http://blog.pearltechnology.com/chrome-extensions/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed</link>
		<comments>http://blog.pearltechnology.com/chrome-extensions/#comments</comments>
		<pubDate>Wed, 06 Apr 2011 13:42:54 +0000</pubDate>
		<dc:creator>BJ</dc:creator>
				<category><![CDATA[Application Development]]></category>
		<category><![CDATA[Miscellaneous]]></category>
		<category><![CDATA[chrome extensions]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[lorem ipsum generator]]></category>

		<guid isPermaLink="false">http://blog.pearltechnology.com/?p=1108</guid>
		<description><![CDATA[Discovering any tool, extension, shortcut etc that helps make your life easier is always a good thing. While testing an application, I had two tabs open in Chrome. Refreshing each tab individually after updating the application is not a big deal, but having to constantly do it gets annoying. So, after searching I found a [...]]]></description>
			<content:encoded><![CDATA[<p>Discovering any tool, extension, shortcut etc that helps make your life easier is always a good thing. While testing an application, I had two tabs open in Chrome. Refreshing each tab individually after updating the application is not a big deal, but having to constantly do it gets annoying. So, after searching I found a Chrome extension that will refresh all open tabs. All extensions can be found in the <a href="https://chrome.google.com/webstore" target="_blank">Chrome Web Store</a>. The web store has many, many extensions that are grouped by different categories, themes, collections and can be searched as well.</p>
<p>A few other handy extensions besides &#8220;Reload All Tabs&#8221; are: JavaScript Beautifer, jQuery API browser, and Lorem Ipsum Generator.</p>
<p>The JavaScript Beautifier extension will &#8220;beautify&#8221; a long, hard to read JavaScript file that looks like this:</p>
<p>if(typeof deconcept==&#8221;undefined&#8221;){var deconcept=new Object();}if(typeof deconcept.util==&#8221;undefined&#8221;){deconcept.util=new Object();}if(typeof deconcept.SWFObjectUtil==&#8221;undefined&#8221;){deconcept.SWFObjectUtil=new Object();}deconcept.SWFObject=function(_1,id,w,h,_5,c,_7,_8,_9,_a){if(!document.getElementById){return;}this.DETECT_KEY=_a?_a:&#8221;detectflash&#8221;;this.skipDetect=deconcept.util.getRequestParameter(this.DETECT_KEY);  &#8230;</p>
<p>and make it look like this:</p>
<p><img class="alignleft size-full wp-image-1128" title="JS-Beautifier" src="http://blog.pearltechnology.com/wp-content/uploads/2011/03/JS-Beautifier1.png" alt="JS-Beautifier" width="600" height="500" /></p>
<p>For anyone that likes jQuery, the jQuery API browser will also come in handy. It provides a quick search through the API documentation. Simply type in what you want to search for and you&#8217;ll receive your results.</p>
<p><img class="alignleft size-full wp-image-1126" title="jQueryAPI" src="http://blog.pearltechnology.com/wp-content/uploads/2011/03/jQueryAPI1.png" alt="jQueryAPI" width="679" height="331" /></p>
<p>A lot of times while testing an application you&#8217;ll need some generic text to populate text fields. The Lorem Ipsum Generator will provide you with random &#8220;Lorem Ipsum&#8221; text. You can specify how many paragraphs and words per paragraph you would like.</p>
<p><img class="alignleft size-full wp-image-1137" title="LoremIpsumGenerator" src="http://blog.pearltechnology.com/wp-content/uploads/2011/03/LoremIpsumGenerator.png" alt="LoremIpsumGenerator" width="600" height="155" /></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.pearltechnology.com/chrome-extensions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Joke isn’t a joke any more… Just be creative!</title>
		<link>http://blog.pearltechnology.com/joke-isn%e2%80%99t-a-joke-any-more%e2%80%a6-just-be-creative/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed</link>
		<comments>http://blog.pearltechnology.com/joke-isn%e2%80%99t-a-joke-any-more%e2%80%a6-just-be-creative/#comments</comments>
		<pubDate>Wed, 30 Mar 2011 21:00:23 +0000</pubDate>
		<dc:creator>Geer</dc:creator>
				<category><![CDATA[Application Development]]></category>
		<category><![CDATA[Cloud Storage]]></category>

		<guid isPermaLink="false">http://blog.pearltechnology.com/?p=1090</guid>
		<description><![CDATA[Sometimes, we make fun of people with crazy ideas. But think about it, aren't their ideas pretty cool?]]></description>
			<content:encoded><![CDATA[<p>During a presentation given to all our team members (including IT and non-IT, and management and non-management), I was asked what we as application/software developers can actually do as far as development goes.  To answer the question, I gave two true/false questions back to the audiences.</p>
<p>The first question was “We can do anything you can think of”, and the second one was “We can do anything that makes sense”.  In my opinion, the first is a false statement, but the second is definitely true.  I was not trying to “insult” my colleagues by implying “what they can think of does not make sense”.  What I really meant by that was that not every idea or customer’s requirement that sounds good is feasible in the real world.  Hardware and software limitations do exist, and sometimes there are things we should not do due to considerations in certain aspects like security and performance.  Hopefully, they won’t tag me as some slaggy developers who always say things like “Oh, no… you can’t do this”, or “It’s impossible”, or just laugh at you and your “stupid” ideas, simply because they lack the knowledge and skills, or they are not creative enough.</p>
<p>Here is one of my favorite jokes.</p>
<p style="padding-left: 30px;"><em>Boss: Hey, why the Ctrl+C and Ctrl+V (the hotkeys in Windows to copy and paste content) doesn’t work for me as you just showed me the other day?</em></p>
<p style="padding-left: 30px;"><em>Me: What happened, boss?</em></p>
<p style="padding-left: 30px;"><em>After me doing some investigation, analysis, troubleshooting, testing, validation, and whatever that could be. </em></p>
<p style="padding-left: 30px;"><em>Basically, a few seconds later, I told my boss: “Boss, it’s not going to work, if you press Ctrl+C on your computer at home and press Ctrl+V on the computer in your office”.</em></p>
<p>By the way, my real boss is twice as smart as the boss in this joke.  What!?  Doesn’t sound like he is a smart guy either, does it?  How about 4 times smarter… maybe 8 or 16 times?  Wait, I was trying to praise him.  How do I do this?  All right, my real boss is 2^n times smarter than the boss in the joke above (where n represents a positive integer which equals to a magic number m which can be used to calculate how many times that my boss is smarter than the boss in the joke by using the formula 2^m).  Sounds much better now?  Anyway, my boss is a smart guy.</p>
<p>So, I thought about this joke and asked myself: is there a way to make it work?  I think there is.  With the convenience of the Internet and the power of technology, we as application/software developers can probably make it happen, regardless of whether it is cost-effective or not.  We can develop an application and install it on the boss’s home computer, so when he presses Ctrl+C on his home computer, the content he tries to copy is pushed into the Cloud for storage.  On his office computer, we can load a similar application which allows him to pull the content back from the Cloud.  In addition, if he has a smartphone, he may be able to get the content on his phone as well.  Actually, there are companies doing just this.  Online storage/backup solutions can back up your files and store them in the Cloud (at a secret and secure location or multiple locations).  Sometimes, it’s done automatically in the background which means you don’t need to press Ctrl+C or even notice its existence.  The files stored in the Cloud can be retrieved on-demand or automatically on the other endpoints which could be your laptops, computers or smartphones.</p>
<p>In the end, the joke wasn’t a joke any more.  The boss’s idea wasn’t stupid either.  Online storage service is now a billion-dollar business.  People always say there is no stupid idea.  I couldn’t agree more on that.  So, be creative.  Find a billion-dollar idea for yourself.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.pearltechnology.com/joke-isn%e2%80%99t-a-joke-any-more%e2%80%a6-just-be-creative/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Focus on Security in the SDLC</title>
		<link>http://blog.pearltechnology.com/focus-on-security-in-the-sdlc/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed</link>
		<comments>http://blog.pearltechnology.com/focus-on-security-in-the-sdlc/#comments</comments>
		<pubDate>Tue, 29 Mar 2011 18:33:10 +0000</pubDate>
		<dc:creator>JoeK</dc:creator>
				<category><![CDATA[Application Development]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[development security]]></category>
		<category><![CDATA[OWASP]]></category>
		<category><![CDATA[SDLC]]></category>
		<category><![CDATA[secure development lifecycle]]></category>

		<guid isPermaLink="false">http://blog.pearltechnology.com/?p=1140</guid>
		<description><![CDATA[Development teams need to start including a Security mindset throughout their development lifecycle plans.  Application vulnerabilties continue to be the #1 security concern of IT professionals but most companies still do not have a formal security policy around the applications they create.]]></description>
			<content:encoded><![CDATA[<p>Now that I have that PM stuff behind me I have time to refocus my efforts on furthering the team&#8217;s understanding and attention on IT Security&#8217;s role on the development lifecycle.  (ISC)2 recently commissioned Frost &amp; Sullivan to provide a detailed report on trends and opportunities emergine in the IS profession worldwide.  Their results showed that the top security concern were Application Vulnerabilities at 75%, with Mobile Devices (66%) and Viruses (65%) coming in second and third, respectively.</p>
<p>What this report says to me is that there are still a lot of development teams that don&#8217;t take security seriously enough when releasing applications to the web.  I thought it was very telling when the mySQL.com website was brought down by a SQL injection attack this past weekend.  Without the inclusion of a security mindset during all phases of a development project you are leaving yourself open to vulnerabilities. </p>
<p>A Forrester Consulting report commissioned by Microsoft in November of 2010 showed that &#8220;most companies choose to transfer risk from development to operations, where remediation cost for vulnerabilities are the highest.&#8221;  The report went on to show that almost half of companies do not perform any type of security testing on third party code.</p>
<p>We, as developers, must help change those numbers and show the importance of security in the SDLC.  We have to educate ourselves first, then bring our arguments to the business owners to show the positive impact taking a little bit of time up front will bring to the organization.  Compliance shouldn&#8217;t, and can&#8217;t, be the only reason to pay attention to software security.</p>
<p>There are resources out there that I would recommend every developer to familiarize yourself with:</p>
<p><a href="http://www.owasp.org">http://www.owasp.org</a> &#8211; Open Web Application Security Project, an open source community focused on the security of application software. </p>
<p><a href="http://www.isc2.org">http://www.isc2.org</a> - A leader in educating and certifying security professionals (I have my CSSLP through this organization)</p>
<p><a href="http://www.microsoft.com/security/sdl/">http://www.microsoft.com/security/sdl/</a> - Yes, even Microsoft has a Security SDL for us .NET developers that need to make sure our software is secure.</p>
<p>Know of any more?  Leave a comment and discuss&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.pearltechnology.com/focus-on-security-in-the-sdlc/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Case Insensitive XML Search</title>
		<link>http://blog.pearltechnology.com/case-insensitive-xml-search/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed</link>
		<comments>http://blog.pearltechnology.com/case-insensitive-xml-search/#comments</comments>
		<pubDate>Wed, 23 Mar 2011 20:54:23 +0000</pubDate>
		<dc:creator>AaronH</dc:creator>
				<category><![CDATA[Application Development]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Case Insensitive]]></category>
		<category><![CDATA[LINQ]]></category>
		<category><![CDATA[Parsing XML]]></category>
		<category><![CDATA[XDocument]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[XmlDocument]]></category>
		<category><![CDATA[XPath]]></category>

		<guid isPermaLink="false">http://blog.pearltechnology.com/?p=1043</guid>
		<description><![CDATA[Often times you need to be able to search through XML snippets using case insensitivity. You may want to handle variations in user typing or just different system configuration setups (you may not have total control over the XML creation). On my venture to find the best case agnostic XML parsing in .NET, I came [...]]]></description>
			<content:encoded><![CDATA[<p>Often times you need to be able to search through XML snippets using case insensitivity. You may want to handle variations in user typing or just different system configuration setups (<i>you may not have total control over the XML creation</i>). On my venture to find the best case agnostic XML parsing in .NET, I came across only one way to do it using XPath and the translation function. I chose not to use translation since I needed a centralized reusable function to compare two element values. </p>
<p>My first discovery is that XPath in .NET only supports XPath 1.0 &#8211; meaning you don&#8217;t have many native functions to build from. However, Microsoft allows you to extend XPath using <a href="http://msdn.microsoft.com/en-us/library/dd567715.aspx">XSLT Context Extensions</a>. The process of setting up the extensions is quite tedious, but it would seem worth the effort if it can centralize reusable parsing functions. However, about this time I discovered that LINQ to XML would provide a great wrapper on top of the basic XmlDocument operations using XDocument. Here we go through the process used to create a reusable search routine for XML content.</p>
<p>To demonstrate our search process, we created a sample XML document (<a href="http://blog.pearltechnology.com/wp-content/uploads/2011/03/business.xml#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed">business.xml</a>). Here is a brief section for reference.</p>
<pre name="code" language="xml">
<?xml version="1.0" encoding="utf-8" ?>
<company id="pt" name="Pearl Technology" description="software, IT support, and security solutions">
  <services count="5">
    <service id="appdev" name="Application Development" description="custom .NET software solutions" cost="350">
<products count="4">
<product id="biztlk" name="BizTalk Server" description="enterprise service bus"></product>
<product id="shrpnt" name="SharePoint Server" description="portal collaboration and Enterprise search"></product>
<product id="sqlsrv" name="SQL Server" description="relation database management system"></product>
<product id="iissrv" name="IIS" description="web application server"></product>
      </products>
    </service>
</services>
</company>
</pre>
<p>We want to now search for all services that match the given product name &#8220;Sharepoint&#8221;. Our first approach is to do the traditional XPath workflow using the XmlDocument class. Here is the snippet.</p>
<pre name="code" language="csharp">
             string searchKey = "Sharepoint"; // search string to find in product name

            // retrieve and load source XML document from output directory
            XmlDocument businessXML = new XmlDocument();
            businessXML.Load(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "business.xml"));

            // parse using strictly XPath (could also use confusing translate function - but needs repeated for each call)
            string xPath = string.Format("/company/services/service[products/product[contains(@name,'{0}')]]", searchKey);
            var services = businessXML.SelectNodes(xPath);
            if (services != null &#038;&#038; services.Count > 0)
            {
                foreach (XmlNode node in services)
                    Console.WriteLine("{0}\n{1}", node.OuterXml, new string('-', 70));
            }
            else
                Console.WriteLine("Could not find search key: {0} using XPath", searchKey);
</pre>
<p>The results that come back demonstrate that we are not matching all possibilities. Pearl provides SharePoint services for both <a href="http://www.pearltechnology.com/services/application-development/app-dev-services/servers">Application Development</a> and <a href="http://www.pearltechnology.com/services/microsoft-services/products-expertise/microsoft-office-sharepoint-server-moss">Microsoft Services</a>. The problem with our basic XPath search is that it is not case agnostic. We have variations of &#8220;Sharepoint&#8221; in our data &#8211; <i>Sharepoint and SharePoint</i>. In order to capture all variations, we now tackle the same problem with LINQ to SQL and extension methods.</p>
<p>Below we see the use of XDocument in place of XmlDocument, now replaced by parsing the original XmlDocument source. We also include a reference to <i>System.Xml.XPath</i> namespace to enable XPath-support within the LINQ to XML statements (using <i>XPathSelectElements</i>). Our LINQ statement is using a similar XPath as before with the exception of the filtering which is now handled by the lambda function <strong>HasValue(searchkey)</strong>.</p>
<pre name="code" language="csharp">
            // simple parse using LINQ to XML and XPath for navigation (easier to understand)
            XElement bizXML = XDocument.Parse(businessXML.OuterXml).Root;
            var items = (from service in bizXML.XPathSelectElements("/company/services/service/products/product")
                         where service.Attributes("name").HasValue(searchKey)
                         select service.Parent.Parent);

            if (items != null &#038;&#038; items.Count() > 0)
            {
                foreach (XElement node in items)
                    Console.WriteLine(string.Format("{0}\n{1}", node.ToString(), new string('-', 70)));
            }
            else
                Console.WriteLine("Could not find search key: {0} using LINQ to XML", searchKey);
</pre>
<p>The lambda function (HasValue) exists in a utility class XMLSearchExtensions &#8211; satisfying our primary goal to create a reusable case agnostic search routine. The extension methods are filtering on XAttributes, but could easily be extended to cover enumerable XElements as well. </p>
<pre name="code" language="csharp">
    /// <summary>
    /// XML Extension Methods for parsing XML using case insensitivity
    /// </summary>
    public static class XMLSearchExtensions
    {
        /// <summary>
        /// Handles case when attribute is missing
        /// </summary>
        public static bool HasValue(this IEnumerable<XAttribute> nodes, string searchKey)
        {
            return nodes.Any(GetValue(searchKey));
        }
        /// <summary>
        /// Search Expression using Case Insensitve Compare (resusable search filter)
        /// </summary>
        public static Func<XAttribute, bool> GetValue(string searchKey)
        {
            return name => name.Value.ToLowerInvariant().Contains(searchKey.ToLowerInvariant());
        }
    }
</pre>
<p>The <strong>HasValue</strong> extension uses the <a href="http://msdn.microsoft.com/en-us/library/bb337697.aspx">Any</a> LINQ command to safely ignore cases when the attribute may not be present in the current enumerable item. This adds greater flexibility if you cannot control the XML source. The <strong>GetValue</strong> delegate is called for each item and by comparing each element using the <i>Contains</i> we can easily support case insensitive filtering with ease. We could also extend this library to support Equals, StartsWith, or other behaviors you want to centrally control.</p>
<p>The entire solution can be <a href="http://blog.pearltechnology.com/wp-content/uploads/2011/03/CaseInsensitiveXPathQuery.zip#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed">downloaded here</a>. This exercise demonstrates the importance and sophistication that LINQ-powered applications can provide when working with XML.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.pearltechnology.com/case-insensitive-xml-search/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

