<?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>ScarTech &#187; C#</title>
	<atom:link href="http://www.scartech.net/category/c/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.scartech.net</link>
	<description>The musings of a confessed code junkie and a game geek.</description>
	<lastBuildDate>Wed, 07 Jul 2010 01:34:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Auto Format Code in Visual Studio 2008</title>
		<link>http://www.scartech.net/2009/01/27/auto-format-code-in-visual-studio-2008/</link>
		<comments>http://www.scartech.net/2009/01/27/auto-format-code-in-visual-studio-2008/#comments</comments>
		<pubDate>Wed, 28 Jan 2009 00:53:19 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[VB.NET]]></category>

		<guid isPermaLink="false">http://www.scartech.net/?p=389</guid>
		<description><![CDATA[My new favorite macro in Visual Studio 2008 is control-D then control-K. Hit that key sequence and voila: all code on the page has been formatted. It&#8217;s especially helpful when copy-pasting. Just a tip from Tim to make your life easier!]]></description>
			<content:encoded><![CDATA[<p>My new favorite macro in <a href="http://www.microsoft.com/visualstudio/en-us/default.mspx">Visual Studio 2008</a> is control-D then control-K. Hit that key sequence and voila: all code on the page has been formatted. It&#8217;s especially helpful when copy-pasting. Just a tip from Tim to make your life easier! <img src='http://www.scartech.net/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.scartech.net/2009/01/27/auto-format-code-in-visual-studio-2008/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Is it null, or is it empty?</title>
		<link>http://www.scartech.net/2008/06/03/is-it-null-or-is-it-empty/</link>
		<comments>http://www.scartech.net/2008/06/03/is-it-null-or-is-it-empty/#comments</comments>
		<pubDate>Wed, 04 Jun 2008 01:27:58 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[VB.NET]]></category>

		<guid isPermaLink="false">http://www.scartech.net/2008/06/03/is-it-null-or-is-it-empty/</guid>
		<description><![CDATA[The IsNullOrEmpty method was added to the String class in the 2.0 Framework, and it makes testing for an empty or null string as easy as a single function call. Instead of having to test the String object if it&#8217;s null then checking if it&#8217;s empty, this can now be done in one easy method [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://msdn.microsoft.com/en-us/library/system.string.isnullorempty.aspx">IsNullOrEmpty</a> method was added to the <a href="http://msdn.microsoft.com/en-us/library/system.string.aspx">String</a> class in the 2.0 Framework, and it makes testing for an empty or null string as easy as a single function call. Instead of having to test the String object if it&#8217;s null then checking if it&#8217;s empty, this can now be done in one easy method call.<br />
VB.NET</p>
<blockquote>
<pre><span style="color: Blue">Dim</span> s <span style="color: Blue">As</span> <span style="color: Blue">String</span>

<span style="color: Blue">If</span> <span style="color: Blue">String</span>.IsNullOrEmpty(s) <span style="color: Blue">Then</span>
  Console.WriteLine(<span style="color: Maroon">"String is null or empty."</span>)
<span style="color: Blue">Else</span>
  Console.WriteLine(<span style="color: Blue">String</span>.Format(<span style="color: Maroon">"String = {0}"</span>, s))
<span style="color: Blue">EndIf</span></pre>
</blockquote>
<p>This isn&#8217;t exactly an earth shattering discovery, but it&#8217;s useful nonetheless.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.scartech.net/2008/06/03/is-it-null-or-is-it-empty/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting Serious About Security &#8211; Part 2 &#8211; XSS</title>
		<link>http://www.scartech.net/2008/04/14/getting-serious-about-security-part-2/</link>
		<comments>http://www.scartech.net/2008/04/14/getting-serious-about-security-part-2/#comments</comments>
		<pubDate>Tue, 15 Apr 2008 00:59:20 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://www.scartech.net/2008/04/14/getting-serious-about-security-part-2/</guid>
		<description><![CDATA[Cross site scripting can be a tough vulnerability to eliminate, but it doesn&#8217;t necessarily have to be. If you&#8217;re working on an ASP.NET project, the Microsoft Anti-XSS library is easy to use and freely available. Like a lot of developers, I&#8217;ve rolled my own anti-XSS by escaping specific characters, but it&#8217;s usually clunky and let&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://en.wikipedia.org/wiki/Cross-site_scripting">Cross site scripting</a> can be a tough vulnerability to eliminate, but it doesn&#8217;t necessarily have to be. If you&#8217;re working on an ASP.NET project, the <a href="http://msdn2.microsoft.com/en-us/library/aa973813.aspx">Microsoft Anti-XSS</a> library is easy to use and freely available. Like a lot of developers, I&#8217;ve rolled my own anti-XSS by escaping specific characters, but it&#8217;s usually clunky and let&#8217;s face it. There are still bound to be vulnerabilities. The MS library can be used to encode HTML, HTML attributes, JavaScript, VBScript, as well as encode for XML and XML attributes.<br />
Always encode data from untrusted inputs. Just a few examples include:</p>
<ul>
<li>Databases</li>
<li>Form fields</li>
<li>Session variables</li>
<li>Query string</li>
<li> Cookies</li>
</ul>
<p>Using the library is very simple. Just add a reference to the dll to your project, and you&#8217;re ready to go. Here&#8217;s a quick and dirty code example encoding a value from the query string:</p>
<blockquote>
<pre><span style="color: Blue">string</span> Name = AntiXss.HtmlEncode(Request.QueryString[<span style="color: Maroon">"Name"</span>]);</pre>
</blockquote>
<p>A good rule to live by is &#8220;When in doubt. Encode it.&#8221; Just don&#8217;t encode it twice. <img src='http://www.scartech.net/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>You can download the library from Microsoft <a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=EFB9C819-53FF-4F82-BFAF-E11625130C25&amp;displaylang=en">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.scartech.net/2008/04/14/getting-serious-about-security-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Who watches the watcher?</title>
		<link>http://www.scartech.net/2008/03/13/who-watches-the-watcher/</link>
		<comments>http://www.scartech.net/2008/03/13/who-watches-the-watcher/#comments</comments>
		<pubDate>Thu, 13 Mar 2008 18:06:44 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[VB.NET]]></category>

		<guid isPermaLink="false">http://www.scartech.net/2008/03/13/who-watches-the-watcher/</guid>
		<description><![CDATA[I recently completed a project at work that included the requirement to monitor data files on 30 or more different Windows NT4 machines for changes. Naturally I thought of using the FileSystemWatcher class in the System.IO namespace. As anyone who has used the FileSystemWatcher has come to realize, it can be unreliable. Specifically, if one [...]]]></description>
			<content:encoded><![CDATA[<p>I recently completed a project at work that included the requirement to monitor data files on 30 or more different Windows NT4 machines for changes. Naturally I thought of using the FileSystemWatcher class in the System.IO namespace. As anyone who has used the FileSystemWatcher has come to realize, it can be unreliable. Specifically, if one of the NT4 machines were rebooted, the watcher would &#8220;lose&#8221; its ability to capture the file modification events I needed. What was my solution? Well, it&#8217;s a bit of a hack. Actually, it&#8217;s a really big hack. I used the Timer class in the System.Threading namespace to restart the watchers at a specified interval and to check for changes to the files that I might have missed. The files don&#8217;t change very often, so the solution has worked so far. I also can&#8217;t install anything on the NT4 machines, so this is what I was forced to do. Come on. I&#8217;m not the only one to hack something together like this. Am I?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.scartech.net/2008/03/13/who-watches-the-watcher/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>iTunes SDK and C# &#8211; Part 2</title>
		<link>http://www.scartech.net/2007/10/11/itunes-sdk-and-c-part-2/</link>
		<comments>http://www.scartech.net/2007/10/11/itunes-sdk-and-c-part-2/#comments</comments>
		<pubDate>Fri, 12 Oct 2007 02:40:12 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[iTunes]]></category>

		<guid isPermaLink="false">http://www.scartech.net/archives/20</guid>
		<description><![CDATA[In part one of my series on scripting iTunes using C# I showed you how to remove dead tracks from your iTunes library. Now let&#8217;s take it one step further and get rid of all those duplicate tracks you might have. For my purposes, I determined a duplicate track to be any track that has the same artist, [...]]]></description>
			<content:encoded><![CDATA[<p>In part one of my series on scripting iTunes using C# I showed you how to remove dead tracks from your iTunes library. Now let&#8217;s take it one step further and get rid of all those duplicate tracks you might have. For my purposes, I determined a duplicate track to be any track that has the same artist, album and track name as another track in the library. When I find a duplicate, I want to keep the track with a higher bitrate. iTunes will show you a list of the duplicates in your library, but I&#8217;m much to lazy to sort out what should be deleted and what shouldn&#8217;t.</p>
<p>I used a Dictionary object to store the tracks I checked with the key being the track name. If a matching name is found, then I dig a little deeper to verify that a duplicate has actually been found, then I keep the one with a higher bitrate.</p>
<p>Download the VS2008 C# Express project <a href="http://www.scartech.net/wp-content/uploads/itunescomsample2.zip">here</a>.</p>
<p>Here&#8217;s a code sample:</p>
<blockquote><p>//create a reference to iTunes <br />
iTunesAppClass iTunes = new iTunesAppClass();</p>
<p>//get a reference to the collection of all tracks<br />
IITTrackCollection tracks = iTunes.LibraryPlaylist.Tracks;</p>
<p>int trackCount = tracks.Count;<br />
Dictionary&lt;string, IITTrack&gt; trackCollection = new Dictionary&lt;string, IITTrack&gt;();<br />
ArrayList tracksToRemove = new ArrayList();</p>
<p>for (int i = trackCount; i &gt; 0; i&#8211;)<br />
{<br />
        if (tracks[i].Kind == ITTrackKind.ITTrackKindFile)<br />
        {        <br />
             string trackKey = tracks[i].Name + tracks[i].Artist + tracks[i].Album;</p>
<p>            if (!trackCollection.ContainsKey(trackKey))<br />
            {<br />
               trackCollection.Add(trackKey, tracks[i]);<br />
            }<br />
            else<br />
            {<br />
                if (trackCollection[trackKey].Album != tracks[i].Album ||<br />
                     trackCollection[trackKey].Artist != tracks[i].Artist)<br />
                {<br />
                    trackCollection.Add(trackKey, tracks[i]);<br />
                 }<br />
                 else if (trackCollection[trackKey].BitRate &gt; tracks[i].BitRate)<br />
                 {<br />
                      tracksToRemove.Add(tracks[i]);<br />
                  }<br />
                  else<br />
                  {<br />
                      tracksToRemove.Add(tracks[i]);<br />
                   }                           <br />
            }<br />
     }     <br />
}                          </p>
<p>//now remove all duplicates<br />
for (int i = 0; i &lt; tracksToRemove.Count; i++)<br />
{<br />
     tracksToRemove[i].Delete();<br />
}</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.scartech.net/2007/10/11/itunes-sdk-and-c-part-2/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>iTunes SDK and C# &#8211; Part 1</title>
		<link>http://www.scartech.net/2007/09/28/itunes-sdk-and-c-part-1/</link>
		<comments>http://www.scartech.net/2007/09/28/itunes-sdk-and-c-part-1/#comments</comments>
		<pubDate>Sat, 29 Sep 2007 02:06:04 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://www.scartech.net/archives/11</guid>
		<description><![CDATA[If you&#8217;re like me you&#8217;ve got thousands of songs in your iTunes library. I got a new notebook PC a couple months back, and I decided to move all my music to it since it&#8217;s got plenty of disk space. I know I had lots of songs in my library whose files didn&#8217;t exist anymore. [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re like me you&#8217;ve got thousands of songs in your iTunes library. I got a new notebook PC a couple months back, and I decided to move all my music to it since it&#8217;s got plenty of disk space. I know I had lots of songs in my library whose files didn&#8217;t exist anymore. There&#8217;s a script for removing dead tracks included with the iTunes COM download, so I figured I would port it over to a C# project.</p>
<p>The code is pretty straightforward. Get a reference to iTunes, check the file location of each track in the library and delete the tracks whose files don&#8217;t exist.<br />
<font size="2" color="#2b91af"> </font> </p>
<blockquote><p><font size="2" color="#008000">//create a reference to iTunes</font></p>
<p><font size="2" color="#2b91af">iTunesAppClass</font><font size="2"> iTunes = </font><font size="2" color="#0000ff">new</font><font size="2"> </font><font size="2" color="#2b91af">iTunesAppClass</font><font size="2">();</font></p>
<p><font size="2" color="#008000">//get a reference to the collection of all tracks</font></p>
<p><font size="2" color="#2b91af">IITTrackCollection</font><font size="2"> tracks = iTunes.LibraryPlaylist.Tracks;</font></p>
<p><font size="2" color="#0000ff">for</font><font size="2"> (</font><font size="2" color="#0000ff">int</font><font size="2"> i = trackCount; i &gt; 0; i&#8211;)</font></p>
<p><font size="2">{</font></p>
<p><font size="2">      </font><font color="#2b91af">IITTrack</font><font size="2"> track = tracks[i];</font></p>
<p><font color="#0000ff">      if</font><font size="2"> (track.Kind == </font><font color="#2b91af">ITTrackKind</font><font size="2">.ITTrackKindFile)</font></p>
<p><font size="2">      </font><font size="2">{</font></p>
<p><font size="2">            </font><font color="#2b91af">IITFileOrCDTrack</font><font size="2"> fileTrack = (</font><font color="#2b91af">IITFileOrCDTrack</font><font size="2">)track;</font><font size="2" color="#008000">           </font></p>
<p><font size="2" color="#008000">            //if the file doesn&#8217;t exist, we&#8217;ll delete it from iTunes</font><font size="2" color="#0000ff">           </font></p>
<p><font size="2" color="#0000ff">           if</font><font size="2"> (fileTrack.Location == </font><font size="2" color="#2b91af">String</font><font size="2">.Empty || !System.IO.</font><font color="#2b91af">File</font>.Exists(fileTrack.Location))<font size="2" color="#008000"> </font><font size="2">            </font></p>
<p><font size="2">          {</font></p>
<p><font size="2">                  fileTrack.Delete();</font></p>
<p><font size="2">            }</font></p>
<p><font size="2">      }</font></p>
<p><font size="2">}</font></p></blockquote>
<p>You can download the project here (<a href="http://www.scartech.net/wp-content/uploads/itunescomsample.zip" title="Download Project">Download Project</a>). I put it into a WinForm, used a worker thread to take care of the iTunes work because it can take some time to check a 10K song library, and output the dead tracks removed to a list box.</p>
<p><a target="_blank" href="http://www.scartech.net/wp-content/uploads/itunescsharp.jpg"><img src="http://www.scartech.net/wp-content/uploads/itunescsharp.thumbnail.jpg" alt="itunescsharp.jpg" /></a></p>
<p>I think in part 2 I&#8217;ll add the ability to find duplicate songs and remove the copy with the lower bitrate. I know for sure that I&#8217;ve got quite a few of them. Any other ideas for what can be done with the iTunes SDK to clean up your music library or to just make life simpler?</p>
<p>Here&#8217;s what I used for this project:</p>
<li><a href="http://msdn2.microsoft.com/en-us/express/future/bb421473.aspx">Visual C# 2008 Express Edition</a></li>
<li><a href="http://www.apple.com/itunes/">iTunes 7.4.2.4</a></li>
<li><a href="http://developer.apple.com/sdk/itunescomsdk.html">iTunes COM for Windows SDK</a></li>
<p>FYI. I found about 175 dead tracks out of over 7300 in my library.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.scartech.net/2007/09/28/itunes-sdk-and-c-part-1/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
