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

<channel>
	<title>DataBatrix &#187; .NET 2.0</title>
	<atom:link href="http://www.databatrix.com/tag/net-2-0/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.databatrix.com</link>
	<description>The workings of Eric Bridges</description>
	<lastBuildDate>Thu, 01 Dec 2011 23:47:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.3</generator>
		<item>
		<title>.NET Serialization: Binary, SOAP, and XML (VB)</title>
		<link>http://www.databatrix.com/2009/10/net-serialization-binary-soap-and-xml-vb/</link>
		<comments>http://www.databatrix.com/2009/10/net-serialization-binary-soap-and-xml-vb/#comments</comments>
		<pubDate>Thu, 08 Oct 2009 23:43:50 +0000</pubDate>
		<dc:creator>Eric</dc:creator>
				<category><![CDATA[.NET 2.0]]></category>
		<category><![CDATA[.NET 3.5]]></category>
		<category><![CDATA[ASP]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[Binary]]></category>
		<category><![CDATA[Serialization]]></category>
		<category><![CDATA[SOAP]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://www.databatrix.com/?p=227</guid>
		<description><![CDATA[In .NET when you need to shrink an object into a more portable format you have 3 choices.  Binary, SOAP, or XML.  The process of shrinking and expanding the object is called serialization and deserialization.  Each option has it&#8217;s own advantages which I will explain. Binary You can serialize an object into binary format quite [...]]]></description>
			<content:encoded><![CDATA[<p>In .NET when you need to shrink an object into a more portable format you have 3 choices.  Binary, SOAP, or XML.  The process of shrinking and expanding the object is called serialization and deserialization.  Each option has it&#8217;s own advantages which I will explain.</p>
<h2>Binary</h2>
<p>You can serialize an object into binary format quite easily using the .NET Framework.  This is the quickest and smallest way to serialize; however, the binary format can only be deserialized using the same .NET Framework.  This may be a problem for interoperability.  It must be noted that this format will serialize Public and Private members (unlike XML serialization).</p>
<p>The example below shows how to serialize an object called &#8220;newCustomer&#8221;:</p>
<pre class="brush:vb">        Dim newCustomer As Contact = GetSampleContact()

        Using fs As New IO.FileStream(filePathandName &amp; ".bin", IO.FileMode.Create)
            Dim binFormatter As New Runtime.Serialization.Formatters.Binary.BinaryFormatter()
            binFormatter.Serialize(fs, newCustomer)
        End Using</pre>
<p>And here is the reverse to deserialize:</p>
<pre class="brush:vb">        Dim readCustomer As Contact

        Using fs As New IO.FileStream(filePathandName &amp; ".bin", IO.FileMode.Open, IO.FileAccess.Read)
            Dim binFormatter As New Runtime.Serialization.Formatters.Binary.BinaryFormatter()
            readCustomer = CType(binFormatter.Deserialize(fs), Contact)
        End Using</pre>
<h2>SOAP</h2>
<p>SOAP is another method.  This is similar to the binary method except the serialized data is stored in a standardized form (SOAP) which will easily allow interoperability.  Public and Private members are serialized using this method as well.<br />
To serialize:</p>
<pre class="brush:vb">        Dim newCustomer As Contact = GetSampleContact()
        Using fs As New IO.FileStream(filePathandName &amp; "SOAP.xml", IO.FileMode.Create)
            Dim soapFormattter As New Runtime.Serialization.Formatters.Soap.SoapFormatter()
            soapFormattter.Serialize(fs, newCustomer)
        End Using</pre>
<p>And to deserialize:</p>
<pre class="brush:vb">        Dim readCustomer As Contact
        Using fs As New IO.FileStream(filePathandName &amp; "SOAP.xml", IO.FileMode.Open, IO.FileAccess.Read)
            Dim soapFormattter As New Runtime.Serialization.Formatters.Soap.SoapFormatter()
            readCustomer = CType(soapFormattter.Deserialize(fs), Contact)
        End Using</pre>
<h2>XML</h2>
<p>A third choice is using the XMLSerializer class.  This method will only serialize Public properties and members and the object must be marked with the Serializable attribute and contain an empty constructor.  This method of serialization will be smaller in size than the SOAP method since less information is serialized.  Here is an example of such class:</p>
<pre class="brush:vb">     &lt;Serializable()&gt; Class Contact

        Private _FirstName As String
        Public Property FirstName() As String
            Get
                Return _FirstName
            End Get
            Set(ByVal value As String)
                _FirstName = value
            End Set
        End Property

        Private _LastName As String
        Public Property LastName() As String
            Get
                Return _LastName
            End Get
            Set(ByVal value As String)
                _LastName = value
            End Set
        End Property

        Private _MiddleI As String
        Public Property MiddleI() As String
            Get
                Return _MiddleI
            End Get
            Set(ByVal value As String)
                _MiddleI = value
            End Set
        End Property

        Private _PIN As String
        Public WriteOnly Property PIN() As String
            Set(ByVal value As String)
                _PIN = value
            End Set
        End Property

        Sub New()

        End Sub

        Sub New(ByVal fName As String, ByVal middleI As String, ByVal lName As String, ByVal p As String)
            _FirstName = fName
            _MiddleI = middleI
            _LastName = lName
            _PIN = p
        End Sub
    End Class</pre>
<p>Here is how you would serialize using the XMLSerializer:</p>
<pre class="brush:vb">        Dim newCustomer As Contact = GetSampleContact()
        Using fs As New IO.FileStream(filePathandName &amp; ".xml", IO.FileMode.Create)
            Dim xmlFormatter As New Xml.Serialization.XmlSerializer(GetType(Contact))
            xmlFormatter.Serialize(fs, newCustomer)
        End Using</pre>
<p>And to deserialize:</p>
<pre class="brush:vb">        Dim readCustomer As Contact
        Using fs As New IO.FileStream(filePathandName &amp; ".xml", IO.FileMode.Open, IO.FileAccess.Read)
            Dim xmlFormatter As New Xml.Serialization.XmlSerializer(GetType(Contact))
            readCustomer = CType(xmlFormatter.Deserialize(fs), Contact)
        End Using</pre>
<p><img class="alignnone size-full wp-image-232" title="Serialization Demo" src="http://www.databatrix.com/wp-content/uploads/2009/10/Serialization.JPG" alt="Serialization Demo" width="505" height="336" /></p>
<p>You can download a sample serialization demo project that I created to demonstrate: <a title="Serialization Demo Project.zip" href="http://www.databatrix.com/wp-content/uploads/2009/10/SerializationDemo.zip">SerializationDemoProject.zip</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.databatrix.com/2009/10/net-serialization-binary-soap-and-xml-vb/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JobTime: Time Clock Web Application And Job Cost Tracking</title>
		<link>http://www.databatrix.com/2009/09/jobtime-time-clock-web-application-and-job-cost-tracking/</link>
		<comments>http://www.databatrix.com/2009/09/jobtime-time-clock-web-application-and-job-cost-tracking/#comments</comments>
		<pubDate>Sat, 05 Sep 2009 13:18:06 +0000</pubDate>
		<dc:creator>Eric</dc:creator>
				<category><![CDATA[.NET 2.0]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Web Applications]]></category>
		<category><![CDATA[Payroll]]></category>
		<category><![CDATA[Timeclock]]></category>

		<guid isPermaLink="false">http://www.databatrix.com/?p=214</guid>
		<description><![CDATA[Background The company needed to track time logged to particular jobs/projects.  The initial idea was to use a site like ClickTime.  However, for an employee to log time against a job, you would need to tell ClickTime all of your jobs (which would be tedious) or configure an integration app to automatically populate the available [...]]]></description>
			<content:encoded><![CDATA[<h3>Background</h3>
<p>The company needed to track time logged to particular jobs/projects.  The initial idea was to use a site like <a href="http://www.clicktime.com/" target="_blank">ClickTime</a>.  However, for an employee to log time against a job, you would need to tell ClickTime all of your jobs (which would be tedious) or configure an integration app to automatically populate the available jobs/projects.</p>
<h3>Solution</h3>
<p>I created a web application that would allow employees to log time against jobs/projects.  It would search instantly against their project management software for a list of available jobs.  The type of work was categorized for reporting.  Since we would have the employee&#8217;s hours, it would be used for payroll.  I implemented an export feature for preparing the payroll information for ADP and EDH.  Work time for each project was then entered into the project management software to be calculated as job cost.  As a bonus, you could use the gathered data to calculate each employees &#8220;utilization&#8221;.</p>
<table border="0">
<tbody>
<tr>
<td>
<p><div id="attachment_217" class="wp-caption alignnone" style="width: 160px"><a href="http://www.databatrix.com/wp-content/uploads/2009/09/MainScreen.JPG"><img class="size-thumbnail wp-image-217" title="MainScreen" src="http://www.databatrix.com/wp-content/uploads/2009/09/MainScreen-150x150.jpg" alt="Landing page." width="150" height="150" /></a><p class="wp-caption-text">Landing page.</p></div></td>
<td>
<p><div id="attachment_216" class="wp-caption alignnone" style="width: 160px"><a href="http://www.databatrix.com/wp-content/uploads/2009/09/EnterTime.JPG"><img class="size-thumbnail wp-image-216" title="EnterTime" src="http://www.databatrix.com/wp-content/uploads/2009/09/EnterTime-150x150.jpg" alt="Enter time for a particular project/job." width="150" height="150" /></a><p class="wp-caption-text">Enter time for a particular project/job.</p></div></td>
</tr>
<tr>
<td>
<p><div id="attachment_215" class="wp-caption alignnone" style="width: 160px"><a href="http://www.databatrix.com/wp-content/uploads/2009/09/ApplyJobCost.JPG"><img class="size-thumbnail wp-image-215" title="ApplyJobCost" src="http://www.databatrix.com/wp-content/uploads/2009/09/ApplyJobCost-150x150.jpg" alt="Apply costs to each job." width="150" height="150" /></a><p class="wp-caption-text">Apply costs to each job.</p></div></td>
<td>
<p><div id="attachment_218" class="wp-caption alignnone" style="width: 160px"><a href="http://www.databatrix.com/wp-content/uploads/2009/09/PayRoll.JPG"><img class="size-thumbnail wp-image-218" title="PayRoll" src="http://www.databatrix.com/wp-content/uploads/2009/09/PayRoll-150x150.jpg" alt="Payroll export options." width="150" height="150" /></a><p class="wp-caption-text">Payroll export options.</p></div></td>
</tr>
<tr>
<td>
<p><div id="attachment_219" class="wp-caption alignnone" style="width: 160px"><a href="http://www.databatrix.com/wp-content/uploads/2009/09/Utilization.JPG"><img class="size-thumbnail wp-image-219" title="Utilization" src="http://www.databatrix.com/wp-content/uploads/2009/09/Utilization-150x150.jpg" alt="Utilization" width="150" height="150" /></a><p class="wp-caption-text">Utilization</p></div></td>
<td> </td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://www.databatrix.com/2009/09/jobtime-time-clock-web-application-and-job-cost-tracking/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Automatic Email Alerts From Any SQL Query</title>
		<link>http://www.databatrix.com/2009/09/automatic-email-alerts-from-any-sql-query/</link>
		<comments>http://www.databatrix.com/2009/09/automatic-email-alerts-from-any-sql-query/#comments</comments>
		<pubDate>Wed, 02 Sep 2009 13:24:40 +0000</pubDate>
		<dc:creator>Eric</dc:creator>
				<category><![CDATA[.NET 2.0]]></category>
		<category><![CDATA[Desktop Applications]]></category>
		<category><![CDATA[MS SQL]]></category>

		<guid isPermaLink="false">http://www.databatrix.com/?p=188</guid>
		<description><![CDATA[Problem Reminder emails were needed to be sent out to remind sales staff to follow up on projects. Solution I developed a simple command line executable that takes 1 parameter which is an XML file.  The contents of the XML file would look something like: &#60;?xml version="1.0" encoding="utf-8" ?&#62; &#60;Settings&#62; &#60;ErrorEmail&#62; &#60;Email&#62;email@gmail.com&#60;/Email&#62; &#60;/ErrorEmail&#62; &#60;SummaryEmail&#62; &#60;Email&#62;email@gmail.com&#60;/Email&#62; [...]]]></description>
			<content:encoded><![CDATA[<h3>Problem</h3>
<p>Reminder emails were needed to be sent out to remind sales staff to follow up on projects.</p>
<h3>Solution</h3>
<p>I developed a simple command line executable that takes 1 parameter which is an XML file.  The contents of the XML file would look something like:</p>
<pre class="brush: xml">&lt;?xml version="1.0" encoding="utf-8" ?&gt;
&lt;Settings&gt;
	&lt;ErrorEmail&gt;
		&lt;Email&gt;email@gmail.com&lt;/Email&gt;
	&lt;/ErrorEmail&gt;
	&lt;SummaryEmail&gt;
		&lt;Email&gt;email@gmail.com&lt;/Email&gt;
	&lt;/SummaryEmail&gt;
	&lt;Query&gt;
		SELECT * FROM Projects
		WHERE Cancelled = 0 And Completed = 0 AND BookDate IS NULL
		AND FollowUpBy &lt;= getdate()
	&lt;/Query&gt;
	&lt;SQLConnectionString&gt;Server=SQLServer;Database=MainDatabase;Persist Security Info=True;Integrated Security=true&lt;/SQLConnectionString&gt;
	&lt;TemplateEmailFileName&gt;EmailTemplate.txt&lt;/TemplateEmailFileName&gt;
	&lt;EmailSubject&gt;Alert Email For Project#&lt;:ProjectID:&gt;&lt;/EmailSubject&gt;
	&lt;EmailDomain&gt;mycompany.com&lt;/EmailDomain&gt;
	&lt;ToAddressDatabaseField&gt;Salesperson&lt;/ToAddressDatabaseField&gt;
	&lt;ToAddressFieldIsEmail&gt;0&lt;/ToAddressFieldIsEmail&gt;
	&lt;SMTPSettings&gt;
		&lt;SMTPServer&gt;smtp.gmail.com&lt;/SMTPServer&gt;
		&lt;EnableSSL&gt;1&lt;/EnableSSL&gt;
		&lt;RequiresAuthentication&gt;1&lt;/RequiresAuthentication&gt;
		&lt;Username&gt;email@gmail.com&lt;/Username&gt;
		&lt;Password&gt;*******&lt;/Password&gt;
		&lt;Port&gt;587&lt;/Port&gt;
		&lt;FromAddress&gt;email@gmail.com&lt;/FromAddress&gt;
	&lt;/SMTPSettings&gt;
	&lt;LogFileDirectory&gt;Daily&lt;/LogFileDirectory&gt;
&lt;/Settings&gt;</pre>
<p>The command line executable would then run the query (&lt;Query&gt;) against the supplied database in the XML file.  For each row returned, the program will send out an email to the user.  Which user?  What email?  The recipients email address would need to be one of the fields returned from the query and noted in the XML file in the element &lt;ToAddressDatabaseField&gt;.  The template for the email body is supplied by the &lt;TemplateEmailFileName&gt; element.   To make the email custom, it is possible to insert fields returned from the database into the email template.  For example, lets say the query returned a field called &#8220;FirstName&#8221;.  In the email template text file, you could have:</p>
<pre>Hello &lt;:FirstName:&gt;,</pre>
<p>When the program ran, it would swap &#8220;&lt;:FirstName:&gt;&#8221; with the contents from the database.  This is similar to a mail merge for emails.  Since all of the values are configurable in the XML file, the usage possibilities are unlimited!  Let say you needed to run this once a week, no problem.  Set up a Windows Scheduled Task to run the executable at the specified interval.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.databatrix.com/2009/09/automatic-email-alerts-from-any-sql-query/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A .NET Bit.ly API Helper Class (Visual Basic.NET)</title>
		<link>http://www.databatrix.com/2009/08/a-net-bit-ly-api-helper-class-visual-basic-net/</link>
		<comments>http://www.databatrix.com/2009/08/a-net-bit-ly-api-helper-class-visual-basic-net/#comments</comments>
		<pubDate>Mon, 24 Aug 2009 21:19:19 +0000</pubDate>
		<dc:creator>Eric</dc:creator>
				<category><![CDATA[.NET 2.0]]></category>
		<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[Web Services]]></category>
		<category><![CDATA[bit.ly]]></category>
		<category><![CDATA[Facebook]]></category>
		<category><![CDATA[Twitter]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://www.databatrix.com/?p=162</guid>
		<description><![CDATA[I decided to write a helper class for using the Bit.ly API for creating short urls.  You know, those tiny links that you see all over Facebook, Twitter, etc.  The snippet below shows how you would use the helper class.  Not only can you shorten an url, you can shorted multiple urls in a single [...]]]></description>
			<content:encoded><![CDATA[<p>I decided to write a helper class for using the Bit.ly API for creating short urls.  You know, those tiny links that you see all over Facebook, Twitter, etc.  The snippet below shows how you would use the helper class.  Not only can you shorten an url, you can shorted multiple urls in a single call as well as get stats and info about a bit.ly url.  If you are looking to incorporate bit.ly short urls in your application using their API access, this will save you some time.  The class uses the XmlSerializer for reading bit.ly&#8217;s response.</p>
<pre class="brush: vb">        ' Pass username and API key to instantiate
        Dim newbitlyAPI As New DataBatrix.bitlyAPI.bitlyAPI("bitlyapidemo", "R_0da49e0a9118ff35f52f629d2d71bf07")

        ' Sample of creating 1 short URL
        Dim shortenResponse As DataBatrix.bitlyAPI.bitlyShortenResponse = newbitlyAPI.Shorten("http://www.databatrix.com")
        Dim shortURL As String = ""
        If shortenResponse.results.Count &gt; 0 Then
            shortURL = shortenResponse.results(0).shortUrl
        End If

        ' Sample of creating multiple short URLs
        Dim longUrls() As String = {"http://www.databatrix.com", "http://www.google.com"}
        Dim shortenResponses As DataBatrix.bitlyAPI.bitlyShortenResponse = newbitlyAPI.Shorten(longUrls)
        Dim shortURLs(1) As String
        For i As Integer = 0 To shortenResponses.results.Count - 1
            shortURLs(i) = shortenResponses.results(i).shortUrl

        Next

        ' Sample of getting bit.ly info...
        Dim info As DataBatrix.bitlyAPI.bitlyInfoResponse = newbitlyAPI.Info("2bYgqR")

        ' Sample of getting bit.ly stats...
        Dim stats As DataBatrix.bitlyAPI.bitlyStatsResponse = newbitlyAPI.Stats("http://bit.ly/1RmnUT")</pre>
<p>Below is the helper class that I created.  You can download the VB file <a href="http://www.databatrix.com/wp-content/uploads/2009/08/bitlyAPI.vb">bitlyAPI.vb</a> or a sample project <a href="http://www.databatrix.com/wp-content/uploads/2009/08/TestBitly.zip">TestBitly Project Files</a>.</p>
<pre class="brush: vb">Imports System.Web
Imports System.Xml
Imports System.Xml.Serialization

Namespace DataBatrix.bitlyAPI
    Public Class bitlyAPI
        Const BaseAPIUrl As String = "http://api.bit.ly/"
        Const version As String = "2.0.1"
        Const format As String = "xml"

        Public login As String = String.Empty
        Public apiKey As String = String.Empty

        Sub New(ByVal login As String, ByVal apiKey As String)
            Me.login = login
            Me.apiKey = apiKey

        End Sub

        Private Function BuildBaseRequestURL(ByVal applicationName As String) As System.Text.StringBuilder
            Dim RequestUrl As New System.Text.StringBuilder()
            With RequestUrl
                .Append(BaseAPIUrl &amp; HttpUtility.UrlEncode(applicationName) &amp; "?")
                .Append("version=" &amp; HttpUtility.UrlEncode(version) &amp; "&amp;")
                .Append("format=" &amp; HttpUtility.UrlEncode(format) &amp; "&amp;")
                .Append("login=" &amp; HttpUtility.UrlEncode(login) &amp; "&amp;")
                .Append("apiKey=" &amp; HttpUtility.UrlEncode(apiKey) &amp; "&amp;")
            End With
            Return RequestUrl
        End Function

        Public Function Shorten(ByVal longUrl As String) As bitlyShortenResponse
            Dim logUrls() As String = {longUrl}
            Return Shorten(logUrls)
        End Function

        Public Function Shorten(ByVal longUrl() As String) As bitlyShortenResponse
            Dim RequestUrl As System.Text.StringBuilder = BuildBaseRequestURL("shorten")
            For Each s As String In longUrl
                RequestUrl.Append("&amp;longUrl=" &amp; HttpUtility.UrlEncode(s))

            Next
            Dim responseObj As DataBatrix.bitlyAPI.bitlyShortenResponse = Nothing
            Try
                Dim serializer = New XmlSerializer(GetType(DataBatrix.bitlyAPI.bitlyShortenResponse))
                Using reader As XmlTextReader = New XmlTextReader(RequestUrl.ToString())
                    responseObj = CType(serializer.Deserialize(reader), DataBatrix.bitlyAPI.bitlyShortenResponse)
                End Using

            Catch ex As Exception

            End Try

            If responseObj.errorCode &gt; 0 Then
                Throw New ApplicationException("Error from bit.ly: " &amp; responseObj.errorMessage)
            End If
            Return responseObj
        End Function
        Public Function Info(ByVal hash As String) As bitlyInfoResponse
            Dim RequestUrl As System.Text.StringBuilder = BuildBaseRequestURL("info")
            With RequestUrl
                .Append("hash=" &amp; HttpUtility.UrlEncode(hash))
            End With

            Dim responseObj As DataBatrix.bitlyAPI.bitlyInfoResponse = Nothing
            Try
                Dim serializer = New XmlSerializer(GetType(DataBatrix.bitlyAPI.bitlyInfoResponse))
                Using reader As XmlTextReader = New XmlTextReader(RequestUrl.ToString())
                    responseObj = CType(serializer.Deserialize(reader), DataBatrix.bitlyAPI.bitlyInfoResponse)
                End Using

            Catch ex As Exception
                Throw New ApplicationException("API Error: " &amp; ex.Message)
            End Try
            If responseObj.errorCode &gt; 0 Then
                Throw New ApplicationException("Error from bit.ly: " &amp; responseObj.errorMessage)
            End If
            Return responseObj
        End Function

        Public Function Stats(ByVal shortUrl As String) As bitlyStatsResponse
            Dim RequestUrl As System.Text.StringBuilder = BuildBaseRequestURL("stats")
            With RequestUrl
                .Append("shortUrl=" &amp; HttpUtility.UrlEncode(shortUrl))

            End With

            Dim responseObj As DataBatrix.bitlyAPI.bitlyStatsResponse = Nothing
            Try
                Dim serializer = New XmlSerializer(GetType(DataBatrix.bitlyAPI.bitlyStatsResponse))
                Using reader As XmlTextReader = New XmlTextReader(RequestUrl.ToString())
                    responseObj = CType(serializer.Deserialize(reader), DataBatrix.bitlyAPI.bitlyStatsResponse)
                End Using

            Catch ex As Exception
                Throw New ApplicationException("API Error: " &amp; ex.Message)
            End Try
            If responseObj.errorCode &gt; 0 Then
                Throw New ApplicationException("Error from bit.ly: " &amp; responseObj.errorMessage)
            End If
            Return responseObj
        End Function

    End Class

    Public MustInherit Class bitlyResponseBase
        &lt;Xml.Serialization.XmlElement("errorCode")&gt; _
        Public errorCode As Integer = 0

        &lt;Xml.Serialization.XmlElement("errorMessage")&gt; _
        Public errorMessage As String = String.Empty

        &lt;Xml.Serialization.XmlElement("statusCode")&gt; _
        Public statusCode As String = String.Empty

    End Class

    &lt;System.Serializable(), Xml.Serialization.XmlRoot("bitly")&gt; _
    Public Class bitlyShortenResponse
        Inherits bitlyResponseBase

        &lt;Xml.Serialization.XmlArray("results"), Xml.Serialization.XmlArrayItem("nodeKeyVal")&gt; _
        Public results As New List(Of KeyVal)

        Public Class KeyVal
            &lt;Xml.Serialization.XmlElement("userHash")&gt; _
             Public userHash As String

            &lt;Xml.Serialization.XmlElement("shortKeywordUrl")&gt; _
             Public shortKeywordUrl As String

            &lt;Xml.Serialization.XmlElement("hash")&gt; _
             Public hash As String

            &lt;Xml.Serialization.XmlElement("nodeKey")&gt; _
             Public longUrl As String

            &lt;Xml.Serialization.XmlElement("shortUrl")&gt; _
             Public shortUrl As String

        End Class
    End Class

    &lt;System.Serializable(), Xml.Serialization.XmlRoot("bitly")&gt; _
    Public Class bitlyInfoResponse
        Inherits bitlyResponseBase

        &lt;Xml.Serialization.XmlArray("results"), Xml.Serialization.XmlArrayItem("doc")&gt; _
        Public results As New List(Of bitlyInfoResultItem)

        Public Class bitlyInfoResultItem
            &lt;Xml.Serialization.XmlElement("shortenedByUser")&gt; _
            Public shortenedByUser As String
            &lt;Xml.Serialization.XmlElement("keywords")&gt; _
            Public keywords As String
            &lt;Xml.Serialization.XmlElement("hash")&gt; _
            Public hash As String
            &lt;Xml.Serialization.XmlElement("exif")&gt; _
            Public exif As String
            &lt;Xml.Serialization.XmlElement("surbl")&gt; _
            Public surbl As String
            &lt;Xml.Serialization.XmlElement("contentLength")&gt; _
            Public contentLength As String
            &lt;Xml.Serialization.XmlElement("id3")&gt; _
            Public id3 As String
            &lt;Xml.Serialization.XmlElement("calais")&gt; _
            Public calais As String
            &lt;Xml.Serialization.XmlElement("longUrl")&gt; _
            Public longUrl As String
            &lt;Xml.Serialization.XmlElement("version")&gt; _
            Public version As String
            &lt;Xml.Serialization.XmlElement("htmlMetaDescription")&gt; _
            Public htmlMetaDescription As String
            &lt;Xml.Serialization.XmlElement("htmlMetaKeywords")&gt; _
            Public htmlMetaKeywords As String
            &lt;Xml.Serialization.XmlElement("calaisId")&gt; _
            Public calaisId As String
            &lt;Xml.Serialization.XmlElement("thumbnail")&gt; _
            Public thumbnail As thumbnailObj
            &lt;Xml.Serialization.XmlElement("contentType")&gt; _
            Public contentType As String
            &lt;Xml.Serialization.XmlArray("users"), Xml.Serialization.XmlArrayItem("item")&gt; _
            Public users As List(Of String)
            &lt;Xml.Serialization.XmlElement("globalHash")&gt; _
            Public globalHash As String
            &lt;Xml.Serialization.XmlElement("htmlTitle")&gt; _
            Public htmlTitle As String
            &lt;Xml.Serialization.XmlElement("metacarta")&gt; _
            Public metacarta As String
            &lt;Xml.Serialization.XmlElement("mirrorUrl")&gt; _
            Public mirrorUrl As String
            &lt;Xml.Serialization.XmlElement("keyword")&gt; _
            Public keyword As String
            &lt;Xml.Serialization.XmlElement("calaisResolutions")&gt; _
            Public calaisResolutions As String
            &lt;Xml.Serialization.XmlElement("userHash")&gt; _
            Public userHash As String

            Public Class thumbnailObj
                &lt;Xml.Serialization.XmlElement("large")&gt; _
                Public large As String
                &lt;Xml.Serialization.XmlElement("small")&gt; _
                Public small As String
                &lt;Xml.Serialization.XmlElement("medium")&gt; _
                Public medium As String
            End Class

        End Class
    End Class

    &lt;System.Serializable(), Xml.Serialization.XmlRoot("bitly")&gt; _
Public Class bitlyStatsResponse
        Inherits bitlyResponseBase

        &lt;Xml.Serialization.XmlElement("hash")&gt; _
        Public hash As String
        &lt;Xml.Serialization.XmlElement("clicks")&gt; _
        Public clicks As String

        Public Class bitlyStatsResultItem
            &lt;Xml.Serialization.XmlElement("None")&gt; _
            Public None As String
            &lt;Xml.Serialization.XmlElement("direct")&gt; _
            Public direct As String
            &lt;Xml.Serialization.XmlArray("nodeKeyVal"), XmlArrayItem("nodeKeyVal")&gt; _
            Public nodeKeyValue As List(Of KeyValue)
            &lt;Xml.Serialization.XmlElement("nodeKey")&gt; _
            Public nodeKey As String

            Public Class KeyValue
                &lt;Xml.Serialization.XmlElement("nodeValue")&gt; _
            Public nodeValue As String
                &lt;Xml.Serialization.XmlElement("nodeKey")&gt; _
                Public nodeKey As String
            End Class
        End Class
    End Class

End Namespace</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.databatrix.com/2009/08/a-net-bit-ly-api-helper-class-visual-basic-net/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Custom Replace with Regular Expressions in .NET</title>
		<link>http://www.databatrix.com/2009/08/custom-replace-with-regular-expressions-in-net/</link>
		<comments>http://www.databatrix.com/2009/08/custom-replace-with-regular-expressions-in-net/#comments</comments>
		<pubDate>Thu, 20 Aug 2009 19:05:34 +0000</pubDate>
		<dc:creator>Eric</dc:creator>
				<category><![CDATA[.NET 2.0]]></category>
		<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[Regular Expressions]]></category>
		<category><![CDATA[Delegates]]></category>

		<guid isPermaLink="false">http://www.databatrix.com/?p=149</guid>
		<description><![CDATA[This is the second time I have had to do something like this.  So this time I am posting it for my reference.  Regular expressions are amazing and amazingly difficult to understand sometimes, but they come in very handy.  I was in a situation where I was going to need to  feed in a custom [...]]]></description>
			<content:encoded><![CDATA[<p>This is the second time I have had to do something like this.  So this time I am posting it for my reference.  Regular expressions are amazing and amazingly difficult to understand sometimes, but they come in very handy.  I was in a situation where I was going to need to  feed in a custom template to be used similar to a &#8220;mail merge&#8221; situation.  I would query a database, then for each record I would fill out an email using an email template.  I decided to go with &lt;:FieldName:&gt; as the nomenclature of how a field would be inserted.  For example, here are the query results:</p>
<table border="0">
<tbody>
<tr>
<td>FirstName</td>
<td>LastName</td>
<td>Company</td>
</tr>
<tr>
<td>Eric</td>
<td>Bridges</td>
<td>DataBatrix</td>
</tr>
</tbody>
</table>
<p>My email template may look something like this:</p>
<pre>Dear &lt;:FirstName:&gt; &lt;:LastName:&gt;,</pre>
<pre>You work for &lt;:Company:&gt;!</pre>
<p>For the purpose of my project, I did not know what fields were going to be returned or what the email template looked like.  I needed a simple way to replace all of the field placeholders with actual data.  Regular expressions to the rescue!  You can use a delegate to run your own replace function.  I called my method MatchHandler which is passed a Match variable (the match that is found).  In my example below, I replaced it with the corresponding item from _reader (my sqldatareader row).</p>
<pre class="brush: vb">    Private Function MatchHandler(ByVal m As Match) As String
        Dim fieldName As String = m.Groups("fieldName").ToString()
        If HasField(fieldName) Then
            Return _reader(fieldName)
        Else
            Return m.ToString()
        End If
    End Function</pre>
<p>Next we have to create our delegate.  Delegates are basically pointers for methods (functions/subs).  I called my delegate &#8220;MatchDelegate&#8221; and pass it the address of my function I created above.</p>
<pre class="brush: vb">    Dim MatchDelegate As New MatchEvaluator(AddressOf MatchHandler)</pre>
<p>Now to make it work!  Define your regular expression pattern and instantiate a new RegularExpression object.  Use the Replace method and pass the string to search and the delegate that we created.</p>
<pre class="brush: vb">    Private Function MergeFields(ByVal body As String) As String
        Dim returnValue As String = ""
        Dim pattern As String = "&lt;:(?&lt;fieldName:&gt;(.+?)):&gt;"
        Dim regex As New Text.RegularExpressions.Regex(pattern)
        returnValue = regex.Replace(body, MatchDelegate)
        Return returnValue
    End Function</pre>
<p>That&#8217;s it!  Now you can do whatever you like when a match is found in your Replace method.</p>
<p>In case you were wondering what &#8220;(?&lt;fieldName:&gt;(.+?))&#8221; in the pattern was all about, check out <a href="http://www.regular-expressions.info/named.html" target="_blank">this link talking about regular expression groups</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.databatrix.com/2009/08/custom-replace-with-regular-expressions-in-net/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Outlook Signature</title>
		<link>http://www.databatrix.com/2009/08/outlook-signature/</link>
		<comments>http://www.databatrix.com/2009/08/outlook-signature/#comments</comments>
		<pubDate>Tue, 18 Aug 2009 00:53:25 +0000</pubDate>
		<dc:creator>Eric</dc:creator>
				<category><![CDATA[.NET 2.0]]></category>
		<category><![CDATA[Desktop Applications]]></category>
		<category><![CDATA[FTP]]></category>
		<category><![CDATA[Microsoft Office Interop]]></category>

		<guid isPermaLink="false">http://www.databatrix.com/2009/08/outlook-signature/</guid>
		<description><![CDATA[Background: My company wanted to standardize the email signature for all of the employees.  The signature was to contain images and links. Problem: Creating a signature in Microsoft Outlook that contains images and links is not the easiest thing in the world.  Not to mention having everyone in the company try to create their own, [...]]]></description>
			<content:encoded><![CDATA[<h3>Background:</h3>
<p>My company wanted to standardize the email signature for all of the employees.  The signature was to contain images and links.</p>
<h3>Problem:</h3>
<p>Creating a signature in Microsoft Outlook that contains images and links is not the easiest thing in the world.  Not to mention having everyone in the company try to create their own, they would never end up being standardized and turn into a nightmare for training.</p>
<h3>Solution:</h3>
<p>The  solution was to create a simple desktop application that helps the user create their Outlook signature.  The basic template for the signature would originate from a central location so that updates would be easy.  The email signature also contains a header that is placed at the top of the email.</p>
<h3>Result:</h3>
<p><a href="http://www.databatrix.com/wp-content/uploads/2009/08/OutlookSignature1.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="OutlookSignature1" src="http://www.databatrix.com/wp-content/uploads/2009/08/OutlookSignature1_thumb.png" border="0" alt="OutlookSignature1" width="260" height="188" /></a>Fig. 1</p>
<p><a href="http://www.databatrix.com/wp-content/uploads/2009/08/OutlookSignature2.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="OutlookSignature2" src="http://www.databatrix.com/wp-content/uploads/2009/08/OutlookSignature2_thumb.png" border="0" alt="OutlookSignature2" width="260" height="149" /></a>Fig. 2 </p>
<p>I created a simple desktop application that allows the user to enter their specific signature details (Fig. 1).  When you hit the &#8220;Create Signature&#8221; several things happen.  First the email template is downloaded from a specified FTP site.  I choose FTP so that the application would work when the user was at home connected to the Internet.  Next the program inserts all of your specific info the template.  Then it saves the signature files in the appropriate folders where signature and theme files are kept.  Yes, THEME files too!  Since my company wanted a header image at the top, I had to use a theme for the template.  If I had kept everything as a signature it would always insert 3 lines at the top (that you would have to delete for every email) and spell check would not work (since Outlook does not spell check your signature).  The final step the program does is set Outlook to use the new theme for new emails and the signature for all forwards and replies.  Why not have the theme set for all emails and not even use a signature?  Outlook only uses the theme for new emails&#8230;not sure why, but that&#8217;s the way it is (or was at the time).  The program can be ran multiple times incase updates need to be made to the signature.  (For example, we did a Happy Holidays theme that we ran for a few months.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.databatrix.com/2009/08/outlook-signature/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Inventory Application</title>
		<link>http://www.databatrix.com/2009/08/inventory-application/</link>
		<comments>http://www.databatrix.com/2009/08/inventory-application/#comments</comments>
		<pubDate>Tue, 18 Aug 2009 00:50:05 +0000</pubDate>
		<dc:creator>Eric</dc:creator>
				<category><![CDATA[.NET 2.0]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Desktop Applications]]></category>
		<category><![CDATA[MS SQL]]></category>
		<category><![CDATA[Web Applications]]></category>

		<guid isPermaLink="false">http://www.databatrix.com/2009/08/inventory-application/</guid>
		<description><![CDATA[Background: As for any company, physical inventory time is never fun.&#160; Our inventory software did not have a good interface for doing this. Problem: The process of taking physical inventory was long and tedious.&#160; The process typically involved printing our a huge list of parts, write in the quantity next to the part, then someone [...]]]></description>
			<content:encoded><![CDATA[<h3>Background:</h3>
<p>As for any company, physical inventory time is never fun.&#160; Our inventory software did not have a good interface for doing this.</p>
<h3>Problem:</h3>
<p>The process of taking physical inventory was long and tedious.&#160; The process typically involved printing our a huge list of parts, write in the quantity next to the part, then someone would enter that info in an Excel spreadsheet so that it could be imported back into our inventory software to reconcile.&#160; Another issue was finding the inventory items themselves, most items were organized well, but some could only be found by the &quot;one guy&quot; that knows where everything is located.&#160; Identification of parts and part numbers was needed.</p>
<h3>Solution:</h3>
<p>The solution was to create a desktop application that could be used to take physical inventory.&#160; The application would search against our existing parts database and store inventory quantities in a separate table that could later be reconciled.&#160; The application would also print out a part identification label on a thermal printer that was to be placed on the shelf of each item.&#160; This would make subsequent physical inventories much easier.</p>
<h3>Result:</h3>
<p><a href="http://www.databatrix.com/wp-content/uploads/2009/08/Inventory1.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Inventory1" border="0" alt="Inventory1" src="http://www.databatrix.com/wp-content/uploads/2009/08/Inventory1_thumb.png" width="260" height="132" /></a>Fig. 1</p>
<p><a href="http://www.databatrix.com/wp-content/uploads/2009/08/Inventory2.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Inventory2" border="0" alt="Inventory2" src="http://www.databatrix.com/wp-content/uploads/2009/08/Inventory2_thumb.png" width="260" height="153" /></a>Fig. 2</p>
<p><a href="http://www.databatrix.com/wp-content/uploads/2009/08/Inventory3.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Inventory3" border="0" alt="Inventory3" src="http://www.databatrix.com/wp-content/uploads/2009/08/Inventory3_thumb.png" width="260" height="213" /></a>Fig. 3&#160;&#160; </p>
<p>I created a desktop application the keep track of inventory.&#160; The application also has the ability to print out part identification stickers on a thermal printer that included part information along with a barcode.&#160; Fig. 2 shows the part detail screen.&#160; You can find out various information from the Detail screen as well as adjust inventory levels.&#160; You can pull up a part by either searching by part number or scan the corresponding barcode the program had previously printed out.   <br />The application was such a success, I created a web interface to allow certain other employees access to inventory levels.&#160; Also various reports were created that were needed Accounting purposes.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.databatrix.com/2009/08/inventory-application/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Desktop Tools</title>
		<link>http://www.databatrix.com/2009/08/desktop-tools/</link>
		<comments>http://www.databatrix.com/2009/08/desktop-tools/#comments</comments>
		<pubDate>Mon, 17 Aug 2009 23:51:09 +0000</pubDate>
		<dc:creator>Eric</dc:creator>
				<category><![CDATA[.NET 2.0]]></category>
		<category><![CDATA[Desktop Applications]]></category>
		<category><![CDATA[MS SQL]]></category>
		<category><![CDATA[Web Services]]></category>

		<guid isPermaLink="false">http://www.databatrix.com/2009/08/desktop-tools/</guid>
		<description><![CDATA[Background: I created a single page web page that was set as the background using the Active Desktop function of Windows XP.&#160; This web page allowed you to search the employee database for phone numbers or extensions.&#160; It also had a section to calculate shipping for certain items my company sells. Problem: Active Desktop started [...]]]></description>
			<content:encoded><![CDATA[<h3>Background:</h3>
<p>I created a single page web page that was set as the background using the Active Desktop function of Windows XP.&#160; This web page allowed you to search the employee database for phone numbers or extensions.&#160; It also had a section to calculate shipping for certain items my company sells.</p>
<h3>Problem:</h3>
<p>Active Desktop started messing up when laptop users would boot without a internet connection present.&#160; Also, since the web page was hosted on the company Intranet, a login dialog box would pop-up if IE was not configured properly which was confusing to some users.</p>
<h3>Solution:</h3>
<p>Rebuild the web page to not use Active Desktop, but still have the tools easily accessible.&#160; Having a bookmark to the web page was not considered &quot;easily accessible&quot;.</p>
<h3>Result:</h3>
<p><a href="http://www.databatrix.com/wp-content/uploads/2009/08/Desktop_Tools1.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Desktop_Tools1" border="0" alt="Desktop_Tools1" src="http://www.databatrix.com/wp-content/uploads/2009/08/Desktop_Tools1_thumb.png" width="260" height="179" /></a> Fig. 1</p>
<p><a href="http://www.databatrix.com/wp-content/uploads/2009/08/Desktop_Tools2.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Desktop_Tools2" border="0" alt="Desktop_Tools2" src="http://www.databatrix.com/wp-content/uploads/2009/08/Desktop_Tools2_thumb.png" width="260" height="196" /></a>Fig. 2</p>
<p><a href="http://www.databatrix.com/wp-content/uploads/2009/08/Desktop_Tools3.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Desktop_Tools3" border="0" alt="Desktop_Tools3" src="http://www.databatrix.com/wp-content/uploads/2009/08/Desktop_Tools3_thumb.png" width="235" height="260" /></a>&#160; Fig. 3</p>
<p>I decided to created a small application that runs in the system tray.&#160; Right-clicking the icon in the tray would expand a menu of available tools.&#160; Fig. 1 shows the menu and the employee search box that appears after clicking &quot;People Finder&quot;.&#160; Certain menu items are shown/hidden depending on the user&#8217;s login.&#160; For example, my login shows 6 items, but &quot;Support Ticket&quot; and &quot;Cams&quot; are not show for others.&#160; Rights are stored in the SQL database and not in the application so allowing access is simple and does not require an application update.&#160; Since we are on the subject of databases&#8230;how should the application connect to it?&#160; I decided to not connect directly to the database since the user would have to be on the network or have their VPN connected, but instead indirectly by using web services.&#160; Using web services allowed the application to work as long as any Internet connection was present.&#160; If a connection was not present, the application hides menu items that require a connection or certain rights.&#160; I created a separate web site that hosted the web service application that basically would act as a proxy for my application.   <br />Since I knew I would be updating the application as time went by, I wanted the application to be able to update itself.&#160; I accomplished this by using some of the &quot;Click Once&quot; features of Visual Studio.&#160; Instead of using the default settings, I handled the Click Once part programmatically so that I could force the update.    <br /><a href="http://www.databatrix.com/wp-content/uploads/2009/08/Desktop_Tool1.jpg"><img style="border-bottom: 0px; border-left: 0px; display: inline; margin-left: 0px; border-top: 0px; margin-right: 0px; border-right: 0px" title="Desktop_Tool1" border="0" alt="Desktop_Tool1" align="left" src="http://www.databatrix.com/wp-content/uploads/2009/08/Desktop_Tool1_thumb.jpg" width="260" height="213" /></a> I added a &quot;Sales Links&quot; item that expands into a limitless list of links and sub-links.&#160; The links can be&#160; URLs, local folders, or anything that you can type into the Start&gt;Run box!&#160; Users with permission can easily modify and add links.&#160; The application refreshes the links from the database every 30 minutes.    <br />Lets talk security&#8230;    <br />Since only a standard Internet connection is needed for the application to work, there were a couple of security concerns.&#160; The web service application was open to the public!&#160; That&#8217;s okay, lots of web service applications are open to the public&#8230;that&#8217;s kind of the point of them.&#160; I decided to use &quot;keys&quot; that had to be passed each time the application consumed a web service.&#160; In other words, a password (or key) is passed to the web service and every method (function) the web service has requires a password.&#160; What about updates?&#160; The application needs to look in a public place for updates.&#160; If its public then everyone could download the program.&#160; That&#8217;s okay too!&#160; I just had to put some security measures in place with the application is launched.&#160; Let&#8217;s just say that when the program starts it knows if it is suppose to be on that computer, if the check fails the application quits.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.databatrix.com/2009/08/desktop-tools/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

