<?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"
	>

<channel>
	<title>Bee Eee Blog</title>
	<atom:link href="http://blog.bee-eee.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.bee-eee.com</link>
	<description>-- C# hints and tips</description>
	<pubDate>Fri, 31 Oct 2008 17:15:26 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.2</generator>
	<language>en</language>
			<item>
		<title>c# Property Grid - Getting a combo box</title>
		<link>http://blog.bee-eee.com/2008/10/31/c-property-grid-getting-a-combo-box/</link>
		<comments>http://blog.bee-eee.com/2008/10/31/c-property-grid-getting-a-combo-box/#comments</comments>
		<pubDate>Fri, 31 Oct 2008 17:15:26 +0000</pubDate>
		<dc:creator>brian</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.bee-eee.com/?p=52</guid>
		<description><![CDATA[You&#8217;d think getting a combox display into the property grid would be really simple to do since it&#8217;s used everywhere in Visual Studio 2008.  And although it isn&#8217;t horrible it isn&#8217;t exactly straight forward.  I found a couple of dead-ends, poorly explained, or difficult to find the pith of examples.  Finally I ran across this [...]]]></description>
			<content:encoded><![CDATA[<p>You&#8217;d think getting a combox display into the property grid would be really simple to do since it&#8217;s used everywhere in Visual Studio 2008.  And although it isn&#8217;t horrible it isn&#8217;t exactly straight forward.  I found a couple of dead-ends, poorly explained, or difficult to find the pith of examples.  Finally I ran across <a href="http://gaaton.blogspot.com/2007/11/how-to-add-combobox-to-propertygrid.html" target="_self">this </a>one at <a href="http://gaaton.blogspot.com/">http://gaaton.blogspot.com/</a> It&#8217;s nice and concise, easy to understand, and easy to adapt.  I&#8217;m going to put in my sample which essentially taken from gaaton.</p>
<pre class="code">
internal class ProtcolConverter : StringConverter
    {
        public override bool
            GetStandardValuesSupported(
            ITypeDescriptorContext context)
        {
            //True - means show a Combobox
            //and False for show a Modal
            return true;
        }

        public override bool
            GetStandardValuesExclusive(
            ITypeDescriptorContext context)
        {
            //False - a option to edit values
            //and True - set values to state readonly
            return true;
        }

        public override StandardValuesCollection
            GetStandardValues(
            ITypeDescriptorContext context)
        {
            return new StandardValuesCollection(
                new string[] { "net.tcp", "http" });
        }
    }
</pre>
<p>And finally the we need to attach the string converter to the property by the following.</p>
<pre class="code">
[TypeConverter(typeof(ProtcolConverter))]
public string ServiceProtocol
{
     get { return MediaServiceConfig.WCFProtocol; }
     set { MediaServiceConfig.WCFProtocol = value; }
}
</pre>
<p>Enjoy.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bee-eee.com/2008/10/31/c-property-grid-getting-a-combo-box/feed/</wfw:commentRss>
		</item>
		<item>
		<title>MS SQL tricks for uniqueidentifers or Guid and date time.</title>
		<link>http://blog.bee-eee.com/2008/10/29/ms-sql-tricks-for-uniqueidentifers-or-guid-and-date-time/</link>
		<comments>http://blog.bee-eee.com/2008/10/29/ms-sql-tricks-for-uniqueidentifers-or-guid-and-date-time/#comments</comments>
		<pubDate>Wed, 29 Oct 2008 20:12:38 +0000</pubDate>
		<dc:creator>brian</dc:creator>
		
		<category><![CDATA[mmsql]]></category>

		<guid isPermaLink="false">http://blog.bee-eee.com/?p=50</guid>
		<description><![CDATA[In MS SQL Server 2005 the following code is how to get a new uniqueidentifier, and the current date and time.
SELECT newid(),getdate()
Produces these results.
------------------------------------ -----------------------
125700F3-8FB8-496F-8EA4-35D9CB9E8415 2008-10-29 13:09:54.557
(1 row(s) affected)
]]></description>
			<content:encoded><![CDATA[<p>In MS SQL Server 2005 the following code is how to get a new uniqueidentifier, and the current date and time.</p>
<pre class="code">SELECT newid(),getdate()</pre>
<p>Produces these results.</p>
<pre class="code">------------------------------------ -----------------------
125700F3-8FB8-496F-8EA4-35D9CB9E8415 2008-10-29 13:09:54.557
(1 row(s) affected)</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.bee-eee.com/2008/10/29/ms-sql-tricks-for-uniqueidentifers-or-guid-and-date-time/feed/</wfw:commentRss>
		</item>
		<item>
		<title>c# linq to sql string comparisons</title>
		<link>http://blog.bee-eee.com/2008/10/27/c-linq-to-sql-string-comparisons/</link>
		<comments>http://blog.bee-eee.com/2008/10/27/c-linq-to-sql-string-comparisons/#comments</comments>
		<pubDate>Mon, 27 Oct 2008 20:21:02 +0000</pubDate>
		<dc:creator>brian</dc:creator>
		
		<category><![CDATA[.NET]]></category>

		<category><![CDATA[c#]]></category>

		<category><![CDATA[coding]]></category>

		<category><![CDATA[linq]]></category>

		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://blog.bee-eee.com/?p=48</guid>
		<description><![CDATA[There are four different string comparisons for handling string fields with linq to sql.  They are as follows:
The exact macth
DataContext dc = new DataContext(...)
var results =
  from row in dc.table
  where row.string_column == "Exact Match"
  select row;
Begins With:
DataContext dc = new DataContext(...)
var results =
  from row in dc.table
  where row.string_column.StartsWith("Ex")
 [...]]]></description>
			<content:encoded><![CDATA[<p>There are four different string comparisons for handling string fields with linq to sql.  They are as follows:</p>
<p><strong>The exact macth</strong></p>
<pre class="code">DataContext dc = new DataContext(...)
var results =
  from row in dc.table
  where row.string_column == "Exact Match"
  select row;</pre>
<p><strong>Begins With:</strong></p>
<pre class="code">DataContext dc = new DataContext(...)
var results =
  from row in dc.table
  where row.string_column.StartsWith("Ex")
  select row;</pre>
<p>produces an sql match string &#8220;Ex%&#8221;</p>
<p><strong>Contains</strong></p>
<pre class="code">DataContext dc = new DataContext(...)
var results =
  from row in dc.table
  where row.string_column.Contains("Ex")
  select row;</pre>
<p>Which is equivalent to &#8220;%Ex%&#8221;</p>
<p><strong>Ends With</strong></p>
<pre class="code">DataContext dc = new DataContext(...)
var results =
  from row in dc.table
  where row.string_column.EndsWith("Ex")
  select row;</pre>
<p>Which is equivalent to &#8220;%Ex&#8221;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bee-eee.com/2008/10/27/c-linq-to-sql-string-comparisons/feed/</wfw:commentRss>
		</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 know before hand so at first [...]]]></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>
		</item>
		<item>
		<title>c# non-blocking sockets</title>
		<link>http://blog.bee-eee.com/2008/09/15/c-non-blocking-sockets/</link>
		<comments>http://blog.bee-eee.com/2008/09/15/c-non-blocking-sockets/#comments</comments>
		<pubDate>Mon, 15 Sep 2008 17:13:43 +0000</pubDate>
		<dc:creator>brian</dc:creator>
		
		<category><![CDATA[.NET]]></category>

		<category><![CDATA[c#]]></category>

		<category><![CDATA[networking]]></category>

		<guid isPermaLink="false">http://blog.bee-eee.com/2008/09/15/c-non-blocking-sockets/</guid>
		<description><![CDATA[There doesn&#8217;t seem to be much written on blocking socket with c#.  So I&#8217;ll write a very short piece, and I&#8217;ll only concentrate on client sockets.
Creating a socket is easy here is how:

using System.Net.Sockets;

//...

// Creating a connection
Socket client;
client = new Socket( AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp );
client.Connect(hostName, port);
client.Blocking = false; // This needs to be done after [...]]]></description>
			<content:encoded><![CDATA[<p>There doesn&#8217;t seem to be much written on blocking socket with c#.  So I&#8217;ll write a very short piece, and I&#8217;ll only concentrate on client sockets.</p>
<p>Creating a socket is easy here is how:</p>
<pre class="code">
using System.Net.Sockets;

//...

// Creating a connection
Socket client;
client = new Socket( AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp );
client.Connect(hostName, port);
client.Blocking = false; // This needs to be done after Connect or it will error out.</pre>
<p>Here&#8217;s how to write data to the socket</p>
<pre class="code">
// Writing information to the socket
byte[] buffer = ASCIIEncoding.ASCII.GetBytes(messageText);
foreach (byte c in buffer)
{
	SocketError err = SocketError.WouldBlock;
	// need to try again if the socket would have blocked
	while ( err == SocketError.WouldBlock )
	{
		// this version of Send must be used or an exception would be thrown, which I feel is a pain
		// to deal with -- this way you can see handle the error appropriately.
		client.Send(buffer, 0, 1, SocketFlags.None, out err );
	}

	if ( err != SocketError.Success )
	{
		// handle error
		break;
	}
}</pre>
<p>And now code to read from a non-blocking socket</p>
<pre class="code">
// Reading from the socket
// this loop keeps going until there is a socket error or a '0' byte is read which
// in this example marks the end of the message
System.Text.StringBuilder message = new System.Text.StringBuilder();
while ( true )
{
	byte c = 0;
	int bytesRead;
	SocketError err;
	// read a character.
	bytesRead = client.Receive(buffer, 0, 1, SocketFlags.None, out err );
	// checking what happened
	if ( SocketError.Success == err )
	{
		// read a byte!  Let's process it
		if ( bytesRead &gt; 0 )
		{
			// found a null character -- in this case it makes the end of a message.
			if (c == 0)
			{
				// null terminated message received
				break;
			}
			else
				message.Append((char)c);
			}
		}
	}
	else if ( SocketError.WouldBlock != err )
	{
		break;
	}
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.bee-eee.com/2008/09/15/c-non-blocking-sockets/feed/</wfw:commentRss>
		</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 isn&#8217;t it?  Just got to [...]]]></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>
		</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
... do [...]]]></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>
		</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>
		</item>
		<item>
		<title>c# getting the application directory.</title>
		<link>http://blog.bee-eee.com/2008/06/04/c-getting-the-application-directory/</link>
		<comments>http://blog.bee-eee.com/2008/06/04/c-getting-the-application-directory/#comments</comments>
		<pubDate>Wed, 04 Jun 2008 16:39:24 +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-the-application-directory/</guid>
		<description><![CDATA[Getting the directory that the application is in at run-time is nice.  Here&#8217;s the code.

string appDir = AppDomain.CurrentDomain.BaseDirectory;

]]></description>
			<content:encoded><![CDATA[<p>Getting the directory that the application is in at run-time is nice.  Here&#8217;s the code.</p>
<pre class="code">
string appDir = AppDomain.CurrentDomain.BaseDirectory;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.bee-eee.com/2008/06/04/c-getting-the-application-directory/feed/</wfw:commentRss>
		</item>
		<item>
		<title>c# Mandelbrot fractal unleashed!</title>
		<link>http://blog.bee-eee.com/2008/05/15/c-mandelbrot-fractal-unleashed/</link>
		<comments>http://blog.bee-eee.com/2008/05/15/c-mandelbrot-fractal-unleashed/#comments</comments>
		<pubDate>Fri, 16 May 2008 03:17:28 +0000</pubDate>
		<dc:creator>brian</dc:creator>
		
		<category><![CDATA[.NET]]></category>

		<category><![CDATA[c#]]></category>

		<category><![CDATA[coding]]></category>

		<category><![CDATA[graphics]]></category>

		<category><![CDATA[fractals]]></category>

		<guid isPermaLink="false">http://blog.bee-eee.com/2008/05/15/c-mandelbrot-fractal-unleashed/</guid>
		<description><![CDATA[I remember the first time I saw the Mandelbrot set.  It was incredible!  After I had successfully programmed at it on my 8088 (a very old DOS computer).  I would wait 10 minutes at a time for a screen to pop up.  The detail was nothing short of amazing.  The swirls, the shapes, the colors.  [...]]]></description>
			<content:encoded><![CDATA[<p>I remember the first time I saw the Mandelbrot set.  It was incredible!  After I had successfully programmed at it on my 8088 (a very old DOS computer).  I would wait 10 minutes at a time for a screen to pop up.  The detail was nothing short of amazing.  The swirls, the shapes, the colors.  The neatest thing was the ability to zoom into it to reveal more and more and more detail.</p>
<p>Well it&#8217;s been many years and computers have improved a great deal as have the tools to program them.  So I wrote another Mandelbrot explorer.</p>
<p><a href="http://blog.bee-eee.com/wp-content/uploads/2008/05/madel.jpg" title="Mandelbrot Image"><img src="http://blog.bee-eee.com/wp-content/uploads/2008/05/madel.thumbnail.jpg" alt="Mandelbrot Image" /></a></p>
<p>What is the Mandelbrot set? Well&#8230;.  In short it is X<sub>n+1</sub> = X<sub>n</sub><sup>2</sup> + C iterated until the magnitude of X<sub>n</sub> is greater than 4 or the maximum number of iterations is met then the number of iterations is used as the color of the pixel.   X<sub>n</sub> is a complex number, C is another complex number where the x coordinate of the pixel defines the real part and the y coordinate defines the imaginary part of the number. The magnitude is defined as X<sup>2</sup> + Absolute Value of (X<sub>i</sub><sup>2</sup>).   Then this process is repeated for each pixel.  Holy smoke that is a mouthful!</p>
<p>Anyway take a peek at the code if you&#8217;d like and surely get the app and have fun exploring the Mandelbrot set.</p>
<p>To zoom in a spot just click on it.  The number is the number of iterations.  The more iterations the deeper the pattern goes (well until you run into percision problems).</p>
<p><a href="http://blog.bee-eee.com/wp-content/uploads/2008/05/mandelbrot.zip" title="Mandelbrot Executable">Mandelbrot Executable</a></p>
<p><a href="http://blog.bee-eee.com/wp-content/uploads/2008/05/mandelbrot-source-vs2008.zip" title="Mandelbrot source code.">Mandelbrot source code.</a></p>
<p>Have fun!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bee-eee.com/2008/05/15/c-mandelbrot-fractal-unleashed/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
