<?xml version="1.0" ?><rss version="0.91"><channel><title>Nullify.net</title><link>http://www.nullify.net/</link><description>Technical fixes and help articles by Simon Soanes</description><language>en-uk</language><copyright>Copyright 2008 Simon Soanes</copyright><lastBuildDate>Wed, 20 Aug 2008 11:06:10 GMT</lastBuildDate><generator>c3 RSS Module</generator><docs>http://www.nullify.net/Default.aspx?page=rss</docs><managingEditor>simon@nullifynetwork.com</managingEditor><webMaster>simon@nullifynetwork.com</webMaster><ttl>60</ttl><item><link>http://www.nullify.net/ViewArticle.aspx?article=306</link><title>Visual Studio 2008 SP1</title><description><![CDATA[<p><span style="font-size: smaller">(It's very rare that I post during work hours, but my excuse is I need to pass the links around between machines and this is the easiest way)</span></p>
<p>Microsoft have released Visual Studio 2008 Service Pack 1!&nbsp; Hopefully there's many good fixes in it, I haven't had time to beta test it so am really looking forward to it.</p>
<p>Finally it's also now possible to install SQL Server 2008...</p>
<p>The release is available <a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=AB99342F-5D1A-413D-8319-81DA479AB0D7&amp;displaylang=en">along with .NET 3.5 SP1</a> in the form of <a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=27673C47-B3B5-4C67-BD99-84E525B5CE61&amp;displaylang=en">an ISO image</a>&nbsp;or the <a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=FBEE1648-7106-44A7-9649-6D9F6D58056E&amp;displaylang=en">web installer</a>!&nbsp; The <a href="http://msdn.microsoft.com/en-us/vstudio/products/cc533447.aspx">release notes</a> (contains&nbsp;details of both updates)&nbsp;are also available.</p>]]></description><guid>http://www.nullify.net/ViewArticle.aspx?article=306</guid><pubDate>Tue, 12 Aug 2008 09:30:18 GMT</pubDate><category>Blog</category></item>
<item><link>http://www.nullify.net/ViewArticle.aspx?article=305</link><title>SQL Server TCP port list</title><description><![CDATA[<p>Just a quick post with the ports for SQL Server as I keep muddling up the browser and the db engine:-</p>
<p>The database engine is&nbsp;port 1433<br />
&nbsp;<br />
SQL Browser is on port 1434<br />
&nbsp;<br />
And finally analysis services is on port 2383</p>]]></description><guid>http://www.nullify.net/ViewArticle.aspx?article=305</guid><pubDate>Sun, 10 Aug 2008 15:02:49 GMT</pubDate><category>Blog</category></item>
<item><link>http://www.nullify.net/ViewArticle.aspx?article=304</link><title>A comprehensive Microsoft DNS Server management implementation in C#</title><description><![CDATA[<p>Okay so to make up for not having posted a single codeblog entry in several months I have a mammoth one here that has taken&nbsp;over 6 hours to figure out and write.</p>
<p>The following is a class that implements near-full support for the WMI interface to the MS DNS Server on Windows Server 2003 (also should work on Windows Server 2008&nbsp;and if you install an add-on you can probably use it under Server 2000 but I have only briefly tried server 2008).&nbsp; I wrote this out of frustration when I googled for an easy way to create a DNS record programmatically in Microsoft DNS Server and there was a distinct absence of actually useful information (there were just a couple of poor examples and no really complete solutions).&nbsp; You can use this to allow you to modify a DNS zone in C# (dynamic DNS hosting under Windows&nbsp;anyone?) or for running your webhosting businesses automation from ASP.NET.&nbsp; Note that I haven't tested deleting!</p>
<p>This class requires both a reference to and a using statement for System.Management from .NET 2.0.&nbsp; I included the&nbsp;entire thing as if it were a single file for the ease of demonstration - you probably want to remove the DNSServer class and its helper classes (which are included within it) and put them into a seperate file.</p>
<!-- code formatted by http://manoli.net/csharpformat/ -->
<pre class="csharpcode">
<span class="kwrd">using</span> System;
<span class="kwrd">using</span> System.Collections.Generic;
<span class="kwrd">using</span> System.Linq;
<span class="kwrd">using</span> System.Text;
<span class="kwrd">using</span> System.Management;

<span class="kwrd">namespace</span> DNSManager
{
    <span class="preproc">#region</span> Example usage code
    <span class="kwrd">class</span> Program
    {
        <span class="kwrd">static</span> <span class="kwrd">void</span> Main(<span class="kwrd">string</span>[] args)
        {
            Console.Write(<span class="str">"Connecting to the DNS Server..."</span>);
            DNSServer d = <span class="kwrd">new</span> DNSServer(<span class="str">"vex.nullify.net"</span>); <span class="rem">//my internal DNS Server, change to yours.</span>
                                                            <span class="rem">//You will need to be able to get to it using WMI.</span>
            Console.WriteLine(<span class="str">"Connected to the DNS Server"</span>);

            Console.Write(<span class="str">"Creating a new zone as a test..."</span>);
            <span class="kwrd">try</span>
            {
                d.CreateNewZone(<span class="str">"testzone.uk.nullify.net."</span>, DNSServer.NewZoneType.Primary);
                Console.WriteLine(<span class="str">"OK"</span>);
            }
            <span class="kwrd">catch</span> (Exception)
            {
                Console.WriteLine(<span class="str">"Failed to create a new zone, it probably exists."</span>);
            }

            Console.Write(<span class="str">"Creating a DNS record as a test..."</span>);
            <span class="kwrd">try</span>
            {
                d.CreateDNSRecord(<span class="str">"testzone.uk.nullify.net."</span>, <span class="str">"test1.testzone.uk.nullify.net. IN CNAME xerxes.nullify.net."</span>);
                Console.WriteLine(<span class="str">"OK"</span>);
            }
            <span class="kwrd">catch</span> (Exception)
            {
                Console.WriteLine(<span class="str">"Failed to create a new resource record, it probably exists"</span>);
            }

            Console.WriteLine(<span class="str">"Getting a list of domains:"</span>);
            <span class="kwrd">foreach</span> (DNSServer.DNSDomain domain <span class="kwrd">in</span> d.GetListOfDomains())
            {
                Console.WriteLine(<span class="str">"\t"</span>+domain.Name+<span class="str">" ("</span>+domain.ZoneType+<span class="str">")"</span>);
                <span class="rem">//and a list of all the records in the domain:-</span>
                <span class="kwrd">foreach</span> (DNSServer.DNSRecord record <span class="kwrd">in</span> d.GetRecordsForDomain(domain.Name))
                {
                    Console.WriteLine(<span class="str">"\t\t"</span>+record);
                    <span class="rem">//any domains we are primary for we could go and edit the record now!</span>
                }
            }

            Console.WriteLine(<span class="str">"Fetching existing named entry (can be really slow, read the warning):-"</span>);
            DNSServer.DNSRecord[] records = d.GetExistingDNSRecords(<span class="str">"test1.testzone.uk.nullify.net."</span>);
            <span class="kwrd">foreach</span> (DNSServer.DNSRecord record <span class="kwrd">in</span> records)
            {
                Console.WriteLine(<span class="str">"\t\t"</span> + record);
                record.Target = <span class="str">"shodan.nullify.net."</span>;
                record.SaveChanges();
            }
        }
    }
    <span class="preproc">#endregion</span>

    <span class="preproc">#region</span> Real code

    <span class="rem">/// &lt;summary&gt;</span>
    <span class="rem">/// A Microsoft DNS Server class that abstracts out calls to WMI for MS DNS Server</span>
    <span class="rem">/// &lt;/summary&gt;</span>
    <span class="rem">/// &lt;remarks&gt;</span>
    <span class="rem">/// WMI Documentation: </span>
    <span class="rem">/// http://msdn.microsoft.com/en-us/library/ms682123(VS.85).aspx</span>
    <span class="rem">/// System.Management Documentation: </span>
    <span class="rem">/// http://msdn.microsoft.com/en-us/library/system.management.managementobjectcollection%28VS.71%29.aspx</span>
    <span class="rem">/// &lt;/remarks&gt;</span>
    <span class="rem">/// &lt;c&gt;(c) 2008 Simon Soanes, All Rights Reserved.  No warranties express or implied.</span>
    <span class="rem">/// DO NOT redistribute this source code publically without a link to the origin and this copyright</span>
    <span class="rem">/// notice fully intact, also please send any modifications back to me at simon@nullifynetwork.com</span>
    <span class="rem">/// Including in your software is fine although attribution would be nice.&lt;/c&gt;</span>
    <span class="kwrd">public</span> <span class="kwrd">class</span> DNSServer
    {

        <span class="preproc">#region</span> Supporting classes
        <span class="rem">/// &lt;summary&gt;</span>
        <span class="rem">/// Different types of DNS zone in MS DNS Server</span>
        <span class="rem">/// &lt;/summary&gt;</span>
        <span class="kwrd">public</span> <span class="kwrd">enum</span> ZoneType
        {
            DSIntegrated,
            Primary,
            Secondary
        }

        <span class="rem">/// &lt;summary&gt;</span>
        <span class="rem">/// Different types of DNS zone in MS DNS Server</span>
        <span class="rem">/// &lt;/summary&gt;</span>
        <span class="rem">/// &lt;remarks&gt;For creation of new zones the list is different&lt;/remarks&gt;</span>
        <span class="kwrd">public</span> <span class="kwrd">enum</span> NewZoneType
        {
            Primary,
            Secondary,
            <span class="rem">/// &lt;remarks&gt;Server 2003+ only&lt;/remarks&gt;</span>
            Stub,
            <span class="rem">/// &lt;remarks&gt;Server 2003+ only&lt;/remarks&gt;</span>
            Forwarder
        }

        <span class="rem">/// &lt;summary&gt;</span>
        <span class="rem">/// A zone in MS DNS Server</span>
        <span class="rem">/// &lt;/summary&gt;</span>
        <span class="kwrd">public</span> <span class="kwrd">class</span> DNSDomain
        {        
            <span class="rem">/// &lt;summary&gt;</span>
            <span class="rem">/// Create a DNS zone</span>
            <span class="rem">/// &lt;/summary&gt;</span>
            <span class="rem">/// &lt;param name="name"&gt;The name of the DNS zone&lt;/param&gt;</span>
            <span class="rem">/// &lt;param name="wmiObject"&gt;The object that represents it in MS DNS server&lt;/param&gt;</span>
            <span class="rem">/// &lt;param name="server"&gt;The DNS Server it is to be managed by&lt;/param&gt;</span>
            <span class="kwrd">public</span> DNSDomain(<span class="kwrd">string</span> name, ManagementBaseObject wmiObject, DNSServer server)
            {
                _name = name;
                _wmiObject = wmiObject;
                _server = server;
            }

            <span class="kwrd">private</span> DNSServer _server = <span class="kwrd">null</span>;

            <span class="kwrd">private</span> <span class="kwrd">string</span> _name = <span class="str">""</span>;

            <span class="rem">/// &lt;summary&gt;</span>
            <span class="rem">/// The name of the DNS zone</span>
            <span class="rem">/// &lt;/summary&gt;</span>
            <span class="kwrd">public</span> <span class="kwrd">string</span> Name
            {
                get { <span class="kwrd">return</span> _name; }
                set { _name = <span class="kwrd">value</span>; }
            }

            <span class="rem">/// &lt;summary&gt;</span>
            <span class="rem">/// The zone type</span>
            <span class="rem">/// &lt;/summary&gt;</span>
            <span class="kwrd">public</span> ZoneType ZoneType
            {
                get
                {
                    <span class="rem">//_wmiObject["ZoneType"].ToString()</span>
                    <span class="kwrd">return</span> (ZoneType)Convert.ToInt32(_wmiObject[<span class="str">"ZoneType"</span>]);
                }
            }

            <span class="rem">/// &lt;summary&gt;</span>
            <span class="rem">/// Is this a reverse DNS zone?</span>
            <span class="rem">/// &lt;/summary&gt;</span>
            <span class="kwrd">public</span> <span class="kwrd">bool</span> ReverseZone
            {
                get
                {
                    <span class="kwrd">if</span> (_wmiObject[<span class="str">"Reverse"</span>].ToString() == <span class="str">"1"</span>)
                    {
                        <span class="kwrd">return</span> <span class="kwrd">true</span>;
                    }
                    <span class="kwrd">else</span>
                    {
                        <span class="kwrd">return</span> <span class="kwrd">false</span>;
                    }
                }
            }

            <span class="kwrd">private</span> ManagementBaseObject _wmiObject = <span class="kwrd">null</span>;

            <span class="rem">/// &lt;summary&gt;</span>
            <span class="rem">/// Get a list of all objects at the base of this zone</span>
            <span class="rem">/// &lt;/summary&gt;</span>
            <span class="rem">/// &lt;returns&gt;A list of &lt;see cref="DNSRecord"/&gt;&lt;/returns&gt;</span>
            <span class="kwrd">public</span> DNSRecord[] GetAllRecords()
            {
                <span class="kwrd">return</span> _server.GetRecordsForDomain(_name);
            }

            <span class="rem">/// &lt;summary&gt;</span>
            <span class="rem">/// Create a new DNS host record</span>
            <span class="rem">/// &lt;/summary&gt;</span>
            <span class="rem">/// &lt;param name="record"&gt;The record to create&lt;/param&gt;</span>
            <span class="kwrd">public</span> <span class="kwrd">void</span> CreateDNSRecord(DNSRecord record)
            {
                _server.CreateDNSRecord(_name, record.ToString());
            }

            <span class="kwrd">public</span> <span class="kwrd">override</span> <span class="kwrd">string</span> ToString()
            {
                <span class="kwrd">return</span> _name;
            }
        }

        <span class="rem">/// &lt;summary&gt;</span>
        <span class="rem">/// An entry in a zone</span>
        <span class="rem">/// &lt;/summary&gt;</span>
        <span class="kwrd">public</span> <span class="kwrd">class</span> DNSRecord
        {
            <span class="rem">/// &lt;summary&gt;</span>
            <span class="rem">/// Create an class wrapping a DNS record</span>
            <span class="rem">/// Defaults to 1 hour TTL</span>
            <span class="rem">/// &lt;/summary&gt;</span>
            <span class="rem">/// &lt;param name="domain"&gt;&lt;/param&gt;</span>
            <span class="rem">/// &lt;param name="recordType"&gt;&lt;/param&gt;</span>
            <span class="rem">/// &lt;param name="target"&gt;&lt;/param&gt;</span>
            <span class="kwrd">public</span> DNSRecord(<span class="kwrd">string</span> domain, DNSRecordType recordType, <span class="kwrd">string</span> target) : 
                <span class="kwrd">this</span>(domain, recordType, target, <span class="kwrd">new</span> TimeSpan(1, 0, 0))
            {
            }

            <span class="rem">/// &lt;summary&gt;</span>
            <span class="rem">/// Create an class wrapping a DNS record</span>
            <span class="rem">/// &lt;/summary&gt;</span>
            <span class="rem">/// &lt;param name="domain"&gt;&lt;/param&gt;</span>
            <span class="rem">/// &lt;param name="recordType"&gt;&lt;/param&gt;</span>
            <span class="rem">/// &lt;param name="target"&gt;&lt;/param&gt;</span>
            <span class="rem">/// &lt;param name="ttl"&gt;&lt;/param&gt;</span>
            <span class="kwrd">public</span> DNSRecord(<span class="kwrd">string</span> domain, DNSRecordType recordType, <span class="kwrd">string</span> target, TimeSpan ttl)
            {
                _host = domain;
                _ttl = ttl;
                _target = target;
                _recordType = recordType;
            }

            <span class="rem">/// &lt;summary&gt;</span>
            <span class="rem">/// Create an class wrapping a DNS record</span>
            <span class="rem">/// &lt;/summary&gt;</span>
            <span class="rem">/// &lt;param name="wmiObject"&gt;&lt;/param&gt;</span>
            <span class="kwrd">public</span> DNSRecord(ManagementObject wmiObject)
            {
                _wmiObject = wmiObject;
                _host = wmiObject[<span class="str">"OwnerName"</span>].ToString();
                _target = wmiObject[<span class="str">"RecordData"</span>].ToString();
                <span class="kwrd">string</span>[] recordParts = wmiObject[<span class="str">"TextRepresentation"</span>].ToString().Split(<span class="str">' '</span>, <span class="str">'\t'</span>);
                <span class="kwrd">if</span> (recordParts.Length &gt; 2)
                {
                    <span class="rem">//the third offset is the location in the textual version of the data where the record type is.</span>
                    <span class="rem">//counting from zero that is location 2 in the array.</span>
                    _recordType = <span class="kwrd">new</span> DNSRecordType(recordParts[2]); 
                }
                _ttl = <span class="kwrd">new</span> TimeSpan(0, 0, Convert.ToInt32(wmiObject[<span class="str">"TTL"</span>]));
            }

            <span class="kwrd">private</span> ManagementObject _wmiObject = <span class="kwrd">null</span>;

            <span class="kwrd">private</span> <span class="kwrd">string</span> _target = <span class="str">""</span>;

            <span class="rem">/// &lt;summary&gt;</span>
            <span class="rem">/// The value of the target is what is written to DNS as the value of a record</span>
            <span class="rem">/// &lt;/summary&gt;</span>
            <span class="rem">/// &lt;remarks&gt;For MX records include the priority as a number with a space or tab between it and the actual target&lt;/remarks&gt;</span>
            <span class="kwrd">public</span> <span class="kwrd">string</span> Target
            {
                get { <span class="kwrd">return</span> _target; }
                set { _target = <span class="kwrd">value</span>; }
            }

            <span class="rem">/// &lt;summary&gt;</span>
            <span class="rem">/// Save the changes to the resource record</span>
            <span class="rem">/// &lt;/summary&gt;</span>
            <span class="kwrd">public</span> <span class="kwrd">void</span> SaveChanges()
            {
                <span class="rem">//We can call modify and if we have the method available it will work as the sub-class may have it!!</span>
                <span class="rem">//Some types DO NOT implement it or implement it differently</span>

                ManagementBaseObject parameters = _wmiObject.GetMethodParameters(<span class="str">"Modify"</span>);
                <span class="kwrd">bool</span> supported = <span class="kwrd">false</span>;

                <span class="rem">//This is a cludge based on the various types that are implemented by MS as they didn't stick to a simple value</span>

                <span class="rem">//To add more, please refer to </span>
                <span class="kwrd">if</span> (RecordType.TextRepresentation == <span class="str">"A"</span>)
                {
                    parameters[<span class="str">"IPAddress"</span>] = _target;
                    parameters[<span class="str">"TTL"</span>] = _ttl.TotalSeconds;
                    supported = <span class="kwrd">true</span>;
                }

                <span class="kwrd">if</span> (RecordType.TextRepresentation == <span class="str">"AAAA"</span>)
                {
                    parameters[<span class="str">"IPv6Address"</span>] = _target;
                    parameters[<span class="str">"TTL"</span>] = _ttl.TotalSeconds;
                    supported = <span class="kwrd">true</span>;
                }

                <span class="kwrd">if</span> (RecordType.TextRepresentation == <span class="str">"CNAME"</span>)
                {
                    parameters[<span class="str">"PrimaryName"</span>] = _target;
                    parameters[<span class="str">"TTL"</span>] = _ttl.TotalSeconds;
                    supported = <span class="kwrd">true</span>;
                }

                <span class="kwrd">if</span> (RecordType.TextRepresentation == <span class="str">"TXT"</span>)
                {
                    parameters[<span class="str">"DescriptiveText"</span>] = _target;
                    parameters[<span class="str">"TTL"</span>] = _ttl.TotalSeconds;
                    supported = <span class="kwrd">true</span>;
                }

                <span class="kwrd">if</span> (RecordType.TextRepresentation == <span class="str">"MX"</span>)
                {
                    <span class="kwrd">string</span>[] components = _target.Trim().Split(<span class="str">' '</span>, <span class="str">'\t'</span>);
                    <span class="kwrd">if</span> (components.Length &gt; 1)
                    {
                        parameters[<span class="str">"Preference"</span>] = Convert.ToUInt16(components[0]); <span class="rem">//the preference is a UINT16 in MS DNS Server</span>
                        parameters[<span class="str">"MailExchange"</span>] = components[1]; <span class="rem">//the actual host name</span>
                        <span class="rem">//NOT SUPPORTED BY MX ACCORDING TO THE DOCUMENTATION!? parameters["TTL"] = _ttl;</span>
                        supported = <span class="kwrd">true</span>;
                    }
                }

                Exception temporaryException = <span class="kwrd">null</span>;
                <span class="kwrd">try</span>
                {
                    <span class="rem">//This supports improving this classes implementation of this method and adding </span>
                    ManagementBaseObject lastDitchParameters = OnSaveChanges(parameters);
                    <span class="kwrd">if</span> (lastDitchParameters != <span class="kwrd">null</span>)
                    {
                        parameters = lastDitchParameters;
                        supported = <span class="kwrd">true</span>;
                    }
                }
                <span class="kwrd">catch</span> (Exception ex) <span class="rem">//catch all as we do not know what someone will modify OnSaveChanges() to throw or cause</span>
                {
                    <span class="kwrd">if</span> (!supported) <span class="rem">//if we support the data type already then we don't care about exceptions as at worst case</span>
                        <span class="kwrd">throw</span>;
                    <span class="kwrd">else</span>
                        temporaryException = ex;
                }

                <span class="kwrd">if</span> (supported)
                {
                    <span class="kwrd">try</span>
                    {
                        _wmiObject = (ManagementObject)_wmiObject.InvokeMethod(<span class="str">"Modify"</span>, parameters, <span class="kwrd">null</span>);
                    }
                    <span class="kwrd">catch</span> (Exception ex)
                    {
                        <span class="kwrd">if</span> (temporaryException != <span class="kwrd">null</span>)
                        {
                            <span class="kwrd">throw</span> <span class="kwrd">new</span> ApplicationException(<span class="str">"There were two exceptions, the primary failure"</span>+
                                <span class="str">" was an exception that is encapsulated in this message however additionaly "</span>+
                                <span class="str">"a virtual method that was optional to functionality also threw an exception "</span>+
                                <span class="str">"but this was withheld till after the operation failed. Please examine the"</span>+
                                <span class="str">" InnerException property for copy of the virtual methods exception.  The "</span>+
                                <span class="str">"virtual methods exception message was: "</span> + temporaryException.Message+<span class="str">".  "</span>+
                                <span class="str">"The primary exceptions message (a "</span>+ex.GetType().FullName.ToString()+<span class="str">") "</span>+
                                <span class="str">"was: "</span>+ex.Message, temporaryException);
                        }
                        <span class="kwrd">else</span>
                        {
                            <span class="kwrd">throw</span>;
                        }
                    }
                    
                    <span class="kwrd">if</span> (temporaryException != <span class="kwrd">null</span>)
                    {
                        <span class="kwrd">throw</span> <span class="kwrd">new</span> ApplicationException(<span class="str">"A virtual method that was optional to functionality "</span>+
                            <span class="str">"threw an exception but this was withheld till after the operation completed "</span>+
                            <span class="str">"successfully, please examine the InnerException property for a full copy of this "</span>+
                            <span class="str">"exception.  The message was: "</span> + temporaryException.Message, temporaryException);
                    }
                }
                <span class="kwrd">else</span>
                {
                    <span class="kwrd">throw</span> <span class="kwrd">new</span> NotSupportedException(<span class="str">"The data type you attmpted to use ("</span>+
                        RecordType.TextRepresentation+<span class="str">") was not supported, please implement support for"</span>+
                    <span class="str">"it by overriding the method OnSaveChanges() and returning an array of filled WMI parameters "</span>+
                    <span class="str">"or by updating this implementation."</span>);
                }
            }

            <span class="rem">/// &lt;summary&gt;</span>
            <span class="rem">/// Method to override to add additional methods to the DNS save changes support</span>
            <span class="rem">/// &lt;/summary&gt;</span>
            <span class="rem">/// &lt;param name="parametersIn"&gt;An array of parameters (not yet filled in if it's an </span>
            <span class="rem">/// unknown type, potentially partially filled for known types)&lt;/param&gt;</span>
            <span class="rem">/// &lt;returns&gt;An array of filled in parameters, or null if the parameters are unknown&lt;/returns&gt;</span>
            <span class="kwrd">public</span> <span class="kwrd">virtual</span> ManagementBaseObject OnSaveChanges(ManagementBaseObject parametersIn)
            {
                <span class="kwrd">return</span> <span class="kwrd">null</span>;
            }

            <span class="rem">/// &lt;summary&gt;</span>
            <span class="rem">/// Delete a record from DNS</span>
            <span class="rem">/// &lt;/summary&gt;</span>
            <span class="kwrd">public</span> <span class="kwrd">void</span> Delete()
            {
                _wmiObject.Delete();
                <span class="rem">//well that was easy...</span>
            }

            <span class="kwrd">private</span> TimeSpan _ttl = <span class="kwrd">new</span> TimeSpan(0, 1, 0);

            <span class="rem">/// &lt;summary&gt;</span>
            <span class="rem">/// The time that the resolvers should cache this record for</span>
            <span class="rem">/// &lt;/summary&gt;</span>
            <span class="kwrd">public</span> TimeSpan Ttl
            {
                get { <span class="kwrd">return</span> _ttl; }
                set { _ttl = <span class="kwrd">value</span>; }
            }

            <span class="kwrd">private</span> DNSRecordType _recordType = <span class="kwrd">null</span>;

            <span class="rem">/// &lt;summary&gt;</span>
            <span class="rem">/// The record type</span>
            <span class="rem">/// &lt;/summary&gt;</span>
            <span class="kwrd">public</span> DNSRecordType RecordType
            {
                get { <span class="kwrd">return</span> _recordType; }
            }
            <span class="kwrd">private</span> <span class="kwrd">string</span> _host = <span class="str">""</span>;

            <span class="rem">/// &lt;summary&gt;</span>
            <span class="rem">/// The location in the DNS system for this record</span>
            <span class="rem">/// &lt;/summary&gt;</span>
            <span class="kwrd">public</span> <span class="kwrd">string</span> DomainHost
            {
                get { <span class="kwrd">return</span> _host; }
                set { _host = <span class="kwrd">value</span>; }
            }

            <span class="kwrd">public</span> <span class="kwrd">override</span> <span class="kwrd">string</span> ToString()
            {
                <span class="kwrd">return</span> _host + <span class="str">" "</span> + _recordType.ToString() + <span class="str">" "</span> + _target;
            }
        }

        <span class="rem">/// &lt;summary&gt;</span>
        <span class="rem">/// The type of record in MS DNS Server</span>
        <span class="rem">/// &lt;/summary&gt;</span>
        <span class="kwrd">public</span> <span class="kwrd">class</span> DNSRecordType
        {
            <span class="rem">/// &lt;summary&gt;</span>
            <span class="rem">/// Create a new DNS record type</span>
            <span class="rem">/// &lt;/summary&gt;</span>
            <span class="rem">/// &lt;param name="textRepresentation"&gt;The type to create&lt;/param&gt;</span>
            <span class="kwrd">public</span> DNSRecordType(<span class="kwrd">string</span> textRepresentation)
            {
                _textRepresentation = textRepresentation;
            }
            <span class="kwrd">private</span> <span class="kwrd">string</span> _textRepresentation = <span class="str">""</span>;

            <span class="rem">/// &lt;summary&gt;</span>
            <span class="rem">/// The text representation of the record type</span>
            <span class="rem">/// &lt;/summary&gt;</span>
            <span class="kwrd">public</span> <span class="kwrd">string</span> TextRepresentation
            {
                get
                {
                    <span class="kwrd">return</span> _textRepresentation.ToUpper();
                }
            }

            <span class="kwrd">private</span> <span class="kwrd">string</span> _recordMode = <span class="str">"IN"</span>;

            <span class="rem">/// &lt;summary&gt;</span>
            <span class="rem">/// The mode of the record, usually IN but could oneday be something else like OUT</span>
            <span class="rem">/// &lt;/summary&gt;</span>
            <span class="kwrd">public</span> <span class="kwrd">string</span> RecordMode
            {
                get
                {
                    <span class="kwrd">return</span> _recordMode;
                }
                set
                {
                    _recordMode = <span class="kwrd">value</span>;
                }
            }

            <span class="kwrd">public</span> <span class="kwrd">override</span> <span class="kwrd">string</span> ToString()
            {
                <span class="kwrd">return</span> _recordMode+<span class="str">" "</span>+_textRepresentation;
            }

            <span class="preproc">#region</span> Some Defaults!
            <span class="rem">/// &lt;summary&gt;</span>
            <span class="rem">/// An alias</span>
            <span class="rem">/// &lt;/summary&gt;</span>
            <span class="kwrd">public</span> <span class="kwrd">static</span> DNSRecordType CNAME 
            {
                get    { <span class="kwrd">return</span> <span class="kwrd">new</span> DNSRecordType(<span class="str">"CNAME"</span>); }
            }

            <span class="rem">/// &lt;summary&gt;</span>
            <span class="rem">/// An IPv4 address</span>
            <span class="rem">/// &lt;/summary&gt;</span>
            <span class="kwrd">public</span> <span class="kwrd">static</span> DNSRecordType A
            {
                get { <span class="kwrd">return</span> <span class="kwrd">new</span> DNSRecordType(<span class="str">"A"</span>); }
            }
            
            <span class="rem">/// &lt;summary&gt;</span>
            <span class="rem">/// A reverse host address inside yoursubnet.in-addr.arpa</span>
            <span class="rem">/// &lt;/summary&gt;</span>
            <span class="kwrd">public</span> <span class="kwrd">static</span> DNSRecordType PTR
            {
                get { <span class="kwrd">return</span> <span class="kwrd">new</span> DNSRecordType(<span class="str">"PTR"</span>); }
            }
    
            <span class="rem">/// &lt;summary&gt;</span>
            <span class="rem">/// An MX record (mail exchange)</span>
            <span class="rem">/// &lt;/summary&gt;</span>
            <span class="kwrd">public</span> <span class="kwrd">static</span> DNSRecordType MX
            {
                get { <span class="kwrd">return</span> <span class="kwrd">new</span> DNSRecordType(<span class="str">"MX"</span>); }
            }

            <span class="rem">/// &lt;summary&gt;</span>
            <span class="rem">/// An IPv6 host address</span>
            <span class="rem">/// &lt;/summary&gt;</span>
            <span class="kwrd">public</span> <span class="kwrd">static</span> DNSRecordType AAAA
            {
                get { <span class="kwrd">return</span> <span class="kwrd">new</span> DNSRecordType(<span class="str">"AAAA"</span>); }
            }

            <span class="rem">/// &lt;summary&gt;</span>
            <span class="rem">/// A text record</span>
            <span class="rem">/// &lt;/summary&gt;</span>
            <span class="kwrd">public</span> <span class="kwrd">static</span> DNSRecordType TXT
            {
                get { <span class="kwrd">return</span> <span class="kwrd">new</span> DNSRecordType(<span class="str">"TXT"</span>); }
            }

            <span class="rem">/// &lt;summary&gt;</span>
            <span class="rem">/// A nameserver record (domain delegation)</span>
            <span class="rem">/// &lt;/summary&gt;</span>
            <span class="kwrd">public</span> <span class="kwrd">static</span> DNSRecordType NS
            {
                get { <span class="kwrd">return</span> <span class="kwrd">new</span> DNSRecordType(<span class="str">"NS"</span>); }
            }

            <span class="rem">/// &lt;summary&gt;</span>
            <span class="rem">/// An SOA record (start of authority)</span>
            <span class="rem">/// &lt;/summary&gt;</span>
            <span class="kwrd">public</span> <span class="kwrd">static</span> DNSRecordType SOA
            {
                get { <span class="kwrd">return</span> <span class="kwrd">new</span> DNSRecordType(<span class="str">"SOA"</span>); }
            }

            <span class="preproc">#endregion</span>
        }
        
<span class="preproc">#endregion</span>

        <span class="rem">/// &lt;summary&gt;</span>
        <span class="rem">/// Create a new DNS Server connection</span>
        <span class="rem">/// &lt;/summary&gt;</span>
        <span class="rem">/// &lt;param name="server"&gt;The hostname, IP or FQDN of a DNS server you have access to with the current credentials&lt;/param&gt;</span>
        <span class="kwrd">public</span> DNSServer(<span class="kwrd">string</span> server)
        {
            ConnectionOptions co = <span class="kwrd">new</span> ConnectionOptions();
            _scope = <span class="kwrd">new</span> ManagementScope(String.Format(<span class="str">@"\\{0}\Root\MicrosoftDNS"</span>, server), co);
            _scope.Connect();  <span class="rem">//no disconnect method appears to exist so we do not need to manage the </span>
                               <span class="rem">//persistence of this connection and tidy up</span>
        }

        <span class="rem">/// &lt;summary&gt;</span>
        <span class="rem">/// Create a new DNS Server connection</span>
        <span class="rem">/// &lt;/summary&gt;</span>
        <span class="rem">/// &lt;param name="server"&gt;The hostname, IP or FQDN of a DNS server you have access to with the current credentials&lt;/param&gt;</span>
        <span class="rem">/// &lt;param name="username"&gt;The username to connect with&lt;/param&gt;</span>
        <span class="rem">/// &lt;param name="password"&gt;The users password&lt;/param&gt;</span>
        <span class="kwrd">public</span> DNSServer(<span class="kwrd">string</span> server, <span class="kwrd">string</span> username, <span class="kwrd">string</span> password)
        {
            ConnectionOptions co = <span class="kwrd">new</span> ConnectionOptions();
            co.Username = username;
            co.Password = password;
            co.Impersonation = ImpersonationLevel.Impersonate;
            _scope = <span class="kwrd">new</span> ManagementScope(String.Format(<span class="str">@"\\{0}\Root\MicrosoftDNS"</span>, server), co);
            _scope.Connect();
        }

        <span class="kwrd">private</span> <span class="kwrd">string</span> _server = <span class="str">""</span>;

        <span class="rem">/// &lt;summary&gt;</span>
        <span class="rem">/// The server this connection applies to</span>
        <span class="rem">/// &lt;/summary&gt;</span>
        <span class="kwrd">public</span> <span class="kwrd">string</span> Server
        {
            get { <span class="kwrd">return</span> _server; }
        }

        <span class="kwrd">private</span> ManagementScope _scope = <span class="kwrd">null</span>;

        <span class="rem">/// &lt;summary&gt;</span>
        <span class="rem">/// Return a list of domains managed by this instance of MS DNS Server</span>
        <span class="rem">/// &lt;/summary&gt;</span>
        <span class="rem">/// &lt;returns&gt;&lt;/returns&gt;</span>
        <span class="kwrd">public</span> DNSDomain[] GetListOfDomains()
        {
            ManagementClass mc = <span class="kwrd">new</span> ManagementClass(_scope, <span class="kwrd">new</span> ManagementPath(<span class="str">"MicrosoftDNS_Zone"</span>), <span class="kwrd">null</span>);
            mc.Get();
            ManagementObjectCollection collection =  mc.GetInstances();

            List&lt;DNSDomain&gt; domains = <span class="kwrd">new</span> List&lt;DNSDomain&gt;();
            <span class="kwrd">foreach</span> (ManagementObject p <span class="kwrd">in</span> collection)
            {
                domains.Add(<span class="kwrd">new</span> DNSDomain(p[<span class="str">"ContainerName"</span>].ToString(), p, <span class="kwrd">this</span>));
            }

            <span class="kwrd">return</span> domains.ToArray();
        }

        <span class="rem">/// &lt;summary&gt;</span>
        <span class="rem">/// Return a list of records for a domain, note that it may include records</span>
        <span class="rem">/// that are stubs to other domains inside the zone and does not automatically</span>
        <span class="rem">/// recurse.</span>
        <span class="rem">/// &lt;/summary&gt;</span>
        <span class="rem">/// &lt;param name="domain"&gt;The domain to connect to&lt;/param&gt;</span>
        <span class="rem">/// &lt;returns&gt;&lt;/returns&gt;</span>
        <span class="kwrd">public</span> DNSRecord[] GetRecordsForDomain(<span class="kwrd">string</span> domain)
        {
            <span class="kwrd">string</span> query = String.Format(<span class="str">"SELECT * FROM MicrosoftDNS_ResourceRecord WHERE DomainName='{0}'"</span>, domain);
            ManagementObjectSearcher searcher = <span class="kwrd">new</span> ManagementObjectSearcher(_scope, <span class="kwrd">new</span> ObjectQuery(query));
            
            ManagementObjectCollection collection = searcher.Get();

            List&lt;DNSRecord&gt; records = <span class="kwrd">new</span> List&lt;DNSRecord&gt;();
            <span class="kwrd">foreach</span> (ManagementObject p <span class="kwrd">in</span> collection)
            {
                records.Add(<span class="kwrd">new</span> DNSRecord(p));
            }

            <span class="kwrd">return</span> records.ToArray();
        }

        <span class="rem">/// &lt;summary&gt;</span>
        <span class="rem">/// Create a new DNS host record</span>
        <span class="rem">/// &lt;/summary&gt;</span>
        <span class="rem">/// &lt;param name="zone"&gt;&lt;/param&gt;</span>
        <span class="rem">/// &lt;param name="bindStyleHostEntry"&gt;&lt;/param&gt;</span>
        <span class="rem">/// &lt;returns&gt;&lt;/returns&gt;</span>
        <span class="kwrd">public</span> <span class="kwrd">void</span> CreateDNSRecord(<span class="kwrd">string</span> zone, <span class="kwrd">string</span> bindStyleHostEntry)
        {
            <span class="kwrd">try</span>
            {
                ManagementObject mc = <span class="kwrd">new</span> ManagementClass(_scope, <span class="kwrd">new</span> ManagementPath(<span class="str">"MicrosoftDNS_ResourceRecord"</span>), <span class="kwrd">null</span>);
                mc.Get();
                ManagementBaseObject parameters = mc.GetMethodParameters(<span class="str">"CreateInstanceFromTextRepresentation"</span>);
                parameters[<span class="str">"ContainerName"</span>] = zone;
                parameters[<span class="str">"DnsServerName"</span>] = _server;
                parameters[<span class="str">"TextRepresentation"</span>] = bindStyleHostEntry;
                ManagementBaseObject createdEntry = mc.InvokeMethod(<span class="str">"CreateInstanceFromTextRepresentation"</span>, parameters, <span class="kwrd">null</span>);
                <span class="rem">//return createdEntry; (no reason unless you changed your mind and wanted to delete it?!)</span>
            }
            <span class="kwrd">catch</span> (ManagementException) <span class="rem">//the details on this exception appear useless.</span>
            {
                <span class="kwrd">throw</span> <span class="kwrd">new</span> ApplicationException(<span class="str">"Unable to create the record "</span> + bindStyleHostEntry + <span class="str">", please check"</span>+
                    <span class="str">" the format and that it does not already exist."</span>);
            }
        }

        <span class="rem">/// &lt;summary&gt;</span>
        <span class="rem">/// Create a new DNS host record</span>
        <span class="rem">/// &lt;/summary&gt;</span>
        <span class="rem">/// &lt;param name="zone"&gt;&lt;/param&gt;</span>
        <span class="rem">/// &lt;param name="record"&gt;&lt;/param&gt;</span>
        <span class="kwrd">public</span> <span class="kwrd">void</span> CreateDNSRecord(<span class="kwrd">string</span> zone, DNSRecord record)
        {
            CreateDNSRecord(zone, record.ToString());
        }

        <span class="rem">/// &lt;summary&gt;</span>
        <span class="rem">/// Fetch DNS records for a particular name</span>
        <span class="rem">/// WARNING: This method has performance issues, iterate over the results of getting all the records for a domain instead.</span>
        <span class="rem">/// &lt;/summary&gt;</span>
        <span class="rem">/// &lt;remarks&gt;Returns a collection as one hostname/entry can have multiple records but it can take longer</span>
        <span class="rem">/// than getting all the records and scanning them!&lt;/remarks&gt;</span>
        <span class="rem">/// &lt;param name="hostName"&gt;The name to look up&lt;/param&gt;</span>
        <span class="rem">/// &lt;returns&gt;&lt;/returns&gt;</span>
        <span class="kwrd">public</span> DNSRecord[] GetExistingDNSRecords(<span class="kwrd">string</span> hostName)
        {
            <span class="kwrd">string</span> query = String.Format(<span class="str">"SELECT * FROM MicrosoftDNS_ResourceRecord WHERE OwnerName='{0}'"</span>, hostName);
            ManagementObjectSearcher searcher = <span class="kwrd">new</span> ManagementObjectSearcher(_scope, <span class="kwrd">new</span> ObjectQuery(query));

            ManagementObjectCollection collection = searcher.Get();
            List&lt;DNSRecord&gt; records = <span class="kwrd">new</span> List&lt;DNSRecord&gt;();
            <span class="kwrd">foreach</span> (ManagementObject p <span class="kwrd">in</span> collection)
            {
                records.Add(<span class="kwrd">new</span> DNSRecord(p));
            }

            <span class="kwrd">return</span> records.ToArray();
        }

        <span class="rem">/// &lt;summary&gt;</span>
        <span class="rem">/// Create a new zone in MS DNS Server</span>
        <span class="rem">/// &lt;/summary&gt;</span>
        <span class="rem">/// &lt;param name="zoneName"&gt;The zone to create&lt;/param&gt;</span>
        <span class="rem">/// &lt;param name="zoneType"&gt;The type of zone to create&lt;/param&gt;</span>
        <span class="rem">/// &lt;returns&gt;The domain&lt;/returns&gt;</span>
        <span class="kwrd">public</span> DNSDomain CreateNewZone(<span class="kwrd">string</span> zoneName, NewZoneType zoneType)
        {
            <span class="kwrd">try</span>
            {
                ManagementObject mc = <span class="kwrd">new</span> ManagementClass(_scope, <span class="kwrd">new</span> ManagementPath(<span class="str">"MicrosoftDNS_Zone"</span>), <span class="kwrd">null</span>);
                mc.Get();
                ManagementBaseObject parameters = mc.GetMethodParameters(<span class="str">"CreateZone"</span>);

                <span class="rem">/*</span>
<span class="rem">                [in]            string ZoneName,</span>
<span class="rem">                [in]            uint32 ZoneType,</span>
<span class="rem">                [in]            boolean DsIntegrated,   (will always be false for us, if you need AD integration you will need to change this.</span>
<span class="rem">                [in, optional]  string DataFileName,</span>
<span class="rem">                [in, optional]  string IpAddr[],</span>
<span class="rem">                [in, optional]  string AdminEmailName,</span>
<span class="rem">                */</span>

                parameters[<span class="str">"ZoneName"</span>] = zoneName;
                parameters[<span class="str">"ZoneType"</span>] = (UInt32)zoneType;
                parameters[<span class="str">"DsIntegrated"</span>] = 0; <span class="rem">//false</span>
                ManagementBaseObject createdEntry = mc.InvokeMethod(<span class="str">"CreateZone"</span>, parameters, <span class="kwrd">null</span>);
                DNSDomain d = <span class="kwrd">new</span> DNSDomain(zoneName, createdEntry, <span class="kwrd">this</span>);
                <span class="kwrd">return</span> d;
            }
            <span class="kwrd">catch</span> (ManagementException) <span class="rem">//returns generic error when it already exists, I'm guessing this is a generic answer!</span>
            {
                <span class="kwrd">throw</span> <span class="kwrd">new</span> ApplicationException(<span class="str">"Unable to create the zone "</span>+zoneName+<span class="str">", please check "</span>+
                    <span class="str">"the format of the name and that it does not already exist."</span>);
            }
        }

        <span class="kwrd">public</span> <span class="kwrd">override</span> <span class="kwrd">string</span> ToString()
        {
            <span class="kwrd">return</span> _server;
        }
    }
    <span class="preproc">#endregion</span>
}
</pre>]]></description><guid>http://www.nullify.net/ViewArticle.aspx?article=304</guid><pubDate>Sat, 09 Aug 2008 22:59:02 GMT</pubDate><category>CodeBlog</category></item>
<item><link>http://www.nullify.net/ViewArticle.aspx?article=303</link><title>.NET Framework SP1 released (or escaped)?</title><description><![CDATA[<p>Here I am installing SQL Server 2008 and I notice that it's installing .NET Framework 3.5 SP1.</p>
<p>There's a total lack of announcements so I'm not sure, but given that it's bonded at the hip with Visual Studio 2008 SP1 I am expecting it to install that next (and saw it when extracting the ISO).&nbsp; Only thing is it seems (updated&nbsp;this post&nbsp;after hitting this)&nbsp;you can't use the SP1 that is shipped with SQL server to update your normal copy of VS2k8, it only does the limited shell.</p>
<p>I have found what seems to be the sole blog entry over at blogs.msdn.com that has any mention of it: <a href="http://blogs.msdn.com/euanga/archive/2008/08/07/sql-server-2008-installation-confusion-vs-2008-sp1-and-netfx-3-5-sp1.aspx">http://blogs.msdn.com/euanga/archive/2008/08/07/sql-server-2008-installation-confusion-vs-2008-sp1-and-netfx-3-5-sp1.aspx</a>&nbsp;which seems to confirm it's the RTM version&nbsp;at least but it opens a can of worms by saying that you need VS 2008 SP1 and that it isn't available to install against the non-sql server bits.</p>
<p>Regardless of if it has&nbsp;been officially released, .NET 3.5 SP1&nbsp;(but apparently not&nbsp;yet Visual&nbsp;Studio SP1 and all its goodness) is certainly out now anyway...</p>]]></description><guid>http://www.nullify.net/ViewArticle.aspx?article=303</guid><pubDate>Thu, 07 Aug 2008 22:13:27 GMT</pubDate><category>Blog</category></item>
<item><link>http://www.nullify.net/ViewArticle.aspx?article=302</link><title>SQL Server 2008 is out!</title><description><![CDATA[<p>Well the subject says it all!</p>
<p>MSDN subscribers can now download SQL Server 2008 - I'm sure an SQL Express 2008 edition will come out soon.&nbsp; Interestingly there is an extra edition available on MSDN - &quot;Web Edition&quot;, this is pure speculation but I'm guessing this is standard edition without CALs (or SQL Express without the memory, cpu&nbsp;and filesize restrictions if you want to look&nbsp;at it that way)&nbsp;so you can use it on webservers.</p>
<p>I downloaded a copy of it this morning and will install it in a bit to try it out.&nbsp; Hopefully the software at work will be fine with it (we tested on an old release candidate but haven't recently) but it'll be good to have the new data types (finally we&nbsp;get a seperate date and time type, and the spatial data types are awesome)&nbsp;and an improved management studio either way.</p>
<p>Another feature that will be good is the ability to dictate the resources a particular database (or user) can take up, preventing a particular website or application consuming all the resources on a server.</p>]]></description><guid>http://www.nullify.net/ViewArticle.aspx?article=302</guid><pubDate>Thu, 07 Aug 2008 19:40:08 GMT</pubDate><category>News</category></item>
<item><link>http://www.nullify.net/ViewArticle.aspx?article=301</link><title>A game for your brain</title><description><![CDATA[<p><a href="http://fantasticcontraption.com/">http://fantasticcontraption.com/</a>&nbsp;is quite possibly the best free web game I've encountered.</p>
<p>In it you get to solve complex (or seemingly simple looking) physics puzzles to move one item to another with only bars that you join together and motors (wheels in the game) that turn uncontrollably.&nbsp; It is then your job to make sense of these and make them do what you command!&nbsp; A very simple premise that rapidly gets out of control.</p>
<p>(<a href="http://www.ninja-monkey.co.uk/">Chris</a>&nbsp;gets the&nbsp;blame for suggesting it to me and&nbsp;making it consume a huge amount of my free time today...)</p>]]></description><guid>http://www.nullify.net/ViewArticle.aspx?article=301</guid><pubDate>Sun, 27 Jul 2008 22:56:42 GMT</pubDate><category>Blog</category></item>
<item><link>http://www.nullify.net/ViewArticle.aspx?article=300</link><title>Houston Data Center Outage</title><description><![CDATA[<p>My site and a bunch of hosted sites were down over the weekend due to an explosion at the datacentre where the servers are located in Houston.&nbsp; This is now fixed.</p>
<p>No e-mail was lost as the server in New York was still up, but it's still mighty annoying.</p>]]></description><guid>http://www.nullify.net/ViewArticle.aspx?article=300</guid><pubDate>Mon, 02 Jun 2008 11:45:10 GMT</pubDate><category>News</category></item>
<item><link>http://www.nullify.net/ViewArticle.aspx?article=299</link><title>Log parser!</title><description><![CDATA[<p>I just encountered a small tool Microsoft released in 2005 called <a href="http://www.microsoft.com/technet/scriptcenter/tools/logparser/default.mspx">Log Parser 2.2</a>.&nbsp; This is a tool that allows you to take literally any data format anywhere and turn it into anything, very handy - particularly when processing IIS logfiles.</p>
<p>The site that used to exist for it has vanished, but there's still a few good resources out there related to it:-</p>
<p><a href="http://www.microsoft.com/emea/spotlight/sessionh.aspx?videoid=265">Alexis Eller's talk on using log parser</a>&nbsp;(I couldn't find a&nbsp;blog for her unfortunately)</p>
<p><a href="http://technet.microsoft.com/en-us/library/bb878032.aspx">Professor Windows - May 2005 article</a>&nbsp;which has a lot of good examples.</p>
<p><strong>Update</strong> - I am trying to build a replacement for tools like Webalizer which aren't maintained anymore (or are insanely complex to install and configure and maintain strange files as 'summaries').&nbsp; I am currently using the following command to create and maintain a multiple GB database containing an indexed set of logfiles and getting back graphs of the data instantly for display in <a href="http://teethgrinder.co.uk/open-flash-chart/">Open Flash Chart</a>.</p>
<p>The command I'm using is:</p>
<pre>
&quot;C:\Program Files\Log Parser 2.2\logparser&quot; &quot;select 1, * into WebLog 
from &lt;MyIISSiteNumber&gt;&quot; -i:IISW3C -o:SQL -server:(local) -database:NullifyDBLog 
-driver:&quot;SQL Server&quot; -createTable:ON 
-transactionRowCount 100 -iCheckpoint:CheckpointFile.lpc</pre>
<p>Which is working really well, it took about 30 minutes to process 4 or 5 years of logs and now updates the database near&nbsp;instantly!</p>
<p>Watch out for the fact that LogParser isn't too bright when making tables, to do this with my log format you need to create extra indexes, I opted for indexing obvious things like date, time, the uri, the referrer, the bytes transferred and the user agent.</p>]]></description><guid>http://www.nullify.net/ViewArticle.aspx?article=299</guid><pubDate>Mon, 19 May 2008 21:03:49 GMT</pubDate><category>Blog</category></item>
<item><link>http://www.nullify.net/ViewArticle.aspx?article=298</link><title>Visio from Visual Studio 2008</title><description><![CDATA[<p>Just so I don't forget, Visio UML generation is no longer available in Visual Studio 2008 out of the box; to add it back in just run the following reg file (adapted for your file paths obviously):</p> <p><font face="Courier New" size="2">Windows Registry Editor Version 5.00</font></p> <p><font face="Courier New" size="2">[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\9.0\Editors\{742C6336-9457-4885-8778-CBEC892F8EA2}]<br />"DisplayName"="#14"<br />"Package"="{FED78099-10D1-4A78-B037-ABCFA1A107B3}"<br />"ExcludeDefTextEditor"=dword:00000001<br />@="Visio Editor"</font></p> <p><font face="Courier New" size="2">[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\9.0\Editors\{742C6336-9457-4885-8778-CBEC892F8EA2}\Extensions]<br />"vsd"=dword:00000032</font></p> <p><font face="Courier New" size="2">[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\9.0\OutputWindow\{BC5C26E6-DF2B-46C9-B74E-0E057228055D}]<br />@="#2"<br />"Package"="{FED78099-10D1-4A78-B037-ABCFA1A107B3}"<br />"InitiallyInvisible"=dword:00000001<br />"Name"="Visio UML"</font></p> <p><font face="Courier New" size="2">[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\9.0\Packages\{FED78099-10D1-4A78-B037-ABCFA1A107B3}]<br />"InprocServer32"="C:\\PROGRA~1\\MICROS~1\\Office12\\UMLVS.DLL"<br />@="VisioUml Package"</font></p> <p><font face="Courier New" size="2">[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\9.0\Packages\{FED78099-10D1-4A78-B037-ABCFA1A107B3}\SatelliteDll]<br />"Path"="C:\\Program Files\\Microsoft Office\\Office12\\"<br />"DllName"="UMLVSUI.Dll"</font></p> <p><font face="Courier New" size="2">[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\9.0\Menus]<br />"{FED78099-10D1-4A78-B037-ABCFA1A107B3}"=", 1000, 1"</font></p> <p><font face="Courier New" size="2">[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\9.0\Projects\{D1DCDB85-C5E8-11D2-BFCA-00C04F990235}\AddItemTemplates\TemplateDirs\{FED78099-10D1-4A78-B037-ABCFA1A107B3}\/1031]<br />@="#213"<br />"TemplatesDir"="C:\\Program Files\\Microsoft Office\\Office12\\1031\\Vsdir\\"<br />"Package"="{FED78099-10D1-4A78-B037-ABCFA1A107B3}"<br />"SortPriority"=dword:00000032</font></p> <p>(Taken from <a href="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2488400&amp;SiteID=1">http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2488400&amp;SiteID=1</a>&nbsp;)</p>]]></description><guid>http://www.nullify.net/ViewArticle.aspx?article=298</guid><pubDate>Mon, 07 Apr 2008 15:38:59 GMT</pubDate><category>Blog</category></item>
<item><link>http://www.nullify.net/ViewArticle.aspx?article=297</link><title>Speech Recognition in .NET 3</title><description><![CDATA[<p>I was trying to get speech recognition to work&nbsp;as easily as <a href="/ViewArticle.aspx?article=288">text-to-speech synthesis</a>&nbsp;and noticed that there's a gotcha in that you can't use it from an <strike>MTA</strike> STA&nbsp;thread, so you need to invoke it on another thread.&nbsp; Calling BeginInvoke on an anonymous delegate instance of voidDelegate sorts this pretty easily and is a nice and brief method of avoiding the problem.</p>
<p>Here's the necessary code to make a&nbsp;blank form with&nbsp;two text boxes&nbsp;(called TextBox1 and TextBox2)&nbsp;do speech recognition continually.&nbsp; To use this code you need a reference to System.Speech.DLL and a using clause pointing to System.Speech.Recognition.</p>
<p>Note that hypothesized text is also displayed, so you can see the speech recognition engine 'thinking' which is handy as it lets you tell if you need to do more training with the engine.</p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; color: maroon; font-family: Consolas">private</span><span style="font-size: 10pt; font-family: Consolas"> <span style="color: maroon">void</span> Form1_Load(<span style="color: maroon">object</span> sender, <span style="color: #2b91af">EventArgs</span> e)</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; font-family: Consolas">{</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; font-family: Consolas"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>InitSpeechRecognition();</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; font-family: Consolas">}</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; font-family: Consolas">&nbsp;</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; color: #2b91af; font-family: Consolas">SpeechRecognitionEngine</span><span style="font-size: 10pt; font-family: Consolas"> _recognitionEngine;</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; font-family: Consolas">&nbsp;</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; color: maroon; font-family: Consolas">public</span><span style="font-size: 10pt; font-family: Consolas"> <span style="color: maroon">void</span> InitSpeechRecognition()</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; font-family: Consolas">{</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; font-family: Consolas"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #2b91af">voidDelegate</span> d = <span style="color: maroon">new</span> <span style="color: #2b91af">voidDelegate</span>(initSpeechRecognition);</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; font-family: Consolas"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>d.BeginInvoke(<span style="color: maroon">null</span>, <span style="color: maroon">null</span>);</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; font-family: Consolas">}</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; font-family: Consolas">&nbsp;</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; color: maroon; font-family: Consolas">private</span><span style="font-size: 10pt; font-family: Consolas"> <span style="color: maroon">delegate</span> <span style="color: maroon">void</span> <span style="color: #2b91af">voidDelegate</span>();</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; font-family: Consolas">&nbsp;</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; color: maroon; font-family: Consolas">private</span><span style="font-size: 10pt; font-family: Consolas"> <span style="color: maroon">void</span> initSpeechRecognition()</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; font-family: Consolas">{</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; font-family: Consolas"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>_recognitionEngine = <span style="color: maroon">new</span> System.Speech.Recognition.<span style="color: #2b91af">SpeechRecognitionEngine</span>();</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; font-family: Consolas"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>_recognitionEngine.SetInputToDefaultAudioDevice();</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; font-family: Consolas"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #2b91af">DictationGrammar</span> d = <span style="color: maroon">new</span> <span style="color: #2b91af">DictationGrammar</span>();</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; font-family: Consolas"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>d.SpeechRecognized += <span style="color: maroon">new</span> <span style="color: #2b91af">EventHandler</span>&lt;<span style="color: #2b91af">SpeechRecognizedEventArgs</span>&gt;(d_SpeechRecognized);</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; font-family: Consolas"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>_recognitionEngine.UnloadAllGrammars();</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; font-family: Consolas"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>_recognitionEngine.SpeechHypothesized += <span style="color: maroon">new</span> <span style="color: #2b91af">EventHandler</span>&lt;<span style="color: #2b91af">SpeechHypothesizedEventArgs</span>&gt;(r_SpeechHypothesized);</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; font-family: Consolas"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>_recognitionEngine.RecognizeCompleted += <span style="color: maroon">new</span> <span style="color: #2b91af">EventHandler</span>&lt;<span style="color: #2b91af">RecognizeCompletedEventArgs</span>&gt;(r_RecognizeCompleted);</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; font-family: Consolas"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>_recognitionEngine.LoadGrammar(d);</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; font-family: Consolas"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>_recognitionEngine.RecognizeAsync();</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; font-family: Consolas">}</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; font-family: Consolas">&nbsp;</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; color: maroon; font-family: Consolas">void</span><span style="font-size: 10pt; font-family: Consolas"> r_RecognizeCompleted(<span style="color: maroon">object</span> sender, <span style="color: #2b91af">RecognizeCompletedEventArgs</span> e)</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; font-family: Consolas">{</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; font-family: Consolas"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>BeginRecognition();</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; font-family: Consolas">}</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; font-family: Consolas">&nbsp;</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; color: maroon; font-family: Consolas">delegate</span><span style="font-size: 10pt; font-family: Consolas"> <span style="color: maroon">void</span> <span style="color: #2b91af">SpeechHypothesizedPassThroughDelegate</span>(<span style="color: maroon">object</span> sender, <span style="color: #2b91af">SpeechHypothesizedEventArgs</span> e);</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; font-family: Consolas">&nbsp;</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; color: maroon; font-family: Consolas">void</span><span style="font-size: 10pt; font-family: Consolas"> r_SpeechHypothesized(<span style="color: maroon">object</span> sender, <span style="color: #2b91af">SpeechHypothesizedEventArgs</span> e)</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; font-family: Consolas">{</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; font-family: Consolas"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: maroon">if</span> (<span style="color: maroon">this</span>.InvokeRequired)</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; font-family: Consolas"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; font-family: Consolas"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: maroon">this</span>.Invoke(<span style="color: maroon">new</span> <span style="color: #2b91af">SpeechHypothesizedPassThroughDelegate</span>(r_SpeechHypothesized), sender, e);</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; font-family: Consolas"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; font-family: Consolas"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: maroon">else</span></span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; font-family: Consolas"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; font-family: Consolas"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>textBox2.Text = e.Result.Text;</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; font-family: Consolas"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; font-family: Consolas">}</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; font-family: Consolas">&nbsp;</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; color: maroon; font-family: Consolas">delegate</span><span style="font-size: 10pt; font-family: Consolas"> <span style="color: maroon">void</span> <span style="color: #2b91af">SpeechPassThroughDelegate</span>(<span style="color: maroon">object</span> sender, <span style="color: #2b91af">SpeechRecognizedEventArgs</span> e);</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; font-family: Consolas">&nbsp;</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; color: maroon; font-family: Consolas">void</span><span style="font-size: 10pt; font-family: Consolas"> d_SpeechRecognized(<span style="color: maroon">object</span> sender, <span style="color: #2b91af">SpeechRecognizedEventArgs</span> e)</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; font-family: Consolas">{</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; font-family: Consolas"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: maroon">if</span> (<span style="color: maroon">this</span>.InvokeRequired)</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; font-family: Consolas"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; font-family: Consolas"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: maroon">this</span>.Invoke(<span style="color: maroon">new</span> <span style="color: #2b91af">SpeechPassThroughDelegate</span>(d_SpeechRecognized), sender, e);</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; font-family: Consolas"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; font-family: Consolas"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: maroon">else</span></span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; font-family: Consolas"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; font-family: Consolas"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: green">//display the recognised text, or process it here</span></span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; font-family: Consolas"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>textBox1.Text += e.Result.Text + <span style="color: #a31515">&quot; &quot;</span>;</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; font-family: Consolas"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; font-family: Consolas">}</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; font-family: Consolas">&nbsp;</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; color: maroon; font-family: Consolas">private</span><span style="font-size: 10pt; font-family: Consolas"> <span style="color: maroon">void</span> BeginRecognition()</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; font-family: Consolas">{</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; font-family: Consolas"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: maroon">new</span> <span style="color: #2b91af">voidDelegate</span>(<span style="color: maroon">delegate</span>()</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; font-family: Consolas"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; font-family: Consolas"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>_recognitionEngine.RecognizeAsync();</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; font-family: Consolas"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}).BeginInvoke(<span style="color: maroon">null</span>, <span style="color: maroon">null</span>);</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; font-family: Consolas">}</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; font-family: Consolas">&nbsp;</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; color: maroon; font-family: Consolas">private</span><span style="font-size: 10pt; font-family: Consolas"> <span style="color: maroon">void</span> StopRecognition()</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; font-family: Consolas">{</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; font-family: Consolas"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: maroon">new</span> <span style="color: #2b91af">voidDelegate</span>(<span style="color: maroon">delegate</span>()</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; font-family: Consolas"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; font-family: Consolas"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>_recognitionEngine.RecognizeAsyncStop();</span></p>
<p style="margin: 0cm 0cm 0pt; line-height: normal"><span style="font-size: 10pt; font-family: Consolas"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}).BeginInvoke(<span style="color: maroon">null</span>, <span style="color: maroon">null</span>);</span></p>
<p style="margin: 0cm 0cm 10pt"><span style="font-size: 10pt; line-height: 115%; font-family: Consolas">}</span></p>]]></description><guid>http://www.nullify.net/ViewArticle.aspx?article=297</guid><pubDate>Sat, 05 Apr 2008 17:42:56 GMT</pubDate><category>CodeBlog</category></item>
<item><link>http://www.nullify.net/ViewArticle.aspx?article=296</link><title>Hosting the Windows Forms designer</title><description><![CDATA[There's an example over on <a href="http://www.divil.co.uk/net/articles/designers/hosting.asp">divelements blog</a> about how to host the winforms designer, as there seems to be a lack of documentation anywhere...]]></description><guid>http://www.nullify.net/ViewArticle.aspx?article=296</guid><pubDate>Sun, 16 Mar 2008 13:35:16 GMT</pubDate><category>Blog</category></item>
<item><link>http://www.nullify.net/ViewArticle.aspx?article=295</link><title>Automatically parallelising lots of methods</title><description><![CDATA[<p>I wanted to run a bunch of methods simultaneously on as many threads as possible to get the job done, but still wait at the end.&nbsp; I know MS have something coming to solve this, but wanted a lightweight solution, so here it is:</p>
<div style="line-height: normal"><span style="font-family: Courier New"><span style="font-size: 10pt; color: maroon">public</span><span style="font-size: 10pt"> <span style="color: maroon">class</span> <span style="color: #2b91af">Parallel</span></span></span></div>
<div style="line-height: normal"><span style="font-family: Courier New"><span style="font-size: 10pt">{</span></span></div>
<div style="line-height: normal"><span style="font-family: Courier New"><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: maroon">public</span> <span style="color: maroon">static</span> T[] ExecuteWaitAll&lt;T&gt;(<span style="color: #2b91af">Func</span>&lt;T&gt;[] functions)</span></span></div>
<div style="line-height: normal"><span style="font-family: Courier New"><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</span></span></div>
<div style="line-height: normal"><span style="font-family: Courier New"><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: #2b91af">List</span>&lt;T&gt; resultSet = <span style="color: maroon">new</span> <span style="color: #2b91af">List</span>&lt;T&gt;();</span></span></div>
<div style="line-height: normal"><span style="font-family: Courier New"><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: maroon">int</span> i = 0;</span></span></div>
<div style="line-height: normal"><span style="font-family: Courier New"><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: maroon">object</span> lockObject = <span style="color: maroon">new</span> <span style="color: maroon">object</span>();</span></span></div>
<div style="line-height: normal"><span style="font-family: Courier New"><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: maroon">foreach</span> (<span style="color: #2b91af">Func</span>&lt;T&gt; function <span style="color: maroon">in</span> functions)</span></span></div>
<div style="line-height: normal"><span style="font-family: Courier New"><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</span></span></div>
<div style="line-height: normal"><span style="font-family: Courier New"><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: maroon">lock</span> (lockObject)</span></span></div>
<div style="line-height: normal"><span style="font-family: Courier New"><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</span></span></div>
<div style="line-height: normal"><span style="font-family: Courier New"><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; i++;</span></span></div>
<div style="line-height: normal"><span style="font-family: Courier New"><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; function.BeginInvoke(<span style="color: maroon">delegate</span>(<span style="color: #2b91af">IAsyncResult</span> result)</span></span></div>
<div style="line-height: normal"><span style="font-family: Courier New"><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</span></span></div>
<div style="line-height: normal"><span style="font-family: Courier New"><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: maroon">lock</span> (lockObject)</span></span></div>
<div style="line-height: normal"><span style="font-family: Courier New"><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</span></span></div>
<div style="line-height: normal"><span style="font-family: Courier New"><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; resultSet.Add(function.EndInvoke(result));</span></span></div>
<div style="line-height: normal"><span style="font-family: Courier New"><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; i--;</span></span></div>
<div style="line-height: normal"><span style="font-family: Courier New"><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span></span></div>
<div style="line-height: normal"><span style="font-family: Courier New"><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }, <span style="color: maroon">null</span>);</span></span></div>
<div style="line-height: normal"><span style="font-family: Courier New"><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span></span></div>
<div style="line-height: normal"><span style="font-family: Courier New"><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span></span></div>
<div style="line-height: normal">&nbsp;</div>
<div style="line-height: normal"><span style="font-family: Courier New"><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: maroon">while</span> (i &gt; 0)</span></span></div>
<div style="line-height: normal"><span style="font-family: Courier New"><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</span></span></div>
<div style="line-height: normal"><span style="font-family: Courier New"><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: #2b91af">Thread</span>.Sleep(1);</span></span></div>
<div style="line-height: normal"><span style="font-family: Courier New"><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span></span></div>
<div style="line-height: normal"><span style="font-family: Courier New"><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: maroon">return</span> resultSet.ToArray();</span></span></div>
<div style="line-height: normal"><span style="font-family: Courier New"><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span></span></div>
<div style="margin: 0cm 0cm 10pt"><span style="font-family: Courier New"><span style="font-size: 10pt; line-height: 115%">}</span></span></div>
<p>To use this, you simply call it with a list of delegates you want to execute, and define the return type:</p>
<div style="line-height: normal"><span style="font-family: Courier New"><span style="font-size: 10pt; color: maroon">public</span><span style="font-size: 10pt"> <span style="color: maroon">void</span> ExecuteWait()</span></span></div>
<div style="line-height: normal"><span style="font-family: Courier New"><span style="font-size: 10pt">{</span></span></div>
<div style="line-height: normal"><span style="font-family: Courier New"><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: #2b91af">List</span>&lt;<span style="color: #2b91af">Func</span>&lt;<span style="color: maroon">int</span>&gt;&gt; list = <span style="color: maroon">new</span> <span style="color: #2b91af">List</span>&lt;<span style="color: #2b91af">Func</span>&lt;<span style="color: maroon">int</span>&gt;&gt;();</span></span></div>
<div style="line-height: normal"><span style="font-family: Courier New"><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: maroon">for</span> (<span style="color: maroon">int</span> i=0; i&lt;100; i++)</span></span></div>
<div style="line-height: normal"><span style="font-family: Courier New"><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</span></span></div>
<div style="line-height: normal"><span style="font-family: Courier New"><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; list.Add(<span style="color: maroon">new</span> <span style="color: #2b91af">Func</span>&lt;<span style="color: maroon">int</span>&gt;(<span style="color: maroon">delegate</span>()</span></span></div>
<div style="line-height: normal"><span style="font-family: Courier New"><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</span></span></div>
<div style="line-height: normal"><span style="font-family: Courier New"><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: #2b91af">Thread</span>.Sleep(1000);</span></span></div>
<div style="line-height: normal"><span style="font-family: Courier New"><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: maroon">return</span> 1;</span></span></div>
<div style="line-height: normal"><span style="font-family: Courier New"><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }));</span></span></div>
<div style="line-height: normal"><span style="font-family: Courier New"><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span></span></div>
<div style="line-height: normal"><span style="font-family: Courier New"><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></div>
<div style="line-height: normal"><span style="font-family: Courier New"><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: maroon">int</span>[] quantity = <span style="color: #2b91af">Parallel</span>.ExecuteWaitAll&lt;<span style="color: maroon">int</span>&gt;(list.ToArray());</span></span></div>
<div style="line-height: normal"><span style="font-family: Courier New"><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: maroon">int</span> count = 0;</span></span></div>
<div style="line-height: normal"><span style="font-family: Courier New"><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: maroon">foreach</span> (<span style="color: maroon">int</span> result <span style="color: maroon">in</span> quantity)</span></span></div>
<div style="line-height: normal"><span style="font-family: Courier New"><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</span></span></div>
<div style="line-height: normal"><span style="font-family: Courier New"><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; count += result;</span></span></div>
<div style="line-height: normal"><span style="font-family: Courier New"><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span></span></div>
<div style="margin: 0cm 0cm 10pt"><span style="font-family: Courier New"><span style="font-size: 10pt; line-height: 115%">}</span></span></div>
<p>The result is now valid for 100 executions but took a lot less time than 100 seconds to calculate.&nbsp; You could of course just be running four things at the same time, all different using this.</p>]]></description><guid>http://www.nullify.net/ViewArticle.aspx?article=295</guid><pubDate>Mon, 18 Feb 2008 17:34:24 GMT</pubDate><category>CodeBlog</category></item>
<item><link>http://www.nullify.net/ViewArticle.aspx?article=294</link><title>Span tag in server controls without asking</title><description><![CDATA[<p>This is really simple but annoyed me for a few minutes until I got .NET Reflector up, so hopefully this will help someone else.</p>
<p>The render method on ASP.NET WebControl based server controls seems to be adding a span tag around the&nbsp;HTML output for some reason, to fix this simply override the Render method:</p>
<p dir="ltr" style="margin-right: 0px"><font face="Courier New"><font size="2"><font color="#800000">protected</font> <font color="#800000">override</font> <font color="#800000">void</font> Render(<font color="#2b91af">HtmlTextWriter</font></font></font><font face="Courier New" size="2"> writer)<br />
{<br />
&nbsp;&nbsp;&nbsp; RenderContents(writer);<br />
}</font></p>]]></description><guid>http://www.nullify.net/ViewArticle.aspx?article=294</guid><pubDate>Thu, 14 Feb 2008 22:08:19 GMT</pubDate><category>CodeBlog</category></item>
<item><link>http://www.nullify.net/ViewArticle.aspx?article=293</link><title>Windows Server 2008 Released!!</title><description><![CDATA[<p>Well Microsoft have just released Windows Server 2008 and Visa service pack 1 to manufacturing.&nbsp; Still waiting for SQL Server 2008, but the stack is almost complete :)</p>
<p>Excellent features I'm looking forward to are:</p>
<ul>
    <li>IIS 7 on a server OS!</li>
    <li>IPv6 file and print sharing (and oh my goodness is file and print sharing faster)</li>
    <li>IPv6 over VPN!!</li>
    <li>RDP over IPv6! (Can you tell I'm an IPv6 fan)</li>
    <li>Application level terminal services (like Citrix has)</li>
    <li>Fail back router support!&nbsp; If you bring one down and then back up, it doesn't keep using the failover!</li>
    <li>IPv6 enabled by default and not uninstallable (disabling will have to do for people who don't want to use it which should result in a lot more IPv6 compatible servers).</li>
    <li>Read only domain controllers - good for if the domain controller is sighted somewhere insecure.</li>
    <li>ADAM is now a first class citizen if you need an LDAP server but not active directory.&nbsp; Active directory is also no longer completely intrinsyc to the server once promoted too!</li>
</ul>
<p>The only unfortunate thing I can see is the removal of the basic firewall and OSPF from routing and remote access, but the basic firewall has been replaced by windows firewall - I just hope you can still define rules for the other hosts in the network.</p>]]></description><guid>http://www.nullify.net/ViewArticle.aspx?article=293</guid><pubDate>Mon, 04 Feb 2008 19:01:41 GMT</pubDate><category>News</category></item>
<item><link>http://www.nullify.net/ViewArticle.aspx?article=292</link><title>Hosting the Windows Workflow Foundation Designer</title><description><![CDATA[<p>There's an article on MSDN about <a href="http://msdn2.microsoft.com/en-us/library/aa480213.aspx">how to host the Windows Workflow Foundation design surface</a> (which is a redistributable).</p>
<p>The example code is really complete and worth a look at, it's almost an out-of-the-box copy of just the workflow designer from Visual Studio.</p>
<p>If your end user requires more flexibility than most you can offer them drag-and-drop customisation of particular processes in your system (like creating a new customer could be made to go off and send details to a webservice without you, the developer; needing to get involved).</p>]]></description><guid>http://www.nullify.net/ViewArticle.aspx?article=292</guid><pubDate>Sun, 20 Jan 2008 15:01:47 GMT</pubDate><category>CodeBlog</category></item>
<item><link>http://www.nullify.net/ViewArticle.aspx?article=291</link><title>Extension Methods</title><description><![CDATA[<p><font face="Calibri">Just a single snippet of code to work from, I included explanations in the comments.&nbsp;This is really a very easy to use feature in C# 3.&nbsp;Unfortunately you can&rsquo;t create extension properties yet, but that will likely be coming soon.</font></p>
<p><span style="font-size: 10pt; color: maroon; font-family: Consolas">namespace</span><span style="font-size: 10pt; font-family: Consolas"> ExtensionMethods</span> <br />
<span style="font-size: 10pt; font-family: Consolas">{</span> <br />
<span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: green">//Note that this class is static, it must be to contain extension methods and</span></span> <br />
<span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: green">//it also can't reside inside another class.</span></span> <br />
<span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: maroon">public</span> <span style="color: maroon">static</span> <span style="color: maroon">class</span> <span style="color: #2b91af">ExampleExtensionMethod</span></span> <br />
<span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</span>&nbsp;<br />
<span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: green">//This is the extension method</span></span><br />
<span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: Consolas"><span style="color: maroon">public</span> <span style="color: maroon">static</span> <span style="color: maroon">bool</span> HasLetterAInIt(<span style="color: maroon">this</span> <span style="color: maroon">string</span> s)</span> <br />
<span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</span> <br />
<span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: green">//Just return if it contains the capital letter A as this is just an</span></span> <br />
<span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: green">//example</span></span> <br />
<span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: maroon">return</span> s.Contains(<span style="color: #a31515">&quot;A&quot;</span>);</span> <br />
<span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span> <br />
<span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span> <br />
<span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><br />
<span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: maroon">class</span> <span style="color: #2b91af">Program</span></span> <br />
<span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</span><br />
<span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: maroon">static</span> <span style="color: maroon">void</span> Main(<span style="color: maroon">string</span>[] args)</span> <br />
<span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</span> <br />
<span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: green">//This will print false</span></span> <br />
<span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: #2b91af">Console</span>.WriteLine(<span style="color: #a31515">&quot;TEST&quot;</span>.HasLetterAInIt().ToString());</span> <br />
<span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: green">//whilst this will print true</span></span> <br />
<span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: #2b91af">Console</span>.WriteLine(<span style="color: #a31515">&quot;AAHH!!&quot;</span>.HasLetterAInIt().ToString());</span> <br />
<span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span> <br />
<span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span> <br />
<span style="font-size: 10pt; font-family: Consolas">}</span></p>]]></description><guid>http://www.nullify.net/ViewArticle.aspx?article=291</guid><pubDate>Sun, 20 Jan 2008 14:41:57 GMT</pubDate><category>CodeBlog</category></item>
<item><link>http://www.nullify.net/ViewArticle.aspx?article=290</link><title>Using LINQ with SQL Compact Edition</title><description><![CDATA[<p><font face="Calibri">Create a .NET 3.5 Console, Windows Forms or WPF project, add an SQL Compact Edition local database, I left the default name of Database1.sdf for the example.&nbsp;Just right click and open it from solution explorer and add some tables.&nbsp;I added two tables: &nbsp;Person and Pet, with a relationship between the two (right click the child table, choose properties to get the add relationship option).</font></p>
<div style="margin: 0cm 0cm 10pt"><font face="Calibri">Next you want to add a command to visual studios tools menu, using Tools, External Tools&hellip; This command will allow you to generate a Linq To SQL DBML file which describes the contents of the database.&nbsp;Once we have that Linq is perfectly compatible with SQL Compact Edition &ndash; but the Visual Studio design tools aren&rsquo;t so we need to do this manually.</font></div>
<div style="margin: 0cm 0cm 10pt"><span style="color: #365f91"><font face="Calibri">Title: </font>&nbsp;Make &amp;Linq classes for Database<br />
Command: &nbsp;C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\SqlMetal.exe<br />
Arguments:&nbsp;$(ItemPath) /dbml:$(ItemFileName).dbml<br />
Initial Directory: $(ItemDir)</span></div>
<div style="margin: 0cm 0cm 10pt"><font face="Calibri">Now this tool will let you generate your DBML, select your Database1.sdf file then choose Tools, &ldquo;Make Linq classes for Database&rdquo;.&nbsp;It should pop up and seemingly do something in a command prompt.</font></div>
<div style="margin: 0cm 0cm 10pt"><font face="Calibri">Now right click your project, choose Add existing item and then change the filetype to either Data Files or All files.&nbsp;You should see there&rsquo;s a new file called Database1.dbml &ndash; select this file and add it to your solution.</font></div>
<div style="margin: 0cm 0cm 10pt"><font face="Calibri">Bingo!&nbsp;It is now available to be edited in Linq &ndash; you can double click this dbml file and you&rsquo;ll get the designer up &ndash; it should show your classes (NOTE: At this point I should add that relationships weren&rsquo;t automatically generated for compact edition).</font></div>
<div style="margin: 0cm 0cm 10pt"><font face="Calibri">Now it&rsquo;s time to use Linq to actually connect and query/save some data.&nbsp;This is where Linq takes a lot of the hassle out of building software that talks to databases, it simply works.</font></div>
<div style="line-height: normal"><span style="font-size: 10pt; color: maroon; font-family: Consolas">static</span><span style="font-size: 10pt; font-family: Consolas"> <span style="color: maroon">void</span> Main(<span style="color: maroon">string</span>[] args)</span></div>
<div style="line-height: normal"><span style="font-size: 10pt; font-family: Consolas">{</span></div>
<div style="line-height: normal"><span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: green">//Connect to the database itself.</span></span></div>
<div style="line-height: normal"><span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: maroon">using</span> (<span style="color: #2b91af">Database1</span> db = <span style="color: maroon">new</span> <span style="color: #2b91af">Database1</span>(<span style="color: #a31515">&quot;Database1.sdf&quot;</span>))</span></div>
<div style="line-height: normal"><span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</span></div>
<div style="line-height: normal"><span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: green">//This is easy because we used SqlMetal to generate</span></span></div>
<div style="line-height: normal"><span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: green">//the dbml targetting an SQL Compact edition database.</span></span></div>
<div style="line-height: normal"><span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: green">//Normally you'd have to specify a full connection string.</span></span></div>
<div style="line-height: normal">&nbsp;</div>
<div style="line-height: normal"><span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: green">//obviously remove these two lines if you don't want to start with an empty database each time.</span></span></div>
<div style="line-height: normal"><span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.Person.DeleteAllOnSubmit(db.Person);</span></div>
<div style="line-height: normal"><span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.SubmitChanges();</span></div>
<div style="line-height: normal">&nbsp;</div>
<div style="line-height: normal"><span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: green">//Create a couple of Person entities</span></span></div>
<div style="line-height: normal"><span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: #2b91af">Person</span> simon = <span style="color: maroon">new</span> <span style="color: #2b91af">Person</span>();</span></div>
<div style="line-height: normal"><span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; simon.Name = <span style="color: #a31515">&quot;Simon&quot;</span>;</span></div>
<div style="line-height: normal"><span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; simon.EMail = <span style="color: #a31515">&quot;me@myhost&quot;</span>;</span></div>
<div style="line-height: normal">&nbsp;</div>
<div style="line-height: normal"><span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: green">//and a cat for me</span></span></div>
<div style="line-height: normal"><span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: #2b91af">Pet</span> cat = <span style="color: maroon">new</span> <span style="color: #2b91af">Pet</span>();</span></div>
<div style="line-height: normal"><span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cat.Name = <span style="color: #a31515">&quot;Fluffy&quot;</span>;</span></div>
<div style="line-height: normal"><span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; simon.Pets.Add(cat);</span></div>
<div style="line-height: normal">&nbsp;</div>
<div style="line-height: normal"><span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.Person.InsertOnSubmit(simon);</span></div>
<div style="line-height: normal">&nbsp;</div>
<div style="line-height: normal"><span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: #2b91af">Person</span> fred = <span style="color: maroon">new</span> <span style="color: #2b91af">Person</span>();</span></div>
<div style="line-height: normal"><span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fred.Name = <span style="color: #a31515">&quot;Fred&quot;</span>;</span></div>
<div style="line-height: normal"><span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fred.EMail = <span style="color: #a31515">&quot;them@myhost&quot;</span>;</span></div>
<div style="line-height: normal"><span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.Person.InsertOnSubmit(fred);</span></div>
<div style="line-height: normal">&nbsp;</div>
<div style="line-height: normal"><span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: green">//now actually add them to the database</span></span></div>
<div style="line-height: normal"><span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.SubmitChanges();</span></div>
<div style="line-height: normal">&nbsp;</div>
<div style="line-height: normal"><span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: green">//Select the names of some people&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></div>
<div style="line-height: normal"><span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: maroon">var</span> names = <span style="color: maroon">from</span> <span style="color: #2b91af">Person</span> p <span style="color: maroon">in</span> db.Person</span></div>
<div style="line-height: normal"><span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: maroon">select</span> p.Name;</span></div>
<div style="line-height: normal">&nbsp;</div>
<div style="line-height: normal"><span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: green">//Print those names</span></span></div>
<div style="line-height: normal"><span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: maroon">foreach</span> (<span style="color: maroon">string</span> name <span style="color: maroon">in</span> names)</span></div>
<div style="line-height: normal"><span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</span></div>
<div style="line-height: normal"><span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: #2b91af">Console</span>.WriteLine(name);</span></div>
<div style="line-height: normal"><span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span></div>
<div style="line-height: normal">&nbsp;</div>
<div style="line-height: normal"><span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: green">//but you can also get back the entities instead of just names</span></span></div>
<div style="line-height: normal"><span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: green">//this is handy if you require more than just one item for a particular person</span></span></div>
<div style="line-height: normal"><span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: maroon">var</span> people = <span style="color: maroon">from</span> <span style="color: #2b91af">Person</span> p <span style="color: maroon">in</span> db.Person</span></div>
<div style="line-height: normal"><span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<span style="color: maroon">select</span> p;</span></div>
<div style="line-height: normal">&nbsp;</div>
<div style="line-height: normal"><span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: maroon">foreach</span> (<span style="color: #2b91af">Person</span> person <span style="color: maroon">in</span> people)</span></div>
<div style="line-height: normal"><span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</span></div>
<div style="line-height: normal"><span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: #2b91af">Console</span>.WriteLine(<span style="color: #2b91af">String</span>.Format(<span style="color: #a31515">&quot;{0} has an e-mail adddress of {1}&quot;</span>, person.Name, person.EMail));</span></div>
<div style="line-height: normal"><span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span></div>
<div style="line-height: normal">&nbsp;</div>
<div style="line-height: normal"><span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: green">//but what if you want multiple items not all in one person?</span></span></div>
<div style="line-height: normal"><span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: green">//well you can use anonymous classes</span></span></div>
<div style="line-height: normal"><span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: maroon">var</span> peopleAndPets = <span style="color: maroon">from</span> <span style="color: #2b91af">Person</span> p <span style="color: maroon">in</span> db.Person</span></div>
<div style="line-height: normal"><span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: maroon">orderby</span> p.Pets.Count <span style="color: maroon">descending</span></span></div>
<div style="line-height: normal"><span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: maroon">select</span> <span style="color: maroon">new</span> { p.Name, p.Pets.Count };</span></div>
<div style="line-height: normal">&nbsp;</div>
<div style="line-height: normal"><span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: green">//this is where the var keyword becomes essential.&nbsp;peopleAndPets</span></span></div>
<div style="line-height: normal"><span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: green">//is not of a type that can be described before compilation.</span></span></div>
<div style="line-height: normal"><span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: maroon">foreach</span> (<span style="color: maroon">var</span> quantity <span style="color: maroon">in</span> peopleAndPets)</span></div>
<div style="line-height: normal"><span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</span></div>
<div style="line-height: normal"><span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: #2b91af">Console</span>.WriteLine(<span style="color: #2b91af">String</span>.Format(<span style="color: #a31515">&quot;{0} has {1} pets&quot;</span>, quantity.Name, quantity.Count.ToString()));</span></div>
<div style="line-height: normal"><span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span></div>
<div style="line-height: normal"><span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span></div>
<div style="line-height: normal">&nbsp;</div>
<div style="line-height: normal"><span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: #2b91af">Console</span>.WriteLine(<span style="color: #a31515">&quot;The example is over!&quot;</span>);</span></div>
<div style="line-height: normal"><span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: #2b91af">Console</span>.ReadKey();</span></div>
<div style="margin: 0cm 0cm 10pt"><span style="font-size: 10pt; line-height: 115%; font-family: Consolas">}</span></div>]]></description><guid>http://www.nullify.net/ViewArticle.aspx?article=290</guid><pubDate>Sun, 20 Jan 2008 14:25:35 GMT</pubDate><category>CodeBlog</category></item>
<item><link>http://www.nullify.net/ViewArticle.aspx?article=288</link><title>Text to Speech Synthesis in 1 minute under .NET 3.0</title><description><![CDATA[<p><font face="Calibri">This is really easy and quick, but something that is handy.&nbsp;Getting speech synthesis to work under .NET 3.0 is really a breeze.</font></p>
<div style="margin: 0cm 0cm 10pt"><font face="Calibri">First, add a reference to System.Speech &ndash; this contains the managed speech API, it allows you to do recognition and synthesis extremely easily.</font></div>
<div style="margin: 0cm 0cm 10pt"><font face="Calibri">Next, add the following to an empty console application/button click event:</font></div>
<div style="line-height: normal"><span style="font-size: 10pt; color: maroon; font-family: Consolas">using</span><span style="font-size: 10pt; font-family: Consolas"> (System.Speech.Synthesis.<span style="color: #2b91af">SpeechSynthesizer</span> synth = <span style="color: maroon">new</span> System.Speech.Synthesis.<span style="color: #2b91af">SpeechSynthesizer</span>())</span></div>
<div style="line-height: normal"><span style="font-size: 10pt; font-family: Consolas">{</span><br />
<span style="font-size: 10pt; font-family: Consolas"><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>synth.SelectVoiceByHints(System.Speech.Synthesis.<span style="color: #2b91af">VoiceGender</span>.Female, System.Speech.Synthesis.<span style="color: #2b91af">VoiceAge</span>.Teen, 0);</span></div>
<div style="line-height: normal"><span style="font-size: 10pt; font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;synth.Speak(<span style="color: #a31515">&quot;Hello world!&quot;</span>);</span></div>
<div style="margin: 0cm 0cm 10pt"><span style="font-size: 10pt; line-height: 115%; font-family: Consolas">}</span></div>
<div style="margin: 0cm 0cm 10pt"><font face="Calibri">And you&rsquo;re done!&nbsp;That should have taken less than a minute if your references dialog didn&rsquo;t take ages to load.</font></div>
<div style="margin: 0cm 0cm 10pt"><font face="Calibri">If you have Microsoft Anna (you have Windows Vista, Autoroute or Streets and Trips installed) then this will use that preferentially (that&rsquo;s the SelectVoiceByHints line), otherwise it may use Microsoft Sam which sounds pretty bad but works well.</font></div>]]></description><guid>http://www.nullify.net/ViewArticle.aspx?article=288</guid><pubDate>Sun, 20 Jan 2008 13:36:24 GMT</pubDate><category>CodeBlog</category></item>
<item><link>http://www.nullify.net/ViewArticle.aspx?article=287</link><title>Fix for compact framework 3.5 designer not showing</title><description><![CDATA[<p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><font face="Calibri">If you’re getting the Windows Forms designer instead of the Compact Framework 3.5 designer then you likely have a problem in your registry.<span style="mso-spacerun: yes">&nbsp; </span>When you try to compile the build succeeds, but then you get the following warning:</font></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="FONT-SIZE: 9pt; COLOR: #365f91; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-themecolor: accent1; mso-themeshade: 191">C:\WINDOWS\Microsoft.NET\Framework\v3.5\Microsoft.CompactFramework.Common.targets : warning : An internal error occurred in PlatformVerificationTask. System.Exception: Could not locate an IAsmmetaBindingService for platform PocketPC.<span style="mso-spacerun: yes">&nbsp; </span>Check your registry settings for the platform.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="FONT-SIZE: 9pt; COLOR: #365f91; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-themecolor: accent1; mso-themeshade: 191">C:\WINDOWS\Microsoft.NET\Framework\v3.5\Microsoft.CompactFramework.Common.targets : warning :<span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>at Microsoft.CompactFramework.Build.AsmmetaContext..ctor(String ndpversion, String platformFamily, String platformID, ICollection references)<o:p></o:p></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="FONT-SIZE: 9pt; COLOR: #365f91; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-themecolor: accent1; mso-themeshade: 191">C:\WINDOWS\Microsoft.NET\Framework\v3.5\Microsoft.CompactFramework.Common.targets : warning :<span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>at Microsoft.CompactFramework.Build.Tasks.PlatformVerificationTask.Execute()<o:p></o:p></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><font face="Calibri">This also manifests itself in the </font><span style="FONT-SIZE: 10pt; COLOR: #a31515; LINE-HEIGHT: 115%; FONT-FAMILY: Consolas; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">GetDeviceFrameworkPath</span><font face="Calibri"> entry not accepted by the schema in the “<span style="COLOR: #365f91; mso-themecolor: accent1; mso-themeshade: 191">C:\WINDOWS\Microsoft.NET\Framework\v3.5\Microsoft.CompactFramework.Common.targets</span>” file. </font></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><font face="Calibri">Well, there’s an easy enough solution to these problems, the AsmmetaBinder entries are missing from the registry in each of the sub-types under:</font></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="FONT-SIZE: 9pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'">HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETCompactFramework\v3.5.0.0<o:p></o:p></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><font face="Calibri">So here’s the entries you need to copy into notepad, save as fix.reg or similar and then double click:-</font></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="FONT-SIZE: 9pt; COLOR: #365f91; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; mso-themecolor: accent1; mso-themeshade: 191">Windows Registry Editor Version 5.00<o:p></o:p></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="FONT-SIZE: 9pt; COLOR: #365f91; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; mso-themecolor: accent1; mso-themeshade: 191">[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETCompactFramework\v3.5.0.0\PocketPC\AsmmetaBinder]<br />"TypeName"="Microsoft.CompactFramework.Build.PocketPC.BindingService, Microsoft.CompactFramework.Build.Tasks, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, Custom=null"<br /><br />[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETCompactFramework\v3.5.0.0\PocketPC\AsmmetaBinder\4118C335-430C-497f-BE48-11C3316B135E]<br />"TypeName"="Microsoft.CompactFramework.Build.WM50PocketPC.BindingService, Microsoft.CompactFramework.Build.Tasks, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, Custom=null"<br /><br />[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETCompactFramework\v3.5.0.0\Smartphone\AsmmetaBinder]<br />"TypeName"="Microsoft.CompactFramework.Build.SmartPhone.BindingService, Microsoft.CompactFramework.Build.Tasks, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, Custom=null"<br /><br />[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETCompactFramework\v3.5.0.0\Smartphone\AsmmetaBinder\BD0CC567-F6FD-4ca3-99D2-063EFDFC0A39]<br />"TypeName"="Microsoft.CompactFramework.Build.WM50SmartPhone.BindingService, Microsoft.CompactFramework.Build.Tasks, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, Custom=null"<br /><br />[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETCompactFramework\v3.5.0.0\WindowsCE\AsmmetaBinder]<br />"TypeName"="Microsoft.CompactFramework.Build.WindowsCE.BindingService, Microsoft.CompactFramework.Build.Tasks, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, Custom=null"</span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="FONT-SIZE: 9pt; COLOR: #365f91; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; mso-themecolor: accent1; mso-themeshade: 191"><font size="3"><font color="#000000"><font face="Calibri">This one has been annoying me for a while now, as I do a bit of compact framework development.<span style="mso-spacerun: yes">&nbsp; </span>I simply compared two exactly similar XP machines entire compact framework installs – files, registry settings, etc till I found the differences between a working and non-working system.<o:p></o:p></font></font></font></span></p>]]></description><guid>http://www.nullify.net/ViewArticle.aspx?article=287</guid><pubDate>Sun, 20 Jan 2008 13:24:37 GMT</pubDate><category>Blog</category></item>
<item><link>http://www.nullify.net/ViewArticle.aspx?article=285</link><title>64K limit on data lengths in WCF</title><description><![CDATA[<p>There's a limit on the data sent and recieved in WCF, resulting in errors like this when the webservice sends back larger messages:</p> <p>"The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element."</p> <p>The fix for this is to create a new binding with much larger limits:</p> <p><font size="2"><font face="Courier New">System.ServiceModel.</font><font face="Courier New"><font color="#2b91af">BasicHttpBinding</font> binding = <font color="#800000">new</font> System.ServiceModel.<font color="#2b91af">BasicHttpBinding</font></font><font face="Courier New">();<br /></font></font><font size="2"><font face="Courier New">binding.MaxBufferSize = 1024 * 1024 * 2; </font><font color="#008000"><font face="Courier New">//bit bigger than default<br /></font></font></font><font size="2"><font face="Courier New">binding.MaxReceivedMessageSize = 1024 * 1024 * 2;</font><font color="#008000"><font face="Courier New"><br /></font></font></font><font face="Courier New" size="2">binding.ReaderQuotas.MaxStringContentLength = 1024 * 1024 * 2;<br /></font><font size="2"><font face="Courier New">ServiceReference1.</font><font face="Courier New"><font color="#2b91af">MyServicesSoapClient</font> client = <font color="#800000">new</font> ServiceReference1.<font color="#2b91af">MyServicesSoapClient</font>(binding, <font color="#800000">new</font> System.ServiceModel.<font color="#2b91af">EndpointAddress</font>(<font color="#a31515">"http://myservice/service.asmx"</font>));</p></font></font>]]></description><guid>http://www.nullify.net/ViewArticle.aspx?article=285</guid><pubDate>Mon, 03 Dec 2007 11:10:24 GMT</pubDate><category>CodeBlog</category></item>
</channel></rss>