<?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>Dave Corun&#039;s Blog</title>
	<atom:link href="http://davecorun.com/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://davecorun.com/blog</link>
	<description>Musings on Software Development</description>
	<lastBuildDate>Wed, 31 Oct 2012 12:48:30 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5</generator>
		<item>
		<title>$ vs. jQuery</title>
		<link>http://davecorun.com/blog/2012/10/31/vs-jquery/</link>
		<comments>http://davecorun.com/blog/2012/10/31/vs-jquery/#comments</comments>
		<pubDate>Wed, 31 Oct 2012 12:48:30 +0000</pubDate>
		<dc:creator>Dave Corun</dc:creator>
				<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://davecorun.com/blog/?p=95</guid>
		<description><![CDATA[Short Version: Use jQuery, not $ Long Version: When I was a younger man, I had to battle a rather complex bug in an application with 6 different JavaScript frameworks and different versions of each one.&#160; It was a mess. When you use $ you’re simply using that character as an alias for jQuery.&#160; Lots [...]]]></description>
				<content:encoded><![CDATA[<p><b>Short Version:</b></p>
<p>Use jQuery, not $</p>
<p><b>Long Version:</b></p>
<p>When I was a younger man, I had to battle a rather complex bug in an application with 6 different JavaScript frameworks and different versions of each one.&#160; It was a mess.</p>
<p>When you use $ you’re simply using that character as an alias for jQuery.&#160; Lots of people use $.&#160; People write blogs and books and write $.</p>
<p><i>However</i>, <b>prototype.js</b> also uses that alias.</p>
<p>Only one can “win” and unfortunately many other 3rd party libraries, including JavaScriptSpellchecker.com, have <b>prototype.js</b> in its gooey center.&#160; This means that any page that has the spellcheck on it could effectively take ownership of $ when you least expect it.&#160; It’s awesome.</p>
<p>There is a workaround, which is to call <b>jQuery.noConflict()</b> before you go to use jQuery, but I think we all agree that’s rather silly.</p>
<p>So please, type out jQuery and not $.</p>
<p><b>Example:</b></p>
<p>jQuery.ajax()</p>
<p>&#160;</p>
<p>It’s only 5 more characters to type…</p>
<p>// Dave</p>
]]></content:encoded>
			<wfw:commentRss>http://davecorun.com/blog/2012/10/31/vs-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CRM 2011&#8211;Retrieve Plugin</title>
		<link>http://davecorun.com/blog/2012/01/05/crm-2011retrieve-plugin/</link>
		<comments>http://davecorun.com/blog/2012/01/05/crm-2011retrieve-plugin/#comments</comments>
		<pubDate>Thu, 05 Jan 2012 22:05:52 +0000</pubDate>
		<dc:creator>Dave Corun</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[CRM]]></category>

		<guid isPermaLink="false">http://davecorun.com/blog/?p=86</guid>
		<description><![CDATA[So you want to write a plugin that executes every time a user opens a record. Usually this would be frowned upon because this code could easily present a performance issues, especially if the data you’re gathering is hosted on an external resource. In the off-change you do need to do this, here is the [...]]]></description>
				<content:encoded><![CDATA[<p>So you want to write a plugin that executes every time a user opens a record.</p>
<p>Usually this would be frowned upon because this code could easily present a performance issues, especially if the data you’re gathering is hosted on an external resource.</p>
<p>In the off-change you do need to do this, here is the solution:</p>
<p>&#160;</p>
<p>First, create a new Plugin and sign the assembly with a key:</p>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">void</span> Execute(IServiceProvider serviceProvider)
{
    <span class="rem">// Obtain the execution context from the service provider.</span>
    Microsoft.Xrm.Sdk.IPluginExecutionContext context = (Microsoft.Xrm.Sdk.IPluginExecutionContext)
        serviceProvider.GetService(<span class="kwrd">typeof</span>(Microsoft.Xrm.Sdk.IPluginExecutionContext));

    <span class="kwrd">if</span> (context.Depth == 1)
    {
        IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(<span class="kwrd">typeof</span>(IOrganizationServiceFactory));
        IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

        <span class="rem">// Obtain the target entity from the input parmameters.</span>
        EntityReference entity = (EntityReference)context.InputParameters[<span class="str">&quot;Target&quot;</span>];

        ColumnSet cols = <span class="kwrd">new</span> ColumnSet(
                             <span class="kwrd">new</span> String[] { <span class="str">&quot;lastname&quot;</span>, <span class="str">&quot;firstname&quot;</span>, <span class="str">&quot;address1_name&quot;</span> });

        var contact = service.Retrieve(<span class="str">&quot;contact&quot;</span>, entity.Id, cols);

        <span class="kwrd">if</span> (contact != <span class="kwrd">null</span>)
        {
            <span class="kwrd">if</span> (contact.Attributes.Contains(<span class="str">&quot;address1_name&quot;</span>) == <span class="kwrd">false</span>)
            {
                Random rndgen = <span class="kwrd">new</span> Random();
                contact.Attributes.Add(<span class="str">&quot;address1_name&quot;</span>, <span class="str">&quot;first time value: &quot;</span> + rndgen.Next().ToString());
            }
            <span class="kwrd">else</span>
            {
                contact[<span class="str">&quot;address1_name&quot;</span>] = <span class="str">&quot;i already exist&quot;</span>;
            }
            service.Update(contact);
        }
    }
}</pre>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>&#160;</p>
<p>Next, hop over to the Plugin Registration Tool (included with the CRM SDK) and register the plugin as follows:</p>
<p><a href="http://davecorun.com/blog/wp-content/uploads/2011/08/image.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://davecorun.com/blog/wp-content/uploads/2011/08/image_thumb.png" width="475" height="470" /></a></p>
<p>&#160;</p>
<p>What you’ll end up with in this example is:</p>
<p>On first open of the record:</p>
<p><a href="http://davecorun.com/blog/wp-content/uploads/2011/08/clip_image002.jpg"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="clip_image002" border="0" alt="clip_image002" src="http://davecorun.com/blog/wp-content/uploads/2011/08/clip_image002_thumb.jpg" width="352" height="87" /></a></p>
<p>On all future opens of the record:</p>
<p><a href="http://davecorun.com/blog/wp-content/uploads/2011/08/clip_image0025.jpg"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="clip_image002[5]" border="0" alt="clip_image002[5]" src="http://davecorun.com/blog/wp-content/uploads/2011/08/clip_image0025_thumb.jpg" width="302" height="68" /></a></p>
<p>&#160;</p>
<p>&#160;</p>
<p>This has <strong>not</strong> been tested with CRM 2011 Online.&#160; Use at your own risk, your mileage may vary. <img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://davecorun.com/blog/wp-content/uploads/2011/08/wlEmoticon-smile.png" /></p>
<p>&#160;</p>
<p>// Dave</p>
]]></content:encoded>
			<wfw:commentRss>http://davecorun.com/blog/2012/01/05/crm-2011retrieve-plugin/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Creating Business Units and Teams Programmatically</title>
		<link>http://davecorun.com/blog/2012/01/05/creating-business-units-and-teams-programmatically/</link>
		<comments>http://davecorun.com/blog/2012/01/05/creating-business-units-and-teams-programmatically/#comments</comments>
		<pubDate>Thu, 05 Jan 2012 22:05:38 +0000</pubDate>
		<dc:creator>Dave Corun</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Dynamics CRM]]></category>

		<guid isPermaLink="false">http://davecorun.com/blog/?p=84</guid>
		<description><![CDATA[Assumed Background Information: Introduction to Entities in Microsoft Dynamics CRM http://msdn.microsoft.com/en-us/library/gg309396.aspx You may find yourself working on a complex CRM implementation where you need to create a number of Business Units and Teams. You may find it helpful to create a utility to do this activity on your behalf. This following code reads the list [...]]]></description>
				<content:encoded><![CDATA[<p>Assumed Background Information:</p>
<p><b><i>Introduction to Entities in Microsoft Dynamics CRM</i></b></p>
<p><a href="http://msdn.microsoft.com/en-us/library/gg309396.aspx">http://msdn.microsoft.com/en-us/library/gg309396.aspx</a></p>
<p>You may find yourself working on a complex CRM implementation where you need to create a number of Business Units and Teams.</p>
<p>You may find it helpful to create a utility to do this activity on your behalf.</p>
<p>This following code reads the list of Business Units and Teams from an XML file and calls the methods below to do the heavy lifting.</p>
<h3>Creating a Business Unit</h3>
<pre class="csharpcode"><span class="rem">/// &lt;summary&gt;</span>
<span class="rem">/// Creates the BusinessUnit with the given name</span>
<span class="rem">/// &lt;/summary&gt;</span>
<span class="rem">/// &lt;param name=&quot;strParentName&quot;&gt;ParentBusiness Unit Name&lt;/param&gt;</span>
<span class="rem">/// &lt;param name=&quot;strName&quot;&gt;Name of Business Unit needs to be created&lt;/param&gt;</span>
<span class="kwrd">private</span> <span class="kwrd">void</span> CreateBusinessUnit(<span class="kwrd">string</span> strParentName, <span class="kwrd">string</span> strName)
{
    <span class="kwrd">try</span>
    {
        Entity e = <span class="kwrd">new</span> Entity(<span class="str">&quot;businessunit&quot;</span>);
        e.Attributes[<span class="str">&quot;name&quot;</span>] = strName;

        <span class="rem">//Get the Parent BusinessUnit Guid from the Parent BusinessUnit Name</span>
        <span class="kwrd">string</span> strParentGuid = strParentName;

        <span class="rem">//Check for the valid Guid. If it is not a guid retrieve the guid based on the name of the business unit</span>
        <span class="kwrd">if</span> (!IsGUID(strParentGuid))
        {
            strParentGuid = GetParentUnitId(strParentName);
        }


        <span class="rem">//If Guid Exists then place it into the ParentBusinessUnitId lookup field of BusinessUnit entity</span>
        <span class="kwrd">if</span> (strParentGuid.Length &gt; 0)
        {
            EntityReference erParentBusinessUnit = <span class="kwrd">new</span> EntityReference(<span class="str">&quot;businessunit&quot;</span>, <span class="kwrd">new</span> Guid(strParentGuid));
            e.Attributes[<span class="str">&quot;parentbusinessunitid&quot;</span>] = erParentBusinessUnit;
        }

        <span class="rem">//Create the BusinessUnit</span>
        _service.Create(e);
        Console.WriteLine(<span class="str">&quot;Created BusinessUnit : &quot;</span> + strName + <span class="str">&quot; Successfully&quot;</span>);
    }
    <span class="kwrd">catch</span> (Exception ex)
    {
        Console.WriteLine(<span class="str">&quot;Error While Creating a Business Unit :  &quot;</span> + strName + <span class="str">&quot;. Error Message: &quot;</span> + ex.Message);
    }

}</pre>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>&#160;</p>
<p>&#160;</p>
<p><strong>Creating a Team</strong></p>
<pre class="csharpcode"><span class="kwrd">private</span> <span class="kwrd">void</span> CreateTeam(<span class="kwrd">string</span> strBUName, <span class="kwrd">string</span> strTeamName)
{
    <span class="kwrd">try</span>
    {
        Entity e = <span class="kwrd">new</span> Entity(<span class="str">&quot;team&quot;</span>);
        e.Attributes[<span class="str">&quot;name&quot;</span>] = strTeamName;

        <span class="rem">//Get the Business Unit Name which the team belongs to</span>
        <span class="kwrd">string</span> strBU = GetParentUnitId(strBUName);

        <span class="rem">//If Guid Exists then place it into the BusinessUnit lookup field of Team entity</span>
        <span class="kwrd">if</span> (strBU.Length &gt; 0)
        {
            EntityReference erBusinessUnit = <span class="kwrd">new</span> EntityReference(<span class="str">&quot;businessunit&quot;</span>, <span class="kwrd">new</span> Guid(strBU));
            e.Attributes[<span class="str">&quot;businessunitid&quot;</span>] = erBusinessUnit;
        }

        <span class="rem">//Create the Team</span>
        _service.Create(e);
        Console.WriteLine(<span class="str">&quot;Created Team : &quot;</span> + strTeamName + <span class="str">&quot; Successfully under Business Unit: &quot;</span> + strBUName);
    }
    <span class="kwrd">catch</span> (Exception ex)
    {
        Console.WriteLine(<span class="str">&quot;Error While Creating a Team:  &quot;</span> + strTeamName + <span class="str">&quot;. Error Message: &quot;</span> + ex.Message);
    }

}</pre>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>&#160;</p>
<h3>Getting the ID of the Business Unit</h3>
<pre class="csharpcode"><span class="rem">/// &lt;summary&gt;</span>
<span class="rem">///  Gets the BusinessUnitID when the Businessunit name is passed</span>
<span class="rem">/// &lt;/summary&gt;</span>
<span class="rem">/// &lt;param name=&quot;BUName&quot;&gt;BusinessUnit Name&lt;/param&gt;</span>
<span class="rem">/// &lt;returns&gt;Business Unit Guid&lt;/returns&gt;</span>
<span class="kwrd">private</span> <span class="kwrd">string</span> GetParentUnitId(<span class="kwrd">string</span> BUName)
{
    <span class="kwrd">try</span>
    {
        <span class="rem">//Checks whether the BUName is empty or null and then proceed into the query </span>
        <span class="kwrd">if</span> (BUName != <span class="kwrd">null</span> &amp;&amp; BUName.Length &gt; 0)
        {
            QueryByAttribute qba = <span class="kwrd">new</span> QueryByAttribute(<span class="str">&quot;businessunit&quot;</span>);
            <span class="rem">//Condition parameters is Businessunit Name</span>
            qba.AddAttributeValue(<span class="str">&quot;name&quot;</span>, BUName);
            <span class="rem">//Values need to be retrieved is the Guid of Business Unit</span>
            qba.ColumnSet = <span class="kwrd">new</span> ColumnSet(<span class="str">&quot;businessunitid&quot;</span>, <span class="str">&quot;createdon&quot;</span>);


            DataCollection&lt;Entity&gt; dcBUDetails;

            <span class="rem">//Retrieve the value based on the condition given</span>
            dcBUDetails = _serviceProxy.RetrieveMultiple(qba).Entities;

            <span class="rem">//Return the Guid of the BusinessUnit</span>
            <span class="kwrd">if</span> (dcBUDetails.Count == 1)
            {
                <span class="kwrd">if</span> (dcBUDetails[0] != <span class="kwrd">null</span>)
                {
                    <span class="kwrd">if</span> (dcBUDetails[0].Id != <span class="kwrd">null</span>)
                    {
                        <span class="kwrd">return</span> dcBUDetails[0].Id.ToString();
                    }
                }
            }
            <span class="kwrd">else</span>
            {

                <span class="rem">//Where there are more than one BusinessUnit with the same name take the latest created business unit to create the team or business  unit</span>
                <span class="kwrd">string</span> id = <span class="kwrd">string</span>.Empty;
                DateTime dtMax = <span class="kwrd">new</span> DateTime();
                <span class="rem">//Get the date of creation of the first BU</span>
                DateTime.TryParse(dcBUDetails[0].Attributes[<span class="str">&quot;createdon&quot;</span>].ToString(), <span class="kwrd">out</span> dtMax);
                <span class="kwrd">for</span> (<span class="kwrd">int</span> i = 1; i &lt; dcBUDetails.Count; i++)
                {
                    <span class="rem">//Compare all the BU with the same name and get the latest Business unit created to create a team</span>
                    DateTime dt;
                    DateTime.TryParse(dcBUDetails[i].Attributes[<span class="str">&quot;createdon&quot;</span>].ToString(), <span class="kwrd">out</span> dt);
                    <span class="kwrd">if</span> (dt &gt; dtMax)
                    {
                        dtMax = dt;
                        id = dcBUDetails[i].Id.ToString();
                    }

                }
                <span class="kwrd">return</span> id;
            }
        }
    }
    <span class="kwrd">catch</span> (Exception ex)
    {
        Console.WriteLine(<span class="str">&quot;Error While retrieving Guid of Business Unit &quot;</span> + ex.Message);
    }

    <span class="kwrd">return</span> <span class="str">&quot;&quot;</span>;

}</pre>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
]]></content:encoded>
			<wfw:commentRss>http://davecorun.com/blog/2012/01/05/creating-business-units-and-teams-programmatically/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Learning SQL</title>
		<link>http://davecorun.com/blog/2011/06/06/learning-sql/</link>
		<comments>http://davecorun.com/blog/2011/06/06/learning-sql/#comments</comments>
		<pubDate>Mon, 06 Jun 2011 13:48:22 +0000</pubDate>
		<dc:creator>Dave Corun</dc:creator>
				<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://davecorun.com/blog/2011/06/06/learning-sql/</guid>
		<description><![CDATA[Hey how are you? What steps should I take to become a SQL Developer? &#160; If I was just learning, I would start by installing the SQL Server Express edition locally (free): http://www.microsoft.com/express/Database/ It should come with a number of tutorials and walkthroughs. From there, I&#8217;d recommend looking at the MCTS Certification. It&#8217;s the baseline [...]]]></description>
				<content:encoded><![CDATA[<p><em>Hey how are you?</em></p>
<p><em>What steps should I take to become a SQL Developer?</em></p>
<p>&#160;</p>
<p>If I was just learning, I would start by installing the SQL Server Express edition locally (free):</p>
<p><a href="http://www.microsoft.com/express/Database/">http://www.microsoft.com/express/Database/</a></p>
<p>It should come with a number of tutorials and walkthroughs.</p>
<p>From there, I&#8217;d recommend looking at the MCTS Certification. It&#8217;s the baseline certification for those new to SQL Server:</p>
<p><a href="http://www.microsoft.com/learning/en/us/certification/cert-sql-server.aspx#tab2">http://www.microsoft.com/learning/en/us/certification/cert-sql-server.aspx#tab2</a></p>
<p>In particular, 70-433 is all about database development.</p>
<p><a href="http://www.microsoft.com/learning/en/us/exam.aspx?ID=70-433&amp;locale=en-us#tab3">http://www.microsoft.com/learning/en/us/exam.aspx?ID=70-433&amp;locale=en-us#tab3</a></p>
<p>If you look over the Skills Measured, you&#8217;ll get a good feel for what a typical SQL Developer needs to know. Under Preparation Materials you&#8217;ll find a number of resources, including eLearning and MSPress training kits. Typically you can find the training kit books on the cheap at amazon.com, because once someone has passed the cert, they don&#8217;t have a need for it anymore.</p>
<p>I&#8217;m not saying you should get the certification. It&#8217;s just a good way to have an outline and an ultimate goal. The learning material will also be a bit more structured this way.</p>
<p>Hope this helps!</p>
<p>// Dave </p>
]]></content:encoded>
			<wfw:commentRss>http://davecorun.com/blog/2011/06/06/learning-sql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dynamics CRM 4.0 &#8211;Custom ASPX Page in a Multi-Tenancy Environment</title>
		<link>http://davecorun.com/blog/2011/02/23/dynamics-crm-4-0-custom-aspx-page-in-a-multi-tenancy-environment/</link>
		<comments>http://davecorun.com/blog/2011/02/23/dynamics-crm-4-0-custom-aspx-page-in-a-multi-tenancy-environment/#comments</comments>
		<pubDate>Wed, 23 Feb 2011 14:41:34 +0000</pubDate>
		<dc:creator>Dave Corun</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Dynamics]]></category>

		<guid isPermaLink="false">http://davecorun.com/blog/2011/02/23/dynamics-crm-4-0-custom-aspx-page-in-a-multi-tenancy-environment/</guid>
		<description><![CDATA[&#160; When OnPremise Dynamics CRM 4.0 is configured with a single organization, it sends the organization name in the query string. When OnPremise Dynamics CRM 4.0 is configured with multiple organizations, it sends the organization name in the path. Here’s how to do a quick fallback if you need the custom page to work in [...]]]></description>
				<content:encoded><![CDATA[<p>&#160;</p>
<p>When OnPremise Dynamics CRM 4.0 is configured with a single organization, it sends the organization name in the query string.</p>
<p>When OnPremise Dynamics CRM 4.0 is configured with multiple organizations, it sends the organization name in the path.</p>
<p>Here’s how to do a quick fallback if you need the custom page to work in both environments.</p>
<pre class="csharpcode"><span class="rem">// grab the incoming request parameters</span>
Trace.Write(<span class="str">&quot;Request.ApplicationPath: &quot;</span> + Request.ApplicationPath);
Trace.Write(<span class="str">&quot;Request['orgname']: &quot;</span> + Request[<span class="str">&quot;orgname&quot;</span>]);

<span class="rem">// Multi-tenant CRM installations will have the Org Name as part of the Application path.</span>
<span class="kwrd">if</span> (Request.ApplicationPath != <span class="str">&quot;/&quot;</span>)
{
    _orgName = Request.ApplicationPath.Replace(<span class="str">&quot;/&quot;</span>, <span class="str">&quot;&quot;</span>);
}
<span class="kwrd">else</span>
{
    _orgName = Request[<span class="str">&quot;orgname&quot;</span>];
}
Trace.Write(<span class="str">&quot;orgname: &quot;</span> + _orgName);</pre>
<p>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
</p>
<p>Hope this helps!</p>
<p>// Dave</p>
]]></content:encoded>
			<wfw:commentRss>http://davecorun.com/blog/2011/02/23/dynamics-crm-4-0-custom-aspx-page-in-a-multi-tenancy-environment/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Multi-Tenancy IFRAMEs in Dynamics CRM 4.0</title>
		<link>http://davecorun.com/blog/2011/02/23/multi-tenancy-iframes-in-dynamics-crm-4-0/</link>
		<comments>http://davecorun.com/blog/2011/02/23/multi-tenancy-iframes-in-dynamics-crm-4-0/#comments</comments>
		<pubDate>Wed, 23 Feb 2011 14:02:28 +0000</pubDate>
		<dc:creator>Dave Corun</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Dynamics]]></category>

		<guid isPermaLink="false">http://davecorun.com/blog/2011/02/23/multi-tenancy-iframes-in-dynamics-crm-4-0/</guid>
		<description><![CDATA[Before var url = &#34;/userdefined/areas.aspx?oId=&#34; + oId + &#34;&#38;oType=&#34; + oType + &#34;&#38;security=&#34; + security + &#34;&#38;tabSet=&#34; + tabSet; After var url = prependOrgName(&#34;/userdefined/areas.aspx?oId=&#34; + oId + &#34;&#38;oType=&#34; + oType + &#34;&#38;security=&#34; + security + &#34;&#38;tabSet=&#34; + tabSet); http://msdn.microsoft.com/en-us/library/cc905758.aspx &#160; Hope this helps! &#160; // Dave]]></description>
				<content:encoded><![CDATA[<p><b>Before</b></p>
<p>var url = &quot;/userdefined/areas.aspx?oId=&quot; + oId + &quot;&amp;oType=&quot; + oType + &quot;&amp;security=&quot; + security + &quot;&amp;tabSet=&quot; + tabSet;</p>
<p><b>After</b></p>
<p>var url = <b>prependOrgName(</b>&quot;/userdefined/areas.aspx?oId=&quot; + oId + &quot;&amp;oType=&quot; + oType + &quot;&amp;security=&quot; + security + &quot;&amp;tabSet=&quot; + tabSet<b>)</b>;</p>
<p><a href="http://msdn.microsoft.com/en-us/library/cc905758.aspx">http://msdn.microsoft.com/en-us/library/cc905758.aspx</a></p>
<p>&#160;</p>
<p>Hope this helps!</p>
<p>&#160;</p>
<p>// Dave</p>
]]></content:encoded>
			<wfw:commentRss>http://davecorun.com/blog/2011/02/23/multi-tenancy-iframes-in-dynamics-crm-4-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Good Blog Post</title>
		<link>http://davecorun.com/blog/2011/01/28/good-blog-post/</link>
		<comments>http://davecorun.com/blog/2011/01/28/good-blog-post/#comments</comments>
		<pubDate>Fri, 28 Jan 2011 15:33:56 +0000</pubDate>
		<dc:creator>Dave Corun</dc:creator>
				<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://davecorun.com/blog/2011/01/28/good-blog-post/</guid>
		<description><![CDATA[10 Reasons Developers Should Blog &#160; // Dave]]></description>
				<content:encoded><![CDATA[<p><a title="Permanent Link to 10 Reasons Developers Should Blog" href="http://www.msjoe.com/2011/01/10-reasons-developers-should-blog/">10 Reasons Developers Should Blog</a></p>
<p>&#160;</p>
<p>// Dave</p>
]]></content:encoded>
			<wfw:commentRss>http://davecorun.com/blog/2011/01/28/good-blog-post/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Validation Messages &#8211; MVVM Approach</title>
		<link>http://davecorun.com/blog/2010/12/04/validation-messages-mvvm-approach/</link>
		<comments>http://davecorun.com/blog/2010/12/04/validation-messages-mvvm-approach/#comments</comments>
		<pubDate>Sat, 04 Dec 2010 22:51:12 +0000</pubDate>
		<dc:creator>Dave Corun</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[Silverlight]]></category>

		<guid isPermaLink="false">http://davecorun.com/blog/2010/12/04/validation-messages-mvvm-approach/</guid>
		<description><![CDATA[What follows is a simple way to carry along a collection of Validation Messages in your ViewModel, and then bind them to the UI at runtime. &#160; The first step is to create an ObservableCollection of validation messages on the ViewModel class.&#160; This is going to hold the messages at runtime. public ObservableCollection&#60;TLValidationMessage&#62; ValidationMessages { [...]]]></description>
				<content:encoded><![CDATA[<p>What follows is a simple way to carry along a collection of Validation Messages in your ViewModel, and then bind them to the UI at runtime.</p>
<p>&#160;</p>
<p>The first step is to create an <strong>ObservableCollection </strong>of validation messages on the ViewModel class.&#160; This is going to hold the messages at runtime.</p>
<pre class="csharpcode"><span class="kwrd">public</span> ObservableCollection&lt;TLValidationMessage&gt; ValidationMessages
{
    get { <span class="kwrd">return</span> _validationMessages; }
    set
    {
        <span class="kwrd">if</span> (_validationMessages == <span class="kwrd">value</span>) <span class="kwrd">return</span>;
        _validationMessages = <span class="kwrd">value</span>;
        NotifyPropertyChanged(<span class="str">&quot;ValidationMessages&quot;</span>);
    }
}</pre>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>We’ll also need to define what <strong>TLValidationMessages </strong>are.&#160; They’re simply a Message string and a Severity Level, which could be used to change the styling at runtime based on the importance of the message.</p>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">enum</span> SeverityLevel
{
    Error,
    Warning,
    Info
}
<span class="rem">/// &lt;summary&gt;</span>
<span class="rem">/// &lt;/summary&gt;</span>
<span class="kwrd">public</span> <span class="kwrd">class</span> TLValidationMessage
{

    <span class="rem">/// &lt;summary&gt;</span>
    <span class="rem">/// Message to show the user</span>
    <span class="rem">/// &lt;/summary&gt;</span>
    <span class="kwrd">public</span> <span class="kwrd">string</span> Message { get; set; }

    <span class="rem">/// &lt;summary&gt;</span>
    <span class="rem">/// This helps change the styling, based on the severity level.</span>
    <span class="rem">/// &lt;/summary&gt;</span>
    <span class="kwrd">public</span> SeverityLevel Level { get; set; }
}</pre>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>&#160;</p>
<p>Next we’ll create a little helper method on the ViewModel that will add new messages to our collection:</p>
<pre class="csharpcode"><span class="rem">/// &lt;summary&gt;</span>
<span class="rem">/// Adds a validation message to the bottom of the UI, with the appropriate styling.</span>
<span class="rem">/// &lt;/summary&gt;</span>
<span class="rem">/// &lt;param name=&quot;level&quot;&gt;&lt;/param&gt;</span>
<span class="rem">/// &lt;param name=&quot;message&quot;&gt;&lt;/param&gt;</span>
<span class="kwrd">public</span> <span class="kwrd">void</span> AddValidationMessage(SeverityLevel level, <span class="kwrd">string</span> message)
{
    <span class="kwrd">if</span> (ValidationMessages == <span class="kwrd">null</span>) ValidationMessages = <span class="kwrd">new</span> ObservableCollection&lt;TLValidationMessage&gt;();

    ValidationMessages.Add(<span class="kwrd">new</span> TLValidationMessage
                               {
                                   Level = level,
                                   Message = message
                               });
    NotifyPropertyChanged(<span class="str">&quot;ValidationMessages&quot;</span>);
}</pre>
<p>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>Now we’ll need to call this helper method anywhere a validation error occurs (typically in other methods in the ViewModel itself.</p>
<pre class="csharpcode"><span class="kwrd">if</span> (someitem.SomeCollection == <span class="kwrd">null</span>)
{
    AddValidationMessage(SeverityLevel.Error, <span class="str">&quot;There are no items.&quot;</span>);
    <span class="kwrd">return</span>;
}</pre>
<p>Turning our attention to the xaml, we’ll add an <strong>ItemsControl</strong> inside a <strong>Border</strong>, which will display the messages:</p>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">Border</span> <span class="attr">x:Name</span><span class="kwrd">=&quot;Validation&quot;</span> <span class="attr">Grid</span>.<span class="attr">Column</span><span class="kwrd">=&quot;0&quot;</span> <span class="attr">BorderThickness</span><span class="kwrd">=&quot;1&quot;</span> <span class="attr">Grid</span>.<span class="attr">Row</span><span class="kwrd">=&quot;3&quot;</span> <span class="attr">Grid</span>.<span class="attr">ColumnSpan</span><span class="kwrd">=&quot;2&quot;</span> <span class="attr">HorizontalAlignment</span><span class="kwrd">=&quot;Center&quot;</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">ItemsControl</span> <span class="attr">ItemsSource</span><span class="kwrd">=&quot;{Binding ValidationMessages, Mode=OneWay}&quot;</span> <span class="attr">BorderBrush</span><span class="kwrd">=&quot;{x:Null}&quot;</span> <span class="attr">ItemTemplate</span><span class="kwrd">=&quot;{StaticResource ValidationMessageTemplate}&quot;</span> <span class="attr">Foreground</span><span class="kwrd">=&quot;#FFFF0202&quot;</span><span class="kwrd">/&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">Border</span><span class="kwrd">&gt;</span></pre>
<p>You may have noticed the template was set to <strong>ItemTemplate=&quot;{StaticResource ValidationMessageTemplate}&quot;&#160; </strong>Here is the <strong>DataTemplate</strong> to control the display.</p>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">DataTemplate</span> <span class="attr">x:Key</span><span class="kwrd">=&quot;ValidationMessageTemplate&quot;</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">Grid</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">StackPanel</span> <span class="attr">Orientation</span><span class="kwrd">=&quot;Horizontal&quot;</span> <span class="attr">d:LayoutOverrides</span><span class="kwrd">=&quot;Height&quot;</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">TextBlock</span> <span class="attr">Text</span><span class="kwrd">=&quot;{Binding Message}&quot;</span><span class="kwrd">/&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">StackPanel</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">Grid</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">DataTemplate</span><span class="kwrd">&gt;</span></pre>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>As long as you’ve set the <strong>DataContext </strong>of the parent control, and your binding lines up, this will display the Validation Messages as they occur.</p>
<p>Hope this helps!</p>
<p>// Dave</p>
]]></content:encoded>
			<wfw:commentRss>http://davecorun.com/blog/2010/12/04/validation-messages-mvvm-approach/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HttpContext.Current.Session &#8211; Unit Testing</title>
		<link>http://davecorun.com/blog/2010/12/04/httpcontext-current-session-unit-testing/</link>
		<comments>http://davecorun.com/blog/2010/12/04/httpcontext-current-session-unit-testing/#comments</comments>
		<pubDate>Sat, 04 Dec 2010 22:40:34 +0000</pubDate>
		<dc:creator>Dave Corun</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://davecorun.com/blog/2010/12/04/httpcontext-current-session-unit-testing/</guid>
		<description><![CDATA[Here is a quick clever trick for failing over the connection string, in the case that it doesn’t already exist on the HttpContext.Current.Session object. As you may know, Unit Testing frameworks don’t always mock out the HttpContext class properly, if at all.&#160; This is unfortunate if you rely on objects stored there and you still [...]]]></description>
				<content:encoded><![CDATA[<p>Here is a quick clever trick for failing over the connection string, in the case that it doesn’t already exist on the <strong>HttpContext.Current.Session </strong>object.</p>
<p>As you may know, Unit Testing frameworks don’t always mock out the <strong>HttpContext </strong>class properly, if at all.&#160; This is unfortunate if you rely on objects stored there and you still want to unit test them.</p>
<pre class="csharpcode"><span class="kwrd">string</span> connectionString = ConfigurationManager.ConnectionStrings[<span class="str">&quot;DefaultConnectionString&quot;</span>].ConnectionString;

<span class="kwrd">try</span>
{
    <span class="kwrd">if</span> (HttpContext.Current != <span class="kwrd">null</span>)
        <span class="kwrd">if</span> (HttpContext.Current.Session[<span class="str">&quot;ConnectionString&quot;</span>] != <span class="kwrd">null</span>)
            connectionString = HttpContext.Current.Session[<span class="str">&quot;ConnectionString&quot;</span>].ToString();

    <span class="kwrd">using</span> (var cn = <span class="kwrd">new</span> SqlConnection(connectionString))
   {
....</pre>
<p>There are a lot of approaches to this problem, this is but one of them.<br />
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
</p>
<p>Hope this helps!</p>
<p>// Dave</p>
]]></content:encoded>
			<wfw:commentRss>http://davecorun.com/blog/2010/12/04/httpcontext-current-session-unit-testing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My First Windows Phone 7 App</title>
		<link>http://davecorun.com/blog/2010/10/17/my-first-windows-phone-7-app/</link>
		<comments>http://davecorun.com/blog/2010/10/17/my-first-windows-phone-7-app/#comments</comments>
		<pubDate>Sun, 17 Oct 2010 22:25:05 +0000</pubDate>
		<dc:creator>Dave Corun</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[WP7]]></category>

		<guid isPermaLink="false">http://davecorun.com/blog/2010/10/17/my-first-windows-phone-7-app/</guid>
		<description><![CDATA[This will be a good way for me to document what I’m learning, while building my first “real” Windows Phone 7 app. Background My intent is to build a Personal Bartender app. It will look something like this: What I’ve Done So Far I’ve modified PanoramaBackground.png, ApplicationIcon.png, and Background.png that came as part of the [...]]]></description>
				<content:encoded><![CDATA[<p>This will be a good way for me to document what I’m learning, while building my first “real” Windows Phone 7 app.</p>
<p><strong>Background</strong></p>
<p>My intent is to build a Personal Bartender app.</p>
<p>It will look something like this:</p>
<p><a href="http://davecorun.com/blog/wp-content/uploads/2010/10/combined.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="combined" border="0" alt="combined" src="http://davecorun.com/blog/wp-content/uploads/2010/10/combined_thumb.png" width="644" height="247" /></a></p>
<p><strong>What I’ve Done So Far</strong></p>
<p>I’ve modified <strong>PanoramaBackground.png</strong>, <strong>ApplicationIcon.png</strong>, and <strong>Background.png </strong>that came as part of the Panorama Project Template.&#160; With a touch of playing around in Paint.NET I had some images I was relatively happy with.</p>
<p>&#160;</p>
<p>Next, I grabbed a listing of 175 common drink recipes, and converted it to an XML file I could play with.</p>
<p><a href="http://davecorun.com/blog/wp-content/uploads/2010/10/image.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://davecorun.com/blog/wp-content/uploads/2010/10/image_thumb.png" width="410" height="242" /></a></p>
<p>&#160;</p>
<p>I next created a new ViewModel to hold the drink recipes.&#160; Drinks have a Name, and a collection of Ingredients, Instructions, and Comments.</p>
<pre class="csharpcode">    <span class="kwrd">public</span> <span class="kwrd">class</span> DrinkViewModel : INotifyPropertyChanged
    {
        <span class="kwrd">private</span> <span class="kwrd">string</span> _drinkName = <span class="kwrd">string</span>.Empty;
        <span class="kwrd">private</span> <span class="kwrd">string</span> _category = <span class="kwrd">string</span>.Empty;

        <span class="kwrd">public</span> DrinkViewModel()
        {
            Drinks = <span class="kwrd">new</span> ObservableCollection&lt;DrinkViewModel&gt;();
        }

        <span class="kwrd">public</span> ObservableCollection&lt;DrinkViewModel&gt; Drinks { get; set; }

        <span class="kwrd">public</span> <span class="kwrd">string</span> DrinkName
        {
            get { <span class="kwrd">return</span> _drinkName; }
            set
            {
                <span class="kwrd">if</span> (<span class="kwrd">value</span> != _drinkName)
                {
                    _drinkName = <span class="kwrd">value</span>;
                    NotifyPropertyChanged(<span class="str">&quot;DrinkName&quot;</span>);
                }
            }
        }


        <span class="kwrd">public</span> ObservableCollection&lt;<span class="kwrd">string</span>&gt; Ingredients { get; set; }

        <span class="kwrd">public</span> <span class="kwrd">string</span> IngredientsFormatted
        {
            get
            {
                <span class="kwrd">string</span> result = <span class="kwrd">string</span>.Empty;
                <span class="kwrd">if</span> (Ingredients != <span class="kwrd">null</span>)
                    <span class="kwrd">foreach</span> (<span class="kwrd">string</span> ingredient <span class="kwrd">in</span> Ingredients)
                    {
                        result += ingredient + Environment.NewLine;
                    }
                <span class="kwrd">return</span> result;
            }
        }

        <span class="kwrd">public</span> <span class="kwrd">string</span> Category
        {
            get { <span class="kwrd">return</span> _category; }
            set
            {
                <span class="kwrd">if</span> (<span class="kwrd">value</span> != _category)
                {
                    _category = <span class="kwrd">value</span>;
                    NotifyPropertyChanged(<span class="str">&quot;Category&quot;</span>);
                }
            }
        }

        <span class="kwrd">public</span> ObservableCollection&lt;<span class="kwrd">string</span>&gt; Instructions { get; set; }

        <span class="kwrd">public</span> <span class="kwrd">string</span> InstructionsFormatted
        {
            get
            {
                <span class="kwrd">string</span> result = <span class="kwrd">string</span>.Empty;
                <span class="kwrd">if</span> (Instructions != <span class="kwrd">null</span>)
                    <span class="kwrd">foreach</span> (<span class="kwrd">string</span> instruction <span class="kwrd">in</span> Instructions)
                    {
                        result += instruction + Environment.NewLine;
                    }
                <span class="kwrd">return</span> result;
            }
        }

        <span class="kwrd">public</span> ObservableCollection&lt;<span class="kwrd">string</span>&gt; Comments { get; set; }

        <span class="kwrd">public</span> <span class="kwrd">string</span> CommentsFormatted
        {
            get
            {
                <span class="kwrd">string</span> result = <span class="kwrd">string</span>.Empty;
                <span class="kwrd">if</span> (Comments != <span class="kwrd">null</span>)
                    <span class="kwrd">foreach</span> (<span class="kwrd">string</span> comment <span class="kwrd">in</span> Comments)
                    {
                        result += comment + Environment.NewLine;
                    }
                <span class="kwrd">return</span> result;
            }
        }

        <span class="kwrd">public</span> <span class="kwrd">bool</span> IsDataLoaded { get; <span class="kwrd">private</span> set; }

        <span class="preproc">#region</span> INotifyPropertyChanged Members

        <span class="kwrd">public</span> <span class="kwrd">event</span> PropertyChangedEventHandler PropertyChanged;


        <span class="preproc">#endregion</span>

        <span class="kwrd">public</span> <span class="kwrd">void</span> LoadData()
        {
            <span class="kwrd">using</span> (XmlReader reader = XmlReader.Create(<span class="str">&quot;drinks.xml&quot;</span>))
            {
                <span class="kwrd">while</span> (reader.Read())
                {
                    <span class="kwrd">if</span> (reader.IsStartElement())
                    {
                        <span class="kwrd">if</span> (reader.IsEmptyElement)
                            Console.WriteLine(<span class="str">&quot;&lt;{0}/&gt;&quot;</span>, reader.Name);
                        <span class="kwrd">else</span>
                        {
                            Console.Write(<span class="str">&quot;&lt;{0}&gt; &quot;</span>, reader.Name);
                            reader.Read(); <span class="rem">// Read the start tag.</span>

                            <span class="kwrd">if</span> (reader.IsStartElement()) <span class="rem">// Handle nested elements.</span>
                                Console.Write(<span class="str">&quot;\r\n&lt;{0}&gt;&quot;</span>, reader.Name);
                            <span class="kwrd">string</span> drinkName = reader.GetAttribute(<span class="str">&quot;Name&quot;</span>);
                            <span class="kwrd">if</span> (!String.IsNullOrEmpty(drinkName))
                                Drinks.Add(<span class="kwrd">new</span> DrinkViewModel { DrinkName = drinkName });
                            Console.WriteLine(drinkName); <span class="rem">//Read the text content of the element.</span>
                        }
                    }
                    <span class="kwrd">else</span>
                    {
                        Console.Write(<span class="str">&quot;&lt;{0}&gt; &quot;</span>, reader.Name);
                        reader.Read(); <span class="rem">// Read the start tag.</span>

                        <span class="kwrd">if</span> (reader.IsStartElement()) <span class="rem">// Handle nested elements.</span>
                            Console.Write(<span class="str">&quot;\r\n&lt;{0}&gt;&quot;</span>, reader.Name);

                        var drink = <span class="kwrd">new</span> DrinkViewModel();
                        <span class="kwrd">string</span> drinkName = reader.GetAttribute(<span class="str">&quot;Name&quot;</span>);
                        <span class="kwrd">string</span> ingredient = <span class="kwrd">string</span>.Empty;

                        <span class="kwrd">if</span> (!String.IsNullOrEmpty(drinkName))
                        {
                            XmlReader readerSubtree = reader.ReadSubtree();

                            <span class="kwrd">while</span> (readerSubtree.Read())
                            {
                                <span class="kwrd">if</span> (readerSubtree.Name == <span class="str">&quot;Ingredient&quot;</span>)
                                {
                                    ingredient = readerSubtree.GetAttribute(<span class="str">&quot;Ingredient&quot;</span>);

                                    <span class="kwrd">if</span> (drink.Ingredients == <span class="kwrd">null</span>)
                                        drink.Ingredients = <span class="kwrd">new</span> ObservableCollection&lt;<span class="kwrd">string</span>&gt;();

                                    <span class="kwrd">if</span> (ingredient != <span class="kwrd">null</span> &amp;&amp; !ingredient.Contains(<span class="str">&quot;Category:&quot;</span>))
                                        drink.Ingredients.Add(ingredient);

                                    <span class="kwrd">if</span> (ingredient != <span class="kwrd">null</span> &amp;&amp; ingredient.Contains(<span class="str">&quot;Category:&quot;</span>))
                                    {
                                        drink.Category = ingredient.Substring(9);
                                    }
                                }
                            }

                            drink.DrinkName = drinkName;
                            Drinks.Add(drink);
                        }

                        Console.WriteLine(drinkName);
                    }
                }
            }

            IsDataLoaded = <span class="kwrd">true</span>;
        }

        <span class="kwrd">private</span> <span class="kwrd">void</span> NotifyPropertyChanged(String propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            <span class="kwrd">if</span> (<span class="kwrd">null</span> != handler)
            {
                handler(<span class="kwrd">this</span>, <span class="kwrd">new</span> PropertyChangedEventArgs(propertyName));
            }
        }
    }</pre>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>&#160;</p>
<p>Binding this content to the <strong>MainPage.xaml</strong> is also a pretty quick task.&#160; I simply adjusted the <strong>StackPanel</strong> and added some additional <strong>TextBlocks</strong>.</p>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">controls:PanoramaItem</span> <span class="attr">Header</span><span class="kwrd">=&quot;Recent&quot;</span><span class="kwrd">&gt;</span>
    <span class="rem">&lt;!--Double line list with text wrapping--&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">ListBox</span> <span class="attr">Margin</span><span class="kwrd">=&quot;0,0,-12,0&quot;</span>
             <span class="attr">ItemsSource</span><span class="kwrd">=&quot;{Binding Drinks}&quot;</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">ListBox.ItemTemplate</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">DataTemplate</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">StackPanel</span> <span class="attr">Margin</span><span class="kwrd">=&quot;0,0,0,17&quot;</span>
                            <span class="attr">Width</span><span class="kwrd">=&quot;432&quot;</span><span class="kwrd">&gt;</span>
                    <span class="kwrd">&lt;</span><span class="html">TextBlock</span> <span class="attr">Text</span><span class="kwrd">=&quot;{Binding DrinkName,Mode=OneTime}&quot;</span>
                               <span class="attr">TextWrapping</span><span class="kwrd">=&quot;Wrap&quot;</span>
                               <span class="attr">Style</span><span class="kwrd">=&quot;{StaticResource PhoneTextExtraLargeStyle}&quot;</span> <span class="kwrd">/&gt;</span>
                    <span class="kwrd">&lt;</span><span class="html">TextBlock</span> <span class="attr">Text</span><span class="kwrd">=&quot;{Binding Category, Mode=OneTime}&quot;</span>
                               <span class="attr">TextWrapping</span><span class="kwrd">=&quot;Wrap&quot;</span>
                               <span class="attr">Foreground</span><span class="kwrd">=&quot;Yellow&quot;</span>
                               <span class="attr">Style</span><span class="kwrd">=&quot;{StaticResource PhoneTextSmallStyle}&quot;</span> <span class="kwrd">/&gt;</span>
                    <span class="kwrd">&lt;</span><span class="html">TextBlock</span> <span class="attr">Text</span><span class="kwrd">=&quot;{Binding IngredientsFormatted, Mode=OneTime}&quot;</span>
                               <span class="attr">TextWrapping</span><span class="kwrd">=&quot;Wrap&quot;</span>
                               <span class="attr">Style</span><span class="kwrd">=&quot;{StaticResource PhoneTextSmallStyle}&quot;</span> <span class="kwrd">/&gt;</span>
                <span class="kwrd">&lt;/</span><span class="html">StackPanel</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;/</span><span class="html">DataTemplate</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">ListBox.ItemTemplate</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">ListBox</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">controls:PanoramaItem</span><span class="kwrd">&gt;</span></pre>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>&#160;</p>
<p>The result is that I now have a scrollable list of drinks, with their recipes.</p>
<p><a href="http://davecorun.com/blog/wp-content/uploads/2010/10/realdrinks.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="realdrinks" border="0" alt="realdrinks" src="http://davecorun.com/blog/wp-content/uploads/2010/10/realdrinks_thumb.png" width="254" height="484" /></a></p>
<p><strong>Next Steps</strong></p>
<p>I need to add a new Windows Phone Page so that when the user selects a drink, they can view the complete details.&#160; Naturally this needs to work with the back button as well.</p>
<p>&#160;</p>
<p>So far, so good.&#160; Windows Phone development is fun!</p>
<p>// Dave</p>
]]></content:encoded>
			<wfw:commentRss>http://davecorun.com/blog/2010/10/17/my-first-windows-phone-7-app/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
