<?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>CraigW Blog</title>
	<atom:link href="http://www.craigwardman.com/blog/index.php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.craigwardman.com/blog</link>
	<description>A catalogue of my discoveries in software development and related subjects, that I think might be of use or interest to everyone else, or to me when I forget what I did!</description>
	<lastBuildDate>Thu, 08 Dec 2011 12:10:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Fixing Dodgy Characters in SQL</title>
		<link>http://www.craigwardman.com/blog/index.php/2011/12/fixing-dodgy-characters-in-sql/</link>
		<comments>http://www.craigwardman.com/blog/index.php/2011/12/fixing-dodgy-characters-in-sql/#comments</comments>
		<pubDate>Thu, 08 Dec 2011 12:09:03 +0000</pubDate>
		<dc:creator>craig w</dc:creator>
				<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://www.craigwardman.com/blog/?p=161</guid>
		<description><![CDATA[When dealing with Unicode/nvarchar data in SQL, sometimes some unwanted characters can sneak into the database which may break things, or look wrong if you&#8217;re not expecting them. One example of this is if you use an XML serializer on data containing character 0x0B, it will throw an exception. To find and replace this data, [...]]]></description>
			<content:encoded><![CDATA[<p>When dealing with Unicode/nvarchar data in SQL, sometimes some unwanted characters can sneak into the database which may break things, or look wrong if you&#8217;re not expecting them.</p>
<p>One example of this is if you use an XML serializer on data containing character 0x0B, it will throw an exception.</p>
<p>To find and replace this data, you need to use the BINARY collation as SQL will not find any characters outside of the normal set using the normal collations.</p>
<p>Example of a replace 0x0B:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;color: #c0c0c0; font-family: Franklin Gothic Book;"><span style="color: #993333; font-weight: bold;color: #C2964B; font-weight: bold;">UPDATE</span>
MyTable
<span style="color: #993333; font-weight: bold;color: #C2964B; font-weight: bold;">SET</span>
MyField <span style="color: #66cc66;color: #c0c0c0;">=</span> <span style="color: #993333; font-weight: bold;color: #C2964B; font-weight: bold;">REPLACE</span><span style="color: #66cc66;color: #c0c0c0;">&#40;</span>MyField COLLATE 	
Latin1_General_BIN<span style="color: #66cc66;color: #c0c0c0;">,</span> NCHAR<span style="color: #66cc66;color: #c0c0c0;">&#40;</span><span style="color: #cc66cc;color: #8ACCCF;">11</span><span style="color: #66cc66;color: #c0c0c0;">&#41;</span><span style="color: #66cc66;color: #c0c0c0;">,</span> <span style="color: #ff0000;color: #C89191;">''</span><span style="color: #66cc66;color: #c0c0c0;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.craigwardman.com/blog/index.php/2011/12/fixing-dodgy-characters-in-sql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating a Multi-Select Drop Down List in Silverlight</title>
		<link>http://www.craigwardman.com/blog/index.php/2011/08/creating-a-multi-select-drop-down-list-in-silverlight/</link>
		<comments>http://www.craigwardman.com/blog/index.php/2011/08/creating-a-multi-select-drop-down-list-in-silverlight/#comments</comments>
		<pubDate>Wed, 24 Aug 2011 09:55:08 +0000</pubDate>
		<dc:creator>craig w</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C Sharp]]></category>
		<category><![CDATA[Silverlight]]></category>

		<guid isPermaLink="false">http://www.craigwardman.com/blog/?p=157</guid>
		<description><![CDATA[This is quite a common task/requirement, to have a drop down/combo interface with checkable options inside. Silverlight is quite good at this due to its databound approach to displaying and manipulating data. As a preface, lets assume you have wrapped your IEnumerable data in a wrapper class that contains the data item and a &#8216;Selected&#8217; [...]]]></description>
			<content:encoded><![CDATA[<p>This is quite a common task/requirement, to have a drop down/combo interface with checkable options inside. </p>
<p>Silverlight is quite good at this due to its databound approach to displaying and manipulating data.</p>
<p>As a preface, lets assume you have wrapped your IEnumerable data in a wrapper class that contains the data item and a &#8216;Selected&#8217; property, for example:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;color: #c0c0c0; font-family: Franklin Gothic Book;"><span style="color: #0600FF;color: #C2964B; font-weight: bold;">public</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">class</span> SelectableObject <span style="color: #008000;color: #c0c0c0;">:</span> ComponentModel.<span style="color: #0000FF;color: #c0c0c0;">INotifyPropertyChanged</span>
<span style="color: #000000;color: #c0c0c0;">&#123;</span>
&nbsp;
    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">private</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">bool</span> _selected<span style="color: #008000;color: #c0c0c0;">;</span>
    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">public</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">bool</span> Selected
    <span style="color: #000000;color: #c0c0c0;">&#123;</span>
        get <span style="color: #000000;color: #c0c0c0;">&#123;</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">return</span> _selected<span style="color: #008000;color: #c0c0c0;">;</span> <span style="color: #000000;color: #c0c0c0;">&#125;</span>
        set
        <span style="color: #000000;color: #c0c0c0;">&#123;</span>
            _selected <span style="color: #008000;color: #c0c0c0;">=</span> value<span style="color: #008000;color: #c0c0c0;">;</span>
&nbsp;
            OnPropertyChanged<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #666666;color: #C89191;">&quot;Selected&quot;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #008000;color: #c0c0c0;">;</span>
        <span style="color: #000000;color: #c0c0c0;">&#125;</span>
    <span style="color: #000000;color: #c0c0c0;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">public</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">object</span> DataItem <span style="color: #000000;color: #c0c0c0;">&#123;</span> get<span style="color: #008000;color: #c0c0c0;">;</span> set<span style="color: #008000;color: #c0c0c0;">;</span> <span style="color: #000000;color: #c0c0c0;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">public</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">event</span> PropertyChangedEventHandler PropertyChanged<span style="color: #008000;color: #c0c0c0;">;</span>
    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">protected</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">void</span> OnPropertyChanged<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF0000;color: #C2964B; font-weight: bold;">string</span> propertyName<span style="color: #000000;color: #c0c0c0;">&#41;</span>
    <span style="color: #000000;color: #c0c0c0;">&#123;</span>
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">if</span> <span style="color: #000000;color: #c0c0c0;">&#40;</span>PropertyChanged <span style="color: #008000;color: #c0c0c0;">!=</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">null</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
            PropertyChanged<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #0600FF;color: #C2964B; font-weight: bold;">this</span>, <span style="color: #008000;color: #2B91AF;">new</span> PropertyChangedEventArgs<span style="color: #000000;color: #c0c0c0;">&#40;</span>propertyName<span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #008000;color: #c0c0c0;">;</span>
    <span style="color: #000000;color: #c0c0c0;">&#125;</span>
<span style="color: #000000;color: #c0c0c0;">&#125;</span></pre></div></div>

<p>Now that you have a datasource which has the properties needed to bind a selectable list you can display the data in a modified combo box which is designed to work with this kind of data. I based my combo box on the RadComboBox (prism version), but this can likely be easily translated to any other base implementation:</p>
<p>XAML:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;color: #c0c0c0; font-family: Franklin Gothic Book;"><span style="color: #c0c0c0;"><span style="color: #efef8f; font-weight: bold;color: #efef8f;">&lt;UserControl</span> <span style="color: #2b91af;">x:Class</span>=<span style="color: #ff0000;color: #C89191;">&quot;FQNS.MultiSelectDropDown&quot;</span></span>
<span style="color: #c0c0c0;">    <span style="color: #2b91af;">xmlns</span>=<span style="color: #ff0000;color: #C89191;">&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;</span></span>
<span style="color: #c0c0c0;">    <span style="color: #2b91af;">xmlns:x</span>=<span style="color: #ff0000;color: #C89191;">&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;</span></span>
<span style="color: #c0c0c0;">    <span style="color: #2b91af;">xmlns:d</span>=<span style="color: #ff0000;color: #C89191;">&quot;http://schemas.microsoft.com/expression/blend/2008&quot;</span></span>
<span style="color: #c0c0c0;">    <span style="color: #2b91af;">xmlns:mc</span>=<span style="color: #ff0000;color: #C89191;">&quot;http://schemas.openxmlformats.org/markup-compatibility/2006&quot;</span></span>
<span style="color: #c0c0c0;">    <span style="color: #2b91af;">mc:Ignorable</span>=<span style="color: #ff0000;color: #C89191;">&quot;d&quot;</span></span>
<span style="color: #c0c0c0;">             <span style="color: #2b91af;">xmlns:my</span>=<span style="color: #ff0000;color: #C89191;">&quot;clr-namespace:ExternalControls.TelerikForPrism;assembly=ExternalControls.TelerikForPrism&quot;</span></span>
<span style="color: #c0c0c0;">    <span style="color: #2b91af;">d:DesignHeight</span>=<span style="color: #ff0000;color: #C89191;">&quot;300&quot;</span> <span style="color: #2b91af;">d:DesignWidth</span>=<span style="color: #ff0000;color: #C89191;">&quot;400&quot;</span><span style="color: #efef8f; font-weight: bold;">&gt;</span></span>
&nbsp;
    <span style="color: #c0c0c0;"><span style="color: #efef8f; font-weight: bold;color: #efef8f;">&lt;Grid</span> <span style="color: #2b91af;">x:Name</span>=<span style="color: #ff0000;color: #C89191;">&quot;LayoutRoot&quot;</span><span style="color: #efef8f; font-weight: bold;">&gt;</span></span>
        <span style="color: #c0c0c0;"><span style="color: #efef8f; font-weight: bold;color: #efef8f;">&lt;my:PrismRadComboBox</span> <span style="color: #2b91af;">ItemsSource</span>=<span style="color: #ff0000;color: #C89191;">&quot;{Binding}&quot;</span>  <span style="color: #2b91af;">Name</span>=<span style="color: #ff0000;color: #C89191;">&quot;cmbComboBox&quot;</span> <span style="color: #2b91af;">EmptyText</span>=<span style="color: #ff0000;color: #C89191;">&quot;-All-&quot;</span> <span style="color: #2b91af;">Margin</span>=<span style="color: #ff0000;color: #C89191;">&quot;0,0,0,2&quot;</span> <span style="color: #2b91af;">SelectionChanged</span>=<span style="color: #ff0000;color: #C89191;">&quot;cmbComboBox_SelectionChanged&quot;</span> <span style="color: #2b91af;">DropDownClosed</span>=<span style="color: #ff0000;color: #C89191;">&quot;cmbComboBox_DropDownClosed&quot;</span><span style="color: #efef8f; font-weight: bold;">&gt;</span></span>
            <span style="color: #808080; font-style: italic;">&lt;!-- Data Template is defined in code behind--&gt;</span>
        <span style="color: #c0c0c0;"><span style="color: #efef8f; font-weight: bold;color: #efef8f;">&lt;/my:PrismRadComboBox<span style="color: #efef8f; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #c0c0c0;"><span style="color: #efef8f; font-weight: bold;color: #efef8f;">&lt;/Grid<span style="color: #efef8f; font-weight: bold;">&gt;</span></span></span>
<span style="color: #c0c0c0;"><span style="color: #efef8f; font-weight: bold;color: #efef8f;">&lt;/UserControl<span style="color: #efef8f; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Code-behind:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;color: #c0c0c0; font-family: Franklin Gothic Book;"><span style="color: #0600FF;color: #C2964B; font-weight: bold;">public</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">partial</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">class</span> MultiSelectDropDown <span style="color: #008000;color: #c0c0c0;">:</span> UserControl
<span style="color: #000000;color: #c0c0c0;">&#123;</span>
    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">public</span> MultiSelectDropDown<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
    <span style="color: #000000;color: #c0c0c0;">&#123;</span>
        InitializeComponent<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #008000;color: #c0c0c0;">;</span>
&nbsp;
    <span style="color: #000000;color: #c0c0c0;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">private</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">string</span> _displayMemberPath<span style="color: #008000;color: #c0c0c0;">;</span>
    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">public</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">string</span> DisplayMemberPath
    <span style="color: #000000;color: #c0c0c0;">&#123;</span>
        get <span style="color: #000000;color: #c0c0c0;">&#123;</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">return</span> _displayMemberPath<span style="color: #008000;color: #c0c0c0;">;</span> <span style="color: #000000;color: #c0c0c0;">&#125;</span>
        set
        <span style="color: #000000;color: #c0c0c0;">&#123;</span>
            _displayMemberPath <span style="color: #008000;color: #c0c0c0;">=</span> value<span style="color: #008000;color: #c0c0c0;">;</span>
            cmbComboBox.<span style="color: #0000FF;color: #c0c0c0;">ItemTemplate</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #000000;color: #c0c0c0;">&#40;</span>DataTemplate<span style="color: #000000;color: #c0c0c0;">&#41;</span>XamlReader.<span style="color: #0000FF;color: #c0c0c0;">Load</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #666666;">@&quot;
            &lt;DataTemplate xmlns=&quot;</span><span style="color: #666666;color: #C89191;">&quot;http://schemas.microsoft.com/client/2007&quot;</span><span style="color: #666666;color: #C89191;">&quot;&gt;
                &lt;StackPanel Orientation=&quot;</span><span style="color: #666666;color: #C89191;">&quot;Horizontal&quot;</span><span style="color: #666666;color: #C89191;">&quot;&gt;
                    &lt;CheckBox IsChecked=&quot;</span><span style="color: #666666;color: #C89191;">&quot;{Binding Selected, Mode=TwoWay}&quot;</span><span style="color: #666666;color: #C89191;">&quot;&gt;&lt;/CheckBox&gt;
                    &lt;TextBlock Text=&quot;</span><span style="color: #666666;color: #C89191;">&quot;{Binding Path=&quot;</span> <span style="color: #008000;color: #c0c0c0;">+</span> DisplayMemberPath <span style="color: #008000;color: #c0c0c0;">+</span> <span style="color: #666666;">@&quot;}&quot;</span><span style="color: #666666;color: #C89191;">&quot;&gt;&lt;/TextBlock&gt;
                &lt;/StackPanel&gt;
            &lt;/DataTemplate&gt;&quot;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #008000;color: #c0c0c0;">;</span>
        <span style="color: #000000;color: #c0c0c0;">&#125;</span>
    <span style="color: #000000;color: #c0c0c0;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">private</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">void</span> cmbComboBox_SelectionChanged<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF0000;color: #C2964B; font-weight: bold;">object</span> sender, Telerik.<span style="color: #0000FF;color: #c0c0c0;">Windows</span>.<span style="color: #0000FF;color: #c0c0c0;">Controls</span>.<span style="color: #0000FF;color: #c0c0c0;">SelectionChangedEventArgs</span> e<span style="color: #000000;color: #c0c0c0;">&#41;</span>
    <span style="color: #000000;color: #c0c0c0;">&#123;</span>
        <span style="color: #008080; font-style: italic;color: #7F9F7F;">//we actually dont want 'selections' to be made, so always select -1 but tick the selected item</span>
        SetItemSelectedProperty<span style="color: #000000;color: #c0c0c0;">&#40;</span>cmbComboBox.<span style="color: #0000FF;color: #c0c0c0;">SelectedItem</span>, <span style="color: #0600FF;color: #C2964B; font-weight: bold;">true</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #008000;color: #c0c0c0;">;</span>
&nbsp;
        cmbComboBox.<span style="color: #0000FF;color: #c0c0c0;">SelectedIndex</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #008000;color: #c0c0c0;">-</span><span style="color: #FF0000;color: #8ACCCF;">1</span><span style="color: #008000;color: #c0c0c0;">;</span>
    <span style="color: #000000;color: #c0c0c0;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">private</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">void</span> SetComboText<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
    <span style="color: #000000;color: #c0c0c0;">&#123;</span>
        <span style="color: #008080; font-style: italic;color: #7F9F7F;">//at this point the data context should be at least IEnumerable</span>
        IEnumerable objectList <span style="color: #008000;color: #c0c0c0;">=</span> DataContext <span style="color: #0600FF;color: #C2964B; font-weight: bold;">as</span> IEnumerable<span style="color: #008000;color: #c0c0c0;">;</span>
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">if</span> <span style="color: #000000;color: #c0c0c0;">&#40;</span>objectList <span style="color: #008000;color: #c0c0c0;">!=</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">null</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
        <span style="color: #000000;color: #c0c0c0;">&#123;</span>
            List<span style="color: #008000;color: #c0c0c0;">&lt;</span><span style="color: #FF0000;color: #C2964B; font-weight: bold;">object</span><span style="color: #008000;color: #c0c0c0;">&gt;</span> selectedItems <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #0600FF;color: #C2964B; font-weight: bold;">from</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">object</span> o <span style="color: #0600FF;color: #C2964B; font-weight: bold;">in</span> objectList where GetItemSelectedProperty<span style="color: #000000;color: #c0c0c0;">&#40;</span>o<span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #008000;color: #c0c0c0;">==</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">true</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">select</span> o<span style="color: #000000;color: #c0c0c0;">&#41;</span>.<span style="color: #0000FF;color: #c0c0c0;">ToList</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #008000;color: #c0c0c0;">;</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">switch</span> <span style="color: #000000;color: #c0c0c0;">&#40;</span>selectedItems.<span style="color: #0000FF;color: #c0c0c0;">Count</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
            <span style="color: #000000;color: #c0c0c0;">&#123;</span>
                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">case</span> <span style="color: #FF0000;color: #8ACCCF;">0</span><span style="color: #008000;color: #c0c0c0;">:</span>
                    cmbComboBox.<span style="color: #0000FF;color: #c0c0c0;">EmptyText</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #666666;color: #C89191;">&quot;-All-&quot;</span><span style="color: #008000;color: #c0c0c0;">;</span>
                    break<span style="color: #008000;color: #c0c0c0;">;</span>
                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">case</span> <span style="color: #FF0000;color: #8ACCCF;">1</span><span style="color: #008000;color: #c0c0c0;">:</span>
                    cmbComboBox.<span style="color: #0000FF;color: #c0c0c0;">EmptyText</span> <span style="color: #008000;color: #c0c0c0;">=</span> GetItemDisplayProperty<span style="color: #000000;color: #c0c0c0;">&#40;</span>selectedItems<span style="color: #000000;color: #c0c0c0;">&#91;</span><span style="color: #FF0000;color: #8ACCCF;">0</span><span style="color: #000000;color: #c0c0c0;">&#93;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #008000;color: #c0c0c0;">;</span>
                    break<span style="color: #008000;color: #c0c0c0;">;</span>
                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">default</span><span style="color: #008000;color: #c0c0c0;">:</span>
                    cmbComboBox.<span style="color: #0000FF;color: #c0c0c0;">EmptyText</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #666666;color: #C89191;">&quot;Multiple Selections..&quot;</span><span style="color: #008000;color: #c0c0c0;">;</span>
                    break<span style="color: #008000;color: #c0c0c0;">;</span>
            <span style="color: #000000;color: #c0c0c0;">&#125;</span>
&nbsp;
        <span style="color: #000000;color: #c0c0c0;">&#125;</span>
    <span style="color: #000000;color: #c0c0c0;">&#125;</span>
&nbsp;
&nbsp;
    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">private</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">void</span> SetItemSelectedProperty<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF0000;color: #C2964B; font-weight: bold;">object</span> dataItem, <span style="color: #FF0000;color: #C2964B; font-weight: bold;">bool</span> value<span style="color: #000000;color: #c0c0c0;">&#41;</span>
    <span style="color: #000000;color: #c0c0c0;">&#123;</span>
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">if</span> <span style="color: #000000;color: #c0c0c0;">&#40;</span>dataItem <span style="color: #008000;color: #c0c0c0;">!=</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">null</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
        <span style="color: #000000;color: #c0c0c0;">&#123;</span>
            <span style="color: #008080; font-style: italic;color: #7F9F7F;">//get the 'Selected' property and confirm its a correct type</span>
            PropertyInfo selectedProp <span style="color: #008000;color: #c0c0c0;">=</span> dataItem.<span style="color: #0000FF;color: #c0c0c0;">GetType</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>.<span style="color: #0000FF;color: #c0c0c0;">GetProperty</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #666666;color: #C89191;">&quot;Selected&quot;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #008000;color: #c0c0c0;">;</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">if</span> <span style="color: #000000;color: #c0c0c0;">&#40;</span>selectedProp <span style="color: #008000;color: #c0c0c0;">!=</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">null</span> <span style="color: #008000;color: #c0c0c0;">&amp;&amp;</span> selectedProp.<span style="color: #0000FF;color: #c0c0c0;">PropertyType</span> <span style="color: #008000;color: #c0c0c0;">==</span> value.<span style="color: #0000FF;color: #c0c0c0;">GetType</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
            <span style="color: #000000;color: #c0c0c0;">&#123;</span>
                selectedProp.<span style="color: #0000FF;color: #c0c0c0;">SetValue</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>dataItem, value, <span style="color: #0600FF;color: #C2964B; font-weight: bold;">null</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #008000;color: #c0c0c0;">;</span>
            <span style="color: #000000;color: #c0c0c0;">&#125;</span>
        <span style="color: #000000;color: #c0c0c0;">&#125;</span>
    <span style="color: #000000;color: #c0c0c0;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">private</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">bool</span> GetItemSelectedProperty<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF0000;color: #C2964B; font-weight: bold;">object</span> dataItem<span style="color: #000000;color: #c0c0c0;">&#41;</span>
    <span style="color: #000000;color: #c0c0c0;">&#123;</span>
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">if</span> <span style="color: #000000;color: #c0c0c0;">&#40;</span>dataItem <span style="color: #008000;color: #c0c0c0;">!=</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">null</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
        <span style="color: #000000;color: #c0c0c0;">&#123;</span>
            <span style="color: #008080; font-style: italic;color: #7F9F7F;">//get the 'Selected' property and confirm its a boolean type</span>
            PropertyInfo selectedProp <span style="color: #008000;color: #c0c0c0;">=</span> dataItem.<span style="color: #0000FF;color: #c0c0c0;">GetType</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>.<span style="color: #0000FF;color: #c0c0c0;">GetProperty</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #666666;color: #C89191;">&quot;Selected&quot;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #008000;color: #c0c0c0;">;</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">if</span> <span style="color: #000000;color: #c0c0c0;">&#40;</span>selectedProp <span style="color: #008000;color: #c0c0c0;">!=</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">null</span> <span style="color: #008000;color: #c0c0c0;">&amp;&amp;</span> selectedProp.<span style="color: #0000FF;color: #c0c0c0;">PropertyType</span> <span style="color: #008000;color: #c0c0c0;">==</span> <span style="color: #008000;color: #2B91AF;">typeof</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF0000;color: #C2964B; font-weight: bold;">bool</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
            <span style="color: #000000;color: #c0c0c0;">&#123;</span>
                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">return</span> <span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF0000;color: #C2964B; font-weight: bold;">bool</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>selectedProp.<span style="color: #0000FF;color: #c0c0c0;">GetValue</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>dataItem, <span style="color: #0600FF;color: #C2964B; font-weight: bold;">null</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #008000;color: #c0c0c0;">;</span>
            <span style="color: #000000;color: #c0c0c0;">&#125;</span>
        <span style="color: #000000;color: #c0c0c0;">&#125;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;color: #7F9F7F;">//default to not selected</span>
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">return</span> false<span style="color: #008000;color: #c0c0c0;">;</span>
    <span style="color: #000000;color: #c0c0c0;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">private</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">string</span> GetItemDisplayProperty<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF0000;color: #C2964B; font-weight: bold;">object</span> dataItem<span style="color: #000000;color: #c0c0c0;">&#41;</span>
    <span style="color: #000000;color: #c0c0c0;">&#123;</span>
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">if</span> <span style="color: #000000;color: #c0c0c0;">&#40;</span>dataItem <span style="color: #008000;color: #c0c0c0;">==</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">null</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">throw</span> <span style="color: #008000;color: #2B91AF;">new</span> ArgumentNullException<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #666666;color: #C89191;">&quot;dataItem&quot;</span>, <span style="color: #666666;color: #C89191;">&quot;Data Item cannot be NULL&quot;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #008000;color: #c0c0c0;">;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;color: #7F9F7F;">//get the 'DisplayMemberPath' property</span>
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">if</span> <span style="color: #000000;color: #c0c0c0;">&#40;</span>DisplayMemberPath.<span style="color: #0000FF;color: #c0c0c0;">Contains</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #666666;color: #C89191;">&quot;.&quot;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
        <span style="color: #000000;color: #c0c0c0;">&#123;</span>
            <span style="color: #008080; font-style: italic;color: #7F9F7F;">//child property - iterate the tree</span>
            Type currentType <span style="color: #008000;color: #c0c0c0;">=</span> dataItem.<span style="color: #0000FF;color: #c0c0c0;">GetType</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #008000;color: #c0c0c0;">;</span>
            <span style="color: #FF0000;color: #C2964B; font-weight: bold;">object</span> currentValue <span style="color: #008000;color: #c0c0c0;">=</span> dataItem<span style="color: #008000;color: #c0c0c0;">;</span>
&nbsp;
            <span style="color: #FF0000;color: #C2964B; font-weight: bold;">string</span><span style="color: #000000;color: #c0c0c0;">&#91;</span><span style="color: #000000;color: #c0c0c0;">&#93;</span> props <span style="color: #008000;color: #c0c0c0;">=</span> DisplayMemberPath.<span style="color: #0000FF;color: #c0c0c0;">Split</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #666666;color: #C89191;">'.'</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #008000;color: #c0c0c0;">;</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">foreach</span> <span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF0000;color: #C2964B; font-weight: bold;">string</span> p <span style="color: #0600FF;color: #C2964B; font-weight: bold;">in</span> props<span style="color: #000000;color: #c0c0c0;">&#41;</span>
            <span style="color: #000000;color: #c0c0c0;">&#123;</span>
                PropertyInfo thisProp <span style="color: #008000;color: #c0c0c0;">=</span> currentType.<span style="color: #0000FF;color: #c0c0c0;">GetProperty</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>p<span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #008000;color: #c0c0c0;">;</span>
                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">if</span> <span style="color: #000000;color: #c0c0c0;">&#40;</span>thisProp <span style="color: #008000;color: #c0c0c0;">!=</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">null</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
                <span style="color: #000000;color: #c0c0c0;">&#123;</span>
                    currentType <span style="color: #008000;color: #c0c0c0;">=</span> thisProp.<span style="color: #0000FF;color: #c0c0c0;">PropertyType</span><span style="color: #008000;color: #c0c0c0;">;</span>
                    currentValue <span style="color: #008000;color: #c0c0c0;">=</span> thisProp.<span style="color: #0000FF;color: #c0c0c0;">GetValue</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>currentValue, <span style="color: #0600FF;color: #C2964B; font-weight: bold;">null</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #008000;color: #c0c0c0;">;</span>
                <span style="color: #000000;color: #c0c0c0;">&#125;</span>
                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">else</span>
                <span style="color: #000000;color: #c0c0c0;">&#123;</span>
                    break<span style="color: #008000;color: #c0c0c0;">;</span>
                <span style="color: #000000;color: #c0c0c0;">&#125;</span>
            <span style="color: #000000;color: #c0c0c0;">&#125;</span>
&nbsp;
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">return</span> <span style="color: #000000;color: #c0c0c0;">&#40;</span>currentValue <span style="color: #008000;color: #c0c0c0;">!=</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">null</span> <span style="color: #008000;color: #c0c0c0;">?</span> currentValue.<span style="color: #0000FF;color: #c0c0c0;">ToString</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #008000;color: #c0c0c0;">:</span> dataItem.<span style="color: #0000FF;color: #c0c0c0;">ToString</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #008000;color: #c0c0c0;">;</span>
        <span style="color: #000000;color: #c0c0c0;">&#125;</span>
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">else</span>
        <span style="color: #000000;color: #c0c0c0;">&#123;</span>
            <span style="color: #008080; font-style: italic;color: #7F9F7F;">//direct property</span>
            PropertyInfo displayProp <span style="color: #008000;color: #c0c0c0;">=</span> dataItem.<span style="color: #0000FF;color: #c0c0c0;">GetType</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>.<span style="color: #0000FF;color: #c0c0c0;">GetProperty</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>DisplayMemberPath<span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #008000;color: #c0c0c0;">;</span>
&nbsp;
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">if</span> <span style="color: #000000;color: #c0c0c0;">&#40;</span>displayProp <span style="color: #008000;color: #c0c0c0;">!=</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">null</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
            <span style="color: #000000;color: #c0c0c0;">&#123;</span>
                <span style="color: #FF0000;color: #C2964B; font-weight: bold;">object</span> propVal <span style="color: #008000;color: #c0c0c0;">=</span> displayProp.<span style="color: #0000FF;color: #c0c0c0;">GetValue</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>dataItem, <span style="color: #0600FF;color: #C2964B; font-weight: bold;">null</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #008000;color: #c0c0c0;">;</span>
                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">if</span> <span style="color: #000000;color: #c0c0c0;">&#40;</span>propVal <span style="color: #008000;color: #c0c0c0;">!=</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">null</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
                    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">return</span> propVal.<span style="color: #0000FF;color: #c0c0c0;">ToString</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #008000;color: #c0c0c0;">;</span>
            <span style="color: #000000;color: #c0c0c0;">&#125;</span>
        <span style="color: #000000;color: #c0c0c0;">&#125;</span>
        <span style="color: #008080; font-style: italic;color: #7F9F7F;">//default to return the obejct itself</span>
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">return</span> dataItem.<span style="color: #0000FF;color: #c0c0c0;">ToString</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #008000;color: #c0c0c0;">;</span>
    <span style="color: #000000;color: #c0c0c0;">&#125;</span>
&nbsp;
&nbsp;
    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">private</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">void</span> cmbComboBox_DropDownClosed<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF0000;color: #C2964B; font-weight: bold;">object</span> sender, EventArgs e<span style="color: #000000;color: #c0c0c0;">&#41;</span>
    <span style="color: #000000;color: #c0c0c0;">&#123;</span>
            SetComboText<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #008000;color: #c0c0c0;">;</span>
    <span style="color: #000000;color: #c0c0c0;">&#125;</span>
&nbsp;
<span style="color: #000000;color: #c0c0c0;">&#125;</span></pre></div></div>

<p>Example Usage:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;color: #c0c0c0; font-family: Franklin Gothic Book;"><span style="color: #c0c0c0;"><span style="color: #efef8f; font-weight: bold;color: #efef8f;">&lt;my:MultiSelectDropDown</span> <span style="color: #2b91af;">DataContext</span>=<span style="color: #ff0000;color: #C89191;">&quot;{Binding MySelectableDataSource, Mode=TwoWay}&quot;</span> <span style="color: #2b91af;">DisplayMemberPath</span>=<span style="color: #ff0000;color: #C89191;">&quot;DataItem.Name&quot;</span><span style="color: #efef8f; font-weight: bold;">&gt;</span><span style="color: #efef8f; font-weight: bold;color: #efef8f;">&lt;/my:MultiSelectDropDown<span style="color: #efef8f; font-weight: bold;">&gt;</span></span></span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.craigwardman.com/blog/index.php/2011/08/creating-a-multi-select-drop-down-list-in-silverlight/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dynamic OrderBy using LINQ to SQL</title>
		<link>http://www.craigwardman.com/blog/index.php/2011/08/dynamic-orderby-using-linq-to-sql/</link>
		<comments>http://www.craigwardman.com/blog/index.php/2011/08/dynamic-orderby-using-linq-to-sql/#comments</comments>
		<pubDate>Mon, 22 Aug 2011 11:17:41 +0000</pubDate>
		<dc:creator>craig w</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C Sharp]]></category>
		<category><![CDATA[LINQ]]></category>

		<guid isPermaLink="false">http://www.craigwardman.com/blog/?p=154</guid>
		<description><![CDATA[Following on from my last post on Virtual Paging with Silverlight/WCF Services, the next topic to go hand in hand with this is dynamically ordering your data when using LINQ to SQL as a backend. Ordinarily I use my own data architecture, so haven&#8217;t run into this problem of using LINQ to SQL and trying [...]]]></description>
			<content:encoded><![CDATA[<p>Following on from my last post on <a href="/blog/index.php/2011/08/virtual-paging-with-silverlightwcf-services/">Virtual Paging with Silverlight/WCF Services</a>, the next topic to go hand in hand with this is dynamically ordering your data when using LINQ to SQL as a backend.</p>
<p>Ordinarily I use my own data architecture, so haven&#8217;t run into this problem of using LINQ to SQL and trying to pass your order by clause from the UI before; but recently I was working on a project which does use LINQ to SQL (actually its Entity Framework but I guess these things fit together) so this came up, after having accomplished proper server side paging.</p>
<p>When you are paging data you want to page it based on a certain order. The order of the data is seldom hard coded, you want the user to define at runtime how the data should be ordered, e.g. by selecting the column in a grid view. In LINQ to SQL this isn&#8217;t as simple as it should be, unless you download the &#8216;Dynamic LINQ Library&#8217; that Microsoft have published in some of their samples. </p>
<p>Not one for including code libraries unnecessarily I decided to tackle it with a little extra Googling and understanding.</p>
<p>What I came across was basically <a href="http://stackoverflow.com/questions/41244/dynamic-linq-orderby" rel="nofollow" target="_blank">the use of LINQ Expressions in conjunction with reflection</a> to dynamically build the parameters to the LINQ order by clause at runtime.</p>
<p>I only needed this to be very simple, i.e. one column at a time. I therefore defined a simple string which would represent a &#8216;sort expression&#8217; of one column and one direction.</p>
<p>Here is the code to my solution:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;color: #c0c0c0; font-family: Franklin Gothic Book;"><span style="color: #0600FF;color: #C2964B; font-weight: bold;">private</span> IQueryable<span style="color: #008000;color: #c0c0c0;">&lt;</span>YouDataObject<span style="color: #008000;color: #c0c0c0;">&gt;</span> SearchYourDataQuery<span style="color: #000000;color: #c0c0c0;">&#40;</span>
EFDBConnection conn, 
<span style="color: #008080; font-style: italic;color: #7F9F7F;">//some search criteria here,</span>
<span style="color: #FF0000;color: #C2964B; font-weight: bold;">string</span> orderBy<span style="color: #000000;color: #c0c0c0;">&#41;</span>
<span style="color: #000000;color: #c0c0c0;">&#123;</span>
&nbsp;
<span style="color: #008080; font-style: italic;color: #7F9F7F;">//default sort order is start date asc</span>
<span style="color: #0600FF;color: #C2964B; font-weight: bold;">if</span> <span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF0000;color: #C2964B; font-weight: bold;">string</span>.<span style="color: #0000FF;color: #c0c0c0;">IsNullOrEmpty</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>orderBy<span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> orderBy <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #666666;color: #C89191;">&quot;StartDate&quot;</span><span style="color: #008000;color: #c0c0c0;">;</span>
orderBy<span style="color: #008000;color: #c0c0c0;">=</span>orderBy.<span style="color: #0000FF;color: #c0c0c0;">Trim</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #008000;color: #c0c0c0;">;</span>
&nbsp;
<span style="color: #008080; font-style: italic;color: #7F9F7F;">//parse the order by statement </span>
<span style="color: #FF0000;color: #C2964B; font-weight: bold;">string</span> sortExprRegex <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #666666;">@&quot;^(?&lt;orderBy&gt;.+?)\s?(?&lt;direction&gt;ASC|DESC)?$&quot;</span><span style="color: #008000;color: #c0c0c0;">;</span>
<span style="color: #FF0000;color: #C2964B; font-weight: bold;">string</span> sortDirection <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #666666;color: #C89191;">&quot;ASC&quot;</span><span style="color: #008000;color: #c0c0c0;">;</span>
&nbsp;
<span style="color: #0600FF;color: #C2964B; font-weight: bold;">if</span> <span style="color: #000000;color: #c0c0c0;">&#40;</span>Regex.<span style="color: #0000FF;color: #c0c0c0;">IsMatch</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>orderBy, sortExprRegex, RegexOptions.<span style="color: #0000FF;color: #c0c0c0;">IgnoreCase</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
<span style="color: #000000;color: #c0c0c0;">&#123;</span>
    Match orderByParts <span style="color: #008000;color: #c0c0c0;">=</span> Regex.<span style="color: #0000FF;color: #c0c0c0;">Match</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>orderBy, sortExprRegex, RegexOptions.<span style="color: #0000FF;color: #c0c0c0;">IgnoreCase</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #008000;color: #c0c0c0;">;</span>
    orderBy <span style="color: #008000;color: #c0c0c0;">=</span> orderByParts.<span style="color: #0000FF;color: #c0c0c0;">Groups</span><span style="color: #000000;color: #c0c0c0;">&#91;</span><span style="color: #666666;color: #C89191;">&quot;orderBy&quot;</span><span style="color: #000000;color: #c0c0c0;">&#93;</span>.<span style="color: #0000FF;color: #c0c0c0;">Value</span><span style="color: #008000;color: #c0c0c0;">;</span>
    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">if</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #008000;color: #c0c0c0;">!</span><span style="color: #FF0000;color: #C2964B; font-weight: bold;">string</span>.<span style="color: #0000FF;color: #c0c0c0;">IsNullOrEmpty</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>orderByParts.<span style="color: #0000FF;color: #c0c0c0;">Groups</span><span style="color: #000000;color: #c0c0c0;">&#91;</span><span style="color: #666666;color: #C89191;">&quot;direction&quot;</span><span style="color: #000000;color: #c0c0c0;">&#93;</span>.<span style="color: #0000FF;color: #c0c0c0;">Value</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> sortDirection <span style="color: #008000;color: #c0c0c0;">=</span> orderByParts.<span style="color: #0000FF;color: #c0c0c0;">Groups</span><span style="color: #000000;color: #c0c0c0;">&#91;</span><span style="color: #666666;color: #C89191;">&quot;direction&quot;</span><span style="color: #000000;color: #c0c0c0;">&#93;</span>.<span style="color: #0000FF;color: #c0c0c0;">Value</span><span style="color: #008000;color: #c0c0c0;">;</span>
<span style="color: #000000;color: #c0c0c0;">&#125;</span>          
&nbsp;
<span style="color: #008080; font-style: italic;color: #7F9F7F;">//generate the query to get the filtered records</span>
IQueryable<span style="color: #008000;color: #c0c0c0;">&lt;</span>YouDataObject<span style="color: #008000;color: #c0c0c0;">&gt;</span> dataQry <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #0600FF;color: #C2964B; font-weight: bold;">from</span> a <span style="color: #0600FF;color: #C2964B; font-weight: bold;">in</span> conn.<span style="color: #0000FF;color: #c0c0c0;">YourDatas</span>
                                            <span style="color: #008080; font-style: italic;color: #7F9F7F;">//put your joins, where clauses etc</span>
                                            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">select</span> a<span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #008000;color: #c0c0c0;">;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;color: #7F9F7F;">//build an order by statement based on the column name passed to us</span>
ParameterExpression tableParam <span style="color: #008000;color: #c0c0c0;">=</span> Expression.<span style="color: #0000FF;color: #c0c0c0;">Parameter</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #008000;color: #2B91AF;">typeof</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>YouDataObject<span style="color: #000000;color: #c0c0c0;">&#41;</span>, <span style="color: #666666;color: #C89191;">&quot;d&quot;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #008000;color: #c0c0c0;">;</span>
&nbsp;
<span style="color: #008080; font-style: italic;color: #7F9F7F;">//awlays starting property access from the top table</span>
Expression expr <span style="color: #008000;color: #c0c0c0;">=</span> tableParam<span style="color: #008000;color: #c0c0c0;">;</span>
&nbsp;
<span style="color: #008080; font-style: italic;color: #7F9F7F;">//if it has dots then its a child property, i.e of another type</span>
<span style="color: #0600FF;color: #C2964B; font-weight: bold;">if</span> <span style="color: #000000;color: #c0c0c0;">&#40;</span>orderBy.<span style="color: #0000FF;color: #c0c0c0;">Contains</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #666666;color: #C89191;">&quot;.&quot;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
<span style="color: #000000;color: #c0c0c0;">&#123;</span>
    <span style="color: #FF0000;color: #C2964B; font-weight: bold;">string</span><span style="color: #000000;color: #c0c0c0;">&#91;</span><span style="color: #000000;color: #c0c0c0;">&#93;</span> props <span style="color: #008000;color: #c0c0c0;">=</span> orderBy.<span style="color: #0000FF;color: #c0c0c0;">Split</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #666666;color: #C89191;">'.'</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #008000;color: #c0c0c0;">;</span>
&nbsp;
    Type type <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #008000;color: #2B91AF;">typeof</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>YouDataObject<span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #008000;color: #c0c0c0;">;</span>
    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">foreach</span> <span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF0000;color: #C2964B; font-weight: bold;">string</span> prop <span style="color: #0600FF;color: #C2964B; font-weight: bold;">in</span> props<span style="color: #000000;color: #c0c0c0;">&#41;</span>
    <span style="color: #000000;color: #c0c0c0;">&#123;</span>
        <span style="color: #008080; font-style: italic;color: #7F9F7F;">// use reflection (not ComponentModel) to mirror LINQ</span>
        PropertyInfo pi <span style="color: #008000;color: #c0c0c0;">=</span> type.<span style="color: #0000FF;color: #c0c0c0;">GetProperty</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>prop<span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #008000;color: #c0c0c0;">;</span>
        expr <span style="color: #008000;color: #c0c0c0;">=</span> Expression.<span style="color: #0000FF;color: #c0c0c0;">Property</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>expr, pi<span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #008000;color: #c0c0c0;">;</span>
        type <span style="color: #008000;color: #c0c0c0;">=</span> pi.<span style="color: #0000FF;color: #c0c0c0;">PropertyType</span><span style="color: #008000;color: #c0c0c0;">;</span>
    <span style="color: #000000;color: #c0c0c0;">&#125;</span>
&nbsp;
<span style="color: #000000;color: #c0c0c0;">&#125;</span>
<span style="color: #0600FF;color: #C2964B; font-weight: bold;">else</span>
<span style="color: #000000;color: #c0c0c0;">&#123;</span>
    <span style="color: #008080; font-style: italic;color: #7F9F7F;">//no dots means a direct property accessor of the top level table</span>
    expr <span style="color: #008000;color: #c0c0c0;">=</span> Expression.<span style="color: #0000FF;color: #c0c0c0;">Property</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>tableParam, orderBy<span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #008000;color: #c0c0c0;">;</span>
<span style="color: #000000;color: #c0c0c0;">&#125;</span>
&nbsp;
<span style="color: #008080; font-style: italic;color: #7F9F7F;">//create a test of data type, but default is to use 'object'</span>
<span style="color: #0600FF;color: #C2964B; font-weight: bold;">if</span> <span style="color: #000000;color: #c0c0c0;">&#40;</span>expr.<span style="color: #0000FF;color: #c0c0c0;">Type</span> <span style="color: #008000;color: #c0c0c0;">==</span> <span style="color: #008000;color: #2B91AF;">typeof</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>DateTime<span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
<span style="color: #000000;color: #c0c0c0;">&#123;</span>
    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">if</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>sortDirection.<span style="color: #0000FF;color: #c0c0c0;">ToUpper</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #008000;color: #c0c0c0;">==</span> <span style="color: #666666;color: #C89191;">&quot;ASC&quot;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
        dataQry <span style="color: #008000;color: #c0c0c0;">=</span> compQry.<span style="color: #0000FF;color: #c0c0c0;">OrderBy</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>Expression.<span style="color: #0000FF;color: #c0c0c0;">Lambda</span><span style="color: #008000;color: #c0c0c0;">&lt;</span>Func<span style="color: #008000;color: #c0c0c0;">&lt;</span>YouDataObject, DateTime<span style="color: #008000;color: #c0c0c0;">&gt;&gt;</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>expr, tableParam<span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #008000;color: #c0c0c0;">;</span>
    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">else</span>
        dataQry <span style="color: #008000;color: #c0c0c0;">=</span> compQry.<span style="color: #0000FF;color: #c0c0c0;">OrderByDescending</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>Expression.<span style="color: #0000FF;color: #c0c0c0;">Lambda</span><span style="color: #008000;color: #c0c0c0;">&lt;</span>Func<span style="color: #008000;color: #c0c0c0;">&lt;</span>YouDataObject, DateTime<span style="color: #008000;color: #c0c0c0;">&gt;&gt;</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>expr, tableParam<span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #008000;color: #c0c0c0;">;</span>
<span style="color: #000000;color: #c0c0c0;">&#125;</span>
<span style="color: #0600FF;color: #C2964B; font-weight: bold;">else</span>
<span style="color: #000000;color: #c0c0c0;">&#123;</span>
    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">if</span> <span style="color: #000000;color: #c0c0c0;">&#40;</span>sortDirection.<span style="color: #0000FF;color: #c0c0c0;">ToUpper</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #008000;color: #c0c0c0;">==</span> <span style="color: #666666;color: #C89191;">&quot;ASC&quot;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
        dataQry <span style="color: #008000;color: #c0c0c0;">=</span> compQry.<span style="color: #0000FF;color: #c0c0c0;">OrderBy</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>Expression.<span style="color: #0000FF;color: #c0c0c0;">Lambda</span><span style="color: #008000;color: #c0c0c0;">&lt;</span>Func<span style="color: #008000;color: #c0c0c0;">&lt;</span>YouDataObject, <span style="color: #FF0000;color: #C2964B; font-weight: bold;">object</span><span style="color: #008000;color: #c0c0c0;">&gt;&gt;</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>expr, tableParam<span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #008000;color: #c0c0c0;">;</span>
    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">else</span>
        dataQry <span style="color: #008000;color: #c0c0c0;">=</span> compQry.<span style="color: #0000FF;color: #c0c0c0;">OrderByDescending</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>Expression.<span style="color: #0000FF;color: #c0c0c0;">Lambda</span><span style="color: #008000;color: #c0c0c0;">&lt;</span>Func<span style="color: #008000;color: #c0c0c0;">&lt;</span>YouDataObject, <span style="color: #FF0000;color: #C2964B; font-weight: bold;">object</span><span style="color: #008000;color: #c0c0c0;">&gt;&gt;</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>expr, tableParam<span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #008000;color: #c0c0c0;">;</span>
<span style="color: #000000;color: #c0c0c0;">&#125;</span>
&nbsp;
<span style="color: #008080; font-style: italic;color: #7F9F7F;">//return the resulting query</span>
<span style="color: #0600FF;color: #C2964B; font-weight: bold;">return</span> dataQry<span style="color: #008000;color: #c0c0c0;">;</span>
&nbsp;
<span style="color: #000000;color: #c0c0c0;">&#125;</span></pre></div></div>

<p>There are probably ways to neaten up the code and make it more reusable, but I think as a starting point that is hopefully helpful.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.craigwardman.com/blog/index.php/2011/08/dynamic-orderby-using-linq-to-sql/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Virtual Paging with Silverlight/WCF Services</title>
		<link>http://www.craigwardman.com/blog/index.php/2011/08/virtual-paging-with-silverlightwcf-services/</link>
		<comments>http://www.craigwardman.com/blog/index.php/2011/08/virtual-paging-with-silverlightwcf-services/#comments</comments>
		<pubDate>Thu, 18 Aug 2011 14:09:19 +0000</pubDate>
		<dc:creator>craig w</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C Sharp]]></category>
		<category><![CDATA[MVVM]]></category>
		<category><![CDATA[Silverlight]]></category>

		<guid isPermaLink="false">http://www.craigwardman.com/blog/?p=150</guid>
		<description><![CDATA[When you want to page a collection in Silverlight all the online documentation points you to the &#8216;PagedCollectionView&#8217; class, which offers a paging wrapper around an IEnumerable. This needs the full list of IEnumerable data to function in the first place, which is fine for small datasets, but for the most part you want to [...]]]></description>
			<content:encoded><![CDATA[<p>When you want to page a collection in Silverlight all the online documentation points you to the &#8216;PagedCollectionView&#8217; class, which offers a paging wrapper around an IEnumerable.</p>
<p>This needs the full list of IEnumerable data to function in the first place, which is fine for small datasets, but for the most part you want to page a database resultset from many thousands of rows, down to maybe 10 at a time.</p>
<p>Your Silverlight application probably gets its data from a WCF service, either directly or by using RIA Services link, so you want to pass your paging request from Silverlight to the service layer, where it can be transformed through your architecture to more than likely a SQL query, so that one page of data is transported at a time.</p>
<p>There are hints on Google to implement an IPagedCollectionView in order to achieve this. Below shows my version of an IPagedCollectionView which can then be used for &#8216;virtual&#8217; paging of data in Silverlight:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;color: #c0c0c0; font-family: Franklin Gothic Book;"><span style="color: #0600FF;color: #C2964B; font-weight: bold;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;color: #c0c0c0;">;</span>
<span style="color: #0600FF;color: #C2964B; font-weight: bold;">using</span> <span style="color: #008080;">System.Collections.Generic</span><span style="color: #008000;color: #c0c0c0;">;</span>
<span style="color: #0600FF;color: #C2964B; font-weight: bold;">using</span> <span style="color: #008080;">System.Linq</span><span style="color: #008000;color: #c0c0c0;">;</span>
<span style="color: #0600FF;color: #C2964B; font-weight: bold;">using</span> <span style="color: #008080;">System.Text</span><span style="color: #008000;color: #c0c0c0;">;</span>
<span style="color: #0600FF;color: #C2964B; font-weight: bold;">using</span> <span style="color: #008080;">System.ComponentModel</span><span style="color: #008000;color: #c0c0c0;">;</span>
<span style="color: #0600FF;color: #C2964B; font-weight: bold;">using</span> <span style="color: #008080;">System.Collections.Specialized</span><span style="color: #008000;color: #c0c0c0;">;</span>
<span style="color: #0600FF;color: #C2964B; font-weight: bold;">using</span> <span style="color: #008080;">System.Collections</span><span style="color: #008000;color: #c0c0c0;">;</span>
&nbsp;
<span style="color: #008080; font-style: italic;color: #7F9F7F;">/// &lt;summary&gt;</span>
<span style="color: #008080; font-style: italic;color: #7F9F7F;">/// A class which can be used in Silverlight to enable server side (virtual) paging code to store it's view state</span>
<span style="color: #008080; font-style: italic;color: #7F9F7F;">/// &lt;/summary&gt;</span>
<span style="color: #0600FF;color: #C2964B; font-weight: bold;">public</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">class</span> PagedVirtualCollectionView <span style="color: #008000;color: #c0c0c0;">:</span> IPagedCollectionView, IEnumerable, INotifyCollectionChanged, INotifyPropertyChanged
<span style="color: #000000;color: #c0c0c0;">&#123;</span>
    <span style="color: #008080; font-style: italic;color: #7F9F7F;">/// &lt;summary&gt;</span>
    <span style="color: #008080; font-style: italic;color: #7F9F7F;">/// Constructor takes initial page of data as its source</span>
    <span style="color: #008080; font-style: italic;color: #7F9F7F;">/// &lt;/summary&gt;</span>
    <span style="color: #008080; font-style: italic;color: #7F9F7F;">/// &lt;param name=&quot;source&quot;&gt;A page of source data&lt;/param&gt;</span>
    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">public</span> PagedVirtualCollectionView<span style="color: #000000;color: #c0c0c0;">&#40;</span>IEnumerable source<span style="color: #000000;color: #c0c0c0;">&#41;</span>
    <span style="color: #000000;color: #c0c0c0;">&#123;</span>
        _sourceCollection <span style="color: #008000;color: #c0c0c0;">=</span> source<span style="color: #008000;color: #c0c0c0;">;</span>
    <span style="color: #000000;color: #c0c0c0;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">private</span> IEnumerable _sourceCollection<span style="color: #008000;color: #c0c0c0;">;</span>
    <span style="color: #008080; font-style: italic;color: #7F9F7F;">/// &lt;summary&gt;</span>
    <span style="color: #008080; font-style: italic;color: #7F9F7F;">/// The underlying page of source data</span>
    <span style="color: #008080; font-style: italic;color: #7F9F7F;">/// &lt;/summary&gt;</span>
    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">public</span> IEnumerable SourceCollection
    <span style="color: #000000;color: #c0c0c0;">&#123;</span>
        get <span style="color: #000000;color: #c0c0c0;">&#123;</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">return</span> _sourceCollection<span style="color: #008000;color: #c0c0c0;">;</span> <span style="color: #000000;color: #c0c0c0;">&#125;</span>
        set <span style="color: #000000;color: #c0c0c0;">&#123;</span> 
            _sourceCollection <span style="color: #008000;color: #c0c0c0;">=</span> value<span style="color: #008000;color: #c0c0c0;">;</span> 
            OnPropertyChanged<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #666666;color: #C89191;">&quot;SourceCollection&quot;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #008000;color: #c0c0c0;">;</span> 
            OnCollectionChanged<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #008000;color: #2B91AF;">new</span> NotifyCollectionChangedEventArgs<span style="color: #000000;color: #c0c0c0;">&#40;</span>NotifyCollectionChangedAction.<span style="color: #0000FF;color: #c0c0c0;">Reset</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #008000;color: #c0c0c0;">;</span> 
        <span style="color: #000000;color: #c0c0c0;">&#125;</span>
    <span style="color: #000000;color: #c0c0c0;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">private</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">int</span> _VirtualItemCount<span style="color: #008000;color: #c0c0c0;">;</span>
    <span style="color: #008080; font-style: italic;color: #7F9F7F;">/// &lt;summary&gt;</span>
    <span style="color: #008080; font-style: italic;color: #7F9F7F;">/// Get or set this value, which is the total number of records in the database</span>
    <span style="color: #008080; font-style: italic;color: #7F9F7F;">/// &lt;/summary&gt;</span>
    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">public</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">int</span> VirtualItemCount
    <span style="color: #000000;color: #c0c0c0;">&#123;</span>
        get <span style="color: #000000;color: #c0c0c0;">&#123;</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">return</span> _VirtualItemCount<span style="color: #008000;color: #c0c0c0;">;</span> <span style="color: #000000;color: #c0c0c0;">&#125;</span>
        set <span style="color: #000000;color: #c0c0c0;">&#123;</span> 
            _VirtualItemCount <span style="color: #008000;color: #c0c0c0;">=</span> value<span style="color: #008000;color: #c0c0c0;">;</span> 
            OnPropertyChanged<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #666666;color: #C89191;">&quot;VirtualItemCount&quot;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #008000;color: #c0c0c0;">;</span> 
            OnPropertyChanged<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #666666;color: #C89191;">&quot;ItemCount&quot;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #008000;color: #c0c0c0;">;</span> 
            OnPropertyChanged<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #666666;color: #C89191;">&quot;TotalItemCount&quot;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #008000;color: #c0c0c0;">;</span> 
        <span style="color: #000000;color: #c0c0c0;">&#125;</span>
    <span style="color: #000000;color: #c0c0c0;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">public</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">int</span> VirtualPageCount
    <span style="color: #000000;color: #c0c0c0;">&#123;</span>
        get <span style="color: #000000;color: #c0c0c0;">&#123;</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">return</span> <span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF0000;color: #C2964B; font-weight: bold;">int</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>Math.<span style="color: #0000FF;color: #c0c0c0;">Ceiling</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF0000;color: #C2964B; font-weight: bold;">double</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>VirtualItemCount <span style="color: #008000;color: #c0c0c0;">/</span> <span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF0000;color: #C2964B; font-weight: bold;">double</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>PageSize<span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #008000;color: #c0c0c0;">;</span> <span style="color: #000000;color: #c0c0c0;">&#125;</span>
    <span style="color: #000000;color: #c0c0c0;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">private</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">int</span> _pageIndex <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #FF0000;color: #8ACCCF;">0</span><span style="color: #008000;color: #c0c0c0;">;</span>
    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">private</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">int</span> _pageSize<span style="color: #008000;color: #c0c0c0;">;</span>
&nbsp;
    <span style="color: #008080;">#region &quot;IEnumerable&quot;</span>
    <span style="color: #008080; font-style: italic;color: #7F9F7F;">/// &lt;summary&gt;</span>
    <span style="color: #008080; font-style: italic;color: #7F9F7F;">/// For IEnumerable interface, passes the call to the underlying SourceCollection</span>
    <span style="color: #008080; font-style: italic;color: #7F9F7F;">/// &lt;/summary&gt;</span>
    <span style="color: #008080; font-style: italic;color: #7F9F7F;">/// &lt;returns&gt;&lt;/returns&gt;</span>
    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">public</span> IEnumerator GetEnumerator<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
    <span style="color: #000000;color: #c0c0c0;">&#123;</span>
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">return</span> _sourceCollection.<span style="color: #0000FF;color: #c0c0c0;">GetEnumerator</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #008000;color: #c0c0c0;">;</span>
    <span style="color: #000000;color: #c0c0c0;">&#125;</span>
    <span style="color: #008080;">#endregion</span>
&nbsp;
    <span style="color: #008080;">#region &quot;IPagedCollectionView&quot;</span>
    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">public</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">bool</span> CanChangePage
    <span style="color: #000000;color: #c0c0c0;">&#123;</span>
        get <span style="color: #000000;color: #c0c0c0;">&#123;</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">return</span> <span style="color: #008000;color: #c0c0c0;">!</span>_isPageChanging<span style="color: #008000;color: #c0c0c0;">;</span> <span style="color: #000000;color: #c0c0c0;">&#125;</span>
    <span style="color: #000000;color: #c0c0c0;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">private</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">bool</span> _isPageChanging <span style="color: #008000;color: #c0c0c0;">=</span> false<span style="color: #008000;color: #c0c0c0;">;</span>
    <span style="color: #008080; font-style: italic;color: #7F9F7F;">/// &lt;summary&gt;</span>
    <span style="color: #008080; font-style: italic;color: #7F9F7F;">/// Return true between states of page changing and page changed, otherwise false</span>
    <span style="color: #008080; font-style: italic;color: #7F9F7F;">/// &lt;/summary&gt;</span>
    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">public</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">bool</span> IsPageChanging
    <span style="color: #000000;color: #c0c0c0;">&#123;</span>
        get <span style="color: #000000;color: #c0c0c0;">&#123;</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">return</span> _isPageChanging<span style="color: #008000;color: #c0c0c0;">;</span> <span style="color: #000000;color: #c0c0c0;">&#125;</span>
        set <span style="color: #000000;color: #c0c0c0;">&#123;</span> _isPageChanging <span style="color: #008000;color: #c0c0c0;">=</span> value<span style="color: #008000;color: #c0c0c0;">;</span> OnPropertyChanged<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #666666;color: #C89191;">&quot;IsPageChanging&quot;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #008000;color: #c0c0c0;">;</span> <span style="color: #000000;color: #c0c0c0;">&#125;</span>
    <span style="color: #000000;color: #c0c0c0;">&#125;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;color: #7F9F7F;">/// &lt;summary&gt;</span>
    <span style="color: #008080; font-style: italic;color: #7F9F7F;">/// This will be the same as the virtual item count, for use in data paging controls</span>
    <span style="color: #008080; font-style: italic;color: #7F9F7F;">/// &lt;/summary&gt;</span>
    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">public</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">int</span> ItemCount
    <span style="color: #000000;color: #c0c0c0;">&#123;</span>
        get <span style="color: #000000;color: #c0c0c0;">&#123;</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">return</span> VirtualItemCount<span style="color: #008000;color: #c0c0c0;">;</span> <span style="color: #000000;color: #c0c0c0;">&#125;</span>
    <span style="color: #000000;color: #c0c0c0;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">public</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">bool</span> MoveToFirstPage<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
    <span style="color: #000000;color: #c0c0c0;">&#123;</span>
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">return</span> MoveToPage<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF0000;color: #8ACCCF;">0</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #008000;color: #c0c0c0;">;</span>
    <span style="color: #000000;color: #c0c0c0;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">public</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">bool</span> MoveToLastPage<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
    <span style="color: #000000;color: #c0c0c0;">&#123;</span>
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">return</span> MoveToPage<span style="color: #000000;color: #c0c0c0;">&#40;</span>VirtualPageCount <span style="color: #008000;color: #c0c0c0;">-</span> <span style="color: #FF0000;color: #8ACCCF;">1</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #008000;color: #c0c0c0;">;</span>
    <span style="color: #000000;color: #c0c0c0;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">public</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">bool</span> MoveToNextPage<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
    <span style="color: #000000;color: #c0c0c0;">&#123;</span>
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">return</span> MoveToPage<span style="color: #000000;color: #c0c0c0;">&#40;</span>PageIndex <span style="color: #008000;color: #c0c0c0;">+</span> <span style="color: #FF0000;color: #8ACCCF;">1</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #008000;color: #c0c0c0;">;</span>
    <span style="color: #000000;color: #c0c0c0;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">public</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">bool</span> MoveToPage<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF0000;color: #C2964B; font-weight: bold;">int</span> pageIndex<span style="color: #000000;color: #c0c0c0;">&#41;</span>
    <span style="color: #000000;color: #c0c0c0;">&#123;</span>
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">if</span> <span style="color: #000000;color: #c0c0c0;">&#40;</span>pageIndex <span style="color: #008000;color: #c0c0c0;">&gt;=</span> <span style="color: #FF0000;color: #8ACCCF;">0</span> <span style="color: #008000;color: #c0c0c0;">&amp;&amp;</span> pageIndex <span style="color: #008000;color: #c0c0c0;">&lt;=</span> <span style="color: #000000;color: #c0c0c0;">&#40;</span>VirtualPageCount <span style="color: #008000;color: #c0c0c0;">-</span> <span style="color: #FF0000;color: #8ACCCF;">1</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
        <span style="color: #000000;color: #c0c0c0;">&#123;</span>
&nbsp;
&nbsp;
            <span style="color: #008080; font-style: italic;color: #7F9F7F;">//fire the page changing event so the call can be made to load the next page of data</span>
            PageChangingEventArgs pcea <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #008000;color: #2B91AF;">new</span> PageChangingEventArgs<span style="color: #000000;color: #c0c0c0;">&#40;</span>pageIndex<span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #008000;color: #c0c0c0;">;</span>
            OnPageChanging<span style="color: #000000;color: #c0c0c0;">&#40;</span>pcea<span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #008000;color: #c0c0c0;">;</span>
&nbsp;
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">if</span> <span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #008000;color: #c0c0c0;">!</span>pcea.<span style="color: #0000FF;color: #c0c0c0;">Cancel</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
            <span style="color: #000000;color: #c0c0c0;">&#123;</span>
                <span style="color: #008080; font-style: italic;color: #7F9F7F;">//let outside world know we are changing pages</span>
                IsPageChanging <span style="color: #008000;color: #c0c0c0;">=</span> true<span style="color: #008000;color: #c0c0c0;">;</span>
&nbsp;
                <span style="color: #008080; font-style: italic;color: #7F9F7F;">//event handlers have run, we should now be on the new page</span>
                _pageIndex <span style="color: #008000;color: #c0c0c0;">=</span> pageIndex<span style="color: #008000;color: #c0c0c0;">;</span>
&nbsp;
                <span style="color: #008080; font-style: italic;color: #7F9F7F;">//let the outside world know we are no longer changing pages</span>
                IsPageChanging <span style="color: #008000;color: #c0c0c0;">=</span> false<span style="color: #008000;color: #c0c0c0;">;</span>
&nbsp;
                OnPropertyChanged<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #666666;color: #C89191;">&quot;PageIndex&quot;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #008000;color: #c0c0c0;">;</span>
&nbsp;
                <span style="color: #008080; font-style: italic;color: #7F9F7F;">//raise an event to signal the completed change of page</span>
                OnPageChanged<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #008000;color: #c0c0c0;">;</span>
                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">return</span> true<span style="color: #008000;color: #c0c0c0;">;</span>
            <span style="color: #000000;color: #c0c0c0;">&#125;</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">else</span>
            <span style="color: #000000;color: #c0c0c0;">&#123;</span>
                <span style="color: #008080; font-style: italic;color: #7F9F7F;">//event handler cancelled the page change</span>
                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">return</span> false<span style="color: #008000;color: #c0c0c0;">;</span>
            <span style="color: #000000;color: #c0c0c0;">&#125;</span>
&nbsp;
        <span style="color: #000000;color: #c0c0c0;">&#125;</span>
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">else</span>
        <span style="color: #000000;color: #c0c0c0;">&#123;</span>
            <span style="color: #008080; font-style: italic;color: #7F9F7F;">//page index out of bounds, or was busy changing pages</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">return</span> false<span style="color: #008000;color: #c0c0c0;">;</span>
        <span style="color: #000000;color: #c0c0c0;">&#125;</span>
    <span style="color: #000000;color: #c0c0c0;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">public</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">bool</span> MoveToPreviousPage<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
    <span style="color: #000000;color: #c0c0c0;">&#123;</span>
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">return</span> MoveToPage<span style="color: #000000;color: #c0c0c0;">&#40;</span>PageIndex <span style="color: #008000;color: #c0c0c0;">-</span> <span style="color: #FF0000;color: #8ACCCF;">1</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #008000;color: #c0c0c0;">;</span>
    <span style="color: #000000;color: #c0c0c0;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">public</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">event</span> EventHandler<span style="color: #008000;color: #c0c0c0;">&lt;</span>EventArgs<span style="color: #008000;color: #c0c0c0;">&gt;</span> PageChanged<span style="color: #008000;color: #c0c0c0;">;</span>
    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">protected</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">void</span> OnPageChanged<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
    <span style="color: #000000;color: #c0c0c0;">&#123;</span>
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">if</span> <span style="color: #000000;color: #c0c0c0;">&#40;</span>PageChanged <span style="color: #008000;color: #c0c0c0;">!=</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">null</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
            PageChanged<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #0600FF;color: #C2964B; font-weight: bold;">this</span>, EventArgs.<span style="color: #0000FF;color: #c0c0c0;">Empty</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #008000;color: #c0c0c0;">;</span>
    <span style="color: #000000;color: #c0c0c0;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">public</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">event</span> EventHandler<span style="color: #008000;color: #c0c0c0;">&lt;</span>PageChangingEventArgs<span style="color: #008000;color: #c0c0c0;">&gt;</span> PageChanging<span style="color: #008000;color: #c0c0c0;">;</span>
    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">protected</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">void</span> OnPageChanging<span style="color: #000000;color: #c0c0c0;">&#40;</span>PageChangingEventArgs e<span style="color: #000000;color: #c0c0c0;">&#41;</span>
    <span style="color: #000000;color: #c0c0c0;">&#123;</span>
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">if</span> <span style="color: #000000;color: #c0c0c0;">&#40;</span>PageChanging <span style="color: #008000;color: #c0c0c0;">!=</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">null</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
            PageChanging<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #0600FF;color: #C2964B; font-weight: bold;">this</span>, e<span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #008000;color: #c0c0c0;">;</span>
    <span style="color: #000000;color: #c0c0c0;">&#125;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;color: #7F9F7F;">/// &lt;summary&gt;</span>
    <span style="color: #008080; font-style: italic;color: #7F9F7F;">/// Read-only version of page index, use the helper functions to move through the pages</span>
    <span style="color: #008080; font-style: italic;color: #7F9F7F;">/// &lt;/summary&gt;</span>
    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">public</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">int</span> PageIndex
    <span style="color: #000000;color: #c0c0c0;">&#123;</span>
        get <span style="color: #000000;color: #c0c0c0;">&#123;</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">return</span> _pageIndex<span style="color: #008000;color: #c0c0c0;">;</span> <span style="color: #000000;color: #c0c0c0;">&#125;</span>
    <span style="color: #000000;color: #c0c0c0;">&#125;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;color: #7F9F7F;">/// &lt;summary&gt;</span>
    <span style="color: #008080; font-style: italic;color: #7F9F7F;">/// Get/set the page size which will can then be used by the external paging calls</span>
    <span style="color: #008080; font-style: italic;color: #7F9F7F;">/// &lt;/summary&gt;</span>
    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">public</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">int</span> PageSize
    <span style="color: #000000;color: #c0c0c0;">&#123;</span>
        get
        <span style="color: #000000;color: #c0c0c0;">&#123;</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">return</span> _pageSize<span style="color: #008000;color: #c0c0c0;">;</span>
        <span style="color: #000000;color: #c0c0c0;">&#125;</span>
        set
        <span style="color: #000000;color: #c0c0c0;">&#123;</span>
            _pageSize <span style="color: #008000;color: #c0c0c0;">=</span> value<span style="color: #008000;color: #c0c0c0;">;</span>
        <span style="color: #000000;color: #c0c0c0;">&#125;</span>
    <span style="color: #000000;color: #c0c0c0;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">public</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">int</span> TotalItemCount
    <span style="color: #000000;color: #c0c0c0;">&#123;</span>
        <span style="color: #008080; font-style: italic;color: #7F9F7F;">//this will always be the same as virtual item count</span>
        get <span style="color: #000000;color: #c0c0c0;">&#123;</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">return</span> VirtualItemCount<span style="color: #008000;color: #c0c0c0;">;</span> <span style="color: #000000;color: #c0c0c0;">&#125;</span>
    <span style="color: #000000;color: #c0c0c0;">&#125;</span>
    <span style="color: #008080;">#endregion</span>
&nbsp;
    <span style="color: #008080;">#region &quot;INotifyPropertyChanged&quot;</span>
    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">public</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">event</span> PropertyChangedEventHandler PropertyChanged<span style="color: #008000;color: #c0c0c0;">;</span>
    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">protected</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">void</span> OnPropertyChanged<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF0000;color: #C2964B; font-weight: bold;">string</span> propertyName<span style="color: #000000;color: #c0c0c0;">&#41;</span>
    <span style="color: #000000;color: #c0c0c0;">&#123;</span>
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">if</span> <span style="color: #000000;color: #c0c0c0;">&#40;</span>PropertyChanged <span style="color: #008000;color: #c0c0c0;">!=</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">null</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
            PropertyChanged<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #0600FF;color: #C2964B; font-weight: bold;">this</span>, <span style="color: #008000;color: #2B91AF;">new</span> PropertyChangedEventArgs<span style="color: #000000;color: #c0c0c0;">&#40;</span>propertyName<span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #008000;color: #c0c0c0;">;</span>
    <span style="color: #000000;color: #c0c0c0;">&#125;</span>
    <span style="color: #008080;">#endregion</span>
&nbsp;
    <span style="color: #008080;">#region&quot;INotifyCollectionChanged&quot;</span>
    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">public</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">event</span> NotifyCollectionChangedEventHandler CollectionChanged<span style="color: #008000;color: #c0c0c0;">;</span>
    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">protected</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">void</span> OnCollectionChanged<span style="color: #000000;color: #c0c0c0;">&#40;</span>NotifyCollectionChangedEventArgs e<span style="color: #000000;color: #c0c0c0;">&#41;</span>
    <span style="color: #000000;color: #c0c0c0;">&#123;</span>
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">if</span> <span style="color: #000000;color: #c0c0c0;">&#40;</span>CollectionChanged <span style="color: #008000;color: #c0c0c0;">!=</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">null</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
            CollectionChanged<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #0600FF;color: #C2964B; font-weight: bold;">this</span>, e<span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #008000;color: #c0c0c0;">;</span>
    <span style="color: #000000;color: #c0c0c0;">&#125;</span>
    <span style="color: #008080;">#endregion</span>
<span style="color: #000000;color: #c0c0c0;">&#125;</span></pre></div></div>

<p>Basically it works by allowing you to specify a &#8216;VirtualItemCount&#8217; aswel as your &#8216;SourceCollection&#8217; so that you can dictate how many items there are in total (before paging has been applied).</p>
<p>Whether you are using MVVM or traditional DataContext, you should bind your grid and pager to the instance of the PagedVirtualCollectionView and handle the &#8216;PageChanging&#8217; event. You can then replace the &#8216;SourceCollection&#8217; with the current page of data and set the &#8216;VirtualItemCount&#8217; to the total count of records.</p>
<p>E.g.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;color: #c0c0c0; font-family: Franklin Gothic Book;"><span style="color: #0600FF;color: #C2964B; font-weight: bold;">private</span> PagedVirtualCollectionView _SearchResults <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #008000;color: #2B91AF;">new</span> PagedVirtualCollectionView<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #008000;color: #2B91AF;">new</span> List<span style="color: #008000;color: #c0c0c0;">&lt;</span>SearchResult<span style="color: #008000;color: #c0c0c0;">&gt;</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #008000;color: #c0c0c0;">;</span>
<span style="color: #0600FF;color: #C2964B; font-weight: bold;">public</span> PagedVirtualCollectionView SearchResults
<span style="color: #000000;color: #c0c0c0;">&#123;</span>
    get <span style="color: #000000;color: #c0c0c0;">&#123;</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">return</span> _SearchResults<span style="color: #008000;color: #c0c0c0;">;</span> <span style="color: #000000;color: #c0c0c0;">&#125;</span>
<span style="color: #000000;color: #c0c0c0;">&#125;</span>
&nbsp;
<span style="color: #0600FF;color: #C2964B; font-weight: bold;">public</span> MyViewModel<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
<span style="color: #000000;color: #c0c0c0;">&#123;</span>
    _SearchResults.<span style="color: #0000FF;color: #c0c0c0;">PageChanging</span> <span style="color: #008000;color: #c0c0c0;">+=</span> <span style="color: #008000;color: #2B91AF;">new</span> EventHandler<span style="color: #008000;color: #c0c0c0;">&lt;</span>PageChangingEventArgs<span style="color: #008000;color: #c0c0c0;">&gt;</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>SearchResultsPageChangingHandler<span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #008000;color: #c0c0c0;">;</span>
<span style="color: #000000;color: #c0c0c0;">&#125;</span>
&nbsp;
<span style="color: #0600FF;color: #C2964B; font-weight: bold;">protected</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">void</span> SearchResultsPageChangingHandler<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF0000;color: #C2964B; font-weight: bold;">object</span> sender, PageChangingEventArgs e<span style="color: #000000;color: #c0c0c0;">&#41;</span>
<span style="color: #000000;color: #c0c0c0;">&#123;</span>
    UpdateSearchResults<span style="color: #000000;color: #c0c0c0;">&#40;</span>e.<span style="color: #0000FF;color: #c0c0c0;">NewPageIndex</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #008000;color: #c0c0c0;">;</span>
<span style="color: #000000;color: #c0c0c0;">&#125;</span>
&nbsp;
<span style="color: #0600FF;color: #C2964B; font-weight: bold;">public</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">void</span> UpdateSearchResults<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF0000;color: #C2964B; font-weight: bold;">int</span> pageIndex<span style="color: #000000;color: #c0c0c0;">&#41;</span>
<span style="color: #000000;color: #c0c0c0;">&#123;</span>
    <span style="color: #008080; font-style: italic;color: #7F9F7F;">//CALL YOUR SERVICE PASSING pageIndex and SearchResults.PageSize</span>
<span style="color: #000000;color: #c0c0c0;">&#125;</span>
&nbsp;
<span style="color: #0600FF;color: #C2964B; font-weight: bold;">void</span> UpdateSearchResultsCompleted<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF0000;color: #C2964B; font-weight: bold;">object</span> sender, SearchCompletedEventArgs e<span style="color: #000000;color: #c0c0c0;">&#41;</span>
<span style="color: #000000;color: #c0c0c0;">&#123;</span>          
    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">if</span> <span style="color: #000000;color: #c0c0c0;">&#40;</span>e.<span style="color: #0000FF;color: #c0c0c0;">Error</span> <span style="color: #008000;color: #c0c0c0;">==</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">null</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
    <span style="color: #000000;color: #c0c0c0;">&#123;</span>
        SearchResults.<span style="color: #0000FF;color: #c0c0c0;">SourceCollection</span> <span style="color: #008000;color: #c0c0c0;">=</span> e.<span style="color: #0000FF;color: #c0c0c0;">Result</span><span style="color: #008000;color: #c0c0c0;">;</span>
        SearchResults.<span style="color: #0000FF;color: #c0c0c0;">VirtualItemCount</span> <span style="color: #008000;color: #c0c0c0;">=</span> e.<span style="color: #0000FF;color: #c0c0c0;">totalRecords</span><span style="color: #008000;color: #c0c0c0;">;</span> <span style="color: #008080; font-style: italic;color: #7F9F7F;">//totalRecords is defined as an 'out' parameter to the WCF service</span>
    <span style="color: #000000;color: #c0c0c0;">&#125;</span>
<span style="color: #000000;color: #c0c0c0;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.craigwardman.com/blog/index.php/2011/08/virtual-paging-with-silverlightwcf-services/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>IIS 6 Rewriting Problem with .NET 4</title>
		<link>http://www.craigwardman.com/blog/index.php/2011/08/iis-6-rewriting-problem-with-net-4/</link>
		<comments>http://www.craigwardman.com/blog/index.php/2011/08/iis-6-rewriting-problem-with-net-4/#comments</comments>
		<pubDate>Wed, 03 Aug 2011 10:43:00 +0000</pubDate>
		<dc:creator>craig w</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Regular Expressions]]></category>
		<category><![CDATA[SEO]]></category>
		<category><![CDATA[URL Rewriting]]></category>

		<guid isPermaLink="false">http://www.craigwardman.com/blog/?p=146</guid>
		<description><![CDATA[Recently I had a problem with a URL rewriting regular expression not picking up URL requests, resulting in 404 not found errors. The expression was designed to pickup anything that consists of a string containing no dots (extensionless files). This is because I know these files exist only in a database and have a handler. [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I had a problem with a URL rewriting regular expression not picking up URL requests, resulting in 404 not found errors.</p>
<p>The expression was designed to pickup anything that consists of a string containing no dots (extensionless files). This is because I know these files exist only in a database and have a handler. It worked fine until one day it just didn&#8217;t.</p>
<p>After enabling logging in Helicon rewriter, I could see the original URL was not actually being passed through to the Helicon ISAPI filter and infact had already been modified to include &#8216;/eurl.axd/{hash}&#8217; on the end. Hence why the regex was not making a positive match.</p>
<p>A quick Google revealed <a href="http://www.asp.net/learn/whitepapers/aspnet4/breaking-changes#0.1__Toc256770153" target="_blank" rel="nofollow">a change in ASP.NET 4 that seems to handle extensionless file requests</a> slightly differently than before. It looks like .NET 4 is getting in early (ASP.NET never used to fire for non-mapped files, right?) and picking up the extensionless file and (maybe because its IIS 6) is rewriting the URL, as above, with the &#8216;/eurl.axd/{hash}&#8217; part suffixed. </p>
<p>This was now causing a 404. To fix this I simply added a 2nd regular expression that would pick up these requests for extensionless files with aforementioned &#8216;eurl.axd&#8217; suffix so that this will also pass to the database file handler.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.craigwardman.com/blog/index.php/2011/08/iis-6-rewriting-problem-with-net-4/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Silverlight Designer Crashing Visual Studio 2010</title>
		<link>http://www.craigwardman.com/blog/index.php/2011/07/silverlight-designer-crashing-visual-studio-2010/</link>
		<comments>http://www.craigwardman.com/blog/index.php/2011/07/silverlight-designer-crashing-visual-studio-2010/#comments</comments>
		<pubDate>Fri, 08 Jul 2011 14:27:16 +0000</pubDate>
		<dc:creator>craig w</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Development Tools]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.craigwardman.com/blog/?p=143</guid>
		<description><![CDATA[After the Silverlight runtime update to 4.0.60531.0, opening a XAML file in design view was crashing visual studio. There was also a problem in opening the Toolbox, or any designer that loads the toolbox, with Visual Studio crashing when &#8220;Loading toolbox content from package &#8216;Microsoft.VisualStudio.IDE.ToolboxControlsInstaller.ToolboxInstallerPackage&#8217; {2C298B35-07DA-45F1-96A3-BE55D91C8D7A}&#8221; When I found the solution, it appears this probably [...]]]></description>
			<content:encoded><![CDATA[<p>After the Silverlight runtime update to 4.0.60531.0, opening a XAML file in design view was crashing visual studio.</p>
<p>There was also a problem in opening the Toolbox, or any designer that loads the toolbox, with Visual Studio crashing when &#8220;Loading toolbox content from package &#8216;Microsoft.VisualStudio.IDE.ToolboxControlsInstaller.ToolboxInstallerPackage&#8217; {2C298B35-07DA-45F1-96A3-BE55D91C8D7A}&#8221;</p>
<p>When I found the solution, it appears this probably only affects systems where &#8216;System.Windows.dll&#8217; has been previously registered in the GAC.</p>
<p>The solution, is to remove System.Windows from your GAC using the following command from the Visual Studio Command Prompt:<br />
gacutil -u System.Windows</p>
]]></content:encoded>
			<wfw:commentRss>http://www.craigwardman.com/blog/index.php/2011/07/silverlight-designer-crashing-visual-studio-2010/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Finding a Child Control by Type in Silverlight</title>
		<link>http://www.craigwardman.com/blog/index.php/2011/06/finding-a-child-control-by-type-in-silverlight/</link>
		<comments>http://www.craigwardman.com/blog/index.php/2011/06/finding-a-child-control-by-type-in-silverlight/#comments</comments>
		<pubDate>Tue, 07 Jun 2011 15:10:05 +0000</pubDate>
		<dc:creator>craig w</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C Sharp]]></category>
		<category><![CDATA[Silverlight]]></category>

		<guid isPermaLink="false">http://www.craigwardman.com/blog/?p=137</guid>
		<description><![CDATA[Recently I needed to traverse the visual tree of a Silverlight dependancy object (UI element) in order to find a child object with the type I was looking for. As I didn&#8217;t know how far nested the child would be, I wrote a recursive helper function which will scan all child elements looking for the [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I needed to traverse the visual tree of a Silverlight dependancy object (UI element) in order to find a child object with the type I was looking for.</p>
<p>As I didn&#8217;t know how far nested the child would be, I wrote a recursive helper function which will scan all child elements looking for the first instance it finds. I then extended this functionality with a overload allowing to specify the name of the object I was looking for. I thought it might be useful elsewhere, so here it is:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;color: #c0c0c0; font-family: Franklin Gothic Book;"><span style="color: #0600FF;color: #C2964B; font-weight: bold;">private</span> T FindControlByType<span style="color: #008000;color: #c0c0c0;">&lt;</span>T<span style="color: #008000;color: #c0c0c0;">&gt;</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>DependencyObject container<span style="color: #000000;color: #c0c0c0;">&#41;</span> where T <span style="color: #008000;color: #c0c0c0;">:</span> DependencyObject
<span style="color: #000000;color: #c0c0c0;">&#123;</span>
    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">return</span> FindControlByType<span style="color: #008000;color: #c0c0c0;">&lt;</span>T<span style="color: #008000;color: #c0c0c0;">&gt;</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>container, <span style="color: #0600FF;color: #C2964B; font-weight: bold;">null</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #008000;color: #c0c0c0;">;</span>
<span style="color: #000000;color: #c0c0c0;">&#125;</span>
&nbsp;
<span style="color: #0600FF;color: #C2964B; font-weight: bold;">private</span> T FindControlByType<span style="color: #008000;color: #c0c0c0;">&lt;</span>T<span style="color: #008000;color: #c0c0c0;">&gt;</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>DependencyObject container, <span style="color: #FF0000;color: #C2964B; font-weight: bold;">string</span> name<span style="color: #000000;color: #c0c0c0;">&#41;</span> where T <span style="color: #008000;color: #c0c0c0;">:</span> DependencyObject
<span style="color: #000000;color: #c0c0c0;">&#123;</span>
    T foundControl <span style="color: #008000;color: #c0c0c0;">=</span> null<span style="color: #008000;color: #c0c0c0;">;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;color: #7F9F7F;">//for each child object in the container</span>
    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">for</span> <span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF0000;color: #C2964B; font-weight: bold;">int</span> i <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #FF0000;color: #8ACCCF;">0</span><span style="color: #008000;color: #c0c0c0;">;</span> i <span style="color: #008000;color: #c0c0c0;">&lt;</span> VisualTreeHelper.<span style="color: #0000FF;color: #c0c0c0;">GetChildrenCount</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>container<span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #008000;color: #c0c0c0;">;</span> i<span style="color: #008000;color: #c0c0c0;">++</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
    <span style="color: #000000;color: #c0c0c0;">&#123;</span>
        <span style="color: #008080; font-style: italic;color: #7F9F7F;">//is the object of the type we are looking for?</span>
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">if</span> <span style="color: #000000;color: #c0c0c0;">&#40;</span>VisualTreeHelper.<span style="color: #0000FF;color: #c0c0c0;">GetChild</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>container, i<span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #008000;color: #2B91AF;">is</span> T <span style="color: #008000;color: #c0c0c0;">&amp;&amp;</span> <span style="color: #000000;color: #c0c0c0;">&#40;</span>VisualTreeHelper.<span style="color: #0000FF;color: #c0c0c0;">GetChild</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>container, i<span style="color: #000000;color: #c0c0c0;">&#41;</span>.<span style="color: #0000FF;color: #c0c0c0;">GetValue</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>FrameworkElement.<span style="color: #0000FF;color: #c0c0c0;">NameProperty</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>.<span style="color: #0000FF;color: #c0c0c0;">Equals</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>name<span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #008000;color: #c0c0c0;">||</span> name <span style="color: #008000;color: #c0c0c0;">==</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">null</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
        <span style="color: #000000;color: #c0c0c0;">&#123;</span>
            foundControl <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #000000;color: #c0c0c0;">&#40;</span>T<span style="color: #000000;color: #c0c0c0;">&#41;</span>VisualTreeHelper.<span style="color: #0000FF;color: #c0c0c0;">GetChild</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>container, i<span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #008000;color: #c0c0c0;">;</span>
            break<span style="color: #008000;color: #c0c0c0;">;</span>
        <span style="color: #000000;color: #c0c0c0;">&#125;</span>
        <span style="color: #008080; font-style: italic;color: #7F9F7F;">//if not, does it have children?</span>
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">else</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">if</span> <span style="color: #000000;color: #c0c0c0;">&#40;</span>VisualTreeHelper.<span style="color: #0000FF;color: #c0c0c0;">GetChildrenCount</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>VisualTreeHelper.<span style="color: #0000FF;color: #c0c0c0;">GetChild</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>container, i<span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #008000;color: #c0c0c0;">&gt;</span> <span style="color: #FF0000;color: #8ACCCF;">0</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
        <span style="color: #000000;color: #c0c0c0;">&#123;</span>
            <span style="color: #008080; font-style: italic;color: #7F9F7F;">//recursively look at its children</span>
            foundControl <span style="color: #008000;color: #c0c0c0;">=</span> FindControlByType<span style="color: #008000;color: #c0c0c0;">&lt;</span>T<span style="color: #008000;color: #c0c0c0;">&gt;</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>VisualTreeHelper.<span style="color: #0000FF;color: #c0c0c0;">GetChild</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>container, i<span style="color: #000000;color: #c0c0c0;">&#41;</span>, name<span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #008000;color: #c0c0c0;">;</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">if</span> <span style="color: #000000;color: #c0c0c0;">&#40;</span>foundControl <span style="color: #008000;color: #c0c0c0;">!=</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">null</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
                break<span style="color: #008000;color: #c0c0c0;">;</span>
        <span style="color: #000000;color: #c0c0c0;">&#125;</span>
    <span style="color: #000000;color: #c0c0c0;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">return</span> foundControl<span style="color: #008000;color: #c0c0c0;">;</span>
<span style="color: #000000;color: #c0c0c0;">&#125;</span></pre></div></div>

<p>You can tweak the code to accept more parameters if you need more comparisons to match your object.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.craigwardman.com/blog/index.php/2011/06/finding-a-child-control-by-type-in-silverlight/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Out of Coffee Exception</title>
		<link>http://www.craigwardman.com/blog/index.php/2011/02/out-of-coffee-exception/</link>
		<comments>http://www.craigwardman.com/blog/index.php/2011/02/out-of-coffee-exception/#comments</comments>
		<pubDate>Tue, 22 Feb 2011 11:56:29 +0000</pubDate>
		<dc:creator>craig w</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.craigwardman.com/blog/?p=129</guid>
		<description><![CDATA[These errors seem to be becoming more and more frequent and I&#8217;m still looking for a workaround. I have managed to raise emails and audible warnings before this happens, but there seems to be latency issues in getting any response. Sometimes I have to deal with this manually]]></description>
			<content:encoded><![CDATA[<p>These errors seem to be becoming more and more frequent and I&#8217;m still looking for a workaround.</p>
<p><a href="http://www.craigwardman.com/blog/index.php/2011/02/out-of-coffee-exception/coffee-exception/" rel="attachment wp-att-130"><img src="http://www.craigwardman.com/blog/wp-content/uploads/2011/02/coffee-exception.jpg" alt="" title="coffee exception" width="219" height="119" class="alignnone size-full wp-image-130" /></a></p>
<p>I have managed to raise emails and audible warnings before this happens, but there seems to be latency issues in getting any response. Sometimes I have to deal with this manually <img src='http://www.craigwardman.com/blog/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.craigwardman.com/blog/index.php/2011/02/out-of-coffee-exception/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Using Exchange ActiveSync from a .NET Application</title>
		<link>http://www.craigwardman.com/blog/index.php/2010/12/using-exchange-activesync-from-a-net-application/</link>
		<comments>http://www.craigwardman.com/blog/index.php/2010/12/using-exchange-activesync-from-a-net-application/#comments</comments>
		<pubDate>Thu, 16 Dec 2010 15:00:43 +0000</pubDate>
		<dc:creator>craig w</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[VB.NET]]></category>

		<guid isPermaLink="false">http://www.craigwardman.com/blog/?p=122</guid>
		<description><![CDATA[When recently building an Intranet portal site I needed a way of retrieving a user&#8217;s Outlook calendar (which were stored on the Microsoft Exchange server). Due to infrastructure reasons it seemed the best way for me to get to this information was to use Exchange ActiveSync. Exchange ActiveSync allows over-the-air syncing termed &#8220;AirSync&#8221; and is [...]]]></description>
			<content:encoded><![CDATA[<p>When recently building an Intranet portal site I needed a way of retrieving a user&#8217;s Outlook calendar (which were stored on the Microsoft Exchange server). Due to infrastructure reasons it seemed the best way for me to get to this information was to use Exchange ActiveSync.</p>
<p>Exchange ActiveSync allows over-the-air syncing termed &#8220;AirSync&#8221; and is used mainly by mobile devices. It uses HTTP POST (with or without SSL) to send/receive data (see: <a href="http://msdn.microsoft.com/en-us/library/dd299446%28v=EXCHG.80%29.aspx" target="_blank" rel="nofollow">[MS-ASHTTP]</a>) and consists of several commands (see: <a href="http://msdn.microsoft.com/en-us/library/dd299441%28v=EXCHG.80%29.aspx" target="_blank" rel="nofollow">[MS-ASCMD]</a>) which use WBXML encoded XML body content to convey data (see: [<a href="http://msdn.microsoft.com/en-us/library/dd299442%28v=EXCHG.80%29.aspx" target="_blank" rel="nofollow">MS-ASWBXML</a>]).</p>
<p>There are many other accompanying documents which expand on various parts of the protocol, which can be found on the MSDN website under <a href="http://msdn.microsoft.com/en-us/library/cc425499%28v=EXCHG.80%29.aspx" target="_blank" rel="nofollow">Exchange Server Protocol Documents</a>.</p>
<p>Because this is mainly used in mobile development there is very little information or examples of how to use the protocol in a .NET environment, so I thought it would be useful to share my code here for future reference.</p>
<p>I wrote an AirSyncHelper class which can be instantiated with server details and credentials to then send and receive XML data with your chosen ActiveSync command:</p>

<div class="wp_syntax"><div class="code"><pre class="vbnet" style="font-family:monospace;color: #c0c0c0; font-family: Franklin Gothic Book;"><span style="color: #0600FF;color: #C2964B; font-weight: bold;">Namespace</span> Email.<span style="color: #0000FF;color: #c0c0c0;">Exchange</span>.<span style="color: #0000FF;color: #c0c0c0;">AirSync</span>
    <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Public</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Class</span> AirSyncHelper
        <span style="color: #008080; font-style: italic;color: #7F9F7F;">'class was written based on AS2.5 specification</span>
        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Public</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Const</span> AirSyncSupportedVersion <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #808080;color: #C89191;">&quot;2.5&quot;</span>
&nbsp;
        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Private</span> _asCodePages <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #008000;color: #2B91AF;">Dictionary</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>Of <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Integer</span>, EncodingHelpers.<span style="color: #0000FF;color: #c0c0c0;">WBXML</span>.<span style="color: #0000FF;color: #c0c0c0;">WbXmlCodepage</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Private</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">ReadOnly</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Property</span> ASCodePages<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #008000;color: #2B91AF;">Dictionary</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>Of <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Integer</span>, EncodingHelpers.<span style="color: #0000FF;color: #c0c0c0;">WBXML</span>.<span style="color: #0000FF;color: #c0c0c0;">WbXmlCodepage</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
            <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Get</span>
                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span> _asCodePages <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Is</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Nothing</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Then</span>
                    InitAirSyncCodepages<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span>
&nbsp;
                <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Return</span> _asCodePages
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Get</span>
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Property</span>
&nbsp;
        <span style="color: #008080; font-style: italic;color: #7F9F7F;">'host address endpoint where exchange webmail is hosted</span>
        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Private</span> _asHostAddress <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span>
        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Private</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Property</span> ASHostAddress<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span>
            <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Get</span>
                <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Return</span> _asHostAddress
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Get</span>
            <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Set</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF8000;color: #C2964B; font-weight: bold;">ByVal</span> value <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
                _asHostAddress <span style="color: #008000;color: #c0c0c0;">=</span> value
                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span> _asHostAddress.<span style="color: #0000FF;color: #c0c0c0;">EndsWith</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #808080;color: #C89191;">&quot;/&quot;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Then</span> _asHostAddress <span style="color: #008000;color: #c0c0c0;">=</span> _asHostAddress.<span style="color: #0000FF;color: #c0c0c0;">Substring</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF0000;color: #8ACCCF;">0</span>, _asHostAddress.<span style="color: #0000FF;color: #c0c0c0;">Length</span> <span style="color: #008000;color: #c0c0c0;">-</span> <span style="color: #FF0000;color: #8ACCCF;">1</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Set</span>
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Property</span>
&nbsp;
        <span style="color: #008080; font-style: italic;color: #7F9F7F;">'this could be used to have a different mailbox name to the domain login</span>
        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Private</span> _asUsername <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span>
        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Private</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Property</span> ASUsername<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span>
            <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Get</span>
                <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Return</span> _asUsername
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Get</span>
            <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Set</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF8000;color: #C2964B; font-weight: bold;">ByVal</span> value <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
                _asUsername <span style="color: #008000;color: #c0c0c0;">=</span> value
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Set</span>
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Property</span>
&nbsp;
        <span style="color: #008080; font-style: italic;color: #7F9F7F;">'domain login credentials (HTTP Auth)</span>
        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Private</span> _loginUsername <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span>
        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Private</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Property</span> LoginUsername<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span>
            <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Get</span>
                <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Return</span> _loginUsername
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Get</span>
            <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Set</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF8000;color: #C2964B; font-weight: bold;">ByVal</span> value <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
                _loginUsername <span style="color: #008000;color: #c0c0c0;">=</span> value
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Set</span>
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Property</span>
&nbsp;
        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Private</span> _loginDomain <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span>
        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Private</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Property</span> LoginDomain<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span>
            <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Get</span>
                <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Return</span> _loginDomain
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Get</span>
            <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Set</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF8000;color: #C2964B; font-weight: bold;">ByVal</span> value <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
                _loginDomain <span style="color: #008000;color: #c0c0c0;">=</span> value
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Set</span>
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Property</span>
&nbsp;
        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Private</span> _loginPassword <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span>
        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Private</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Property</span> LoginPassword<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span>
            <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Get</span>
                <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Return</span> _loginPassword
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Get</span>
            <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Set</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF8000;color: #C2964B; font-weight: bold;">ByVal</span> value <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
                _loginPassword <span style="color: #008000;color: #c0c0c0;">=</span> value
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Set</span>
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Property</span>
&nbsp;
        <span style="color: #008080; font-style: italic;color: #7F9F7F;">'ActiveSync policy key </span>
        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Private</span> _policyKey <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #808080;color: #C89191;">&quot;&quot;</span>
        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Private</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Property</span> PolicyKey<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span>
            <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Get</span>
                <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Return</span> _policyKey
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Get</span>
            <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Set</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF8000;color: #C2964B; font-weight: bold;">ByVal</span> value <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
                _policyKey <span style="color: #008000;color: #c0c0c0;">=</span> value
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Set</span>
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Property</span>
&nbsp;
        <span style="color: #008080; font-style: italic;color: #7F9F7F;">'base address (with the active sync folder)</span>
        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Private</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">ReadOnly</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Property</span> ActiveSyncBaseAddress<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span>
            <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Get</span>
                <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Return</span> _asHostAddress <span style="color: #008000;color: #c0c0c0;">&amp;</span> <span style="color: #808080;color: #C89191;">&quot;/Microsoft-Server-ActiveSync/&quot;</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Get</span>
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Property</span>
&nbsp;
        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Public</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Sub</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">New</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF8000;color: #C2964B; font-weight: bold;">ByVal</span> hostAddress <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span>, <span style="color: #FF8000;color: #C2964B; font-weight: bold;">ByVal</span> username <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span>, <span style="color: #FF8000;color: #C2964B; font-weight: bold;">ByVal</span> password <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span>, <span style="color: #FF8000;color: #C2964B; font-weight: bold;">ByVal</span> domain <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
            ASHostAddress <span style="color: #008000;color: #c0c0c0;">=</span> hostAddress
            ASUsername <span style="color: #008000;color: #c0c0c0;">=</span> username
            LoginUsername <span style="color: #008000;color: #c0c0c0;">=</span> username
            LoginDomain <span style="color: #008000;color: #c0c0c0;">=</span> domain
            LoginPassword <span style="color: #008000;color: #c0c0c0;">=</span> password
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Sub</span>
&nbsp;
        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Public</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Function</span> IsVersionCompatible<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Boolean</span>
            <span style="color: #008080; font-style: italic;color: #7F9F7F;">'get the options from the server to get the AS Version</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> optReq <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> System.<span style="color: #0000FF;color: #c0c0c0;">Net</span>.<span style="color: #0000FF;color: #c0c0c0;">HttpWebRequest</span> <span style="color: #008000;color: #c0c0c0;">=</span> GetAirSyncWebRequest<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #808080;color: #C89191;">&quot;&quot;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
            optReq.<span style="color: #0600FF;color: #C2964B; font-weight: bold;">Method</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #808080;color: #C89191;">&quot;OPTIONS&quot;</span>
&nbsp;
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> optResp <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> System.<span style="color: #0000FF;color: #c0c0c0;">Net</span>.<span style="color: #0000FF;color: #c0c0c0;">HttpWebResponse</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #0600FF;color: #c0c0c0;">CType</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>optReq.<span style="color: #0000FF;color: #c0c0c0;">GetResponse</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>, System.<span style="color: #0000FF;color: #c0c0c0;">Net</span>.<span style="color: #0000FF;color: #c0c0c0;">HttpWebResponse</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;color: #7F9F7F;">'200 OK?</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span> optResp.<span style="color: #0000FF;color: #c0c0c0;">StatusCode</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #FF0000;color: #8ACCCF;">200</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Then</span>
                <span style="color: #008080; font-style: italic;color: #7F9F7F;">'check server versions</span>
                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> msAsProtocolVersions <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span> <span style="color: #008000;color: #c0c0c0;">=</span> optResp.<span style="color: #0000FF;color: #c0c0c0;">Headers</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #808080;color: #C89191;">&quot;MS-ASProtocolVersions&quot;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span> <span style="color: #804040;">Not</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span>.<span style="color: #0000FF;color: #c0c0c0;">IsNullOrEmpty</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>msAsProtocolVersions<span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Then</span>
                    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> supportedVersions <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #008000;color: #c0c0c0;">=</span> msAsProtocolVersions.<span style="color: #0600FF;color: #c0c0c0;">Split</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #808080;color: #C89191;">&quot;,&quot;</span>c<span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
                    <span style="color: #008080; font-style: italic;color: #7F9F7F;">'must support AirSyncTargetVersion</span>
                    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span> supportedVersions.<span style="color: #0000FF;color: #c0c0c0;">Contains</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>AirSyncSupportedVersion<span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Then</span>
                        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Return</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">True</span>
                    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span>
                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span>
&nbsp;
            <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Return</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">False</span>
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Function</span>
&nbsp;
        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Public</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Sub</span> ObtainPolicyKey<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
            <span style="color: #008080; font-style: italic;color: #7F9F7F;">'in AirSync version 12 the policy type was changed from MS-WAP-Provisioning-XML to MS-EAS-Provisioning-WBXML</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> policyType <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #808080;color: #C89191;">&quot;&quot;</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span> <span style="color: #0600FF;color: #c0c0c0;">CDbl</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>AirSyncSupportedVersion<span style="color: #000000;color: #c0c0c0;">&#41;</span> &gt;<span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #FF0000;color: #8ACCCF;">12</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Then</span>
                policyType <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #808080;color: #C89191;">&quot;MS-EAS-Provisioning-WBXML&quot;</span>
            <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Else</span>
                policyType <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #808080;color: #C89191;">&quot;MS-WAP-Provisioning-XML&quot;</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span>
&nbsp;
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> opkXml <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span> <span style="color: #008000;color: #c0c0c0;">=</span> &lt;?xml version<span style="color: #008000;color: #c0c0c0;">=</span><span style="color: #808080;color: #C89191;">&quot;1.0&quot;</span> encoding<span style="color: #008000;color: #c0c0c0;">=</span><span style="color: #808080;color: #C89191;">&quot;utf-8&quot;</span>?&gt;
                                   &lt;Provision xmlns<span style="color: #008000;color: #c0c0c0;">=</span><span style="color: #808080;color: #C89191;">&quot;Provision:&quot;</span> xmlns:settings<span style="color: #008000;color: #c0c0c0;">=</span><span style="color: #808080;color: #C89191;">&quot;Settings:&quot;</span>&gt;
                                       &lt;Policies&gt;
                                           &lt;Policy&gt;
                                               &lt;PolicyType&gt;<span style="color: #000000;color: #c0c0c0;">&#123;</span>PolicyType<span style="color: #000000;color: #c0c0c0;">&#125;</span>&lt;<span style="color: #008000;color: #c0c0c0;">/</span>PolicyType&gt;
                                           &lt;<span style="color: #008000;color: #c0c0c0;">/</span>Policy&gt;
                                       &lt;<span style="color: #008000;color: #c0c0c0;">/</span>Policies&gt;
                                   &lt;<span style="color: #008000;color: #c0c0c0;">/</span>Provision&gt;.<span style="color: #0000FF;color: #c0c0c0;">ToString</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>.<span style="color: #0600FF;color: #c0c0c0;">Replace</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #808080;color: #C89191;">&quot;{PolicyType}&quot;</span>, policyType<span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> opkResult <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> System.<span style="color: #0000FF;color: #c0c0c0;">Xml</span>.<span style="color: #0000FF;color: #c0c0c0;">XmlDocument</span> <span style="color: #008000;color: #c0c0c0;">=</span> ExecuteAirSyncCommand<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #808080;color: #C89191;">&quot;Provision&quot;</span>, opkXml<span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span> opkResult <span style="color: #FF8000;color: #C2964B; font-weight: bold;">IsNot</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Nothing</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Then</span>
                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> opkNsMgr <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">New</span> Xml.<span style="color: #0000FF;color: #c0c0c0;">XmlNamespaceManager</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>opkResult.<span style="color: #0000FF;color: #c0c0c0;">NameTable</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
                <span style="color: #008080; font-style: italic;color: #7F9F7F;">'since XPATH v1 doesnt support default namespace, add our own prefix</span>
                opkNsMgr.<span style="color: #0000FF;color: #c0c0c0;">AddNamespace</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #808080;color: #C89191;">&quot;dflt&quot;</span>, Codepages.<span style="color: #0000FF;color: #c0c0c0;">Provision_14</span>.<span style="color: #0000FF;color: #c0c0c0;">Instance</span>.<span style="color: #0000FF;color: #c0c0c0;">XmlNs</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
                opkNsMgr.<span style="color: #0000FF;color: #c0c0c0;">AddNamespace</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>Codepages.<span style="color: #0000FF;color: #c0c0c0;">Settings_18</span>.<span style="color: #0000FF;color: #c0c0c0;">Instance</span>.<span style="color: #0000FF;color: #c0c0c0;">XmlPrefix</span>, Codepages.<span style="color: #0000FF;color: #c0c0c0;">Settings_18</span>.<span style="color: #0000FF;color: #c0c0c0;">Instance</span>.<span style="color: #0000FF;color: #c0c0c0;">XmlNs</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
                <span style="color: #008080; font-style: italic;color: #7F9F7F;">'this may not have a key, for e.g if their are no policies applied</span>
                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> pkNode <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> System.<span style="color: #0000FF;color: #c0c0c0;">Xml</span>.<span style="color: #0000FF;color: #c0c0c0;">XmlNode</span> <span style="color: #008000;color: #c0c0c0;">=</span> opkResult.<span style="color: #0000FF;color: #c0c0c0;">SelectSingleNode</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #808080;color: #C89191;">&quot;dflt:Provision/dflt:Policies/dflt:Policy/dflt:PolicyKey&quot;</span>, opkNsMgr<span style="color: #000000;color: #c0c0c0;">&#41;</span>
                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span> pkNode <span style="color: #FF8000;color: #C2964B; font-weight: bold;">IsNot</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Nothing</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Then</span> PolicyKey <span style="color: #008000;color: #c0c0c0;">=</span> pkNode.<span style="color: #0000FF;color: #c0c0c0;">InnerText</span>
&nbsp;
                <span style="color: #008080; font-style: italic;color: #7F9F7F;">'TODO: this might need to reply to the server in future to confirm policy settings, but not for now...</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span>
&nbsp;
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Sub</span>
&nbsp;
        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Public</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Function</span> ExecuteAirSyncCommand<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF8000;color: #C2964B; font-weight: bold;">ByVal</span> <span style="color: #0600FF;color: #c0c0c0;">command</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span>, <span style="color: #FF8000;color: #C2964B; font-weight: bold;">ByVal</span> xmlBody <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> System.<span style="color: #0000FF;color: #c0c0c0;">Xml</span>.<span style="color: #0000FF;color: #c0c0c0;">XmlDocument</span>
            <span style="color: #008080; font-style: italic;color: #7F9F7F;">'create a command query with some dummy device data</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> commandQuery <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span>.<span style="color: #0600FF;color: #c0c0c0;">Format</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #808080;color: #C89191;">&quot;?User={0}&amp;DeviceId=CwWebDevice1234&amp;DeviceType=PocketPC&amp;Cmd={1}&quot;</span>, ASUsername, <span style="color: #0600FF;color: #c0c0c0;">command</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;color: #7F9F7F;">'create a request to execute the command</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> execReq <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> System.<span style="color: #0000FF;color: #c0c0c0;">Net</span>.<span style="color: #0000FF;color: #c0c0c0;">HttpWebRequest</span> <span style="color: #008000;color: #c0c0c0;">=</span> GetAirSyncWebRequest<span style="color: #000000;color: #c0c0c0;">&#40;</span>commandQuery<span style="color: #000000;color: #c0c0c0;">&#41;</span>
            execReq.<span style="color: #0600FF;color: #C2964B; font-weight: bold;">Method</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #808080;color: #C89191;">&quot;POST&quot;</span>
            execReq.<span style="color: #0000FF;color: #c0c0c0;">Headers</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #808080;color: #C89191;">&quot;MS-ASProtocolVersion&quot;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #008000;color: #c0c0c0;">=</span> AirSyncSupportedVersion
            execReq.<span style="color: #0000FF;color: #c0c0c0;">ContentType</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #808080;color: #C89191;">&quot;application/vnd.ms-sync.wbxml&quot;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;color: #7F9F7F;">'convert the xml to wbxml</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> transportData<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Byte</span> <span style="color: #008000;color: #c0c0c0;">=</span> GetWbxmlFromXml<span style="color: #000000;color: #c0c0c0;">&#40;</span>xmlBody<span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
            execReq.<span style="color: #0000FF;color: #c0c0c0;">ContentLength</span> <span style="color: #008000;color: #c0c0c0;">=</span> transportData.<span style="color: #0000FF;color: #c0c0c0;">Length</span>
&nbsp;
            <span style="color: #008080; font-style: italic;color: #7F9F7F;">'transfer the bytes</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> requestStream <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> IO.<span style="color: #0000FF;color: #c0c0c0;">Stream</span> <span style="color: #008000;color: #c0c0c0;">=</span> execReq.<span style="color: #0000FF;color: #c0c0c0;">GetRequestStream</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
            requestStream.<span style="color: #0600FF;color: #C2964B; font-weight: bold;">Write</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>transportData, <span style="color: #FF0000;color: #8ACCCF;">0</span>, transportData.<span style="color: #0000FF;color: #c0c0c0;">Length</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
            requestStream.<span style="color: #0600FF;color: #c0c0c0;">Close</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;color: #7F9F7F;">'get response</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> execResp <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> System.<span style="color: #0000FF;color: #c0c0c0;">Net</span>.<span style="color: #0000FF;color: #c0c0c0;">HttpWebResponse</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #0600FF;color: #c0c0c0;">CType</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>execReq.<span style="color: #0000FF;color: #c0c0c0;">GetResponse</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>, System.<span style="color: #0000FF;color: #c0c0c0;">Net</span>.<span style="color: #0000FF;color: #c0c0c0;">HttpWebResponse</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span> execResp.<span style="color: #0000FF;color: #c0c0c0;">StatusCode</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #FF0000;color: #8ACCCF;">200</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Then</span>
                <span style="color: #008080; font-style: italic;color: #7F9F7F;">'convert the wbxml to xml</span>
                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> wbxmlRespDoc <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">New</span> EncodingHelpers.<span style="color: #0000FF;color: #c0c0c0;">WBXML</span>.<span style="color: #0000FF;color: #c0c0c0;">WbXmlDocument</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>ASCodePages<span style="color: #000000;color: #c0c0c0;">&#41;</span>
                wbxmlRespDoc.<span style="color: #0000FF;color: #c0c0c0;">Load</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>execResp.<span style="color: #0000FF;color: #c0c0c0;">GetResponseStream</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
                <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Return</span> wbxmlRespDoc
            <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Else</span>
                <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Throw</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">New</span> Exception<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #808080;color: #C89191;">&quot;Status from server was not 200 (&quot;</span> <span style="color: #008000;color: #c0c0c0;">&amp;</span> execResp.<span style="color: #0000FF;color: #c0c0c0;">StatusCode</span> <span style="color: #008000;color: #c0c0c0;">&amp;</span> <span style="color: #808080;color: #C89191;">&quot;)&quot;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span>
&nbsp;
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Function</span>
&nbsp;
        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Private</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Function</span> GetAirSyncWebRequest<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF8000;color: #C2964B; font-weight: bold;">ByVal</span> queryString <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> System.<span style="color: #0000FF;color: #c0c0c0;">Net</span>.<span style="color: #0000FF;color: #c0c0c0;">HttpWebRequest</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> fullUrl <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span> <span style="color: #008000;color: #c0c0c0;">=</span> ActiveSyncBaseAddress <span style="color: #008000;color: #c0c0c0;">&amp;</span> <span style="color: #0600FF;color: #c0c0c0;">CStr</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #0600FF;color: #c0c0c0;">IIf</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #804040;">Not</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span>.<span style="color: #0000FF;color: #c0c0c0;">IsNullOrEmpty</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>queryString<span style="color: #000000;color: #c0c0c0;">&#41;</span>, queryString, <span style="color: #808080;color: #C89191;">&quot;&quot;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> asReq <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> System.<span style="color: #0000FF;color: #c0c0c0;">Net</span>.<span style="color: #0000FF;color: #c0c0c0;">HttpWebRequest</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #0600FF;color: #c0c0c0;">CType</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>System.<span style="color: #0000FF;color: #c0c0c0;">Net</span>.<span style="color: #0000FF;color: #c0c0c0;">WebRequest</span>.<span style="color: #0000FF;color: #c0c0c0;">Create</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>fullUrl<span style="color: #000000;color: #c0c0c0;">&#41;</span>, System.<span style="color: #0000FF;color: #c0c0c0;">Net</span>.<span style="color: #0000FF;color: #c0c0c0;">HttpWebRequest</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
            asReq.<span style="color: #0000FF;color: #c0c0c0;">Credentials</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">New</span> System.<span style="color: #0000FF;color: #c0c0c0;">Net</span>.<span style="color: #0000FF;color: #c0c0c0;">NetworkCredential</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>LoginUsername, LoginPassword, LoginDomain<span style="color: #000000;color: #c0c0c0;">&#41;</span>
            <span style="color: #008080; font-style: italic;color: #7F9F7F;">'BASIC: optReq.Headers(&quot;Authorization&quot;) = &quot;Basic &quot; &amp; Convert.ToBase64String(Encoding.UTF8.GetBytes(domain &amp; &quot;\&quot; &amp; username &amp; &quot;:&quot; &amp; password))</span>
            asReq.<span style="color: #0000FF;color: #c0c0c0;">UserAgent</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #808080;color: #C89191;">&quot;Microsoft-Server-AirSyncClient/2.5+(CraigW)&quot;</span>
            asReq.<span style="color: #0000FF;color: #c0c0c0;">KeepAlive</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">True</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span> <span style="color: #804040;">Not</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span>.<span style="color: #0000FF;color: #c0c0c0;">IsNullOrEmpty</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>PolicyKey<span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Then</span> asReq.<span style="color: #0000FF;color: #c0c0c0;">Headers</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #808080;color: #C89191;">&quot;X-MS-PolicyKey&quot;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #008000;color: #c0c0c0;">=</span> PolicyKey
&nbsp;
            <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Return</span> asReq
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Function</span>
&nbsp;
        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Private</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Function</span> GetWbxmlFromXml<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF8000;color: #C2964B; font-weight: bold;">ByVal</span> xml <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Byte</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
            <span style="color: #008080; font-style: italic;color: #7F9F7F;">'create new converter with our code pages</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> wbxmlReqDoc <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">New</span> EncodingHelpers.<span style="color: #0000FF;color: #c0c0c0;">WBXML</span>.<span style="color: #0000FF;color: #c0c0c0;">WbXmlDocument</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>ASCodePages<span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;color: #7F9F7F;">'load the xml source</span>
            wbxmlReqDoc.<span style="color: #0000FF;color: #c0c0c0;">LoadXml</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>xml<span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;color: #7F9F7F;">'return the bytes</span>
            <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Return</span> wbxmlReqDoc.<span style="color: #0000FF;color: #c0c0c0;">GetBytes</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Function</span>
&nbsp;
        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Private</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Sub</span> InitAirSyncCodepages<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
            _asCodePages <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">New</span> <span style="color: #008000;color: #2B91AF;">Dictionary</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>Of <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Integer</span>, EncodingHelpers.<span style="color: #0000FF;color: #c0c0c0;">WBXML</span>.<span style="color: #0000FF;color: #c0c0c0;">WbXmlCodepage</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;color: #7F9F7F;">'AirSync - 0</span>
            _asCodePages.<span style="color: #0000FF;color: #c0c0c0;">Add</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>Codepages.<span style="color: #0000FF;color: #c0c0c0;">AirSync_0</span>.<span style="color: #0000FF;color: #c0c0c0;">Instance</span>.<span style="color: #0000FF;color: #c0c0c0;">Codepage</span>, Codepages.<span style="color: #0000FF;color: #c0c0c0;">AirSync_0</span>.<span style="color: #0000FF;color: #c0c0c0;">Instance</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;color: #7F9F7F;">'Contacts - 1</span>
            _asCodePages.<span style="color: #0000FF;color: #c0c0c0;">Add</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>Codepages.<span style="color: #0000FF;color: #c0c0c0;">Contacts_1</span>.<span style="color: #0000FF;color: #c0c0c0;">Instance</span>.<span style="color: #0000FF;color: #c0c0c0;">Codepage</span>, Codepages.<span style="color: #0000FF;color: #c0c0c0;">Contacts_1</span>.<span style="color: #0000FF;color: #c0c0c0;">Instance</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;color: #7F9F7F;">'Calendar - 4</span>
            _asCodePages.<span style="color: #0000FF;color: #c0c0c0;">Add</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>Codepages.<span style="color: #0000FF;color: #c0c0c0;">Calendar_4</span>.<span style="color: #0000FF;color: #c0c0c0;">Instance</span>.<span style="color: #0000FF;color: #c0c0c0;">Codepage</span>, Codepages.<span style="color: #0000FF;color: #c0c0c0;">Calendar_4</span>.<span style="color: #0000FF;color: #c0c0c0;">Instance</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;color: #7F9F7F;">'FolderHierarchy - 7</span>
            _asCodePages.<span style="color: #0000FF;color: #c0c0c0;">Add</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>Codepages.<span style="color: #0000FF;color: #c0c0c0;">FolderHierarchy_7</span>.<span style="color: #0000FF;color: #c0c0c0;">Instance</span>.<span style="color: #0000FF;color: #c0c0c0;">Codepage</span>, Codepages.<span style="color: #0000FF;color: #c0c0c0;">FolderHierarchy_7</span>.<span style="color: #0000FF;color: #c0c0c0;">Instance</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;color: #7F9F7F;">'Provision - 14</span>
            _asCodePages.<span style="color: #0000FF;color: #c0c0c0;">Add</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>Codepages.<span style="color: #0000FF;color: #c0c0c0;">Provision_14</span>.<span style="color: #0000FF;color: #c0c0c0;">Instance</span>.<span style="color: #0000FF;color: #c0c0c0;">Codepage</span>, Codepages.<span style="color: #0000FF;color: #c0c0c0;">Provision_14</span>.<span style="color: #0000FF;color: #c0c0c0;">Instance</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;color: #7F9F7F;">'AirsyncBase - 17</span>
            _asCodePages.<span style="color: #0000FF;color: #c0c0c0;">Add</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>Codepages.<span style="color: #0000FF;color: #c0c0c0;">AirSyncBase_17</span>.<span style="color: #0000FF;color: #c0c0c0;">Instance</span>.<span style="color: #0000FF;color: #c0c0c0;">Codepage</span>, Codepages.<span style="color: #0000FF;color: #c0c0c0;">AirSyncBase_17</span>.<span style="color: #0000FF;color: #c0c0c0;">Instance</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;color: #7F9F7F;">'Settings  - 18</span>
            _asCodePages.<span style="color: #0000FF;color: #c0c0c0;">Add</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>Codepages.<span style="color: #0000FF;color: #c0c0c0;">Settings_18</span>.<span style="color: #0000FF;color: #c0c0c0;">Instance</span>.<span style="color: #0000FF;color: #c0c0c0;">Codepage</span>, Codepages.<span style="color: #0000FF;color: #c0c0c0;">Settings_18</span>.<span style="color: #0000FF;color: #c0c0c0;">Instance</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
&nbsp;
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Sub</span>
    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Class</span>
<span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Namespace</span></pre></div></div>

<p>As you will see the code relies on an encoder helper for the WBXML format. The WBXML format is, again, not well supported for .NET framework, however I did find a <a href="http://www.codeproject.com/KB/cs/WBXML_document_in_C_.aspx" target="_blank" rel="nofollow">C# sample by Tamir Khason on CodeProject</a>. This example was a good starting point, as I was working in VB.NET on this project I first converted the code to VB.NET and (after fixing some issues caused by the converter) began modifying the code as, by the authors own admission, the code is not fully finished.</p>
<p>My changes are noted in the comments at the top of and throughout the code.</p>
<p>The new version of the class is shown below:</p>

<div class="wp_syntax"><div class="code"><pre class="vbnet" style="font-family:monospace;color: #c0c0c0; font-family: Franklin Gothic Book;"><span style="color: #008080; font-style: italic;color: #7F9F7F;">'CONVERTED FROM ORIGINAL C# CLASS:</span>
<span style="color: #008080; font-style: italic;color: #7F9F7F;">' This class is released under restrictive CPL</span>
<span style="color: #008080; font-style: italic;color: #7F9F7F;">' You can use this code or code, derived from this code in either </span>
<span style="color: #008080; font-style: italic;color: #7F9F7F;">' open source, free or commercial application, however, </span>
<span style="color: #008080; font-style: italic;color: #7F9F7F;">' you should clearly provide my name &quot;Tamir Khason&quot; </span>
<span style="color: #008080; font-style: italic;color: #7F9F7F;">' and link to my blog http://blogs.microsoft.co.il/blogs/tamir/ </span>
<span style="color: #008080; font-style: italic;color: #7F9F7F;">' or my private web site http://khason.biz within any distribution of the software. </span>
<span style="color: #008080; font-style: italic;color: #7F9F7F;">' For more information, contact me at tamir@khason.biz</span>
&nbsp;
&nbsp;
<span style="color: #008080; font-style: italic;color: #7F9F7F;">' Some additional changes were made to give better XML compatibility, (to make compatible for use with AirSync)</span>
<span style="color: #008080; font-style: italic;color: #7F9F7F;">' This includes:</span>
<span style="color: #008080; font-style: italic;color: #7F9F7F;">' - fixed the way tags are closed (using a stack instead of searching the text)</span>
<span style="color: #008080; font-style: italic;color: #7F9F7F;">' - added XML namespace compatibility </span>
<span style="color: #008080; font-style: italic;color: #7F9F7F;">'        -to switch codepages based on xml prefix, not first token found, when encoding XML -&gt; WBXML</span>
<span style="color: #008080; font-style: italic;color: #7F9F7F;">'       - also to encode the namespaces back into the XML output when decoding WBXML -&gt; XML</span>
<span style="color: #008080; font-style: italic;color: #7F9F7F;">' - added extra logic for inclusion of the attriubute wbxml flag (only if token exists)</span>
<span style="color: #008080; font-style: italic;color: #7F9F7F;">' - defined a strongly typed codepage/tags class to define the required extra data (xml namespace/prefix)</span>
<span style="color: #008080; font-style: italic;color: #7F9F7F;">' - added CDATA tags around XML content to prevent xml parser issues</span>
&nbsp;
&nbsp;
&nbsp;
<span style="color: #0600FF;color: #C2964B; font-weight: bold;">Imports</span> System.<span style="color: #0000FF;color: #c0c0c0;">Collections</span>.<span style="color: #0000FF;color: #c0c0c0;">Generic</span>
<span style="color: #0600FF;color: #C2964B; font-weight: bold;">Imports</span> System.<span style="color: #0000FF;color: #c0c0c0;">Text</span>
<span style="color: #0600FF;color: #C2964B; font-weight: bold;">Imports</span> System.<span style="color: #0000FF;color: #c0c0c0;">Xml</span>
<span style="color: #0600FF;color: #C2964B; font-weight: bold;">Imports</span> System.<span style="color: #0000FF;color: #c0c0c0;">IO</span>
<span style="color: #0600FF;color: #C2964B; font-weight: bold;">Imports</span> System.<span style="color: #0000FF;color: #c0c0c0;">Text</span>.<span style="color: #0000FF;color: #c0c0c0;">RegularExpressions</span>
&nbsp;
<span style="color: #0600FF;color: #C2964B; font-weight: bold;">Namespace</span> EncodingHelpers.<span style="color: #0000FF;color: #c0c0c0;">WBXML</span>
    <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Friend</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Class</span> WbXmlDocument
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Inherits</span> XmlDocument
        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Public</span> VersionNumber <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #808080;color: #C89191;">&quot;1.3&quot;</span>
        <span style="color: #008080; font-style: italic;color: #7F9F7F;">'temp</span>
        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Public</span> Charset <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> Encoding
        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Private</span> GlobalTokens <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #008000;color: #2B91AF;">Dictionary</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>Of <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Byte</span>, <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
        <span style="color: #008080; font-style: italic;color: #7F9F7F;">'change this to be strongly typed codepages with additional XML info</span>
        <span style="color: #008080; font-style: italic;color: #7F9F7F;">'Private LocalTokens As Dictionary(Of Integer, Dictionary(Of Byte, String)), </span>
        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Private</span> LocalAttributes <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #008000;color: #2B91AF;">Dictionary</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>Of <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Integer</span>, <span style="color: #008000;color: #2B91AF;">Dictionary</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>Of <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Byte</span>, <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Private</span> LocalTokens <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #008000;color: #2B91AF;">Dictionary</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>Of <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Integer</span>, WbXmlCodepage<span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Public</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Sub</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">New</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
            <span style="color: #FF8000;color: #C2964B; font-weight: bold;">MyBase</span>.<span style="color: #FF8000;color: #C2964B; font-weight: bold;">New</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
            initGlobalTokens<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Sub</span>
&nbsp;
        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Public</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Sub</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">New</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF8000;color: #C2964B; font-weight: bold;">ByVal</span> tokens <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #008000;color: #2B91AF;">Dictionary</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>Of <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Integer</span>, WbXmlCodepage<span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
            <span style="color: #FF8000;color: #C2964B; font-weight: bold;">MyBase</span>.<span style="color: #FF8000;color: #C2964B; font-weight: bold;">New</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
            initGlobalTokens<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
            LocalTokens <span style="color: #008000;color: #c0c0c0;">=</span> tokens
            LocalAttributes <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">New</span> <span style="color: #008000;color: #2B91AF;">Dictionary</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>Of <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Integer</span>, <span style="color: #008000;color: #2B91AF;">Dictionary</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>Of <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Byte</span>, <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Sub</span>
&nbsp;
        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Public</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Sub</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">New</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF8000;color: #C2964B; font-weight: bold;">ByVal</span> tokens <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #008000;color: #2B91AF;">Dictionary</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>Of <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Integer</span>, WbXmlCodepage<span style="color: #000000;color: #c0c0c0;">&#41;</span>, <span style="color: #FF8000;color: #C2964B; font-weight: bold;">ByVal</span> attributes <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #008000;color: #2B91AF;">Dictionary</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>Of <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Integer</span>, <span style="color: #008000;color: #2B91AF;">Dictionary</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>Of <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Byte</span>, <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
            <span style="color: #FF8000;color: #C2964B; font-weight: bold;">MyBase</span>.<span style="color: #FF8000;color: #C2964B; font-weight: bold;">New</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
            initGlobalTokens<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
            LocalTokens <span style="color: #008000;color: #c0c0c0;">=</span> tokens
            LocalAttributes <span style="color: #008000;color: #c0c0c0;">=</span> attributes
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Sub</span>
&nbsp;
        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Private</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Sub</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">New</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF8000;color: #C2964B; font-weight: bold;">ByVal</span> <span style="color: #0600FF;color: #ff0000;">imp</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> XmlImplementation<span style="color: #000000;color: #c0c0c0;">&#41;</span>
            <span style="color: #FF8000;color: #C2964B; font-weight: bold;">MyBase</span>.<span style="color: #FF8000;color: #C2964B; font-weight: bold;">New</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #0600FF;color: #ff0000;">imp</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Sub</span>
        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Private</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Sub</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">New</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF8000;color: #C2964B; font-weight: bold;">ByVal</span> nt <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> XmlNameTable<span style="color: #000000;color: #c0c0c0;">&#41;</span>
            <span style="color: #FF8000;color: #C2964B; font-weight: bold;">MyBase</span>.<span style="color: #FF8000;color: #C2964B; font-weight: bold;">New</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>nt<span style="color: #000000;color: #c0c0c0;">&#41;</span>
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Sub</span>
&nbsp;
        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Private</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Sub</span> initGlobalTokens<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
            GlobalTokens <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">New</span> <span style="color: #008000;color: #2B91AF;">Dictionary</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>Of <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Byte</span>, <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> vals <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #000000;color: #c0c0c0;">&#91;</span><span style="color: #0600FF;color: #C2964B; font-weight: bold;">Enum</span><span style="color: #000000;color: #c0c0c0;">&#93;</span>.<span style="color: #0000FF;color: #c0c0c0;">GetNames</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #804040;">GetType</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>GlobalToken<span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
            <span style="color: #FF8000;color: #C2964B; font-weight: bold;">For</span> i <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Integer</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #FF0000;color: #8ACCCF;">0</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">To</span> vals.<span style="color: #0000FF;color: #c0c0c0;">Length</span> <span style="color: #008000;color: #c0c0c0;">-</span> <span style="color: #FF0000;color: #8ACCCF;">1</span>
                GlobalTokens.<span style="color: #0000FF;color: #c0c0c0;">Add</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #0600FF;color: #c0c0c0;">CByte</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #0600FF;color: #c0c0c0;">CType</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#91;</span><span style="color: #0600FF;color: #C2964B; font-weight: bold;">Enum</span><span style="color: #000000;color: #c0c0c0;">&#93;</span>.<span style="color: #0000FF;color: #c0c0c0;">Parse</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #804040;">GetType</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>GlobalToken<span style="color: #000000;color: #c0c0c0;">&#41;</span>, vals<span style="color: #000000;color: #c0c0c0;">&#40;</span>i<span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>, GlobalToken<span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>, vals<span style="color: #000000;color: #c0c0c0;">&#40;</span>i<span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
            <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Next</span>
&nbsp;
            LocalTokens <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">New</span> <span style="color: #008000;color: #2B91AF;">Dictionary</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>Of <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Integer</span>, WbXmlCodepage<span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Sub</span>
&nbsp;
        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Private</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Enum</span> GlobalToken
            SWITCH_PAGE <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #008000;color: #c0c0c0;">&amp;</span>H0
            <span style="color: #008080; font-style: italic;color: #7F9F7F;">' Change the code page for the current token state. Followed by a single u_int8 indicating the new code page number. </span>
            <span style="color: #000000;color: #c0c0c0;">&#91;</span><span style="color: #0600FF;color: #C2964B; font-weight: bold;">END</span><span style="color: #000000;color: #c0c0c0;">&#93;</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #008000;color: #c0c0c0;">&amp;</span>H1
            <span style="color: #008080; font-style: italic;color: #7F9F7F;">' Indicates the end of an attribute list or the end of an element. </span>
            ENTITY <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #008000;color: #c0c0c0;">&amp;</span>H2
            <span style="color: #008080; font-style: italic;color: #7F9F7F;">' A character entity. Followed by a mb_u_int32 encoding the character entity number. </span>
            STR_I <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #008000;color: #c0c0c0;">&amp;</span>H3
            <span style="color: #008080; font-style: italic;color: #7F9F7F;">'Inline string. Followed by a termstr. </span>
            LITERAL <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #008000;color: #c0c0c0;">&amp;</span>H4
            <span style="color: #008080; font-style: italic;color: #7F9F7F;">' An unknown tag or attribute name. Followed by an mb_u_int32 that encodes an offset into the string table. </span>
            EXT_I_0 <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #008000;color: #c0c0c0;">&amp;</span>H40
            <span style="color: #008080; font-style: italic;color: #7F9F7F;">' Inline string document-type-specific extension token. Token is followed by a termstr. </span>
            EXT_I_1 <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #008000;color: #c0c0c0;">&amp;</span>H41
            <span style="color: #008080; font-style: italic;color: #7F9F7F;">' Inline string document-type-specific extension token. Token is followed by a termstr. </span>
            EXT_I_2 <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #008000;color: #c0c0c0;">&amp;</span>H42
            <span style="color: #008080; font-style: italic;color: #7F9F7F;">' Inline string document-type-specific extension token. Token is followed by a termstr. </span>
            PI <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #008000;color: #c0c0c0;">&amp;</span>H43
            <span style="color: #008080; font-style: italic;color: #7F9F7F;">' Processing instruction. </span>
            LITERAL_C <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #008000;color: #c0c0c0;">&amp;</span>H44
            <span style="color: #008080; font-style: italic;color: #7F9F7F;">' Unknown tag, with content. </span>
            EXT_T_0 <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #008000;color: #c0c0c0;">&amp;</span>H80
            <span style="color: #008080; font-style: italic;color: #7F9F7F;">' Inline integer document-type-specific extension token. Token is followed by a mb_uint_32. </span>
            EXT_T_1 <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #008000;color: #c0c0c0;">&amp;</span>H81
            <span style="color: #008080; font-style: italic;color: #7F9F7F;">' Inline integer document-type-specific extension token. Token is followed by a mb_uint_32. </span>
            EXT_T_2 <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #008000;color: #c0c0c0;">&amp;</span>H82
            <span style="color: #008080; font-style: italic;color: #7F9F7F;">' Inline integer document-type-specific extension token. Token is followed by a mb_uint_32. </span>
            STR_T <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #008000;color: #c0c0c0;">&amp;</span>H83
            <span style="color: #008080; font-style: italic;color: #7F9F7F;">' String table reference. Followed by a mb_u_int32 encoding a byte offset from the beginning of the string table. </span>
            LITERAL_A <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #008000;color: #c0c0c0;">&amp;</span>H84
            <span style="color: #008080; font-style: italic;color: #7F9F7F;">' Unknown tag, with attributes. </span>
            EXT_0 <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #008000;color: #c0c0c0;">&amp;</span>HC0
            <span style="color: #008080; font-style: italic;color: #7F9F7F;">' Single-byte document-type-specific extension token. </span>
            EXT_1 <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #008000;color: #c0c0c0;">&amp;</span>HC1
            <span style="color: #008080; font-style: italic;color: #7F9F7F;">' Single-byte document-type-specific extension token. </span>
            EXT_2 <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #008000;color: #c0c0c0;">&amp;</span>HC2
            <span style="color: #008080; font-style: italic;color: #7F9F7F;">' Single-byte document-type-specific extension token. </span>
            OPAQUE <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #008000;color: #c0c0c0;">&amp;</span>HC3
            <span style="color: #008080; font-style: italic;color: #7F9F7F;">' Opaque document-type-specific data. </span>
            LITERAL_AC <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #008000;color: #c0c0c0;">&amp;</span>HC4
            <span style="color: #008080; font-style: italic;color: #7F9F7F;">' Unknown tag, with content and attributes.</span>
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Enum</span>
&nbsp;
        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Private</span> currentCodePage <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Integer</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #FF0000;color: #8ACCCF;">0</span>
        <span style="color: #008080; font-style: italic;color: #7F9F7F;">'fix for MS 1;</span>
        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Public</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Overrides</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Sub</span> Load<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF8000;color: #C2964B; font-weight: bold;">ByVal</span> inStream <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> Stream<span style="color: #000000;color: #c0c0c0;">&#41;</span>
            Using reader <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">New</span> StreamReader<span style="color: #000000;color: #c0c0c0;">&#40;</span>inStream<span style="color: #000000;color: #c0c0c0;">&#41;</span>
                Load<span style="color: #000000;color: #c0c0c0;">&#40;</span>Encoding.<span style="color: #0000FF;color: #c0c0c0;">UTF8</span>.<span style="color: #0000FF;color: #c0c0c0;">GetBytes</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>reader.<span style="color: #0000FF;color: #c0c0c0;">ReadToEnd</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
                reader.<span style="color: #0600FF;color: #c0c0c0;">Close</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> Using
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Sub</span>
&nbsp;
        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Public</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Overloads</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Sub</span> Load<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF8000;color: #C2964B; font-weight: bold;">ByVal</span> WBXmlData <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Byte</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> waitForAttr <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Boolean</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">False</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> waitForContent <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Boolean</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">False</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> openXmlTags <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">New</span> Stack<span style="color: #000000;color: #c0c0c0;">&#40;</span>Of <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> codepagesUsed <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">New</span> List<span style="color: #000000;color: #c0c0c0;">&#40;</span>Of <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Integer</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span> WBXmlData <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Is</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Nothing</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Then</span>
                <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Return</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span>
&nbsp;
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> builder <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">New</span> StringBuilder<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span> WBXmlData.<span style="color: #0000FF;color: #c0c0c0;">Length</span> &gt; <span style="color: #FF0000;color: #8ACCCF;">3</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Then</span>
                <span style="color: #008080; font-style: italic;color: #7F9F7F;">'first byte -&gt; version number</span>
                VersionNumber <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span>.<span style="color: #0600FF;color: #c0c0c0;">Format</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #808080;color: #C89191;">&quot;1.{0}&quot;</span>, WBXmlData<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF0000;color: #8ACCCF;">0</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
                <span style="color: #008080; font-style: italic;color: #7F9F7F;">'second byte -&gt; public identifier. Void it.</span>
&nbsp;
                <span style="color: #008080; font-style: italic;color: #7F9F7F;">'third byte -&gt; charset (IANA)</span>
                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Try</span>
                    Charset <span style="color: #008000;color: #c0c0c0;">=</span> Encoding.<span style="color: #0000FF;color: #c0c0c0;">GetEncoding</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>WBXmlData<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF0000;color: #8ACCCF;">2</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Catch</span>
                    Charset <span style="color: #008000;color: #c0c0c0;">=</span> Encoding.<span style="color: #0000FF;color: #c0c0c0;">UTF8</span>
                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Try</span>
&nbsp;
                <span style="color: #008080; font-style: italic;color: #7F9F7F;">'forth byte -&gt; string table</span>
                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> stringTableLenght <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Integer</span> <span style="color: #008000;color: #c0c0c0;">=</span> WBXmlData<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF0000;color: #8ACCCF;">3</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
                <span style="color: #FF8000;color: #C2964B; font-weight: bold;">For</span> i <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Integer</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #FF0000;color: #8ACCCF;">4</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">To</span> <span style="color: #FF0000;color: #8ACCCF;">4</span> <span style="color: #008000;color: #c0c0c0;">+</span> <span style="color: #000000;color: #c0c0c0;">&#40;</span>stringTableLenght <span style="color: #008000;color: #c0c0c0;">-</span> <span style="color: #FF0000;color: #8ACCCF;">1</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
                    <span style="color: #008080; font-style: italic;color: #7F9F7F;">'read string table (if exist</span>
                    Console.<span style="color: #0000FF;color: #c0c0c0;">WriteLine</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
                <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Next</span>
&nbsp;
                <span style="color: #008080; font-style: italic;color: #7F9F7F;">'4 + stringTableLenght byte and up -&gt; token structs;</span>
                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> carret <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Integer</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #FF0000;color: #8ACCCF;">4</span> <span style="color: #008000;color: #c0c0c0;">+</span> stringTableLenght
&nbsp;
                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">While</span> carret &lt; WBXmlData.<span style="color: #0000FF;color: #c0c0c0;">Length</span>
                    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span> GlobalTokens.<span style="color: #0000FF;color: #c0c0c0;">ContainsKey</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>WBXmlData<span style="color: #000000;color: #c0c0c0;">&#40;</span>carret<span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Then</span>
                        <span style="color: #008080; font-style: italic;color: #7F9F7F;">'global token;</span>
                        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Select</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Case</span> <span style="color: #0600FF;color: #c0c0c0;">CType</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>WBXmlData<span style="color: #000000;color: #c0c0c0;">&#40;</span>carret<span style="color: #000000;color: #c0c0c0;">&#41;</span>, GlobalToken<span style="color: #000000;color: #c0c0c0;">&#41;</span>
                            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Case</span> GlobalToken.<span style="color: #0000FF;color: #c0c0c0;">SWITCH_PAGE</span>
                                carret <span style="color: #008000;color: #c0c0c0;">+=</span> <span style="color: #FF0000;color: #8ACCCF;">1</span>
                                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span> carret &gt;<span style="color: #008000;color: #c0c0c0;">=</span> WBXmlData.<span style="color: #0000FF;color: #c0c0c0;">Length</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Then</span>
                                    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Exit</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Select</span>
                                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span>
                                currentCodePage <span style="color: #008000;color: #c0c0c0;">=</span> WBXmlData<span style="color: #000000;color: #c0c0c0;">&#40;</span>carret<span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
                                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span> <span style="color: #804040;">Not</span> LocalTokens.<span style="color: #0000FF;color: #c0c0c0;">ContainsKey</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>WBXmlData<span style="color: #000000;color: #c0c0c0;">&#40;</span>carret<span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Then</span>
                                    <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Throw</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">New</span> XmlException<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span>.<span style="color: #0600FF;color: #c0c0c0;">Format</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #808080;color: #C89191;">&quot;Code page {0} was not loaded&quot;</span>, WBXmlData<span style="color: #000000;color: #c0c0c0;">&#40;</span>carret<span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
                                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span>
                                carret <span style="color: #008000;color: #c0c0c0;">+=</span> <span style="color: #FF0000;color: #8ACCCF;">1</span>
                                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Exit</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Select</span>
                            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Case</span> GlobalToken.<span style="color: #0000FF;color: #c0c0c0;">STR_I</span>
                                carret <span style="color: #008000;color: #c0c0c0;">+=</span> <span style="color: #FF0000;color: #8ACCCF;">1</span>
                                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span> carret &gt;<span style="color: #008000;color: #c0c0c0;">=</span> WBXmlData.<span style="color: #0000FF;color: #c0c0c0;">Length</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Then</span>
                                    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Exit</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Select</span>
                                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span>
                                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> <span style="color: #0600FF;color: #c0c0c0;">str</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">New</span> List<span style="color: #000000;color: #c0c0c0;">&#40;</span>Of <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Byte</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
                                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">While</span> WBXmlData<span style="color: #000000;color: #c0c0c0;">&#40;</span>carret<span style="color: #000000;color: #c0c0c0;">&#41;</span> &lt;&gt; <span style="color: #008000;color: #c0c0c0;">&amp;</span>H0
                                    <span style="color: #008080; font-style: italic;color: #7F9F7F;">'fix from Max to Min (incorrect conversion from c# carret++ operator into VB.NET)</span>
                                    <span style="color: #0600FF;color: #c0c0c0;">str</span>.<span style="color: #0000FF;color: #c0c0c0;">Add</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>WBXmlData<span style="color: #000000;color: #c0c0c0;">&#40;</span>System.<span style="color: #0000FF;color: #c0c0c0;">Math</span>.<span style="color: #0000FF;color: #c0c0c0;">Min</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>System.<span style="color: #0000FF;color: #c0c0c0;">Threading</span>.<span style="color: #0000FF;color: #c0c0c0;">Interlocked</span>.<span style="color: #0000FF;color: #c0c0c0;">Increment</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>carret<span style="color: #000000;color: #c0c0c0;">&#41;</span>, carret <span style="color: #008000;color: #c0c0c0;">-</span> <span style="color: #FF0000;color: #8ACCCF;">1</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
                                    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span> carret &gt;<span style="color: #008000;color: #c0c0c0;">=</span> WBXmlData.<span style="color: #0000FF;color: #c0c0c0;">Length</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Then</span>
                                        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Exit</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">While</span>
                                    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span>
                                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">While</span>
                                <span style="color: #008080; font-style: italic;color: #7F9F7F;">'put inside CDATA tags so it doesnt break the parser</span>
                                builder.<span style="color: #0000FF;color: #c0c0c0;">Append</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #808080;color: #C89191;">&quot;&lt;![CDATA[&quot;</span> <span style="color: #008000;color: #c0c0c0;">&amp;</span> UTF8Encoding.<span style="color: #0000FF;color: #c0c0c0;">UTF8</span>.<span style="color: #0000FF;color: #c0c0c0;">GetString</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #0600FF;color: #c0c0c0;">str</span>.<span style="color: #0000FF;color: #c0c0c0;">ToArray</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #008000;color: #c0c0c0;">&amp;</span> <span style="color: #808080;color: #C89191;">&quot;]]&gt;&quot;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
                                carret <span style="color: #008000;color: #c0c0c0;">+=</span> <span style="color: #FF0000;color: #8ACCCF;">1</span>
                                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Exit</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Select</span>
                            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Case</span> GlobalToken.<span style="color: #000000;color: #c0c0c0;">&#91;</span><span style="color: #0600FF;color: #C2964B; font-weight: bold;">END</span><span style="color: #000000;color: #c0c0c0;">&#93;</span>
                                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span> waitForAttr <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Then</span>
                                    builder.<span style="color: #0000FF;color: #c0c0c0;">Append</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>waitForContent, <span style="color: #808080;color: #C89191;">&quot;&gt;&quot;</span>, <span style="color: #808080;color: #C89191;">&quot;/&gt;&quot;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
                                    waitForAttr <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">False</span>
                                <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Else</span>
                                    <span style="color: #008080; font-style: italic;color: #7F9F7F;">'change this to fix problem tags, just use a stack...</span>
                                    <span style="color: #008080; font-style: italic;color: #7F9F7F;">'Dim lastUnclosed As String = findLastUnclosed(builder.ToString())</span>
                                    builder.<span style="color: #0000FF;color: #c0c0c0;">AppendFormat</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #808080;color: #C89191;">&quot;&lt;/{0}&gt;&quot;</span>, openXmlTags.<span style="color: #0000FF;color: #c0c0c0;">Pop</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
                                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span>
                                carret <span style="color: #008000;color: #c0c0c0;">+=</span> <span style="color: #FF0000;color: #8ACCCF;">1</span>
                                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Exit</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Select</span>
                            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Case</span> GlobalToken.<span style="color: #0000FF;color: #c0c0c0;">OPAQUE</span>
                                <span style="color: #008080; font-style: italic;color: #7F9F7F;">'fix from Max to Min (incorrect conversion from c# carret++ operator into VB.NET)</span>
                                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> opLenght <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Byte</span> <span style="color: #008000;color: #c0c0c0;">=</span> WBXmlData<span style="color: #000000;color: #c0c0c0;">&#40;</span>System.<span style="color: #0000FF;color: #c0c0c0;">Math</span>.<span style="color: #0000FF;color: #c0c0c0;">Min</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>System.<span style="color: #0000FF;color: #c0c0c0;">Threading</span>.<span style="color: #0000FF;color: #c0c0c0;">Interlocked</span>.<span style="color: #0000FF;color: #c0c0c0;">Increment</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>carret<span style="color: #000000;color: #c0c0c0;">&#41;</span>, carret <span style="color: #008000;color: #c0c0c0;">-</span> <span style="color: #FF0000;color: #8ACCCF;">1</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
                                builder.<span style="color: #0000FF;color: #c0c0c0;">Append</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>BitConverter.<span style="color: #0000FF;color: #c0c0c0;">ToString</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>WBXmlData, carret, opLenght<span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
                                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Exit</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Select</span>
&nbsp;
                        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Select</span>
                    <span style="color: #FF8000;color: #C2964B; font-weight: bold;">ElseIf</span> LocalTokens<span style="color: #000000;color: #c0c0c0;">&#40;</span>currentCodePage<span style="color: #000000;color: #c0c0c0;">&#41;</span>.<span style="color: #0000FF;color: #c0c0c0;">CodepageTags</span>.<span style="color: #0000FF;color: #c0c0c0;">ContainsKey</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #0600FF;color: #c0c0c0;">CByte</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>WBXmlData<span style="color: #000000;color: #c0c0c0;">&#40;</span>carret<span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #804040;">And</span> <span style="color: #008000;color: #c0c0c0;">&amp;</span>H3F<span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Then</span>
                        <span style="color: #008080; font-style: italic;color: #7F9F7F;">'local tocken;</span>
                        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> tagFromToken <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span> <span style="color: #008000;color: #c0c0c0;">=</span> LocalTokens<span style="color: #000000;color: #c0c0c0;">&#40;</span>currentCodePage<span style="color: #000000;color: #c0c0c0;">&#41;</span>.<span style="color: #0000FF;color: #c0c0c0;">CodepageTags</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #0600FF;color: #c0c0c0;">CByte</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>WBXmlData<span style="color: #000000;color: #c0c0c0;">&#40;</span>carret<span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #804040;">And</span> <span style="color: #008000;color: #c0c0c0;">&amp;</span>H3F<span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
                        <span style="color: #008080; font-style: italic;color: #7F9F7F;">'remember which codepages are being used so we know which namspaces to add to the XML</span>
                        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span> <span style="color: #804040;">Not</span> codepagesUsed.<span style="color: #0000FF;color: #c0c0c0;">Contains</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>currentCodePage<span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Then</span>
                            codepagesUsed.<span style="color: #0000FF;color: #c0c0c0;">Add</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>currentCodePage<span style="color: #000000;color: #c0c0c0;">&#41;</span>
                        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span>
&nbsp;
                        <span style="color: #008080; font-style: italic;color: #7F9F7F;">'if its not the default namespace, we need to encode the tag</span>
                        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span> <span style="color: #804040;">Not</span> currentCodePage <span style="color: #008000;color: #c0c0c0;">=</span> codepagesUsed<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF0000;color: #8ACCCF;">0</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Then</span>
                            tagFromToken <span style="color: #008000;color: #c0c0c0;">=</span> LocalTokens<span style="color: #000000;color: #c0c0c0;">&#40;</span>currentCodePage<span style="color: #000000;color: #c0c0c0;">&#41;</span>.<span style="color: #0000FF;color: #c0c0c0;">XmlPrefix</span> <span style="color: #008000;color: #c0c0c0;">&amp;</span> <span style="color: #808080;color: #C89191;">&quot;:&quot;</span> <span style="color: #008000;color: #c0c0c0;">&amp;</span> tagFromToken
                        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span>
&nbsp;
                        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> hasAttrs <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Boolean</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #0600FF;color: #c0c0c0;">CByte</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>WBXmlData<span style="color: #000000;color: #c0c0c0;">&#40;</span>carret<span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #804040;">And</span> <span style="color: #008000;color: #c0c0c0;">&amp;</span>H80<span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #008000;color: #c0c0c0;">&amp;</span>H80
                        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> hasContent <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Boolean</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #0600FF;color: #c0c0c0;">CByte</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>WBXmlData<span style="color: #000000;color: #c0c0c0;">&#40;</span>carret<span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #804040;">And</span> <span style="color: #008000;color: #c0c0c0;">&amp;</span>H40<span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #008000;color: #c0c0c0;">&amp;</span>H40
                        builder.<span style="color: #0000FF;color: #c0c0c0;">AppendFormat</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #808080;color: #C89191;">&quot;{2}{0}{1}&quot;</span>, tagFromToken, <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>hasAttrs, <span style="color: #808080;color: #C89191;">&quot; &quot;</span>, <span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #804040;">Not</span> hasContent, <span style="color: #808080;color: #C89191;">&quot;/&gt;&quot;</span>, <span style="color: #808080;color: #C89191;">&quot;&gt;&quot;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>, <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #804040;">Not</span> waitForAttr, <span style="color: #808080;color: #C89191;">&quot;&lt;&quot;</span>, <span style="color: #808080;color: #C89191;">&quot;&quot;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
                        waitForAttr <span style="color: #008000;color: #c0c0c0;">=</span> hasAttrs
                        waitForContent <span style="color: #008000;color: #c0c0c0;">=</span> hasContent
                        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span> waitForContent <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Then</span> openXmlTags.<span style="color: #0000FF;color: #c0c0c0;">Push</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>tagFromToken<span style="color: #000000;color: #c0c0c0;">&#41;</span>
                        carret <span style="color: #008000;color: #c0c0c0;">+=</span> <span style="color: #FF0000;color: #8ACCCF;">1</span>
                    <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Else</span>
                        <span style="color: #008080; font-style: italic;color: #7F9F7F;">'nothing</span>
                        carret <span style="color: #008000;color: #c0c0c0;">+=</span> <span style="color: #FF0000;color: #8ACCCF;">1</span>
                        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span> carret &gt;<span style="color: #008000;color: #c0c0c0;">=</span> WBXmlData.<span style="color: #0000FF;color: #c0c0c0;">Length</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Then</span>
                            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Exit</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">While</span>
                        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span>
&nbsp;
                    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span>
                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">While</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span>
&nbsp;
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Try</span>
                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> fullXml <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span> <span style="color: #008000;color: #c0c0c0;">=</span> builder.<span style="color: #0000FF;color: #c0c0c0;">ToString</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
                <span style="color: #008080; font-style: italic;color: #7F9F7F;">'we need to insert the xmlns prefixes in the root node</span>
                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> defaultCodepage <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Integer</span> <span style="color: #008000;color: #c0c0c0;">=</span> codepagesUsed<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF0000;color: #8ACCCF;">0</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> prefixShebang <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span>.<span style="color: #0600FF;color: #c0c0c0;">Format</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #808080;color: #C89191;">&quot; xmlns=&quot;</span><span style="color: #808080;color: #C89191;">&quot;{0}&quot;</span><span style="color: #808080;color: #C89191;">&quot;&quot;</span>, LocalTokens<span style="color: #000000;color: #c0c0c0;">&#40;</span>defaultCodepage<span style="color: #000000;color: #c0c0c0;">&#41;</span>.<span style="color: #0000FF;color: #c0c0c0;">XmlNs</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
                <span style="color: #FF8000;color: #C2964B; font-weight: bold;">For</span> i <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Integer</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #FF0000;color: #8ACCCF;">1</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">To</span> codepagesUsed.<span style="color: #0000FF;color: #c0c0c0;">Count</span> <span style="color: #008000;color: #c0c0c0;">-</span> <span style="color: #FF0000;color: #8ACCCF;">1</span>
                    prefixShebang <span style="color: #008000;color: #c0c0c0;">&amp;=</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span>.<span style="color: #0600FF;color: #c0c0c0;">Format</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #808080;color: #C89191;">&quot; xmlns:{0}=&quot;</span><span style="color: #808080;color: #C89191;">&quot;{1}&quot;</span><span style="color: #808080;color: #C89191;">&quot;&quot;</span>, LocalTokens<span style="color: #000000;color: #c0c0c0;">&#40;</span>codepagesUsed<span style="color: #000000;color: #c0c0c0;">&#40;</span>i<span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>.<span style="color: #0000FF;color: #c0c0c0;">XmlPrefix</span>, LocalTokens<span style="color: #000000;color: #c0c0c0;">&#40;</span>codepagesUsed<span style="color: #000000;color: #c0c0c0;">&#40;</span>i<span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>.<span style="color: #0000FF;color: #c0c0c0;">XmlNs</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
                <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Next</span>
                codepagesUsed.<span style="color: #0000FF;color: #c0c0c0;">Clear</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
                <span style="color: #008080; font-style: italic;color: #7F9F7F;">'inject the namespaces</span>
                fullXml <span style="color: #008000;color: #c0c0c0;">=</span> fullXml.<span style="color: #0000FF;color: #c0c0c0;">Insert</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>fullXml.<span style="color: #0000FF;color: #c0c0c0;">IndexOf</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #808080;color: #C89191;">&quot;&gt;&quot;</span>c<span style="color: #000000;color: #c0c0c0;">&#41;</span>, prefixShebang<span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
                <span style="color: #FF8000;color: #C2964B; font-weight: bold;">MyBase</span>.<span style="color: #0000FF;color: #c0c0c0;">LoadXml</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>fullXml<span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Catch</span> xex <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> XmlException
                <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Throw</span> xex
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Catch</span> ex <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> Exception
                <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Throw</span> ex
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Try</span>
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Sub</span>
&nbsp;
&nbsp;
        <span style="color: #008080; font-style: italic;color: #7F9F7F;">'DEPRECATED - now using a stack to track open tags</span>
        <span style="color: #008080; font-style: italic;color: #7F9F7F;">'Private Function findLastUnclosed(ByVal p As String) As String</span>
        <span style="color: #008080; font-style: italic;color: #7F9F7F;">'    Dim allTagsRX As String = &quot;&lt;(/)?([a-z]+)[^&gt;]*?(/)?&gt;&quot;</span>
        <span style="color: #008080; font-style: italic;color: #7F9F7F;">'    Dim rx As New Regex(allTagsRX, RegexOptions.Compiled Or RegexOptions.IgnoreCase Or RegexOptions.Singleline)</span>
        <span style="color: #008080; font-style: italic;color: #7F9F7F;">'    Dim matches As MatchCollection = rx.Matches(p)</span>
        <span style="color: #008080; font-style: italic;color: #7F9F7F;">'    Dim tags As New List(Of String)()</span>
        <span style="color: #008080; font-style: italic;color: #7F9F7F;">'    For Each m As Match In matches</span>
        <span style="color: #008080; font-style: italic;color: #7F9F7F;">'        If m.Groups(1).Value = String.Empty Then</span>
        <span style="color: #008080; font-style: italic;color: #7F9F7F;">'            tags.Add(m.Groups(2).Value)</span>
        <span style="color: #008080; font-style: italic;color: #7F9F7F;">'        Else</span>
        <span style="color: #008080; font-style: italic;color: #7F9F7F;">'            tags.Remove(m.Groups(2).Value)</span>
        <span style="color: #008080; font-style: italic;color: #7F9F7F;">'        End If</span>
&nbsp;
        <span style="color: #008080; font-style: italic;color: #7F9F7F;">'        If m.Groups(3).Value &lt;&gt; String.Empty Then</span>
        <span style="color: #008080; font-style: italic;color: #7F9F7F;">'            tags.Remove(m.Groups(2).Value)</span>
        <span style="color: #008080; font-style: italic;color: #7F9F7F;">'        End If</span>
        <span style="color: #008080; font-style: italic;color: #7F9F7F;">'    Next</span>
        <span style="color: #008080; font-style: italic;color: #7F9F7F;">'    If tags.Count = 0 Then</span>
        <span style="color: #008080; font-style: italic;color: #7F9F7F;">'        Return String.Empty</span>
        <span style="color: #008080; font-style: italic;color: #7F9F7F;">'    Else</span>
        <span style="color: #008080; font-style: italic;color: #7F9F7F;">'        Return tags(tags.Count - 1)</span>
        <span style="color: #008080; font-style: italic;color: #7F9F7F;">'    End If</span>
&nbsp;
        <span style="color: #008080; font-style: italic;color: #7F9F7F;">'End Function</span>
&nbsp;
        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Private</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Function</span> lookupLocalTokens<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF8000;color: #C2964B; font-weight: bold;">ByVal</span> value <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span>, <span style="color: #FF8000;color: #C2964B; font-weight: bold;">ByRef</span> dicID <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Integer</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Byte</span>
            dicID <span style="color: #008000;color: #c0c0c0;">=</span> currentCodePage
&nbsp;
            <span style="color: #008080; font-style: italic;color: #7F9F7F;">'make sure we are on the right codepage (using xmlprefix)</span>
            <span style="color: #008080; font-style: italic;color: #7F9F7F;">'so we can identify codepage changes in creating WBXML AirSync request.</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span> value.<span style="color: #0000FF;color: #c0c0c0;">Contains</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #808080;color: #C89191;">&quot;:&quot;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Then</span>
                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> parts<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span> <span style="color: #008000;color: #c0c0c0;">=</span> value.<span style="color: #0600FF;color: #c0c0c0;">Split</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #808080;color: #C89191;">&quot;:&quot;</span>c<span style="color: #000000;color: #c0c0c0;">&#41;</span>
                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> prefix <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span> <span style="color: #008000;color: #c0c0c0;">=</span> parts<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF0000;color: #8ACCCF;">0</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
                value <span style="color: #008000;color: #c0c0c0;">=</span> parts<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF0000;color: #8ACCCF;">1</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
                <span style="color: #008080; font-style: italic;color: #7F9F7F;">'find the codepage to which this namespace belongs</span>
                <span style="color: #FF8000;color: #C2964B; font-weight: bold;">For</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Each</span> key <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Integer</span> In LocalTokens.<span style="color: #0000FF;color: #c0c0c0;">Keys</span>
                    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span> LocalTokens<span style="color: #000000;color: #c0c0c0;">&#40;</span>key<span style="color: #000000;color: #c0c0c0;">&#41;</span>.<span style="color: #0000FF;color: #c0c0c0;">XmlPrefix</span> <span style="color: #008000;color: #c0c0c0;">=</span> prefix <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Then</span>
                        dicID <span style="color: #008000;color: #c0c0c0;">=</span> key
                    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span>
                <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Next</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span>
&nbsp;
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span> LocalTokens.<span style="color: #0000FF;color: #c0c0c0;">ContainsKey</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>dicID<span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Then</span>
                <span style="color: #FF8000;color: #C2964B; font-weight: bold;">For</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Each</span> b <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Byte</span> In LocalTokens<span style="color: #000000;color: #c0c0c0;">&#40;</span>dicID<span style="color: #000000;color: #c0c0c0;">&#41;</span>.<span style="color: #0000FF;color: #c0c0c0;">CodepageTags</span>.<span style="color: #0000FF;color: #c0c0c0;">Keys</span>
                    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span> LocalTokens<span style="color: #000000;color: #c0c0c0;">&#40;</span>dicID<span style="color: #000000;color: #c0c0c0;">&#41;</span>.<span style="color: #0000FF;color: #c0c0c0;">CodepageTags</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>b<span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #008000;color: #c0c0c0;">=</span> value <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Then</span>
                        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Return</span> b
                    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span>
                <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Next</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span>
&nbsp;
            <span style="color: #008080; font-style: italic;color: #7F9F7F;">'if we did not find it then mustnt be namespaced, this is the original code which will find the first codepage with a matching token</span>
            <span style="color: #FF8000;color: #C2964B; font-weight: bold;">For</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Each</span> key <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Integer</span> In LocalTokens.<span style="color: #0000FF;color: #c0c0c0;">Keys</span>
                <span style="color: #FF8000;color: #C2964B; font-weight: bold;">For</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Each</span> b <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Byte</span> In LocalTokens<span style="color: #000000;color: #c0c0c0;">&#40;</span>key<span style="color: #000000;color: #c0c0c0;">&#41;</span>.<span style="color: #0000FF;color: #c0c0c0;">CodepageTags</span>.<span style="color: #0000FF;color: #c0c0c0;">Keys</span>
                    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span> LocalTokens<span style="color: #000000;color: #c0c0c0;">&#40;</span>key<span style="color: #000000;color: #c0c0c0;">&#41;</span>.<span style="color: #0000FF;color: #c0c0c0;">CodepageTags</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>b<span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #008000;color: #c0c0c0;">=</span> value <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Then</span>
                        dicID <span style="color: #008000;color: #c0c0c0;">=</span> key
                        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Return</span> b
                    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span>
                <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Next</span>
            <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Next</span>
&nbsp;
&nbsp;
            <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Return</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Byte</span>.<span style="color: #0000FF;color: #c0c0c0;">MinValue</span>
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Function</span>
&nbsp;
        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Private</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Function</span> lookupLocalAttrs<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF8000;color: #C2964B; font-weight: bold;">ByVal</span> value <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span>, <span style="color: #FF8000;color: #C2964B; font-weight: bold;">ByRef</span> dicID <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Integer</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Byte</span>
            dicID <span style="color: #008000;color: #c0c0c0;">=</span> currentCodePage
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span> LocalAttributes.<span style="color: #0000FF;color: #c0c0c0;">ContainsKey</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>dicID<span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Then</span>
                <span style="color: #FF8000;color: #C2964B; font-weight: bold;">For</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Each</span> b <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Byte</span> In LocalAttributes<span style="color: #000000;color: #c0c0c0;">&#40;</span>dicID<span style="color: #000000;color: #c0c0c0;">&#41;</span>.<span style="color: #0000FF;color: #c0c0c0;">Keys</span>
                    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span> LocalAttributes<span style="color: #000000;color: #c0c0c0;">&#40;</span>dicID<span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>b<span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #008000;color: #c0c0c0;">=</span> value <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Then</span>
                        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Return</span> b
                    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span>
                <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Next</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span>
&nbsp;
            <span style="color: #FF8000;color: #C2964B; font-weight: bold;">For</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Each</span> key <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Integer</span> In LocalAttributes.<span style="color: #0000FF;color: #c0c0c0;">Keys</span>
                <span style="color: #FF8000;color: #C2964B; font-weight: bold;">For</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Each</span> b <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Byte</span> In LocalAttributes<span style="color: #000000;color: #c0c0c0;">&#40;</span>key<span style="color: #000000;color: #c0c0c0;">&#41;</span>.<span style="color: #0000FF;color: #c0c0c0;">Keys</span>
                    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span> LocalAttributes<span style="color: #000000;color: #c0c0c0;">&#40;</span>key<span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>b<span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #008000;color: #c0c0c0;">=</span> value <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Then</span>
                        dicID <span style="color: #008000;color: #c0c0c0;">=</span> key
                        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Return</span> b
                    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span>
                <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Next</span>
            <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Next</span>
&nbsp;
&nbsp;
            <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Return</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Byte</span>.<span style="color: #0000FF;color: #c0c0c0;">MinValue</span>
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Function</span>
&nbsp;
        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Public</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Function</span> GetBytes<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Byte</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> resp <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">New</span> List<span style="color: #000000;color: #c0c0c0;">&#40;</span>Of <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Byte</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
            <span style="color: #008080; font-style: italic;color: #7F9F7F;">'version</span>
            resp.<span style="color: #0000FF;color: #c0c0c0;">Add</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>VersionNumber &lt;&gt; <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span>.<span style="color: #FF8000;color: #C2964B; font-weight: bold;">Empty</span>, <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Byte</span>.<span style="color: #0000FF;color: #c0c0c0;">Parse</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>VersionNumber.<span style="color: #0600FF;color: #c0c0c0;">Replace</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #808080;color: #C89191;">&quot;1.&quot;</span>, <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span>.<span style="color: #FF8000;color: #C2964B; font-weight: bold;">Empty</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>, <span style="color: #0600FF;color: #c0c0c0;">CByte</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #008000;color: #c0c0c0;">&amp;</span>H0<span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;color: #7F9F7F;">'public identifier </span>
            resp.<span style="color: #0000FF;color: #c0c0c0;">Add</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #008000;color: #c0c0c0;">&amp;</span>H1<span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;color: #7F9F7F;">'encoding (UTF8)</span>
            resp.<span style="color: #0000FF;color: #c0c0c0;">Add</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #008000;color: #c0c0c0;">&amp;</span>H6A<span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;color: #7F9F7F;">'string table length</span>
            resp.<span style="color: #0000FF;color: #c0c0c0;">Add</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF0000;color: #8ACCCF;">0</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
            Using reader <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> XmlReader <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">New</span> XmlNodeReader<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF8000;color: #C2964B; font-weight: bold;">Me</span>.<span style="color: #0000FF;color: #c0c0c0;">DocumentElement</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
                reader.<span style="color: #0000FF;color: #c0c0c0;">MoveToFirstAttribute</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
                resp.<span style="color: #0000FF;color: #c0c0c0;">AddRange</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>readNode<span style="color: #000000;color: #c0c0c0;">&#40;</span>reader<span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> Using
&nbsp;
            <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Return</span> resp.<span style="color: #0000FF;color: #c0c0c0;">ToArray</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Function</span>
&nbsp;
        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Private</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Overloads</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Function</span> readNode<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF8000;color: #C2964B; font-weight: bold;">ByVal</span> root <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> XmlReader<span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Byte</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> tmpBytes <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">New</span> List<span style="color: #000000;color: #c0c0c0;">&#40;</span>Of <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Byte</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> depth <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Integer</span> <span style="color: #008000;color: #c0c0c0;">=</span> root.<span style="color: #0000FF;color: #c0c0c0;">Depth</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">While</span> root.<span style="color: #0000FF;color: #c0c0c0;">Read</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span> root.<span style="color: #0600FF;color: #c0c0c0;">EOF</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Then</span>
                    <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Return</span> tmpBytes.<span style="color: #0000FF;color: #c0c0c0;">ToArray</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
                <span style="color: #FF8000;color: #C2964B; font-weight: bold;">ElseIf</span> root.<span style="color: #0000FF;color: #c0c0c0;">IsStartElement</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Then</span>
                    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> dicID <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Integer</span> <span style="color: #008000;color: #c0c0c0;">=</span> currentCodePage
                    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> tk <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Byte</span> <span style="color: #008000;color: #c0c0c0;">=</span> lookupLocalTokens<span style="color: #000000;color: #c0c0c0;">&#40;</span>root.<span style="color: #0000FF;color: #c0c0c0;">Name</span>, dicID<span style="color: #000000;color: #c0c0c0;">&#41;</span>
                    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span> tk &lt;&gt; <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Byte</span>.<span style="color: #0000FF;color: #c0c0c0;">MinValue</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Then</span>
&nbsp;
                        tmpBytes.<span style="color: #0000FF;color: #c0c0c0;">AddRange</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>addSwitch<span style="color: #000000;color: #c0c0c0;">&#40;</span>dicID<span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
                        <span style="color: #008080; font-style: italic;color: #7F9F7F;">'test for attributes seperately, if no token we dont wanna encode this</span>
                        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> tagByte <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Byte</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #0600FF;color: #c0c0c0;">CByte</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>tk <span style="color: #008000;color: #c0c0c0;">+</span> <span style="color: #0600FF;color: #c0c0c0;">CByte</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #804040;">Not</span> root.<span style="color: #0000FF;color: #c0c0c0;">IsEmptyElement</span>, <span style="color: #008000;color: #c0c0c0;">&amp;</span>H40, <span style="color: #008000;color: #c0c0c0;">&amp;</span>H0<span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
&nbsp;
                        <span style="color: #008080; font-style: italic;color: #7F9F7F;">'has content &amp; attributes;</span>
                        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span> root.<span style="color: #0000FF;color: #c0c0c0;">HasAttributes</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Then</span>
                            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">While</span> root.<span style="color: #0000FF;color: #c0c0c0;">MoveToNextAttribute</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
                                tk <span style="color: #008000;color: #c0c0c0;">=</span> lookupLocalAttrs<span style="color: #000000;color: #c0c0c0;">&#40;</span>root.<span style="color: #0000FF;color: #c0c0c0;">Name</span>, dicID<span style="color: #000000;color: #c0c0c0;">&#41;</span>
                                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span> tk &lt;&gt; <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Byte</span>.<span style="color: #0000FF;color: #c0c0c0;">MinValue</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Then</span>
                                    <span style="color: #008080; font-style: italic;color: #7F9F7F;">'advise we are putting an attribute</span>
                                    tagByte <span style="color: #008000;color: #c0c0c0;">+=</span> <span style="color: #0600FF;color: #c0c0c0;">CByte</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #008000;color: #c0c0c0;">&amp;</span>H80<span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
                                    <span style="color: #008080; font-style: italic;color: #7F9F7F;">'put the tag byte</span>
                                    tmpBytes.<span style="color: #0000FF;color: #c0c0c0;">Add</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>tagByte<span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
                                    <span style="color: #008080; font-style: italic;color: #7F9F7F;">'now add the attribute</span>
                                    tmpBytes.<span style="color: #0000FF;color: #c0c0c0;">AddRange</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>addSwitch<span style="color: #000000;color: #c0c0c0;">&#40;</span>dicID<span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
                                    tmpBytes.<span style="color: #0000FF;color: #c0c0c0;">Add</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>tk<span style="color: #000000;color: #c0c0c0;">&#41;</span>
                                    tmpBytes.<span style="color: #0000FF;color: #c0c0c0;">Add</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #0600FF;color: #c0c0c0;">CByte</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>GlobalToken.<span style="color: #000000;color: #c0c0c0;">&#91;</span><span style="color: #0600FF;color: #C2964B; font-weight: bold;">END</span><span style="color: #000000;color: #c0c0c0;">&#93;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
                                <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Else</span>
                                    <span style="color: #008080; font-style: italic;color: #7F9F7F;">'just add the tag byte</span>
                                    tmpBytes.<span style="color: #0000FF;color: #c0c0c0;">Add</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>tagByte<span style="color: #000000;color: #c0c0c0;">&#41;</span>
                                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span>
                            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">While</span>
                        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Else</span>
                            <span style="color: #008080; font-style: italic;color: #7F9F7F;">'just add the tag byte</span>
                            tmpBytes.<span style="color: #0000FF;color: #c0c0c0;">Add</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>tagByte<span style="color: #000000;color: #c0c0c0;">&#41;</span>
                        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span>
                    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span>
&nbsp;
                    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span> root.<span style="color: #0000FF;color: #c0c0c0;">NodeType</span> <span style="color: #008000;color: #c0c0c0;">=</span> XmlNodeType.<span style="color: #0000FF;color: #c0c0c0;">Text</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">AndAlso</span> root.<span style="color: #0000FF;color: #c0c0c0;">ValueType</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Is</span> <span style="color: #804040;">GetType</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Then</span>
                        tmpBytes.<span style="color: #0000FF;color: #c0c0c0;">Add</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #0600FF;color: #c0c0c0;">CByte</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>GlobalToken.<span style="color: #0000FF;color: #c0c0c0;">STR_I</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
                        tmpBytes.<span style="color: #0000FF;color: #c0c0c0;">AddRange</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>Encoding.<span style="color: #0000FF;color: #c0c0c0;">UTF8</span>.<span style="color: #0000FF;color: #c0c0c0;">GetBytes</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>root.<span style="color: #0000FF;color: #c0c0c0;">Value</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
                        tmpBytes.<span style="color: #0000FF;color: #c0c0c0;">Add</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #008000;color: #c0c0c0;">&amp;</span>H0<span style="color: #000000;color: #c0c0c0;">&#41;</span>
                    <span style="color: #FF8000;color: #C2964B; font-weight: bold;">ElseIf</span> root.<span style="color: #0000FF;color: #c0c0c0;">Depth</span> &gt; depth <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Then</span>
                        tmpBytes.<span style="color: #0000FF;color: #c0c0c0;">AddRange</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>readNode<span style="color: #000000;color: #c0c0c0;">&#40;</span>root<span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
&nbsp;
                    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span>
                <span style="color: #FF8000;color: #C2964B; font-weight: bold;">ElseIf</span> root.<span style="color: #0000FF;color: #c0c0c0;">NodeType</span> <span style="color: #008000;color: #c0c0c0;">=</span> XmlNodeType.<span style="color: #0000FF;color: #c0c0c0;">Text</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">AndAlso</span> root.<span style="color: #0000FF;color: #c0c0c0;">ValueType</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Is</span> <span style="color: #804040;">GetType</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Then</span>
                    tmpBytes.<span style="color: #0000FF;color: #c0c0c0;">Add</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #0600FF;color: #c0c0c0;">CByte</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>GlobalToken.<span style="color: #0000FF;color: #c0c0c0;">STR_I</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
                    tmpBytes.<span style="color: #0000FF;color: #c0c0c0;">AddRange</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>Encoding.<span style="color: #0000FF;color: #c0c0c0;">UTF8</span>.<span style="color: #0000FF;color: #c0c0c0;">GetBytes</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>root.<span style="color: #0000FF;color: #c0c0c0;">Value</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
                    tmpBytes.<span style="color: #0000FF;color: #c0c0c0;">Add</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #008000;color: #c0c0c0;">&amp;</span>H0<span style="color: #000000;color: #c0c0c0;">&#41;</span>
                <span style="color: #FF8000;color: #C2964B; font-weight: bold;">ElseIf</span> root.<span style="color: #0000FF;color: #c0c0c0;">NodeType</span> <span style="color: #008000;color: #c0c0c0;">=</span> XmlNodeType.<span style="color: #0000FF;color: #c0c0c0;">EndElement</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Then</span>
                    tmpBytes.<span style="color: #0000FF;color: #c0c0c0;">Add</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #0600FF;color: #c0c0c0;">CByte</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>GlobalToken.<span style="color: #000000;color: #c0c0c0;">&#91;</span><span style="color: #0600FF;color: #C2964B; font-weight: bold;">END</span><span style="color: #000000;color: #c0c0c0;">&#93;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
&nbsp;
                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">While</span>
&nbsp;
            <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Return</span> tmpBytes.<span style="color: #0000FF;color: #c0c0c0;">ToArray</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Function</span>
&nbsp;
        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Private</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Function</span> addSwitch<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF8000;color: #C2964B; font-weight: bold;">ByVal</span> dicId <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Integer</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Byte</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> bts <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Byte</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">New</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Byte</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #008000;color: #c0c0c0;">-</span><span style="color: #FF0000;color: #8ACCCF;">1</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #000000;color: #c0c0c0;">&#123;</span><span style="color: #000000;color: #c0c0c0;">&#125;</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span> dicId &lt;&gt; currentCodePage <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Then</span>
                bts <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">New</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Byte</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF0000;color: #8ACCCF;">1</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #000000;color: #c0c0c0;">&#123;</span><span style="color: #000000;color: #c0c0c0;">&#125;</span>
                bts<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF0000;color: #8ACCCF;">0</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #0600FF;color: #c0c0c0;">CByte</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>GlobalToken.<span style="color: #0000FF;color: #c0c0c0;">SWITCH_PAGE</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
                bts<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF0000;color: #8ACCCF;">1</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #0600FF;color: #c0c0c0;">CByte</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>dicId<span style="color: #000000;color: #c0c0c0;">&#41;</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span>
            currentCodePage <span style="color: #008000;color: #c0c0c0;">=</span> dicId
&nbsp;
            <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Return</span> bts
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Function</span>
&nbsp;
&nbsp;
    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Class</span>
<span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Namespace</span></pre></div></div>

<p>My strongly typed WbXmlCodepage class is as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="vbnet" style="font-family:monospace;color: #c0c0c0; font-family: Franklin Gothic Book;"><span style="color: #0600FF;color: #C2964B; font-weight: bold;">Namespace</span> EncodingHelpers.<span style="color: #0000FF;color: #c0c0c0;">WBXML</span>
    <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Public</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Class</span> WbXmlCodepage
&nbsp;
        <span style="color: #008080; font-style: italic;color: #7F9F7F;">'the xml namespace associated with this codepage</span>
        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Private</span> _xmlns <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span>
        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Public</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Property</span> XmlNs<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span>
            <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Get</span>
                <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Return</span> _xmlns
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Get</span>
            <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Set</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF8000;color: #C2964B; font-weight: bold;">ByVal</span> value <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
                _xmlns <span style="color: #008000;color: #c0c0c0;">=</span> value
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Set</span>
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Property</span>
&nbsp;
        <span style="color: #008080; font-style: italic;color: #7F9F7F;">'this xml prefix for the associated namespace</span>
        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Private</span> _xmlPrefix <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span>
        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Public</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Property</span> XmlPrefix<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span>
            <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Get</span>
                <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Return</span> _xmlPrefix
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Get</span>
            <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Set</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF8000;color: #C2964B; font-weight: bold;">ByVal</span> value <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
                _xmlPrefix <span style="color: #008000;color: #c0c0c0;">=</span> value
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Set</span>
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Property</span>
&nbsp;
        <span style="color: #008080; font-style: italic;color: #7F9F7F;">'codepage number</span>
        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Private</span> _codePage <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Integer</span>
        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Public</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Property</span> Codepage<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Integer</span>
            <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Get</span>
                <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Return</span> _codePage
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Get</span>
            <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Set</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF8000;color: #C2964B; font-weight: bold;">ByVal</span> value <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Integer</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
                _codePage <span style="color: #008000;color: #c0c0c0;">=</span> value
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Set</span>
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Property</span>
&nbsp;
        <span style="color: #008080; font-style: italic;color: #7F9F7F;">'the codepage tags</span>
        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Private</span> _codepageTags <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #008000;color: #2B91AF;">Dictionary</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>Of <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Byte</span>, <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Public</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Property</span> CodepageTags<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #008000;color: #2B91AF;">Dictionary</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>Of <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Byte</span>, <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
            <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Get</span>
                <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Return</span> _codepageTags
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Get</span>
            <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Set</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF8000;color: #C2964B; font-weight: bold;">ByVal</span> value <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #008000;color: #2B91AF;">Dictionary</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>Of <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Byte</span>, <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
                _codepageTags <span style="color: #008000;color: #c0c0c0;">=</span> value
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Set</span>
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Property</span>
    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Class</span>
<span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Namespace</span></pre></div></div>

<p>Finally, I seperated out the implementations of each AirSync codepage into a seperate class file. This will make it easier in future as I begin to use more codepages to maintain the code, or if you wish to use a codepage simply create another class and add it to &#8216;InitAirSyncCodepages()&#8217;. I only needed those 7 codepages for the calendar sync and you can <a href="/download.aspx?link=http://download.craigwardman.com/Airsync-Codepage-Classes.zip" target="_blank">download the class files here</a>.</p>
<p>To give an example of how to use the class to download the calendar items, a simple implementation in ASP.NET UserControl is as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;color: #c0c0c0; font-family: Franklin Gothic Book;"><span style="color: #EFEF8F;">&lt;%@ Control <span style="color: #000066;color: #2B91AF;">Language</span><span style="color: #66cc66;color: #c0c0c0;">=</span><span style="color: #ff0000;color: #C89191;">&quot;vb&quot;</span> AutoEventWireup<span style="color: #66cc66;color: #c0c0c0;">=</span><span style="color: #ff0000;color: #C89191;">&quot;false&quot;</span> CodeBehind<span style="color: #66cc66;color: #c0c0c0;">=</span><span style="color: #ff0000;color: #C89191;">&quot;OutlookCalendarWidget.ascx.vb&quot;</span> Inherits<span style="color: #66cc66;color: #c0c0c0;">=</span><span style="color: #ff0000;color: #C89191;">&quot;UserControls.OutlookCalendarWidget&quot;</span> %&gt;</span>
<span style="color: #EFEF8F;">&lt;<span style="color: #000000; font-weight: bold;color: #C2964B; font-weight: bold;">div</span> <span style="color: #000066;color: #2B91AF;">id</span><span style="color: #66cc66;color: #c0c0c0;">=</span><span style="color: #ff0000;color: #C89191;">&quot;ConnectToActiveSync&quot;</span>&gt;</span>
<span style="color: #EFEF8F;">&lt;asp:Panel <span style="color: #000066;color: #2B91AF;">ID</span><span style="color: #66cc66;color: #c0c0c0;">=</span><span style="color: #ff0000;color: #C89191;">&quot;pnlSetUserContext&quot;</span> runat<span style="color: #66cc66;color: #c0c0c0;">=</span><span style="color: #ff0000;color: #C89191;">&quot;server&quot;</span> Visible<span style="color: #66cc66;color: #c0c0c0;">=</span><span style="color: #ff0000;color: #C89191;">&quot;false&quot;</span>  DefaultButton<span style="color: #66cc66;color: #c0c0c0;">=</span><span style="color: #ff0000;color: #C89191;">&quot;btnSetUserContext&quot;</span>&gt;</span>
    Exchange User: <span style="color: #EFEF8F;">&lt;asp:TextBox <span style="color: #000066;color: #2B91AF;">ID</span><span style="color: #66cc66;color: #c0c0c0;">=</span><span style="color: #ff0000;color: #C89191;">&quot;txtUsername&quot;</span> runat<span style="color: #66cc66;color: #c0c0c0;">=</span><span style="color: #ff0000;color: #C89191;">&quot;server&quot;</span>&gt;&lt;<span style="color: #66cc66;color: #c0c0c0;">/</span>asp:TextBox&gt;</span>
    <span style="color: #EFEF8F;">&lt;asp:Button <span style="color: #000066;color: #2B91AF;">ID</span><span style="color: #66cc66;color: #c0c0c0;">=</span><span style="color: #ff0000;color: #C89191;">&quot;btnSetUserContext&quot;</span> runat<span style="color: #66cc66;color: #c0c0c0;">=</span><span style="color: #ff0000;color: #C89191;">&quot;server&quot;</span> <span style="color: #000066;color: #2B91AF;">Text</span><span style="color: #66cc66;color: #c0c0c0;">=</span><span style="color: #ff0000;color: #C89191;">&quot;Begin&quot;</span> <span style="color: #66cc66;color: #c0c0c0;">/</span>&gt;</span>
<span style="color: #EFEF8F;">&lt;<span style="color: #66cc66;color: #c0c0c0;">/</span>asp:Panel&gt;</span>
&nbsp;
<span style="color: #EFEF8F;">&lt;asp:Panel <span style="color: #000066;color: #2B91AF;">ID</span><span style="color: #66cc66;color: #c0c0c0;">=</span><span style="color: #ff0000;color: #C89191;">&quot;pnlSubmitExchangePw&quot;</span> runat<span style="color: #66cc66;color: #c0c0c0;">=</span><span style="color: #ff0000;color: #C89191;">&quot;server&quot;</span> Visible<span style="color: #66cc66;color: #c0c0c0;">=</span><span style="color: #ff0000;color: #C89191;">&quot;false&quot;</span> DefaultButton<span style="color: #66cc66;color: #c0c0c0;">=</span><span style="color: #ff0000;color: #C89191;">&quot;btnSubmitExchangePass&quot;</span>&gt;</span>
In order to connect to Exchange, you will need to provide your login password:
    <span style="color: #EFEF8F;">&lt;asp:TextBox <span style="color: #000066;color: #2B91AF;">ID</span><span style="color: #66cc66;color: #c0c0c0;">=</span><span style="color: #ff0000;color: #C89191;">&quot;txtExchangePass&quot;</span> runat<span style="color: #66cc66;color: #c0c0c0;">=</span><span style="color: #ff0000;color: #C89191;">&quot;server&quot;</span> TextMode<span style="color: #66cc66;color: #c0c0c0;">=</span><span style="color: #ff0000;color: #C89191;">&quot;Password&quot;</span>&gt;&lt;<span style="color: #66cc66;color: #c0c0c0;">/</span>asp:TextBox&gt;</span>
    <span style="color: #EFEF8F;">&lt;asp:Button <span style="color: #000066;color: #2B91AF;">ID</span><span style="color: #66cc66;color: #c0c0c0;">=</span><span style="color: #ff0000;color: #C89191;">&quot;btnSubmitExchangePass&quot;</span> runat<span style="color: #66cc66;color: #c0c0c0;">=</span><span style="color: #ff0000;color: #C89191;">&quot;server&quot;</span> <span style="color: #000066;color: #2B91AF;">Text</span><span style="color: #66cc66;color: #c0c0c0;">=</span><span style="color: #ff0000;color: #C89191;">&quot;Continue&quot;</span> <span style="color: #66cc66;color: #c0c0c0;">/</span>&gt;</span>
<span style="color: #EFEF8F;">&lt;<span style="color: #66cc66;color: #c0c0c0;">/</span>asp:Panel&gt;</span>
<span style="color: #EFEF8F;">&lt;asp:Panel <span style="color: #000066;color: #2B91AF;">ID</span><span style="color: #66cc66;color: #c0c0c0;">=</span><span style="color: #ff0000;color: #C89191;">&quot;pnlEpicFail&quot;</span> runat<span style="color: #66cc66;color: #c0c0c0;">=</span><span style="color: #ff0000;color: #C89191;">&quot;server&quot;</span> visible<span style="color: #66cc66;color: #c0c0c0;">=</span><span style="color: #ff0000;color: #C89191;">&quot;false&quot;</span>&gt;</span>
Could not connect to Exchange server. Check connectivity.
<span style="color: #EFEF8F;">&lt;<span style="color: #66cc66;color: #c0c0c0;">/</span>asp:Panel&gt;</span>
<span style="color: #EFEF8F;">&lt;<span style="color: #66cc66;color: #c0c0c0;">/</span><span style="color: #000000; font-weight: bold;color: #C2964B; font-weight: bold;">div</span>&gt;</span>
&nbsp;
<span style="color: #EFEF8F;">&lt;asp:Panel <span style="color: #000066;color: #2B91AF;">ID</span><span style="color: #66cc66;color: #c0c0c0;">=</span><span style="color: #ff0000;color: #C89191;">&quot;pnlOutlookCalendar&quot;</span> runat<span style="color: #66cc66;color: #c0c0c0;">=</span><span style="color: #ff0000;color: #C89191;">&quot;server&quot;</span> Visible<span style="color: #66cc66;color: #c0c0c0;">=</span><span style="color: #ff0000;color: #C89191;">&quot;false&quot;</span>&gt;</span>
    <span style="color: #EFEF8F;">&lt;asp:Panel <span style="color: #000066;color: #2B91AF;">ID</span><span style="color: #66cc66;color: #c0c0c0;">=</span><span style="color: #ff0000;color: #C89191;">&quot;pnlNotAuth&quot;</span> runat<span style="color: #66cc66;color: #c0c0c0;">=</span><span style="color: #ff0000;color: #C89191;">&quot;server&quot;</span> visible<span style="color: #66cc66;color: #c0c0c0;">=</span><span style="color: #ff0000;color: #C89191;">&quot;false&quot;</span>&gt;</span>
        Not authorised, has your password changed? <span style="color: #EFEF8F;">&lt;asp:Button <span style="color: #000066;color: #2B91AF;">ID</span><span style="color: #66cc66;color: #c0c0c0;">=</span><span style="color: #ff0000;color: #C89191;">&quot;btnResetPassword&quot;</span> runat<span style="color: #66cc66;color: #c0c0c0;">=</span><span style="color: #ff0000;color: #C89191;">&quot;server&quot;</span>  <span style="color: #000066;color: #2B91AF;">Text</span><span style="color: #66cc66;color: #c0c0c0;">=</span><span style="color: #ff0000;color: #C89191;">&quot;Reset Password&quot;</span><span style="color: #66cc66;color: #c0c0c0;">/</span>&gt;</span>
    <span style="color: #EFEF8F;">&lt;<span style="color: #66cc66;color: #c0c0c0;">/</span>asp:Panel&gt;</span>
    <span style="color: #EFEF8F;">&lt;asp:<span style="color: #000066;color: #2B91AF;">Label</span> <span style="color: #000066;color: #2B91AF;">ID</span><span style="color: #66cc66;color: #c0c0c0;">=</span><span style="color: #ff0000;color: #C89191;">&quot;lblActiveSyncErrorMessage&quot;</span> runat<span style="color: #66cc66;color: #c0c0c0;">=</span><span style="color: #ff0000;color: #C89191;">&quot;server&quot;</span>&gt;&lt;<span style="color: #66cc66;color: #c0c0c0;">/</span>asp:Label&gt;</span>
    <span style="color: #EFEF8F;">&lt;asp:Repeater <span style="color: #000066;color: #2B91AF;">ID</span><span style="color: #66cc66;color: #c0c0c0;">=</span><span style="color: #ff0000;color: #C89191;">&quot;rptCalendarItemGroups&quot;</span> runat<span style="color: #66cc66;color: #c0c0c0;">=</span><span style="color: #ff0000;color: #C89191;">&quot;server&quot;</span>&gt;</span>
        <span style="color: #EFEF8F;">&lt;ItemTemplate&gt;</span>
        <span style="color: #EFEF8F;">&lt;<span style="color: #000000; font-weight: bold;color: #C2964B; font-weight: bold;">div</span> <span style="color: #000066;color: #2B91AF;">class</span><span style="color: #66cc66;color: #c0c0c0;">=</span><span style="color: #ff0000;color: #C89191;">&quot;calender-group-title&quot;</span>&gt;&lt;%# Container.DataItem%&gt;&lt;<span style="color: #66cc66;color: #c0c0c0;">/</span><span style="color: #000000; font-weight: bold;color: #C2964B; font-weight: bold;">div</span>&gt;</span>
        <span style="color: #EFEF8F;">&lt;<span style="color: #000000; font-weight: bold;color: #C2964B; font-weight: bold;">div</span> <span style="color: #000066;color: #2B91AF;">class</span><span style="color: #66cc66;color: #c0c0c0;">=</span><span style="color: #ff0000;color: #C89191;">&quot;calendar-group-items&quot;</span>&gt;</span>
            <span style="color: #EFEF8F;">&lt;asp:Repeater <span style="color: #000066;color: #2B91AF;">id</span><span style="color: #66cc66;color: #c0c0c0;">=</span><span style="color: #ff0000;color: #C89191;">&quot;rptCalendarEvents&quot;</span> runat<span style="color: #66cc66;color: #c0c0c0;">=</span><span style="color: #ff0000;color: #C89191;">&quot;server&quot;</span> OnItemDataBound<span style="color: #66cc66;color: #c0c0c0;">=</span><span style="color: #ff0000;color: #C89191;">&quot;rptCalendarEvents_ItemDataBound&quot;</span>&gt;</span>
                <span style="color: #EFEF8F;">&lt;ItemTemplate&gt;</span>
                <span style="color: #EFEF8F;">&lt;asp:Panel <span style="color: #000066;color: #2B91AF;">ID</span><span style="color: #66cc66;color: #c0c0c0;">=</span><span style="color: #ff0000;color: #C89191;">&quot;pnlCalenderItem&quot;</span> CssClass<span style="color: #66cc66;color: #c0c0c0;">=</span><span style="color: #ff0000;color: #C89191;">&quot;calendar-item&quot;</span> runat<span style="color: #66cc66;color: #c0c0c0;">=</span><span style="color: #ff0000;color: #C89191;">&quot;server&quot;</span>&gt;</span>
                    <span style="color: #EFEF8F;">&lt;<span style="color: #000000; font-weight: bold;color: #C2964B; font-weight: bold;">div</span> <span style="color: #000066;color: #2B91AF;">class</span><span style="color: #66cc66;color: #c0c0c0;">=</span><span style="color: #ff0000;color: #C89191;">&quot;calendar-date&quot;</span>&gt;&lt;%# IIf<span style="color: #66cc66;color: #c0c0c0;">&#40;</span>Eval<span style="color: #66cc66;color: #c0c0c0;">&#40;</span><span style="color: #ff0000;color: #C89191;">&quot;GroupName&quot;</span><span style="color: #66cc66;color: #c0c0c0;">&#41;</span> &lt;&gt;</span> &quot;Next Week&quot;, IIf(Eval(&quot;IsAllDay&quot;), &quot;All day&quot;, CDate(Eval(&quot;StartTime&quot;)).ToString(&quot;HH:mm&quot;)), CDate(Eval(&quot;StartTime&quot;)).ToString(&quot;ddd&quot;))%&gt;<span style="color: #EFEF8F;">&lt;<span style="color: #66cc66;color: #c0c0c0;">/</span><span style="color: #000000; font-weight: bold;color: #C2964B; font-weight: bold;">div</span>&gt;</span>
                    <span style="color: #EFEF8F;">&lt;<span style="color: #000000; font-weight: bold;color: #C2964B; font-weight: bold;">div</span> <span style="color: #000066;color: #2B91AF;">class</span><span style="color: #66cc66;color: #c0c0c0;">=</span><span style="color: #ff0000;color: #C89191;">&quot;calendar-subject&quot;</span>&gt;&lt;%# Eval<span style="color: #66cc66;color: #c0c0c0;">&#40;</span><span style="color: #ff0000;color: #C89191;">&quot;Subject&quot;</span><span style="color: #66cc66;color: #c0c0c0;">&#41;</span>%&gt;&lt;<span style="color: #66cc66;color: #c0c0c0;">/</span><span style="color: #000000; font-weight: bold;color: #C2964B; font-weight: bold;">div</span>&gt;</span>
&nbsp;
                    <span style="color: #EFEF8F;">&lt;<span style="color: #000000; font-weight: bold;color: #C2964B; font-weight: bold;">div</span> <span style="color: #000066;color: #2B91AF;">class</span><span style="color: #66cc66;color: #c0c0c0;">=</span><span style="color: #ff0000;color: #C89191;">&quot;calendar-duration&quot;</span>&gt;&lt;%# IIf<span style="color: #66cc66;color: #c0c0c0;">&#40;</span>Not Eval<span style="color: #66cc66;color: #c0c0c0;">&#40;</span><span style="color: #ff0000;color: #C89191;">&quot;IsAllDay&quot;</span><span style="color: #66cc66;color: #c0c0c0;">&#41;</span>, Eval<span style="color: #66cc66;color: #c0c0c0;">&#40;</span><span style="color: #ff0000;color: #C89191;">&quot;TimespanString&quot;</span><span style="color: #66cc66;color: #c0c0c0;">&#41;</span>, <span style="color: #ff0000;color: #C89191;">&quot;&quot;</span><span style="color: #66cc66;color: #c0c0c0;">&#41;</span>%&gt;&lt;<span style="color: #66cc66;color: #c0c0c0;">/</span><span style="color: #000000; font-weight: bold;color: #C2964B; font-weight: bold;">div</span>&gt;</span>
                    <span style="color: #EFEF8F;">&lt;<span style="color: #000000; font-weight: bold;color: #C2964B; font-weight: bold;">div</span> <span style="color: #000066;color: #2B91AF;">class</span><span style="color: #66cc66;color: #c0c0c0;">=</span><span style="color: #ff0000;color: #C89191;">&quot;calendar-location&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;color: #C2964B; font-weight: bold;">span</span> <span style="color: #000066;color: #2B91AF;">title</span><span style="color: #66cc66;color: #c0c0c0;">=</span><span style="color: #ff0000;color: #C89191;">'&lt;%# Eval(&quot;AttendeesList&quot;) %&gt;</span></span>'&gt;<span style="color: #EFEF8F;">&lt;%# IIf<span style="color: #66cc66;color: #c0c0c0;">&#40;</span>Eval<span style="color: #66cc66;color: #c0c0c0;">&#40;</span><span style="color: #ff0000;color: #C89191;">&quot;Location&quot;</span><span style="color: #66cc66;color: #c0c0c0;">&#41;</span> &lt;&gt;</span>&quot;&quot;, &quot;(&quot; <span style="color: #c0c0c0;">&amp; Eval(&quot;Location&quot;) &amp; &quot;)&quot; , &quot;&quot;)%&gt;&lt;/span&gt;&lt;/div&gt;</span>
<span style="color: #c0c0c0;">                &lt;/asp:Panel&gt;</span>
<span style="color: #c0c0c0;">                &lt;/ItemTemplate&gt;</span>
<span style="color: #c0c0c0;">            &lt;/asp:Repeater&gt;</span>
<span style="color: #c0c0c0;">        &lt;/div&gt;</span>
<span style="color: #c0c0c0;">        &lt;/ItemTemplate&gt;</span>
<span style="color: #c0c0c0;">    &lt;/asp:Repeater&gt;</span>
<span style="color: #c0c0c0;">&lt;/asp:Panel&gt;</span></pre></div></div>

<p>Codebehind:</p>

<div class="wp_syntax"><div class="code"><pre class="vbnet" style="font-family:monospace;color: #c0c0c0; font-family: Franklin Gothic Book;"><span style="color: #0600FF;color: #C2964B; font-weight: bold;">Namespace</span> UserControls
    <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Public</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Class</span> OutlookCalendarWidget
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Inherits</span> System.<span style="color: #0000FF;color: #c0c0c0;">Web</span>.<span style="color: #0000FF;color: #c0c0c0;">UI</span>.<span style="color: #0000FF;color: #c0c0c0;">UserControl</span>
&nbsp;
&nbsp;
        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Private</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Const</span> _activeSyncServer <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #808080;color: #C89191;">&quot;https://webmail.yourdomain.com/&quot;</span>
        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Private</span> _calendarItems <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> List<span style="color: #000000;color: #c0c0c0;">&#40;</span>Of CalendarItem<span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Protected</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Class</span> CalendarItem
            <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Public</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Class</span> Attendee
                <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Public</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Property</span> Name <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span>
                <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Public</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Property</span> Email <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span>
&nbsp;
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Class</span>
&nbsp;
            <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Public</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Property</span> IsAllDay <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Boolean</span>
            <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Public</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Property</span> StartTime <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> DateTime
            <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Public</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Property</span> EndTime <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> DateTime
            <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Public</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Property</span> Subject <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span>
            <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Public</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Property</span> Location <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span>
            <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Public</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Property</span> Attendees <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">New</span> List<span style="color: #000000;color: #c0c0c0;">&#40;</span>Of Attendee<span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
            <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Private</span> _groupName <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span>
            <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Public</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">ReadOnly</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Property</span> GroupName <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span>
                <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Get</span>
                    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span>.<span style="color: #0000FF;color: #c0c0c0;">IsNullOrEmpty</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>_groupName<span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Then</span>
                        <span style="color: #008080; font-style: italic;color: #7F9F7F;">'categorize this calendar entry into a group</span>
                        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> daysFromToday <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> TimeSpan <span style="color: #008000;color: #c0c0c0;">=</span> StartTime.<span style="color: #FF0000;color: #C2964B; font-weight: bold;">Date</span>.<span style="color: #0000FF;color: #c0c0c0;">Subtract</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #0600FF;color: #c0c0c0;">Today</span>.<span style="color: #FF0000;color: #C2964B; font-weight: bold;">Date</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
                        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Select</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Case</span> daysFromToday.<span style="color: #0000FF;color: #c0c0c0;">Days</span>
                            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Case</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Is</span> &lt; <span style="color: #FF0000;color: #8ACCCF;">0</span>
                                _groupName <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #808080;color: #C89191;">&quot;Past&quot;</span>
                            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Case</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Is</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #FF0000;color: #8ACCCF;">0</span>
                                _groupName <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #808080;color: #C89191;">&quot;Today&quot;</span>
                            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Case</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Is</span> &lt;<span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #FF0000;color: #8ACCCF;">7</span>
                                _groupName <span style="color: #008000;color: #c0c0c0;">=</span> StartTime.<span style="color: #0000FF;color: #c0c0c0;">ToString</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #808080;color: #C89191;">&quot;dddd&quot;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
                            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Case</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Is</span> &lt;<span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #FF0000;color: #8ACCCF;">14</span>
                                _groupName <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #808080;color: #C89191;">&quot;Next Week&quot;</span>
                            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Case</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Else</span>
                                _groupName <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #808080;color: #C89191;">&quot;Rest of Year&quot;</span>
                        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Select</span>
                    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span>
&nbsp;
                    <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Return</span> _groupName
                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Get</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Property</span>
&nbsp;
            <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Public</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">ReadOnly</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Property</span> TimespanString <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span>
                <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Get</span>
                    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> <span style="color: #0600FF;color: #c0c0c0;">format</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #808080;color: #C89191;">&quot;&quot;</span>
&nbsp;
                    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> elapsed <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> TimeSpan <span style="color: #008000;color: #c0c0c0;">=</span> EndTime.<span style="color: #0000FF;color: #c0c0c0;">Subtract</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>StartTime<span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
                    <span style="color: #008080; font-style: italic;color: #7F9F7F;">'any days?</span>
                    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span> elapsed.<span style="color: #0000FF;color: #c0c0c0;">Days</span> &gt; <span style="color: #FF0000;color: #8ACCCF;">0</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Then</span> <span style="color: #0600FF;color: #c0c0c0;">format</span> <span style="color: #008000;color: #c0c0c0;">&amp;=</span> <span style="color: #808080;color: #C89191;">&quot;d'days'&quot;</span>
&nbsp;
                    <span style="color: #008080; font-style: italic;color: #7F9F7F;">'hours?</span>
                    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span> elapsed.<span style="color: #0000FF;color: #c0c0c0;">Hours</span> &gt; <span style="color: #FF0000;color: #8ACCCF;">0</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Then</span> <span style="color: #0600FF;color: #c0c0c0;">format</span> <span style="color: #008000;color: #c0c0c0;">&amp;=</span> <span style="color: #0600FF;color: #c0c0c0;">CStr</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #0600FF;color: #c0c0c0;">IIf</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #0600FF;color: #c0c0c0;">format</span> &lt;&gt; <span style="color: #808080;color: #C89191;">&quot;&quot;</span>, <span style="color: #808080;color: #C89191;">&quot;\ &quot;</span>, <span style="color: #808080;color: #C89191;">&quot;&quot;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #008000;color: #c0c0c0;">&amp;</span> <span style="color: #808080;color: #C89191;">&quot;h'hrs'&quot;</span>
&nbsp;
                    <span style="color: #008080; font-style: italic;color: #7F9F7F;">'mins?</span>
                    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span> elapsed.<span style="color: #0000FF;color: #c0c0c0;">Minutes</span> &gt; <span style="color: #FF0000;color: #8ACCCF;">0</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Then</span> <span style="color: #0600FF;color: #c0c0c0;">format</span> <span style="color: #008000;color: #c0c0c0;">&amp;=</span> <span style="color: #0600FF;color: #c0c0c0;">CStr</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #0600FF;color: #c0c0c0;">IIf</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #0600FF;color: #c0c0c0;">format</span> &lt;&gt; <span style="color: #808080;color: #C89191;">&quot;&quot;</span>, <span style="color: #808080;color: #C89191;">&quot;\ &quot;</span>, <span style="color: #808080;color: #C89191;">&quot;&quot;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #008000;color: #c0c0c0;">&amp;</span> <span style="color: #808080;color: #C89191;">&quot;m'mins'&quot;</span>
&nbsp;
                    <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Return</span> elapsed.<span style="color: #0000FF;color: #c0c0c0;">ToString</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #0600FF;color: #c0c0c0;">format</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Get</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Property</span>
&nbsp;
            <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Public</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">ReadOnly</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Property</span> AttendeesList <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span>
                <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Get</span>
                    <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Return</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span>.<span style="color: #0600FF;color: #c0c0c0;">Join</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #808080;color: #C89191;">&quot;, &quot;</span>, From a In Attendees <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Select</span> a.<span style="color: #0000FF;color: #c0c0c0;">Name</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Get</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Property</span>
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Class</span>
&nbsp;
&nbsp;
        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Protected</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Sub</span> Page_Load<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF8000;color: #C2964B; font-weight: bold;">ByVal</span> sender <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Object</span>, <span style="color: #FF8000;color: #C2964B; font-weight: bold;">ByVal</span> e <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> System.<span style="color: #0000FF;color: #c0c0c0;">EventArgs</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Handles</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Me</span>.<span style="color: #0000FF;color: #c0c0c0;">Load</span>
&nbsp;
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span> <span style="color: #804040;">Not</span> IsPostBack <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Then</span>
                MessageLoop<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span>
&nbsp;
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Sub</span>
&nbsp;
&nbsp;
        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Private</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Function</span> GetUsername<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span> HttpContext.<span style="color: #0000FF;color: #c0c0c0;">Current</span>.<span style="color: #0000FF;color: #c0c0c0;">User</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">IsNot</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Nothing</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">AndAlso</span> HttpContext.<span style="color: #0000FF;color: #c0c0c0;">Current</span>.<span style="color: #0000FF;color: #c0c0c0;">User</span>.<span style="color: #0000FF;color: #c0c0c0;">Identity</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">IsNot</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Nothing</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">AndAlso</span> <span style="color: #804040;">Not</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span>.<span style="color: #0000FF;color: #c0c0c0;">IsNullOrEmpty</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>HttpContext.<span style="color: #0000FF;color: #c0c0c0;">Current</span>.<span style="color: #0000FF;color: #c0c0c0;">User</span>.<span style="color: #0000FF;color: #c0c0c0;">Identity</span>.<span style="color: #0000FF;color: #c0c0c0;">Name</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Then</span>
                <span style="color: #008080; font-style: italic;color: #7F9F7F;">'domain logged in - get the username</span>
                <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Return</span> HttpContext.<span style="color: #0000FF;color: #c0c0c0;">Current</span>.<span style="color: #0000FF;color: #c0c0c0;">User</span>.<span style="color: #0000FF;color: #c0c0c0;">Identity</span>.<span style="color: #0000FF;color: #c0c0c0;">Name</span>
            <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Else</span>
                <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Return</span> txtUsername.<span style="color: #0000FF;color: #c0c0c0;">Text</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span>
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Function</span>
&nbsp;
        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Private</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Function</span> GetPassword<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span>
            <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Return</span> txtExchangePass.<span style="color: #0000FF;color: #c0c0c0;">Text</span>
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Function</span>
&nbsp;
        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Private</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Sub</span> SyncCalendar<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Try</span>
                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> fullUsername <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span> <span style="color: #008000;color: #c0c0c0;">=</span> GetUsername<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> username <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #808080;color: #C89191;">&quot;&quot;</span>
                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> domain <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #808080;color: #C89191;">&quot;&quot;</span>
&nbsp;
                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> pw <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span> <span style="color: #008000;color: #c0c0c0;">=</span> GetPassword<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
                <span style="color: #008080; font-style: italic;color: #7F9F7F;">'check for domain login</span>
                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span> fullUsername.<span style="color: #0000FF;color: #c0c0c0;">Contains</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #808080;color: #C89191;">&quot;\&quot;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Then</span>
                    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> parts<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span> <span style="color: #008000;color: #c0c0c0;">=</span> fullUsername.<span style="color: #0600FF;color: #c0c0c0;">Split</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #808080;color: #C89191;">&quot;\&quot;</span>c<span style="color: #000000;color: #c0c0c0;">&#41;</span>
                    domain <span style="color: #008000;color: #c0c0c0;">=</span> parts<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF0000;color: #8ACCCF;">0</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
                    username <span style="color: #008000;color: #c0c0c0;">=</span> parts<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF0000;color: #8ACCCF;">1</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
                <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Else</span>
                    username <span style="color: #008000;color: #c0c0c0;">=</span> fullUsername
                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span>
&nbsp;
                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> asHelper <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">New</span> Email.<span style="color: #0000FF;color: #c0c0c0;">Exchange</span>.<span style="color: #0000FF;color: #c0c0c0;">AirSync</span>.<span style="color: #0000FF;color: #c0c0c0;">AirSyncHelper</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>_activeSyncServer, username, pw, domain<span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span> asHelper.<span style="color: #0000FF;color: #c0c0c0;">IsVersionCompatible</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Then</span>
                    <span style="color: #008080; font-style: italic;color: #7F9F7F;">'make sure the policy key is populated (if applicable) - not required for this version</span>
                    <span style="color: #008080; font-style: italic;color: #7F9F7F;">'asHelper.ObtainPolicyKey()</span>
&nbsp;
                    <span style="color: #008080; font-style: italic;color: #7F9F7F;">'do an initial folder sync for the user (resets the sync on the server)</span>
                    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> initFolderSyncResult <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> System.<span style="color: #0000FF;color: #c0c0c0;">Xml</span>.<span style="color: #0000FF;color: #c0c0c0;">XmlDocument</span> <span style="color: #008000;color: #c0c0c0;">=</span> GetFolderSyncResult<span style="color: #000000;color: #c0c0c0;">&#40;</span>asHelper, <span style="color: #808080;color: #C89191;">&quot;0&quot;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
                    <span style="color: #008080; font-style: italic;color: #7F9F7F;">'use a namespace manager for FolderSync</span>
                    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> initFolderSyncNsMgr <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">New</span> System.<span style="color: #0000FF;color: #c0c0c0;">Xml</span>.<span style="color: #0000FF;color: #c0c0c0;">XmlNamespaceManager</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>initFolderSyncResult.<span style="color: #0000FF;color: #c0c0c0;">NameTable</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
                    <span style="color: #008080; font-style: italic;color: #7F9F7F;">'since XPATH 1 doesnt support default namespaces, we will have to invent our own</span>
                    initFolderSyncNsMgr.<span style="color: #0000FF;color: #c0c0c0;">AddNamespace</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #808080;color: #C89191;">&quot;dflt&quot;</span>, Email.<span style="color: #0000FF;color: #c0c0c0;">Exchange</span>.<span style="color: #0000FF;color: #c0c0c0;">AirSync</span>.<span style="color: #0000FF;color: #c0c0c0;">Codepages</span>.<span style="color: #0000FF;color: #c0c0c0;">FolderHierarchy_7</span>.<span style="color: #0000FF;color: #c0c0c0;">Instance</span>.<span style="color: #0000FF;color: #c0c0c0;">XmlNs</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
                    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> statusNode <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> System.<span style="color: #0000FF;color: #c0c0c0;">Xml</span>.<span style="color: #0000FF;color: #c0c0c0;">XmlNode</span> <span style="color: #008000;color: #c0c0c0;">=</span> initFolderSyncResult.<span style="color: #0000FF;color: #c0c0c0;">SelectSingleNode</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #808080;color: #C89191;">&quot;dflt:FolderSync/dflt:Status&quot;</span>, initFolderSyncNsMgr<span style="color: #000000;color: #c0c0c0;">&#41;</span>
                    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span> statusNode <span style="color: #FF8000;color: #C2964B; font-weight: bold;">IsNot</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Nothing</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">AndAlso</span> statusNode.<span style="color: #0000FF;color: #c0c0c0;">InnerText</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #808080;color: #C89191;">&quot;1&quot;</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Then</span>
                        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> folderSyncSyncKeyNode <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> System.<span style="color: #0000FF;color: #c0c0c0;">Xml</span>.<span style="color: #0000FF;color: #c0c0c0;">XmlNode</span> <span style="color: #008000;color: #c0c0c0;">=</span> initFolderSyncResult.<span style="color: #0000FF;color: #c0c0c0;">SelectSingleNode</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #808080;color: #C89191;">&quot;dflt:FolderSync/dflt:SyncKey&quot;</span>, initFolderSyncNsMgr<span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
                        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span> folderSyncSyncKeyNode <span style="color: #FF8000;color: #C2964B; font-weight: bold;">IsNot</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Nothing</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Then</span>
                            <span style="color: #008080; font-style: italic;color: #7F9F7F;">'use the sync key to start a sync session on the server to complete the foldersync cycle</span>
                            GetFolderSyncResult<span style="color: #000000;color: #c0c0c0;">&#40;</span>asHelper, folderSyncSyncKeyNode.<span style="color: #0000FF;color: #c0c0c0;">InnerText</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
                            <span style="color: #008080; font-style: italic;color: #7F9F7F;">'do a sync on the calendar folder by using the server Id of the calendar from the initial sync</span>
                            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> calendarFolderNode <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> System.<span style="color: #0000FF;color: #c0c0c0;">Xml</span>.<span style="color: #0000FF;color: #c0c0c0;">XmlNode</span> <span style="color: #008000;color: #c0c0c0;">=</span> initFolderSyncResult.<span style="color: #0000FF;color: #c0c0c0;">SelectSingleNode</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #808080;color: #C89191;">&quot;dflt:FolderSync/dflt:Changes/dflt:Add[dflt:DisplayName = &quot;</span><span style="color: #808080;color: #C89191;">&quot;Calendar&quot;</span><span style="color: #808080;color: #C89191;">&quot;]&quot;</span>, initFolderSyncNsMgr<span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
                            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span> calendarFolderNode <span style="color: #FF8000;color: #C2964B; font-weight: bold;">IsNot</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Nothing</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Then</span>
                                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> calendarFolderServerId <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span> <span style="color: #008000;color: #c0c0c0;">=</span> calendarFolderNode<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #808080;color: #C89191;">&quot;ServerId&quot;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>.<span style="color: #0000FF;color: #c0c0c0;">InnerText</span>
                                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> initialCalendarSyncResult <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> System.<span style="color: #0000FF;color: #c0c0c0;">Xml</span>.<span style="color: #0000FF;color: #c0c0c0;">XmlDocument</span> <span style="color: #008000;color: #c0c0c0;">=</span> GetSyncResult<span style="color: #000000;color: #c0c0c0;">&#40;</span>asHelper, calendarFolderServerId, <span style="color: #808080;color: #C89191;">&quot;Calendar&quot;</span>, <span style="color: #808080;color: #C89191;">&quot;0&quot;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
                                <span style="color: #008080; font-style: italic;color: #7F9F7F;">'use a namespace manager for Sync</span>
                                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> initCalSyncNsMgr <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">New</span> System.<span style="color: #0000FF;color: #c0c0c0;">Xml</span>.<span style="color: #0000FF;color: #c0c0c0;">XmlNamespaceManager</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>initialCalendarSyncResult.<span style="color: #0000FF;color: #c0c0c0;">NameTable</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
                                <span style="color: #008080; font-style: italic;color: #7F9F7F;">'since XPATH 1 doesnt support default namespaces, we will have to invent our own</span>
                                initCalSyncNsMgr.<span style="color: #0000FF;color: #c0c0c0;">AddNamespace</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #808080;color: #C89191;">&quot;dflt&quot;</span>, Email.<span style="color: #0000FF;color: #c0c0c0;">Exchange</span>.<span style="color: #0000FF;color: #c0c0c0;">AirSync</span>.<span style="color: #0000FF;color: #c0c0c0;">Codepages</span>.<span style="color: #0000FF;color: #c0c0c0;">AirSync_0</span>.<span style="color: #0000FF;color: #c0c0c0;">Instance</span>.<span style="color: #0000FF;color: #c0c0c0;">XmlNs</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
                                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> calendarSyncKeyNode <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> System.<span style="color: #0000FF;color: #c0c0c0;">Xml</span>.<span style="color: #0000FF;color: #c0c0c0;">XmlNode</span> <span style="color: #008000;color: #c0c0c0;">=</span> initialCalendarSyncResult.<span style="color: #0000FF;color: #c0c0c0;">SelectSingleNode</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #808080;color: #C89191;">&quot;dflt:Sync/dflt:Collections/dflt:Collection/dflt:SyncKey&quot;</span>, initCalSyncNsMgr<span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
                                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span> calendarSyncKeyNode <span style="color: #FF8000;color: #C2964B; font-weight: bold;">IsNot</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Nothing</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Then</span>
                                    <span style="color: #008080; font-style: italic;color: #7F9F7F;">'now we can do a second sync to get the juicy stuff</span>
                                    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> calendarSyncKey <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span> <span style="color: #008000;color: #c0c0c0;">=</span> calendarSyncKeyNode.<span style="color: #0000FF;color: #c0c0c0;">InnerText</span>
&nbsp;
                                    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> juicyCalendarSyncResult <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> System.<span style="color: #0000FF;color: #c0c0c0;">Xml</span>.<span style="color: #0000FF;color: #c0c0c0;">XmlDocument</span> <span style="color: #008000;color: #c0c0c0;">=</span> GetSyncResult<span style="color: #000000;color: #c0c0c0;">&#40;</span>asHelper, calendarFolderServerId, <span style="color: #808080;color: #C89191;">&quot;Calendar&quot;</span>, calendarSyncKey<span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
                                    _calendarItems <span style="color: #008000;color: #c0c0c0;">=</span> ParseCalender<span style="color: #000000;color: #c0c0c0;">&#40;</span>juicyCalendarSyncResult<span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
                                    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span> _calendarItems <span style="color: #FF8000;color: #C2964B; font-weight: bold;">IsNot</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Nothing</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">AndAlso</span> _calendarItems.<span style="color: #0000FF;color: #c0c0c0;">Count</span> &gt; <span style="color: #FF0000;color: #8ACCCF;">0</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Then</span>
&nbsp;
                                        <span style="color: #008080; font-style: italic;color: #7F9F7F;">'bind the groups in date order (dont include items from the past)</span>
                                        rptCalendarItemGroups.<span style="color: #0000FF;color: #c0c0c0;">DataSource</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #000000;color: #c0c0c0;">&#40;</span>From ci In _calendarItems Order By ci.<span style="color: #0000FF;color: #c0c0c0;">StartTime</span> Ascending Where ci.<span style="color: #0000FF;color: #c0c0c0;">StartTime</span>.<span style="color: #FF0000;color: #C2964B; font-weight: bold;">Date</span> &gt;<span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #0600FF;color: #c0c0c0;">Today</span>.<span style="color: #FF0000;color: #C2964B; font-weight: bold;">Date</span> <span style="color: #804040;">And</span> ci.<span style="color: #0000FF;color: #c0c0c0;">StartTime</span>.<span style="color: #FF0000;color: #C2964B; font-weight: bold;">Date</span> &lt;<span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #0600FF;color: #c0c0c0;">Today</span>.<span style="color: #FF0000;color: #C2964B; font-weight: bold;">Date</span>.<span style="color: #0000FF;color: #c0c0c0;">AddDays</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF0000;color: #8ACCCF;">14</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> Group ci By ci.<span style="color: #0000FF;color: #c0c0c0;">GroupName</span> Into g <span style="color: #008000;color: #c0c0c0;">=</span> Group <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Select</span> g.<span style="color: #0000FF;color: #c0c0c0;">First</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>.<span style="color: #0000FF;color: #c0c0c0;">GroupName</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
                                        rptCalendarItemGroups.<span style="color: #0000FF;color: #c0c0c0;">DataBind</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
                                        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span> rptCalendarItemGroups.<span style="color: #0000FF;color: #c0c0c0;">Items</span>.<span style="color: #0000FF;color: #c0c0c0;">Count</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #FF0000;color: #8ACCCF;">0</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Then</span> lblActiveSyncErrorMessage.<span style="color: #0000FF;color: #c0c0c0;">Text</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #808080;color: #C89191;">&quot;You have no calendar items to display&quot;</span>
                                    <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Else</span>
                                        <span style="color: #008080; font-style: italic;color: #7F9F7F;">'couldnt do it - after all that!!</span>
                                        lblActiveSyncErrorMessage.<span style="color: #0000FF;color: #c0c0c0;">Text</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #808080;color: #C89191;">&quot;Could not do  sync the calendar folder. &quot;</span>
&nbsp;
                                        <span style="color: #008080; font-style: italic;color: #7F9F7F;">'see if there was a status from AS</span>
                                        <span style="color: #008080; font-style: italic;color: #7F9F7F;">'use a namespace manager for FolderSync</span>
                                        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> statusNsMgr <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">New</span> System.<span style="color: #0000FF;color: #c0c0c0;">Xml</span>.<span style="color: #0000FF;color: #c0c0c0;">XmlNamespaceManager</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>juicyCalendarSyncResult.<span style="color: #0000FF;color: #c0c0c0;">NameTable</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
                                        <span style="color: #008080; font-style: italic;color: #7F9F7F;">'since XPATH 1 doesnt support default namespaces, we will have to invent our own</span>
                                        statusNsMgr.<span style="color: #0000FF;color: #c0c0c0;">AddNamespace</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #808080;color: #C89191;">&quot;dflt&quot;</span>, Email.<span style="color: #0000FF;color: #c0c0c0;">Exchange</span>.<span style="color: #0000FF;color: #c0c0c0;">AirSync</span>.<span style="color: #0000FF;color: #c0c0c0;">Codepages</span>.<span style="color: #0000FF;color: #c0c0c0;">AirSync_0</span>.<span style="color: #0000FF;color: #c0c0c0;">Instance</span>.<span style="color: #0000FF;color: #c0c0c0;">XmlNs</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
                                        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> juicyStatusNode <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> System.<span style="color: #0000FF;color: #c0c0c0;">Xml</span>.<span style="color: #0000FF;color: #c0c0c0;">XmlNode</span> <span style="color: #008000;color: #c0c0c0;">=</span> juicyCalendarSyncResult.<span style="color: #0000FF;color: #c0c0c0;">SelectSingleNode</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #808080;color: #C89191;">&quot;dflt:Sync/dflt:Collections/dflt:Collection/dflt:Status&quot;</span>, statusNsMgr<span style="color: #000000;color: #c0c0c0;">&#41;</span>
                                        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span> juicyStatusNode <span style="color: #FF8000;color: #C2964B; font-weight: bold;">IsNot</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Nothing</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Then</span> lblActiveSyncErrorMessage.<span style="color: #0000FF;color: #c0c0c0;">Text</span> <span style="color: #008000;color: #c0c0c0;">&amp;=</span> <span style="color: #808080;color: #C89191;">&quot; ActiveSync status: &quot;</span> <span style="color: #008000;color: #c0c0c0;">&amp;</span> juicyStatusNode.<span style="color: #0000FF;color: #c0c0c0;">InnerText</span>
                                    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span>
&nbsp;
&nbsp;
                                <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Else</span>
                                    lblActiveSyncErrorMessage.<span style="color: #0000FF;color: #c0c0c0;">Text</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #808080;color: #C89191;">&quot;Could not do initial sync on the calendar folder.&quot;</span>
                                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span>
&nbsp;
&nbsp;
                            <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Else</span>
                                lblActiveSyncErrorMessage.<span style="color: #0000FF;color: #c0c0c0;">Text</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #808080;color: #C89191;">&quot;There is no calendar folder found in the initial folder sync.&quot;</span>
                            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span>
&nbsp;
                        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Else</span>
                            lblActiveSyncErrorMessage.<span style="color: #0000FF;color: #c0c0c0;">Text</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #808080;color: #C89191;">&quot;Could not find SyncKey in FolderSync response.&quot;</span>
                        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span>
&nbsp;
                    <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Else</span>
                        lblActiveSyncErrorMessage.<span style="color: #0000FF;color: #c0c0c0;">Text</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #808080;color: #C89191;">&quot;Initial FolderSync did not complete.&quot;</span>
                        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span> statusNode <span style="color: #FF8000;color: #C2964B; font-weight: bold;">IsNot</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Nothing</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Then</span> lblActiveSyncErrorMessage.<span style="color: #0000FF;color: #c0c0c0;">Text</span> <span style="color: #008000;color: #c0c0c0;">&amp;=</span> <span style="color: #808080;color: #C89191;">&quot; ActiveSync status: &quot;</span> <span style="color: #008000;color: #c0c0c0;">&amp;</span> statusNode.<span style="color: #0000FF;color: #c0c0c0;">InnerText</span>
                    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span>
&nbsp;
&nbsp;
                <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Else</span>
                    <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Throw</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">New</span> Exception<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #808080;color: #C89191;">&quot;Server does not support the correct verion of AirSync. Required version: &quot;</span> <span style="color: #008000;color: #c0c0c0;">&amp;</span> Email.<span style="color: #0000FF;color: #c0c0c0;">Exchange</span>.<span style="color: #0000FF;color: #c0c0c0;">AirSync</span>.<span style="color: #0000FF;color: #c0c0c0;">AirSyncHelper</span>.<span style="color: #0000FF;color: #c0c0c0;">AirSyncSupportedVersion</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Catch</span> wEx <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> Net.<span style="color: #0000FF;color: #c0c0c0;">WebException</span>
                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span> wEx.<span style="color: #0000FF;color: #c0c0c0;">Message</span>.<span style="color: #0000FF;color: #c0c0c0;">Contains</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #808080;color: #C89191;">&quot;401&quot;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Then</span>
                    pnlNotAuth.<span style="color: #0000FF;color: #c0c0c0;">Visible</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">True</span>
                <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Else</span>
                    <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Throw</span> wEx
                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Catch</span> ex <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> Exception
                lblActiveSyncErrorMessage.<span style="color: #0000FF;color: #c0c0c0;">Text</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #808080;color: #C89191;">&quot;Could not connect to ActiveSync. &quot;</span> <span style="color: #008000;color: #c0c0c0;">&amp;</span> ex.<span style="color: #0000FF;color: #c0c0c0;">Message</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Try</span>
&nbsp;
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Sub</span>
&nbsp;
        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Private</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Function</span> GetFolderSyncResult<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF8000;color: #C2964B; font-weight: bold;">ByVal</span> asHelper <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> Email.<span style="color: #0000FF;color: #c0c0c0;">Exchange</span>.<span style="color: #0000FF;color: #c0c0c0;">AirSync</span>.<span style="color: #0000FF;color: #c0c0c0;">AirSyncHelper</span>, <span style="color: #FF8000;color: #C2964B; font-weight: bold;">ByVal</span> syncKey <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> System.<span style="color: #0000FF;color: #c0c0c0;">Xml</span>.<span style="color: #0000FF;color: #c0c0c0;">XmlDocument</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> xmlRequestData <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span> <span style="color: #008000;color: #c0c0c0;">=</span> &lt;?xml version<span style="color: #008000;color: #c0c0c0;">=</span><span style="color: #808080;color: #C89191;">&quot;1.0&quot;</span> encoding<span style="color: #008000;color: #c0c0c0;">=</span><span style="color: #808080;color: #C89191;">&quot;utf-8&quot;</span>?&gt;
                                           &lt;FolderSync xmlns<span style="color: #008000;color: #c0c0c0;">=</span><span style="color: #808080;color: #C89191;">&quot;FolderHierarchy:&quot;</span>&gt;
                                               &lt;SyncKey&gt;<span style="color: #000000;color: #c0c0c0;">&#123;</span>SyncKey<span style="color: #000000;color: #c0c0c0;">&#125;</span>&lt;<span style="color: #008000;color: #c0c0c0;">/</span>SyncKey&gt;
                                           &lt;<span style="color: #008000;color: #c0c0c0;">/</span>FolderSync&gt;.<span style="color: #0000FF;color: #c0c0c0;">ToString</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>.<span style="color: #0600FF;color: #c0c0c0;">Replace</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #808080;color: #C89191;">&quot;{SyncKey}&quot;</span>, syncKey<span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
            <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Return</span> asHelper.<span style="color: #0000FF;color: #c0c0c0;">ExecuteAirSyncCommand</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #808080;color: #C89191;">&quot;FolderSync&quot;</span>, xmlRequestData<span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Function</span>
&nbsp;
        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Private</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Function</span> GetSyncResult<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF8000;color: #C2964B; font-weight: bold;">ByVal</span> asHelper <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> Email.<span style="color: #0000FF;color: #c0c0c0;">Exchange</span>.<span style="color: #0000FF;color: #c0c0c0;">AirSync</span>.<span style="color: #0000FF;color: #c0c0c0;">AirSyncHelper</span>, <span style="color: #FF8000;color: #C2964B; font-weight: bold;">ByVal</span> collectionId <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span>, <span style="color: #FF8000;color: #C2964B; font-weight: bold;">ByVal</span> className <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span>, <span style="color: #FF8000;color: #C2964B; font-weight: bold;">ByVal</span> syncKey <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> System.<span style="color: #0000FF;color: #c0c0c0;">Xml</span>.<span style="color: #0000FF;color: #c0c0c0;">XmlDocument</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> xmlRequestData <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span>
&nbsp;
            <span style="color: #008080; font-style: italic;color: #7F9F7F;">'initial sync has different body content</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span> syncKey <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #808080;color: #C89191;">&quot;0&quot;</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Then</span>
                xmlRequestData <span style="color: #008000;color: #c0c0c0;">=</span> &lt;?xml version<span style="color: #008000;color: #c0c0c0;">=</span><span style="color: #808080;color: #C89191;">&quot;1.0&quot;</span> encoding<span style="color: #008000;color: #c0c0c0;">=</span><span style="color: #808080;color: #C89191;">&quot;utf-8&quot;</span>?&gt;
                                 &lt;Sync xmlns<span style="color: #008000;color: #c0c0c0;">=</span><span style="color: #808080;color: #C89191;">&quot;AirSync:&quot;</span>&gt;
                                     &lt;Collections&gt;
                                         &lt;Collection&gt;
                                             &lt;Class&gt;<span style="color: #000000;color: #c0c0c0;">&#123;</span>ClassName<span style="color: #000000;color: #c0c0c0;">&#125;</span>&lt;<span style="color: #008000;color: #c0c0c0;">/</span>Class&gt;
                                             &lt;SyncKey&gt;<span style="color: #000000;color: #c0c0c0;">&#123;</span>SyncKey<span style="color: #000000;color: #c0c0c0;">&#125;</span>&lt;<span style="color: #008000;color: #c0c0c0;">/</span>SyncKey&gt;
                                             &lt;CollectionId&gt;<span style="color: #000000;color: #c0c0c0;">&#123;</span>CollectionId<span style="color: #000000;color: #c0c0c0;">&#125;</span>&lt;<span style="color: #008000;color: #c0c0c0;">/</span>CollectionId&gt;
                                         &lt;<span style="color: #008000;color: #c0c0c0;">/</span>Collection&gt;
                                     &lt;<span style="color: #008000;color: #c0c0c0;">/</span>Collections&gt;
                                 &lt;<span style="color: #008000;color: #c0c0c0;">/</span>Sync&gt;.<span style="color: #0000FF;color: #c0c0c0;">ToString</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>.<span style="color: #0600FF;color: #c0c0c0;">Replace</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #808080;color: #C89191;">&quot;{SyncKey}&quot;</span>, syncKey<span style="color: #000000;color: #c0c0c0;">&#41;</span>.<span style="color: #0600FF;color: #c0c0c0;">Replace</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #808080;color: #C89191;">&quot;{CollectionId}&quot;</span>, collectionId<span style="color: #000000;color: #c0c0c0;">&#41;</span>.<span style="color: #0600FF;color: #c0c0c0;">Replace</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #808080;color: #C89191;">&quot;{ClassName}&quot;</span>, className<span style="color: #000000;color: #c0c0c0;">&#41;</span>
            <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Else</span>
                xmlRequestData <span style="color: #008000;color: #c0c0c0;">=</span> &lt;?xml version<span style="color: #008000;color: #c0c0c0;">=</span><span style="color: #808080;color: #C89191;">&quot;1.0&quot;</span> encoding<span style="color: #008000;color: #c0c0c0;">=</span><span style="color: #808080;color: #C89191;">&quot;utf-8&quot;</span>?&gt;
                                 &lt;Sync xmlns<span style="color: #008000;color: #c0c0c0;">=</span><span style="color: #808080;color: #C89191;">&quot;AirSync:&quot;</span>&gt;
                                     &lt;Collections&gt;
                                         &lt;Collection&gt;
                                             &lt;Class&gt;<span style="color: #000000;color: #c0c0c0;">&#123;</span>ClassName<span style="color: #000000;color: #c0c0c0;">&#125;</span>&lt;<span style="color: #008000;color: #c0c0c0;">/</span>Class&gt;
                                             &lt;SyncKey&gt;<span style="color: #000000;color: #c0c0c0;">&#123;</span>SyncKey<span style="color: #000000;color: #c0c0c0;">&#125;</span>&lt;<span style="color: #008000;color: #c0c0c0;">/</span>SyncKey&gt;
                                             &lt;CollectionId&gt;<span style="color: #000000;color: #c0c0c0;">&#123;</span>CollectionId<span style="color: #000000;color: #c0c0c0;">&#125;</span>&lt;<span style="color: #008000;color: #c0c0c0;">/</span>CollectionId&gt;
                                             &lt;DeletesAsMoves<span style="color: #008000;color: #c0c0c0;">/</span>&gt;
                                             &lt;GetChanges<span style="color: #008000;color: #c0c0c0;">/</span>&gt;
                                         &lt;<span style="color: #008000;color: #c0c0c0;">/</span>Collection&gt;
                                     &lt;<span style="color: #008000;color: #c0c0c0;">/</span>Collections&gt;
                                 &lt;<span style="color: #008000;color: #c0c0c0;">/</span>Sync&gt;.<span style="color: #0000FF;color: #c0c0c0;">ToString</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>.<span style="color: #0600FF;color: #c0c0c0;">Replace</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #808080;color: #C89191;">&quot;{SyncKey}&quot;</span>, syncKey<span style="color: #000000;color: #c0c0c0;">&#41;</span>.<span style="color: #0600FF;color: #c0c0c0;">Replace</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #808080;color: #C89191;">&quot;{CollectionId}&quot;</span>, collectionId<span style="color: #000000;color: #c0c0c0;">&#41;</span>.<span style="color: #0600FF;color: #c0c0c0;">Replace</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #808080;color: #C89191;">&quot;{ClassName}&quot;</span>, className<span style="color: #000000;color: #c0c0c0;">&#41;</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span>
&nbsp;
            <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Return</span> asHelper.<span style="color: #0000FF;color: #c0c0c0;">ExecuteAirSyncCommand</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #808080;color: #C89191;">&quot;Sync&quot;</span>, xmlRequestData<span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Function</span>
&nbsp;
&nbsp;
        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Private</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Sub</span> rptCalendarItemGroups_ItemDataBound<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF8000;color: #C2964B; font-weight: bold;">ByVal</span> sender <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Object</span>, <span style="color: #FF8000;color: #C2964B; font-weight: bold;">ByVal</span> e <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> System.<span style="color: #0000FF;color: #c0c0c0;">Web</span>.<span style="color: #0000FF;color: #c0c0c0;">UI</span>.<span style="color: #0000FF;color: #c0c0c0;">WebControls</span>.<span style="color: #0000FF;color: #c0c0c0;">RepeaterItemEventArgs</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Handles</span> rptCalendarItemGroups.<span style="color: #0000FF;color: #c0c0c0;">ItemDataBound</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span> e.<span style="color: #0000FF;color: #c0c0c0;">Item</span>.<span style="color: #0000FF;color: #c0c0c0;">ItemType</span> <span style="color: #008000;color: #c0c0c0;">=</span> ListItemType.<span style="color: #0000FF;color: #c0c0c0;">Item</span> Or e.<span style="color: #0000FF;color: #c0c0c0;">Item</span>.<span style="color: #0000FF;color: #c0c0c0;">ItemType</span> <span style="color: #008000;color: #c0c0c0;">=</span> ListItemType.<span style="color: #0000FF;color: #c0c0c0;">AlternatingItem</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Then</span>
                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> rptCalendarEvents <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> Repeater <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #0600FF;color: #c0c0c0;">CType</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>e.<span style="color: #0000FF;color: #c0c0c0;">Item</span>.<span style="color: #0000FF;color: #c0c0c0;">FindControl</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #808080;color: #C89191;">&quot;rptCalendarEvents&quot;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>, Repeater<span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
                rptCalendarEvents.<span style="color: #0000FF;color: #c0c0c0;">DataSource</span> <span style="color: #008000;color: #c0c0c0;">=</span> From ci In _calendarItems Where ci.<span style="color: #0000FF;color: #c0c0c0;">GroupName</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #0600FF;color: #c0c0c0;">CStr</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>e.<span style="color: #0000FF;color: #c0c0c0;">Item</span>.<span style="color: #0000FF;color: #c0c0c0;">DataItem</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> Order By ci.<span style="color: #0000FF;color: #c0c0c0;">StartTime</span> Ascending <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Select</span> ci
                rptCalendarEvents.<span style="color: #0000FF;color: #c0c0c0;">DataBind</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span>
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Sub</span>
&nbsp;
        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Protected</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Sub</span> rptCalendarEvents_ItemDataBound<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF8000;color: #C2964B; font-weight: bold;">ByVal</span> sender <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Object</span>, <span style="color: #FF8000;color: #C2964B; font-weight: bold;">ByVal</span> e <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> System.<span style="color: #0000FF;color: #c0c0c0;">Web</span>.<span style="color: #0000FF;color: #c0c0c0;">UI</span>.<span style="color: #0000FF;color: #c0c0c0;">WebControls</span>.<span style="color: #0000FF;color: #c0c0c0;">RepeaterItemEventArgs</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span> e.<span style="color: #0000FF;color: #c0c0c0;">Item</span>.<span style="color: #0000FF;color: #c0c0c0;">ItemType</span> <span style="color: #008000;color: #c0c0c0;">=</span> ListItemType.<span style="color: #0000FF;color: #c0c0c0;">Item</span> Or e.<span style="color: #0000FF;color: #c0c0c0;">Item</span>.<span style="color: #0000FF;color: #c0c0c0;">ItemType</span> <span style="color: #008000;color: #c0c0c0;">=</span> ListItemType.<span style="color: #0000FF;color: #c0c0c0;">AlternatingItem</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Then</span>
                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span> DirectCast<span style="color: #000000;color: #c0c0c0;">&#40;</span>e.<span style="color: #0000FF;color: #c0c0c0;">Item</span>.<span style="color: #0000FF;color: #c0c0c0;">DataItem</span>, CalendarItem<span style="color: #000000;color: #c0c0c0;">&#41;</span>.<span style="color: #0000FF;color: #c0c0c0;">EndTime</span> &lt; <span style="color: #0600FF;color: #c0c0c0;">Now</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Then</span>
                    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> pnlCalenderItem <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> Panel <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #0600FF;color: #c0c0c0;">CType</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>e.<span style="color: #0000FF;color: #c0c0c0;">Item</span>.<span style="color: #0000FF;color: #c0c0c0;">FindControl</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #808080;color: #C89191;">&quot;pnlCalenderItem&quot;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>, Panel<span style="color: #000000;color: #c0c0c0;">&#41;</span>
                    pnlCalenderItem.<span style="color: #0000FF;color: #c0c0c0;">CssClass</span> <span style="color: #008000;color: #c0c0c0;">&amp;=</span> <span style="color: #808080;color: #C89191;">&quot; strikeout&quot;</span>
                <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span>
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Sub</span>
&nbsp;
        <span style="color: #008080; font-style: italic;color: #7F9F7F;">'Private isAlt As Boolean = False</span>
        <span style="color: #008080; font-style: italic;color: #7F9F7F;">'Protected Function GetCalendarRowIsAlt() As Boolean</span>
        <span style="color: #008080; font-style: italic;color: #7F9F7F;">'    'remember current row</span>
        <span style="color: #008080; font-style: italic;color: #7F9F7F;">'    Dim thisOneIsAlt As Boolean = isAlt</span>
&nbsp;
        <span style="color: #008080; font-style: italic;color: #7F9F7F;">'    'invert for next call</span>
        <span style="color: #008080; font-style: italic;color: #7F9F7F;">'    isAlt = Not isAlt</span>
&nbsp;
        <span style="color: #008080; font-style: italic;color: #7F9F7F;">'    Return thisOneIsAlt</span>
        <span style="color: #008080; font-style: italic;color: #7F9F7F;">'End Function</span>
&nbsp;
        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Private</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Function</span> ParseCalender<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF8000;color: #C2964B; font-weight: bold;">ByVal</span> juicyCalendarSyncResult <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> System.<span style="color: #0000FF;color: #c0c0c0;">Xml</span>.<span style="color: #0000FF;color: #c0c0c0;">XmlDocument</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> List<span style="color: #000000;color: #c0c0c0;">&#40;</span>Of CalendarItem<span style="color: #000000;color: #c0c0c0;">&#41;</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> cItems <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> List<span style="color: #000000;color: #c0c0c0;">&#40;</span>Of CalendarItem<span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Nothing</span>
&nbsp;
            <span style="color: #008080; font-style: italic;color: #7F9F7F;">'use a namespace manager for Calendar Sync</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> juicyCalSyncNsMgr <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">New</span> System.<span style="color: #0000FF;color: #c0c0c0;">Xml</span>.<span style="color: #0000FF;color: #c0c0c0;">XmlNamespaceManager</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>juicyCalendarSyncResult.<span style="color: #0000FF;color: #c0c0c0;">NameTable</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;color: #7F9F7F;">'since XPATH 1 doesnt support default namespaces, we will have to invent our own + register the calendar prefix</span>
            juicyCalSyncNsMgr.<span style="color: #0000FF;color: #c0c0c0;">AddNamespace</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #808080;color: #C89191;">&quot;dflt&quot;</span>, Email.<span style="color: #0000FF;color: #c0c0c0;">Exchange</span>.<span style="color: #0000FF;color: #c0c0c0;">AirSync</span>.<span style="color: #0000FF;color: #c0c0c0;">Codepages</span>.<span style="color: #0000FF;color: #c0c0c0;">AirSync_0</span>.<span style="color: #0000FF;color: #c0c0c0;">Instance</span>.<span style="color: #0000FF;color: #c0c0c0;">XmlNs</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
            juicyCalSyncNsMgr.<span style="color: #0000FF;color: #c0c0c0;">AddNamespace</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>Email.<span style="color: #0000FF;color: #c0c0c0;">Exchange</span>.<span style="color: #0000FF;color: #c0c0c0;">AirSync</span>.<span style="color: #0000FF;color: #c0c0c0;">Codepages</span>.<span style="color: #0000FF;color: #c0c0c0;">Calendar_4</span>.<span style="color: #0000FF;color: #c0c0c0;">Instance</span>.<span style="color: #0000FF;color: #c0c0c0;">XmlPrefix</span>, Email.<span style="color: #0000FF;color: #c0c0c0;">Exchange</span>.<span style="color: #0000FF;color: #c0c0c0;">AirSync</span>.<span style="color: #0000FF;color: #c0c0c0;">Codepages</span>.<span style="color: #0000FF;color: #c0c0c0;">Calendar_4</span>.<span style="color: #0000FF;color: #c0c0c0;">Instance</span>.<span style="color: #0000FF;color: #c0c0c0;">XmlNs</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> juicyStatusNode <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> System.<span style="color: #0000FF;color: #c0c0c0;">Xml</span>.<span style="color: #0000FF;color: #c0c0c0;">XmlNode</span> <span style="color: #008000;color: #c0c0c0;">=</span> juicyCalendarSyncResult.<span style="color: #0000FF;color: #c0c0c0;">SelectSingleNode</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #808080;color: #C89191;">&quot;dflt:Sync/dflt:Collections/dflt:Collection/dflt:Status&quot;</span>, juicyCalSyncNsMgr<span style="color: #000000;color: #c0c0c0;">&#41;</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span> juicyStatusNode <span style="color: #FF8000;color: #C2964B; font-weight: bold;">IsNot</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Nothing</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">AndAlso</span> juicyStatusNode.<span style="color: #0000FF;color: #c0c0c0;">InnerText</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #808080;color: #C89191;">&quot;1&quot;</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Then</span>
                <span style="color: #008080; font-style: italic;color: #7F9F7F;">'we can bindings to repeaterings</span>
                cItems <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">New</span> List<span style="color: #000000;color: #c0c0c0;">&#40;</span>Of CalendarItem<span style="color: #000000;color: #c0c0c0;">&#41;</span>
                <span style="color: #FF8000;color: #C2964B; font-weight: bold;">For</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Each</span> node <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> System.<span style="color: #0000FF;color: #c0c0c0;">Xml</span>.<span style="color: #0000FF;color: #c0c0c0;">XmlNode</span> In juicyCalendarSyncResult.<span style="color: #0000FF;color: #c0c0c0;">SelectNodes</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #808080;color: #C89191;">&quot;dflt:Sync/dflt:Collections/dflt:Collection/dflt:Commands/dflt:Add/dflt:ApplicationData&quot;</span>, juicyCalSyncNsMgr<span style="color: #000000;color: #c0c0c0;">&#41;</span>
                    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> ci <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">New</span> CalendarItem
                    ci.<span style="color: #0000FF;color: #c0c0c0;">StartTime</span> <span style="color: #008000;color: #c0c0c0;">=</span> DateTime.<span style="color: #0000FF;color: #c0c0c0;">ParseExact</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>node<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #808080;color: #C89191;">&quot;StartTime&quot;</span>, <span style="color: #808080;color: #C89191;">&quot;Calendar:&quot;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>.<span style="color: #0000FF;color: #c0c0c0;">InnerText</span>, <span style="color: #808080;color: #C89191;">&quot;yyyyMMdd'T'HHmmss'Z'&quot;</span>, Globalization.<span style="color: #0000FF;color: #c0c0c0;">CultureInfo</span>.<span style="color: #0000FF;color: #c0c0c0;">CurrentCulture</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
                    ci.<span style="color: #0000FF;color: #c0c0c0;">EndTime</span> <span style="color: #008000;color: #c0c0c0;">=</span> DateTime.<span style="color: #0000FF;color: #c0c0c0;">ParseExact</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>node<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #808080;color: #C89191;">&quot;EndTime&quot;</span>, <span style="color: #808080;color: #C89191;">&quot;Calendar:&quot;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>.<span style="color: #0000FF;color: #c0c0c0;">InnerText</span>, <span style="color: #808080;color: #C89191;">&quot;yyyyMMdd'T'HHmmss'Z'&quot;</span>, Globalization.<span style="color: #0000FF;color: #c0c0c0;">CultureInfo</span>.<span style="color: #0000FF;color: #c0c0c0;">CurrentCulture</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
                    ci.<span style="color: #0000FF;color: #c0c0c0;">Subject</span> <span style="color: #008000;color: #c0c0c0;">=</span> node<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #808080;color: #C89191;">&quot;Subject&quot;</span>, <span style="color: #808080;color: #C89191;">&quot;Calendar:&quot;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>.<span style="color: #0000FF;color: #c0c0c0;">InnerText</span>
                    ci.<span style="color: #0000FF;color: #c0c0c0;">IsAllDay</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #000000;color: #c0c0c0;">&#40;</span>node<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #808080;color: #C89191;">&quot;AllDayEvent&quot;</span>, <span style="color: #808080;color: #C89191;">&quot;Calendar:&quot;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">IsNot</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Nothing</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">AndAlso</span> node<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #808080;color: #C89191;">&quot;AllDayEvent&quot;</span>, <span style="color: #808080;color: #C89191;">&quot;Calendar:&quot;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>.<span style="color: #0000FF;color: #c0c0c0;">InnerText</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #808080;color: #C89191;">&quot;1&quot;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
                    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span> node<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #808080;color: #C89191;">&quot;Location&quot;</span>, <span style="color: #808080;color: #C89191;">&quot;Calendar:&quot;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">IsNot</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Nothing</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Then</span>
                        ci.<span style="color: #0000FF;color: #c0c0c0;">Location</span> <span style="color: #008000;color: #c0c0c0;">=</span> node<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #808080;color: #C89191;">&quot;Location&quot;</span>, <span style="color: #808080;color: #C89191;">&quot;Calendar:&quot;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>.<span style="color: #0000FF;color: #c0c0c0;">InnerText</span>
                    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span>
&nbsp;
                    <span style="color: #008080; font-style: italic;color: #7F9F7F;">'get all the accepted attendees</span>
                    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span> node<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #808080;color: #C89191;">&quot;Attendees&quot;</span>, <span style="color: #808080;color: #C89191;">&quot;Calendar:&quot;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">IsNot</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Nothing</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Then</span>
                        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> attendees <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> System.<span style="color: #0000FF;color: #c0c0c0;">Xml</span>.<span style="color: #0000FF;color: #c0c0c0;">XmlNodeList</span> <span style="color: #008000;color: #c0c0c0;">=</span> node.<span style="color: #0000FF;color: #c0c0c0;">SelectNodes</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #808080;color: #C89191;">&quot;calendar:Attendees/calendar:Attendee&quot;</span>, juicyCalSyncNsMgr<span style="color: #000000;color: #c0c0c0;">&#41;</span>
                        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">For</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Each</span> attendee <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> System.<span style="color: #0000FF;color: #c0c0c0;">Xml</span>.<span style="color: #0000FF;color: #c0c0c0;">XmlNode</span> In attendees
                            <span style="color: #008080; font-style: italic;color: #7F9F7F;">'accepted? (or not specified)</span>
                            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span> attendee<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #808080;color: #C89191;">&quot;AttendeeStatus&quot;</span>, <span style="color: #808080;color: #C89191;">&quot;Calendar:&quot;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Is</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Nothing</span> OrElse attendee<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #808080;color: #C89191;">&quot;AttendeeStatus&quot;</span>, <span style="color: #808080;color: #C89191;">&quot;Calendar:&quot;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>.<span style="color: #0000FF;color: #c0c0c0;">InnerText</span> &lt;&gt; <span style="color: #808080;color: #C89191;">&quot;4&quot;</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Then</span>
                                ci.<span style="color: #0000FF;color: #c0c0c0;">Attendees</span>.<span style="color: #0000FF;color: #c0c0c0;">Add</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF8000;color: #C2964B; font-weight: bold;">New</span> CalendarItem.<span style="color: #0000FF;color: #c0c0c0;">Attendee</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">With</span> <span style="color: #000000;color: #c0c0c0;">&#123;</span>
                                                 .<span style="color: #0000FF;color: #c0c0c0;">Name</span> <span style="color: #008000;color: #c0c0c0;">=</span> attendee<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #808080;color: #C89191;">&quot;Attendee_Name&quot;</span>, <span style="color: #808080;color: #C89191;">&quot;Calendar:&quot;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>.<span style="color: #0000FF;color: #c0c0c0;">InnerText</span>,
                                                 .<span style="color: #0000FF;color: #c0c0c0;">Email</span> <span style="color: #008000;color: #c0c0c0;">=</span> attendee<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #808080;color: #C89191;">&quot;Attendee_Email&quot;</span>, <span style="color: #808080;color: #C89191;">&quot;Calendar:&quot;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>.<span style="color: #0000FF;color: #c0c0c0;">InnerText</span><span style="color: #000000;color: #c0c0c0;">&#125;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
                            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span>
                        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Next</span>
&nbsp;
                        <span style="color: #008080; font-style: italic;color: #7F9F7F;">'organizer is attending</span>
                        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span> node<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #808080;color: #C89191;">&quot;Organizer_Name&quot;</span>, <span style="color: #808080;color: #C89191;">&quot;Calendar:&quot;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">IsNot</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Nothing</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Then</span>
                            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Dim</span> organiserName <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">String</span> <span style="color: #008000;color: #c0c0c0;">=</span> node<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #808080;color: #C89191;">&quot;Organizer_Name&quot;</span>, <span style="color: #808080;color: #C89191;">&quot;Calendar:&quot;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>.<span style="color: #0000FF;color: #c0c0c0;">InnerText</span>
                            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span> <span style="color: #804040;">Not</span> ci.<span style="color: #0000FF;color: #c0c0c0;">AttendeesList</span>.<span style="color: #0000FF;color: #c0c0c0;">Contains</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>organiserName<span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Then</span>
                                ci.<span style="color: #0000FF;color: #c0c0c0;">Attendees</span>.<span style="color: #0000FF;color: #c0c0c0;">Add</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF8000;color: #C2964B; font-weight: bold;">New</span> CalendarItem.<span style="color: #0000FF;color: #c0c0c0;">Attendee</span><span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">With</span> <span style="color: #000000;color: #c0c0c0;">&#123;</span>
                                                 .<span style="color: #0000FF;color: #c0c0c0;">Name</span> <span style="color: #008000;color: #c0c0c0;">=</span> organiserName,
                                                 .<span style="color: #0000FF;color: #c0c0c0;">Email</span> <span style="color: #008000;color: #c0c0c0;">=</span> node<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #808080;color: #C89191;">&quot;Organizer_Email&quot;</span>, <span style="color: #808080;color: #C89191;">&quot;Calendar:&quot;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>.<span style="color: #0000FF;color: #c0c0c0;">InnerText</span><span style="color: #000000;color: #c0c0c0;">&#125;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
                            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span>
                        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span>
&nbsp;
                    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span>
&nbsp;
                    cItems.<span style="color: #0000FF;color: #c0c0c0;">Add</span><span style="color: #000000;color: #c0c0c0;">&#40;</span>ci<span style="color: #000000;color: #c0c0c0;">&#41;</span>
                <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Next</span>
&nbsp;
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span>
&nbsp;
            <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Return</span> cItems
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Function</span>
&nbsp;
        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Private</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Sub</span> btnSetUserContext_Click<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF8000;color: #C2964B; font-weight: bold;">ByVal</span> sender <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Object</span>, <span style="color: #FF8000;color: #C2964B; font-weight: bold;">ByVal</span> e <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> System.<span style="color: #0000FF;color: #c0c0c0;">EventArgs</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Handles</span> btnSetUserContext.<span style="color: #0000FF;color: #c0c0c0;">Click</span>
            MessageLoop<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Sub</span>
&nbsp;
        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Private</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Sub</span> MessageLoop<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
            pnlEpicFail.<span style="color: #0000FF;color: #c0c0c0;">Visible</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">False</span>
            pnlOutlookCalendar.<span style="color: #0000FF;color: #c0c0c0;">Visible</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">False</span>
            pnlSetUserContext.<span style="color: #0000FF;color: #c0c0c0;">Visible</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">False</span>
            pnlSubmitExchangePw.<span style="color: #0000FF;color: #c0c0c0;">Visible</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">False</span>
&nbsp;
            <span style="color: #008080; font-style: italic;color: #7F9F7F;">'check we have a username/password and then sync</span>
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span> GetUsername<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #808080;color: #C89191;">&quot;&quot;</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Then</span>
                pnlSetUserContext.<span style="color: #0000FF;color: #c0c0c0;">Visible</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">True</span>
            <span style="color: #FF8000;color: #C2964B; font-weight: bold;">ElseIf</span> GetPassword<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #808080;color: #C89191;">&quot;&quot;</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Then</span>
                pnlSubmitExchangePw.<span style="color: #0000FF;color: #c0c0c0;">Visible</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">True</span>
            <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Else</span>
                pnlOutlookCalendar.<span style="color: #0000FF;color: #c0c0c0;">Visible</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">True</span>
&nbsp;
                SyncCalendar<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
            <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">If</span>
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Sub</span>
&nbsp;
        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Private</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Sub</span> btnSubmitExchangePass_Click<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF8000;color: #C2964B; font-weight: bold;">ByVal</span> sender <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Object</span>, <span style="color: #FF8000;color: #C2964B; font-weight: bold;">ByVal</span> e <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> System.<span style="color: #0000FF;color: #c0c0c0;">EventArgs</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Handles</span> btnSubmitExchangePass.<span style="color: #0000FF;color: #c0c0c0;">Click</span>
&nbsp;
            MessageLoop<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #000000;color: #c0c0c0;">&#41;</span>
&nbsp;
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Sub</span>
&nbsp;
        <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Private</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Sub</span> btnResetPassword_Click<span style="color: #000000;color: #c0c0c0;">&#40;</span><span style="color: #FF8000;color: #C2964B; font-weight: bold;">ByVal</span> sender <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> <span style="color: #FF0000;color: #C2964B; font-weight: bold;">Object</span>, <span style="color: #FF8000;color: #C2964B; font-weight: bold;">ByVal</span> e <span style="color: #FF8000;color: #C2964B; font-weight: bold;">As</span> System.<span style="color: #0000FF;color: #c0c0c0;">EventArgs</span><span style="color: #000000;color: #c0c0c0;">&#41;</span> <span style="color: #FF8000;color: #C2964B; font-weight: bold;">Handles</span> btnResetPassword.<span style="color: #0000FF;color: #c0c0c0;">Click</span>
            <span style="color: #008080; font-style: italic;color: #7F9F7F;">'show the password entry screen</span>
            pnlNotAuth.<span style="color: #0000FF;color: #c0c0c0;">Visible</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">False</span>
            pnlOutlookCalendar.<span style="color: #0000FF;color: #c0c0c0;">Visible</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">False</span>
            pnlSubmitExchangePw.<span style="color: #0000FF;color: #c0c0c0;">Visible</span> <span style="color: #008000;color: #c0c0c0;">=</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">True</span>
        <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Sub</span>
    <span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Class</span>
<span style="color: #0600FF;color: #C2964B; font-weight: bold;">End</span> <span style="color: #0600FF;color: #C2964B; font-weight: bold;">Namespace</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.craigwardman.com/blog/index.php/2010/12/using-exchange-activesync-from-a-net-application/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Silverlight Cross Zone Problem</title>
		<link>http://www.craigwardman.com/blog/index.php/2010/11/silverlight-cross-zone-problem/</link>
		<comments>http://www.craigwardman.com/blog/index.php/2010/11/silverlight-cross-zone-problem/#comments</comments>
		<pubDate>Tue, 09 Nov 2010 15:39:50 +0000</pubDate>
		<dc:creator>craig w</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Silverlight]]></category>

		<guid isPermaLink="false">http://www.craigwardman.com/blog/?p=115</guid>
		<description><![CDATA[The Silverlight client has some self imposed URL access restrictions, which may catch you out from time to time. The most common, cross domain calls, are easy to spot as when something doesn&#8217;t work you will no doubt fire up fiddler and see the request for the cross domain policy file. This will remind you [...]]]></description>
			<content:encoded><![CDATA[<p>The Silverlight client has some self imposed <a href="http://msdn.microsoft.com/en-us/library/cc189008(v=VS.95).aspx" target="_blank" rel="nofollow">URL access restrictions</a>, which may catch you out from time to time.</p>
<p>The most common, cross domain calls, are easy to spot as when something doesn&#8217;t work you will no doubt fire up <a href="http://www.fiddler2.com/fiddler2/" target="_blank" rel="nofollow">fiddler</a> and see the request for the cross domain policy file. This will remind you what you need to do <img src='http://www.craigwardman.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>I haven&#8217;t come across the need to implement cross scheme calls yet, but cross-zone calls have caught me out, as until you encounter it you might not even think it would be an issue.</p>
<p>There is no error generated for a cross-zone call being blocked, there is also no traffic generated from Silverlight (so nothing in Fiddler), the call is blocked before any connection is attempted. So to the developer, your app loads and any calls to the services hosted &#8216;cross zone&#8217; will not work, with no apparent reason.</p>
<p>If this happens to you, you need to check your Internet Explorer settings (even for Firefox hosted Silverlight) to make sure that the client and the server are in the same zone. If they are not you can change your client/server URLs, where they are hosted or change the zone settings in IE (your system administrator may need to push a policy out to intranet users if you choose this option)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.craigwardman.com/blog/index.php/2010/11/silverlight-cross-zone-problem/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

