<?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>udayv . soundc &#187; C#</title>
	<atom:link href="http://www.soundc.de/blog/category/programming/c/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.soundc.de/blog</link>
	<description>Electronic Music, Programming</description>
	<lastBuildDate>Tue, 04 May 2010 14:36:39 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>XML-RPC for Silverlight updates</title>
		<link>http://www.soundc.de/blog/2009/03/01/xml-rpc-for-silverlight-updates/</link>
		<comments>http://www.soundc.de/blog/2009/03/01/xml-rpc-for-silverlight-updates/#comments</comments>
		<pubDate>Sun, 01 Mar 2009 04:51:49 +0000</pubDate>
		<dc:creator>verma</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[rpc]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[xmlrpc]]></category>

		<guid isPermaLink="false">http://www.soundc.de/blog/?p=162</guid>
		<description><![CDATA[I just finished uploading the source for the XmlRpc library for Silverlight.  You can access it at the google code page for xml-rpc for silverlight.  Its work in progress but I believe the library will mature with time. 
I have included some documentation on the Usage wiki page.
/
]]></description>
			<content:encoded><![CDATA[<p>I just finished uploading the source for the XmlRpc library for Silverlight.  You can access it at the google code page for <a href="http://code.google.com/p/xmlrpc-silverlight/">xml-rpc for silverlight</a>.  Its work in progress but I believe the library will mature with time. </p>
<p>I have included some documentation on the Usage wiki page.</p>
<p>/</p>
]]></content:encoded>
			<wfw:commentRss>http://www.soundc.de/blog/2009/03/01/xml-rpc-for-silverlight-updates/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>XML-RPC for Silverlight</title>
		<link>http://www.soundc.de/blog/2009/01/28/xml-rpc-for-silverlight/</link>
		<comments>http://www.soundc.de/blog/2009/01/28/xml-rpc-for-silverlight/#comments</comments>
		<pubDate>Tue, 27 Jan 2009 22:39:24 +0000</pubDate>
		<dc:creator>verma</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[rpc]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.soundc.de/blog/?p=151</guid>
		<description><![CDATA[I have been looking for a nice implementation of XML-RPC for silverlight for a while now.  There are a few good resources out there such as XML-RPC.NET, but they don&#8217;t really work on Silverlight.  
Silverlight is different, that it only has asynchronous network calls and you can&#8217;t really imitate sync calls, which makes [...]]]></description>
			<content:encoded><![CDATA[<p>I have been looking for a nice implementation of XML-RPC for silverlight for a while now.  There are a few good resources out there such as <a href="http://www.xml-rpc.net/">XML-RPC.NET</a>, but they don&#8217;t really work on Silverlight.  </p>
<p>Silverlight is different, that it only has asynchronous network calls and you can&#8217;t really imitate sync calls, which makes the use of a RPC a little weird.</p>
<p>I have written a small XML-RPC library for Silverlight.  Actually its just a single C# file which users can just drag and drop into their projects.  The library is still under development, presently I am hacking together a parser, making sure it works with the most common scenarios.</p>
<p>Here is what the usage of this library looks like.  You instantiate a service class, and then instantiate query requests as shown below:</p>
<pre class="brush: csharp;">
XmlRpcService service
            = new XmlRpcService (&quot;http://betty.userland.com/RPC2&quot;);
XmlRpcRequest req
            = new XmlRpcRequest (service, &quot;examples.getStateName&quot;,
                     new object [] { 10 });
req.XmlRpcCallCompleteHandler
            += new XmlRpcCallComplete (req_XmlRpcCallCompleteHandler);

req.Execute (null);
</pre>
<p>Once your call completes or some error occurs, your event handler is invoked (Here I am just assuming that the call succeeded):</p>
<pre class="brush: csharp;">
void req_XmlRpcCallCompleteHandler (XmlRpcResponse response, object userState) {
    string result = (string)response.TryCast (typeof (string));
    System.Diagnostics.Debug.WriteLine (&quot;Result: &quot; + result);
}
</pre>
<p>You try to cast the response into a string, if it cannot be casted you get back a null or the default value for value types.  TryCast is pretty powerful, you can declare a class and have TryCast map the returned struct (associative array) to that class.  E.g. lets say we have this fault class:</p>
<pre class="brush: csharp;">
public class Fault {
    public int FaultCode;
    public string FaultString;

    public override string  ToString() {
                 return &quot;Fault Code: &quot; + FaultCode.ToString ()
                     + &quot;, Fault String: &quot; + FaultString;
    }
}
</pre>
<p>You can use <i>TryCast</i> to map a fault response to this class.  Note that, the names of the members here actually match with those returned when a fault occurs (see <a href="http://www.xmlrpc.com/spec">XML-RPC spec</a>), case is not important though.  You can use your own classes to map with struct returned as XML-RPC responses, this should be pretty handy.  I will include more details when I actually release the library.  </p>
<p>So a more fault tolerant event handler would look something like this:</p>
<pre class="brush: csharp;">
Fault f = (Fault)response.TryCast (typeof (Fault));
if (f != null) {
    Debug.WriteLine (&quot;Fault occured: &quot; + f.ToString ());
    if (f.FaultCode == -1) {
        Debug.WriteLine (&quot;OMG! -1 ERROR!&quot;);
    }
}
else {
    string result = (string)response.TryCast (typeof (string));
    Debug.WriteLine (&quot;Result: &quot; + result);
}
</pre>
<p>I am still working on a few things with this library, I will post it up here as soon as I am done, I promise!</p>
<p>Stay tuned!</p>
<p>/</p>
]]></content:encoded>
			<wfw:commentRss>http://www.soundc.de/blog/2009/01/28/xml-rpc-for-silverlight/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Smarter Dictionaries in C#.Net</title>
		<link>http://www.soundc.de/blog/2008/08/05/smarter-dictionaries-in-cnet/</link>
		<comments>http://www.soundc.de/blog/2008/08/05/smarter-dictionaries-in-cnet/#comments</comments>
		<pubDate>Tue, 05 Aug 2008 04:38:46 +0000</pubDate>
		<dc:creator>verma</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[Dictionary]]></category>

		<guid isPermaLink="false">http://www.soundc.de/blog/?p=10</guid>
		<description><![CDATA[Alright, here we go.  After a long long long time I have decided to yet again try and maintain a blog.
The other day at work I was trying to use .NET&#8217;s Dictionary class to create a hierarchical structure which allows me to do something like this:

torqueInfo[eAvatarGender.male][eJointName.elbow][eJointDirection.extension]
	= new TorqueCurves(eAvatarGender.male, eJointName.elbow, eJointDirection.extension);

torqueInfo has been defined as:

Dictionary&#60;eAvatarGender, [...]]]></description>
			<content:encoded><![CDATA[<p>Alright, here we go.  After a long long long time I have decided to yet again try and maintain a blog.</p>
<p>The other day at work I was trying to use .NET&#8217;s <kbd>Dictionary</kbd> class to create a hierarchical structure which allows me to do something like this:</p>
<pre class="brush: csharp;">
torqueInfo[eAvatarGender.male][eJointName.elbow][eJointDirection.extension]
	= new TorqueCurves(eAvatarGender.male, eJointName.elbow, eJointDirection.extension);
</pre>
<p><kbd>torqueInfo</kbd> has been defined as:</p>
<pre class="brush: csharp;">
Dictionary&lt;eAvatarGender, Dictionary&lt;eJointName, Dictionary&lt;eJointDirection, TorqueCurves&gt;&gt;&gt; torqueInfo;
</pre>
<p>Using the dictionary object this way would help me reduce my coding clutter to just 3 look-ups instead of coding a 3 level conditional switch (one of the straightforward ways of doing it).  </p>
<p>The problem with this is that unlike C++ <kbd>std::map</kbd> objects, if a .NET dictionary doesn&#8217;t contain the specified key it throws an exception. </p>
<pre class="brush: csharp;">
Dictionary&lt;int, string&gt; keyVal = new Dictionary&lt;int, string&gt; ();
keyVal [5] = &quot;Hello&quot;;		// exception
keyVal.Add (5, &quot;Hello&quot;);	// OK
</pre>
<p>Filling up such a construct with an <kbd>Add</kbd> method could have easily turned into a nightmare.  To tackle this problem, I created my own little dictionary class which could handle unknown keys and allow the programmer to easily populate a complex construct like I mentioned above.  Here&#8217;s what the class looks like:</p>
<pre class="brush: csharp;">
public class SmarterDictionary&lt;TKey, TValue&gt; where TValue : new ()
{
    Dictionary&lt;TKey, TValue&gt; keyVal = new Dictionary&lt;TKey,TValue&gt; ();

    // access operator is all we need!
    public TValue this[TKey key] {
        get {
            if (!keyVal.ContainsKey(key))
                keyVal.Add(key, new TValue ());

            return keyVal[key];
        }
        set {
            keyVal[key] = value;
        }
    }
}
</pre>
<p>HTH</p>
]]></content:encoded>
			<wfw:commentRss>http://www.soundc.de/blog/2008/08/05/smarter-dictionaries-in-cnet/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

