<?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; .NET</title>
	<atom:link href="http://blog.bee-eee.com/category/net/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# Getting a nullable attribute to serialize to xml</title>
		<link>http://blog.bee-eee.com/2009/07/23/c-getting-a-nullable-attribute-to-serialize-to-xml/</link>
		<comments>http://blog.bee-eee.com/2009/07/23/c-getting-a-nullable-attribute-to-serialize-to-xml/#comments</comments>
		<pubDate>Thu, 23 Jul 2009 15:55:12 +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[linq]]></category>

		<guid isPermaLink="false">http://blog.bee-eee.com/?p=76</guid>
		<description><![CDATA[It isn&#8217;t straight forward to get a nullable field to serialize. Technically it isn&#8217;t supported. But I just discovered a way today. You see null strings are supported. The idea is to ignore the real nullable property while substituting the string version as follows: [XmlRoot("Comment")] public class Comment { [XmlIgnore] public DateTime? CommentTime { get; [...]]]></description>
			<content:encoded><![CDATA[<p>It isn&#8217;t straight forward to get a nullable field to serialize.  Technically it isn&#8217;t supported.  But I just discovered a way today.  You see null strings are supported.  The idea is to ignore the real nullable property while substituting the string version as follows:</p>
<pre class="code">
    [XmlRoot("Comment")]
    public class Comment
    {
        [XmlIgnore]
        public DateTime? CommentTime { get; set; }

        [XmlAttribute("CommentTime")]
        public string CommentTimeStr
        {
            get
            {
                return (CommentTime.HasValue) ? CommentTime.Value.ToString() : null;
            }

            set
            {
                if (string.IsNullOrEmpty(value))
                    CommentTime = null;
                else
                    CommentTime = DateTime.Parse(value);
            }
        }
  }
</pre>
<p>Now it can be serialized.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bee-eee.com/2009/07/23/c-getting-a-nullable-attribute-to-serialize-to-xml/feed/</wfw:commentRss>
		<slash:comments>5</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>c# setting caret position for a richedit control</title>
		<link>http://blog.bee-eee.com/2009/01/06/c-setting-caret-position-for-a-richedit-control/</link>
		<comments>http://blog.bee-eee.com/2009/01/06/c-setting-caret-position-for-a-richedit-control/#comments</comments>
		<pubDate>Tue, 06 Jan 2009 16:47:23 +0000</pubDate>
		<dc:creator>brian</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[c#]]></category>

		<guid isPermaLink="false">http://blog.bee-eee.com/?p=67</guid>
		<description><![CDATA[Here&#8217;s the code to set the position of the caret in a richedit control int position = 12; richedit1.Select( position, 0 ); richedit1.ScrollToCaret(); // if you want the position to be shown It&#8217;s that simple.]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s the code to set the position of the caret in a richedit control</p>
<pre class="code">
int position = 12;
richedit1.Select( position, 0 );
richedit1.ScrollToCaret(); // if you want the position to be shown
</pre>
<p>It&#8217;s that simple.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bee-eee.com/2009/01/06/c-setting-caret-position-for-a-richedit-control/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>c# logging linq to sql</title>
		<link>http://blog.bee-eee.com/2009/01/01/c-logging-linq-to-sql/</link>
		<comments>http://blog.bee-eee.com/2009/01/01/c-logging-linq-to-sql/#comments</comments>
		<pubDate>Thu, 01 Jan 2009 19:04:33 +0000</pubDate>
		<dc:creator>brian</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[linq]]></category>
		<category><![CDATA[mmsql]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://blog.bee-eee.com/?p=62</guid>
		<description><![CDATA[I&#8217;ve often been frustrated by the sql that linq produces.  Usually it&#8217;s really good, but occasionally it produced monstrosities.   The hard part is getting at the sql that&#8217;s produced by a function.  Hovering over the statement in the idea is a real pain so instead I created the following class that dumps the sql to [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve often been frustrated by the sql that linq produces.  Usually it&#8217;s really good, but occasionally it produced monstrosities.   The hard part is getting at the sql that&#8217;s produced by a function.  Hovering over the statement in the idea is a real pain so instead I created the following class that dumps the sql to a file</p>
<pre class="code">
public class DCLogger : IDisposable
    {
        private StringWriter writer;

        public DCLogger(System.Data.Linq.DataContext dc)
        {
            writer = new StringWriter();
            dc.Log = writer;
        }

        #region IDisposable Members

        public void Dispose()
        {
            writer.Flush();
            System.IO.File.WriteAllText( "c:\\temp\\sql.log", writer.ToString() );
        }

        #endregion
    }
</pre>
<p>To use it just create it passing it you data context.  The results are written to the file when it&#8217;s disposed.  </p>
<pre class="code">
  using( DCLogger( dc ) )
  {
    // ... some linq statement that executes
  }
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.bee-eee.com/2009/01/01/c-logging-linq-to-sql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</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 [...]]]></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>
		<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# 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 = [...]]]></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>
		<slash:comments>2</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>
	</channel>
</rss>
