<?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>Bee Eee Blog &#187; coding</title>
	<atom:link href="http://blog.bee-eee.com/tag/coding/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.bee-eee.com</link>
	<description>-- C# hints and tips</description>
	<lastBuildDate>Wed, 23 Dec 2009 19:00:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>WCF Resolving error &#8216;The caller was not authenticated by the service.&#8217;</title>
		<link>http://blog.bee-eee.com/2009/09/17/wcf-resolving-error-the-caller-was-not-authenticated-by-the-service/</link>
		<comments>http://blog.bee-eee.com/2009/09/17/wcf-resolving-error-the-caller-was-not-authenticated-by-the-service/#comments</comments>
		<pubDate>Thu, 17 Sep 2009 17:49:10 +0000</pubDate>
		<dc:creator>brian</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[WCF]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[coding]]></category>

		<guid isPermaLink="false">http://blog.bee-eee.com/?p=79</guid>
		<description><![CDATA[I ran across an easy way to get wsHttpBinding to work on a remote machine.  This involves just a little bit of code on the client side to complete the authentication. VPortalDataServiceClient client = new VPortalDataServiceClient(); client.ClientCredentials.Windows.ClientCredential.UserName = "btomas"; client.ClientCredentials.Windows.ClientCredential.Password = "password123"; The UserName is the windows account user name that is hosting the service. [...]]]></description>
			<content:encoded><![CDATA[<p>I ran across an easy way to get wsHttpBinding to work on a remote machine.  This involves just a little bit of code on the client side to complete the authentication.</p>
<pre class="code">                VPortalDataServiceClient client = new VPortalDataServiceClient();
                client.ClientCredentials.Windows.ClientCredential.UserName = "btomas";
                client.ClientCredentials.Windows.ClientCredential.Password = "password123";</pre>
<p>The UserName is the windows account user name that is hosting the service.  This user may just need to be one on the domain that the machine can see &#8212; not exactly sure though.  And the Password is the password of that user.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bee-eee.com/2009/09/17/wcf-resolving-error-the-caller-was-not-authenticated-by-the-service/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>c# finding those blasted predefined IEqualityComparer classes!</title>
		<link>http://blog.bee-eee.com/2009/04/14/c-finding-those-blasted-predefined-iequalitycomparer-classes/</link>
		<comments>http://blog.bee-eee.com/2009/04/14/c-finding-those-blasted-predefined-iequalitycomparer-classes/#comments</comments>
		<pubDate>Tue, 14 Apr 2009 17:28:27 +0000</pubDate>
		<dc:creator>brian</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[coding]]></category>

		<guid isPermaLink="false">http://blog.bee-eee.com/?p=74</guid>
		<description><![CDATA[Why there isn&#8217;t any reference in the IEqualityComparer documentation to pre-implmented classes that override the function I don&#8217;t know. But here&#8217;s one for string comparisons: StringComparer This static class contains many different predefined IEqualityComparer instances to be used in functions like &#8220;Contains&#8221;. Enjoy.]]></description>
			<content:encoded><![CDATA[<p>Why there isn&#8217;t any reference in the IEqualityComparer documentation to pre-implmented classes that override the function I don&#8217;t know.</p>
<p>But here&#8217;s one for string comparisons:</p>
<pre class="code">
StringComparer
</pre>
<p>This static class contains many different predefined IEqualityComparer instances to be used in functions like &#8220;Contains&#8221;.  Enjoy.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bee-eee.com/2009/04/14/c-finding-those-blasted-predefined-iequalitycomparer-classes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>c# Getting your machine&#8217;s IP addresses.</title>
		<link>http://blog.bee-eee.com/2009/03/17/c-getting-your-machines-ip-addresses/</link>
		<comments>http://blog.bee-eee.com/2009/03/17/c-getting-your-machines-ip-addresses/#comments</comments>
		<pubDate>Tue, 17 Mar 2009 15:35:30 +0000</pubDate>
		<dc:creator>brian</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[c# coding GUI]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[networking]]></category>

		<guid isPermaLink="false">http://blog.bee-eee.com/?p=69</guid>
		<description><![CDATA[Here is the simple way to get all of the IP addresses for you machine. This code filters out everything but IPv4 address, but to truly get everything just remove the if statement. string hostName = Dns.GetHostName(); var addrs = Dns.GetHostAddresses(hostName); bool hasIP = false; for (int i = 0; i < addrs.Length; i++) { [...]]]></description>
			<content:encoded><![CDATA[<p>Here is the simple way to get all of the IP addresses for you machine.  This code filters out everything but IPv4 address, but to truly get everything just remove the if statement.</p>
<pre class="code">
string hostName = Dns.GetHostName();
var addrs = Dns.GetHostAddresses(hostName);
bool hasIP = false;
for (int i = 0; i < addrs.Length; i++)
{
    IPAddress addr = addrs[i];
    if (addr.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
    {
        si.DataIP = addr.ToString();
        hasIP = true;
        break;
    }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.bee-eee.com/2009/03/17/c-getting-your-machines-ip-addresses/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MS SQL Delete all the data from the tables.</title>
		<link>http://blog.bee-eee.com/2008/11/21/ms-sql-delete-all-the-data-from-the-tables/</link>
		<comments>http://blog.bee-eee.com/2008/11/21/ms-sql-delete-all-the-data-from-the-tables/#comments</comments>
		<pubDate>Fri, 21 Nov 2008 18:24:45 +0000</pubDate>
		<dc:creator>brian</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[mmsql]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://blog.bee-eee.com/?p=54</guid>
		<description><![CDATA[Here&#8217;s a helpful, and perhaps dangerous, little tidbit of code for SQL Server 2005. It deletes all of the data from all of the tables. To be completely effective, the command may need to be run more than once because of foreign keys. Basically run it until there aren&#8217;t any errors. Then the db is [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a helpful, and perhaps dangerous, little tidbit of code for SQL Server 2005.  It deletes all of the data from all of the tables.  To be completely effective, the command may need to be run more than once because of foreign keys.  Basically run it until there aren&#8217;t any errors.  Then the db is clean and empty of all data.</p>
<p><code>exec sp_MSForeachTable "delete from ?"</code></p>
<p>the sp_MSForeachTable is a very useful system stored procedure.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bee-eee.com/2008/11/21/ms-sql-delete-all-the-data-from-the-tables/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>c# dynamically picking the search direction with linq</title>
		<link>http://blog.bee-eee.com/2008/09/30/c-dynamically-picking-the-search-direction-with-linq/</link>
		<comments>http://blog.bee-eee.com/2008/09/30/c-dynamically-picking-the-search-direction-with-linq/#comments</comments>
		<pubDate>Tue, 30 Sep 2008 20:31:10 +0000</pubDate>
		<dc:creator>brian</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[linq]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[coding]]></category>

		<guid isPermaLink="false">http://blog.bee-eee.com/2008/09/30/c-dynamically-picking-the-search-direction-with-linq/</guid>
		<description><![CDATA[I&#8217;ve recently been writing an application that builds a linq to sql query dynamically.  For instance: MyDataContext dc() = new MyDataContext; var query = dc.MyTables; query = query.Where( t=&#62;t.id &#62; 10); and so I want to order it by a certain column: query = query.OrderBy( t=&#62;t.id ) but the problem is the order direction isn&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve recently been writing an application that builds a linq to sql query dynamically.  For instance:</p>
<pre class="code">
MyDataContext dc() = new MyDataContext;
var query = dc.MyTables;
query = query.Where( t=&gt;t.id &gt; 10);</pre>
<p>and so I want to order it by a certain column:</p>
<pre class="code">
query = query.OrderBy( t=&gt;t.id )</pre>
<p>but the problem is the order direction isn&#8217;t know before hand so at first I was stuck with the following:</p>
<pre class="code">
if ( descending )
    query = query.OrderByDescending( t=&gt;t.id);
else
    query = query.OrderBy(t=&gt;t.id);</pre>
<p>Now if there is only a few possible columns to sort against it isn&#8217;t too bad.  But when you have 10 different possible columns it really makes a lot of extra work just to control to sort direction.  So I made a little helper class that allows the following.  It works with linq and linq to sql:</p>
<pre class="code">
query = query.OrderByAscDec( t=&gt;t.id, descending );</pre>
<p>here&#8217;s the static class that implments the OrderByAscDec function:</p>
<pre class="code">
static class VPLinqExtensions
{
	public static IOrderedQueryable&lt;TSource&gt; OrderByAscDes&lt;TSource, TKey&gt;(
		this IQueryable&lt;TSource&gt; source,
		System.Linq.Expressions.Expression&lt;Func&lt;TSource,
		TKey&gt;&gt; keySelector, bool IsDescending)
	{
		if (IsDescending)
			return source.OrderByDescending(keySelector);
		else
			return source.OrderBy(keySelector);
	}
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.bee-eee.com/2008/09/30/c-dynamically-picking-the-search-direction-with-linq/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>c# Reading the contents of a web page</title>
		<link>http://blog.bee-eee.com/2008/09/10/c-reading-the-contents-of-a-web-page/</link>
		<comments>http://blog.bee-eee.com/2008/09/10/c-reading-the-contents-of-a-web-page/#comments</comments>
		<pubDate>Wed, 10 Sep 2008 16:13:07 +0000</pubDate>
		<dc:creator>brian</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[coding]]></category>

		<guid isPermaLink="false">http://blog.bee-eee.com/2008/09/10/c-reading-the-contents-of-a-web-page/</guid>
		<description><![CDATA[Reading the contents of a web page can be very useful.  Here&#8217;s some code I&#8217;m developing to read the historical stock prices from http://finance.google.com string uri = "http://finance.google.com/finance/historical?cid=667226&#38;startdate=Sep+9%2C+2007&#38;enddate=Sep+10%2C+2008&#38;output=csv"; WebRequest request = WebRequest.Create(uri); WebResponse response = request.GetResponse(); var stream = response.GetResponseStream(); StreamReader reader = new StreamReader(stream, Encoding.GetEncoding("utf-8")); string page = reader.ReadToEnd(); There you go. Very simple [...]]]></description>
			<content:encoded><![CDATA[<p>Reading the contents of a web page can be very useful.  Here&#8217;s some code I&#8217;m developing to read the historical stock prices from http://finance.google.com</p>
<pre class="code">
string uri = "http://finance.google.com/finance/historical?cid=667226&amp;startdate=Sep+9%2C+2007&amp;enddate=Sep+10%2C+2008&amp;output=csv";
WebRequest request = WebRequest.Create(uri);
WebResponse response = request.GetResponse();
var stream = response.GetResponseStream();
StreamReader reader = new StreamReader(stream, Encoding.GetEncoding("utf-8"));
string page = reader.ReadToEnd();</pre>
<p>There you go.  Very simple isn&#8217;t it?  Just got to love .Net</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bee-eee.com/2008/09/10/c-reading-the-contents-of-a-web-page/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>c# timing functions</title>
		<link>http://blog.bee-eee.com/2008/06/12/c-timing-functions/</link>
		<comments>http://blog.bee-eee.com/2008/06/12/c-timing-functions/#comments</comments>
		<pubDate>Thu, 12 Jun 2008 15:25:29 +0000</pubDate>
		<dc:creator>brian</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[coding]]></category>

		<guid isPermaLink="false">http://blog.bee-eee.com/2008/06/12/c-timing-functions/</guid>
		<description><![CDATA[Here are some timing functions that come in the .Net framework.  I&#8217;ve used these for moderately accurate timing code &#8212; at least down to the millisecond level.  For any timing less than about 30 milliseconds these work much better than timer events piled on each other which tend to get inaccurate. int begin = System.Environment.TickCount [...]]]></description>
			<content:encoded><![CDATA[<p>Here are some timing functions that come in the .Net framework.  I&#8217;ve used these for moderately accurate timing code &#8212; at least down to the millisecond level.  For any timing less than about 30 milliseconds these work much better than timer events piled on each other which tend to get inaccurate.</p>
<pre class="code">
int begin = System.Environment.TickCount
... do something
int end = System.Environment.TickCount
int elapsed = end - begin;</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.bee-eee.com/2008/06/12/c-timing-functions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>c# getting a list of files from a directory</title>
		<link>http://blog.bee-eee.com/2008/06/04/c-getting-a-list-of-files-from-a-directory/</link>
		<comments>http://blog.bee-eee.com/2008/06/04/c-getting-a-list-of-files-from-a-directory/#comments</comments>
		<pubDate>Wed, 04 Jun 2008 17:21:40 +0000</pubDate>
		<dc:creator>brian</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[coding]]></category>

		<guid isPermaLink="false">http://blog.bee-eee.com/2008/06/04/c-getting-a-list-of-files-from-a-directory/</guid>
		<description><![CDATA[Here&#8217;s how to get an array of file descriptors (name and other information). System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(Program.DataDirectory); System.IO.FileInfo[] files = di.GetFiles("*.txt");]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s how to get an array of file descriptors (name and other information).</p>
<pre class="code">
System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(Program.DataDirectory);
System.IO.FileInfo[] files = di.GetFiles("*.txt");
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.bee-eee.com/2008/06/04/c-getting-a-list-of-files-from-a-directory/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>c# force uppercase lettering in a ComboBox</title>
		<link>http://blog.bee-eee.com/2008/04/28/c-force-uppercase-lettering-in-a-combobox/</link>
		<comments>http://blog.bee-eee.com/2008/04/28/c-force-uppercase-lettering-in-a-combobox/#comments</comments>
		<pubDate>Mon, 28 Apr 2008 22:50:36 +0000</pubDate>
		<dc:creator>brian</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[c# coding GUI]]></category>
		<category><![CDATA[coding]]></category>

		<guid isPermaLink="false">http://blog.bee-eee.com/2008/04/28/c-force-uppercase-lettering-in-a-combobox/</guid>
		<description><![CDATA[I recently changed from a TextEdit control to a ComboBox and was somewhat annoyed that there wasn&#8217;t a property that forced the input characters to all be uppercase.  So I dug around and came up with the following method using the KeyPress event. private void productNumber_KeyPress(object sender, KeyPressEventArgs e) { char c = e.KeyChar; // [...]]]></description>
			<content:encoded><![CDATA[<p>I recently changed from a TextEdit control to a ComboBox and was somewhat annoyed that there wasn&#8217;t a property that forced the input characters to all be uppercase.  So I dug around and came up with the following method using the KeyPress event.</p>
<pre class="code">
         private void productNumber_KeyPress(object sender, KeyPressEventArgs e)
        {
            char c = e.KeyChar;
            // make it uppercase only
            if (c &gt;= 'a' &amp;&amp; c &lt;= 'z')
            {
                int digit = (int)c;
                digit = digit - 'a' + 'A';
                e.KeyChar = Convert.ToChar(digit);
            }
        }</pre>
<p>When the event handler is called it gives you a chance to edit the hit character.  Just by changing e.KeyChar you change the actual input character.  This is a nifty trick to have under your belt.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bee-eee.com/2008/04/28/c-force-uppercase-lettering-in-a-combobox/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>c# getting rid of the jitter!</title>
		<link>http://blog.bee-eee.com/2008/04/18/c-getting-rid-of-the-jitter/</link>
		<comments>http://blog.bee-eee.com/2008/04/18/c-getting-rid-of-the-jitter/#comments</comments>
		<pubDate>Sat, 19 Apr 2008 03:58:03 +0000</pubDate>
		<dc:creator>brian</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[c# coding GUI]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[graphics]]></category>

		<guid isPermaLink="false">http://blog.bee-eee.com/2008/04/18/c-getting-rid-of-the-jitter/</guid>
		<description><![CDATA[I recently was getting greatly annoyed with some drawing code in my program.  I was drawing a photo that I could zoom and move around.  When I zoomed with the wheel though it would briefly draw the image in two positions.  The first position after it was zoomed, and the second position after it was [...]]]></description>
			<content:encoded><![CDATA[<p>I recently was getting greatly annoyed with some drawing code in my program.  I was drawing a photo that I could zoom and move around.  When I zoomed with the wheel though it would briefly draw the image in two positions.  The first position after it was zoomed, and the second position after it was re-centered on the screen.  Well this looked awful.  Not exactly professional looking.  So I tried a hundered different things.  I tried setting a bool variable in the control to tell the paint function not to draw.  No good.  The drawing was done with asynchronous messages.  Then I tried  BeginInvoke.  That didn&#8217;t work also.  I tried SuspendLayout and ResumeLayout functions of the Control class:  No good.  Finally I just used the Visible property which kind of worked, well I didn&#8217;t get the double picture, but my background was light color and the foreground dark, so there was still a bad looking flicker.  After a couple of hours I finally found the solution at: <a href="http://weblogs.asp.net/jdanforth/archive/2004/03/12/88458.aspx">http://weblogs.asp.net/jdanforth/archive/2004/03/12/88458.aspx</a>.  I worked on the example a little and boiled it down to two functions:  StopDrawing and StartDrawing.</p>
<p>The techinque basically turns of drawing and events to the object on the win32 level underneath .Net.  This is very handy and it worked very very well.  Here is the code.</p>
<pre class="code">
        using System.Runtime.InteropServices;
        private const int WM_SETREDRAW      = 0x000B;
        private const int WM_USER           = 0x400;
        private const int EM_GETEVENTMASK   = (WM_USER + 59);
        private const int EM_SETEVENTMASK   = (WM_USER + 69);

        [DllImport("user32", CharSet = CharSet.Auto)]
        private extern static IntPtr SendMessage(IntPtr hWnd, int msg, int wParam, IntPtr lParam);

        IntPtr eventMask = IntPtr.Zero;

        public void StopDrawing()
        {
            if (drawStopCount == 0)
            {
                // Stop redrawing:
                SendMessage(this.Handle, WM_SETREDRAW, 0, IntPtr.Zero);
                // Stop sending of events:
                eventMask = SendMessage(this.Handle, EM_GETEVENTMASK, 0, IntPtr.Zero);
            }
            drawStopCount++;
        }

        public void StartDrawing()
        {
            drawStopCount--;
            if (drawStopCount == 0)
            {
                // turn on events
                SendMessage(this.Handle, EM_SETEVENTMASK, 0, eventMask);

                // turn on redrawing
                SendMessage(this.Handle, WM_SETREDRAW, 1, IntPtr.Zero);

                Invalidate();
                Refresh();
            }
        }</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.bee-eee.com/2008/04/18/c-getting-rid-of-the-jitter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
