<?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>source code bean &#187; C#</title>
	<atom:link href="http://sourcecodebean.com/archives/category/c/feed" rel="self" type="application/rss+xml" />
	<link>http://sourcecodebean.com</link>
	<description>thoughts and ideas from a .net developer</description>
	<lastBuildDate>Sat, 26 May 2012 09:45:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Deploying your ASP.NET MVC3 site on Mono</title>
		<link>http://sourcecodebean.com/archives/deploying-your-asp-net-mvc3-site-on-mono/1589</link>
		<comments>http://sourcecodebean.com/archives/deploying-your-asp-net-mvc3-site-on-mono/1589#comments</comments>
		<pubDate>Sat, 10 Mar 2012 14:26:49 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Mono]]></category>

		<guid isPermaLink="false">http://sourcecodebean.com/?p=1589</guid>
		<description><![CDATA[In this blog post I am going to show you how easy it is to create a new ASP.NET MVC site and deploy it on Linux/Mono. Step 1 &#8211; Create project Create a new ASP.NET MVC 3 project. Compile and run it. Step 2 &#8211; Add assemblies needed by Mono Add references: System.Web.WebPages System.Web.WebPages.Deployment System.Web.WebPages.Razor [...]]]></description>
			<content:encoded><![CDATA[<p>In this blog post I am going to show you how easy it is to create a new ASP.NET MVC site and deploy it on Linux/Mono. </p>
<p><strong>Step 1 &#8211; Create project</strong><br />
Create a new ASP.NET MVC 3 project. Compile and run it.</p>
<p><a href="http://sourcecodebean.com/wp-content/uploads/2012/03/CreateProject.png"><img src="http://sourcecodebean.com/wp-content/uploads/2012/03/CreateProject.png" alt="" title="CreateProject" width="700" class="aligncenter size-full wp-image-1595" /></a></p>
<p><span id="more-1589"></span><br />
<a href="http://sourcecodebean.com/wp-content/uploads/2012/03/2-CreateProject.png"><img src="http://sourcecodebean.com/wp-content/uploads/2012/03/2-CreateProject.png" alt="" title="2 CreateProject" width="400" class="aligncenter size-full wp-image-1596" /></a></p>
<p><a href="http://sourcecodebean.com/wp-content/uploads/2012/03/3-Up-and-running.png"><img src="http://sourcecodebean.com/wp-content/uploads/2012/03/3-Up-and-running.png" alt="" title="3 Up and running" width="700" class="aligncenter size-full wp-image-1597" /></a></p>
<p><strong>Step 2 &#8211; Add assemblies needed by Mono</strong><br />
Add references:<br />
System.Web.WebPages<br />
System.Web.WebPages.Deployment<br />
System.Web.WebPages.Razor</p>
<p><strong>Step 3 &#8211; Copy local</strong><br />
Make sure to set &#8220;Copy Local&#8221; to True for all of the following assemblies:<br />
System.Web.Helpers<br />
System.Web.Mvc<br />
System.Web.Razor (C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\Assemblies\System.Web.Razor.dll)<br />
System.Web.Routing<br />
System.Web.WebPages<br />
System.Web.WebPages.Deployment<br />
System.Web.WebPages.Razor</p>
<p><a href="http://sourcecodebean.com/wp-content/uploads/2012/03/4.-Copy-local.png"><img src="http://sourcecodebean.com/wp-content/uploads/2012/03/4.-Copy-local.png" alt="" title="4. Copy local" width="435" height="629" class="aligncenter size-full wp-image-1598" /></a></p>
<p>Remove Entity Framework and other unnecessary assemblies. </p>
<p><strong>Step 4 &#8211; Publish your site</strong><br />
Publish it to a directory and copy it to your Linux server</p>
<p><strong>Step 5 &#8211; Get latest Mono and compile it from source</strong><br />
I run Ubuntu 11.10 on my server. Ubuntu has Mono 2.10.6 in its repository, which is quite new, but Mono is moving so fast so I recommend getting the latest version and compiling it from source. The latest version at the time of writing is 2.10.8. <a href="http://www.integratedwebsystems.com/2011/08/install-mono-2-10-3-on-ubuntu-using-bash-script/">Nathan Bridgewater has created a script</a> to simplify this process, if you are running Ubuntu, this is what you will need to run to install Mono:</p>
<pre>
mkdir mono-2.10
cd mono-2.10
wget --no-check-certificate https://github.com/nathanb/iws-snippets/raw/master/mono-install-scripts/ubuntu/install_mono-2.10.sh
chmod 755 install_mono-2.10.sh
./install_mono-2.10.sh
</pre>
<p>It will take a while to compile it, so now is the time to go grab a cup of coffee. </p>
<p><strong>Step 6 &#8211; Run your site with xsp4</strong><br />
Mono have a development web server called xsp4, the first thing we are going to do is to run our site in xsp4 to make sure it works. Mono has been installed to /opt, but does not exist in our PATH, so before we can run Mono we need to setup the mono enviroment variables. To do that I found a script somewhere on the internets, monoenv.sh:</p>
<pre>
MONO_PREFIX=/opt/mono-2.10
export DYLD_LIBRARY_FALLBACK_PATH=/lib:
export LD_LIBRARY_PATH=/lib:/opt/mono-2.10/lib:
export C_INCLUDE_PATH=/include:/include
export ACLOCAL_PATH=/share/aclocal
export PKG_CONFIG_PATH=/lib/pkgconfig:/lib/pkgconfig
export PATH=/bin:/opt/mono-2.10/bin:$PATH
</pre>
<p>At your bash prompt type: source monoenv.sh</p>
<p>Now cd into the directory where you have your published web site and run xsp4. </p>
<p><a href="http://sourcecodebean.com/wp-content/uploads/2012/03/6.-Running-on-mono.png"><img src="http://sourcecodebean.com/wp-content/uploads/2012/03/6.-Running-on-mono.png" alt="" title="6. Running on mono" width="655" height="564" class="aligncenter size-full wp-image-1600" /></a></p>
<p>Now your MVC site should be up running on Mono! </p>
<p>In my next blog post I will cover how to configure your site to run using Nginx and the fastcgi-mono server.</p>
]]></content:encoded>
			<wfw:commentRss>http://sourcecodebean.com/archives/deploying-your-asp-net-mvc3-site-on-mono/1589/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>MongoDB, C# and Mono</title>
		<link>http://sourcecodebean.com/archives/mongodb-c-and-mono/1408</link>
		<comments>http://sourcecodebean.com/archives/mongodb-c-and-mono/1408#comments</comments>
		<pubDate>Wed, 11 Jan 2012 18:53:48 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Mono]]></category>
		<category><![CDATA[NoSQL]]></category>

		<guid isPermaLink="false">http://sourcecodebean.com/?p=1408</guid>
		<description><![CDATA[MongoDB is one of the many free open source NoSQL databases that exist today. I wanted to try out how well the official drivers for C# worked when using Mono. On the MongoDB web site they have pre built binaries of MongoDB for almost every platform, i grabbed the 64 bit binary for OSX. No [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.mongodb.org/">MongoDB</a> is one of the many free open source NoSQL databases that exist today. I wanted to try out how well the official drivers for C# worked when using Mono. </p>
<p>On the MongoDB web site they have pre built binaries of MongoDB for almost every platform, i grabbed the 64 bit binary for OSX. No installation is required, just unzip the file and run the &#8220;mongod&#8221; binary from the directory. There is also a binary called &#8220;mongo&#8221;, this is the <a href="http://www.mongodb.org/display/DOCS/Overview+-+The+MongoDB+Interactive+Shell">mongo interactive shell</a> which is very useful. </p>
<p>The C# drivers are available, both in binary form and as source, from the <a href="http://www.mongodb.org/display/DOCS/CSharp+Language+Center">C# language center</a>. To get started I fired up MonoDevelop 2.8 running on Mono 2.10.8:</p>
<p><a href="http://sourcecodebean.com/wp-content/uploads/2012/01/monodevelop.png"><img src="http://sourcecodebean.com/wp-content/uploads/2012/01/monodevelop-300x187.png" alt="" title="monodevelop" width="300" height="187" class="aligncenter size-medium wp-image-1451" /></a><br />
<a href="http://sourcecodebean.com/wp-content/uploads/2012/01/edit_references.png"><img src="http://sourcecodebean.com/wp-content/uploads/2012/01/edit_references-300x187.png" alt="" title="edit_references" width="300" height="187" class="aligncenter size-medium wp-image-1449" /></a><br />
<a href="http://sourcecodebean.com/wp-content/uploads/2012/01/add_references.png"><img src="http://sourcecodebean.com/wp-content/uploads/2012/01/add_references-300x201.png" alt="" title="add_references" width="300" height="201" class="aligncenter size-medium wp-image-1450" /></a></p>
<p>MonoDevelop has matured a lot since I used it the first time. It is still not as good as Visual Studio, but it is getting there. What takes most time to get used to is the totally different set of shortcuts, and the lack of all ReSharper magic. </p>
<p>Let me break down a simple console application example on how to use MongoDB using the official driver from 10gen: <span id="more-1408"></span></p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">using System;</div>
</li>
<li class="li1">
<div class="de1">using System.<span class="me1">Collections</span>.<span class="me1">Generic</span>;</div>
</li>
<li class="li2">
<div class="de2">using System.<span class="me1">Linq</span>;</div>
</li>
<li class="li1">
<div class="de1">using MongoDB.<span class="me1">Bson</span>;</div>
</li>
<li class="li1">
<div class="de1">using MongoDB.<span class="me1">Driver</span>;</div>
</li>
<li class="li1">
<div class="de1">using MongoDB.<span class="me1">Driver</span>.<span class="me1">Builders</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">namespace MongoDbTest</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span> </div>
</li>
<li class="li1">
<div class="de1">&nbsp; public class Article</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; public MongoDB.<span class="me1">Bson</span>.<span class="me1">ObjectId</span> id <span class="br0">&#123;</span> get; set; <span class="br0">&#125;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; public <span class="kw4">string</span> title <span class="br0">&#123;</span> get; set; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; public <span class="kw4">string</span> status <span class="br0">&#123;</span> get; set; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; public <span class="kw4">string</span><span class="br0">&#91;</span><span class="br0">&#93;</span> tags <span class="br0">&#123;</span> get; set; <span class="br0">&#125;</span>&nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; class MainClass</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; public <span class="kw4">static</span> <span class="kw4">void</span> Main <span class="br0">&#40;</span><span class="kw4">string</span><span class="br0">&#91;</span><span class="br0">&#93;</span> args<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; <span class="co1">// Connect to the database and get a colleciton</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; MongoServer server = MongoServer.<span class="me1">Create</span> <span class="br0">&#40;</span><span class="st0">&quot;mongodb://localhost&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; MongoDatabase db = server.<span class="me1">GetDatabase</span> <span class="br0">&#40;</span><span class="st0">&quot;mongodb-tutorial&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="co1">// Get an article collection</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; MongoCollection&lt;BsonDocument&gt; articles = db.<span class="me1">GetCollection</span>&lt;BsonDocument&gt; <span class="br0">&#40;</span><span class="st0">&quot;articles&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="co1">// Empty the collection (so all runs of this program will result in the same output)</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; articles.<span class="me1">RemoveAll</span> <span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="co1">//&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="co1">// Create two articles</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="co1">//</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; articles.<span class="me1">Save</span> <span class="br0">&#40;</span>new BsonDocument</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><span class="st0">&quot;title&quot;</span>, <span class="st0">&quot;A MongoDB article&quot;</span><span class="br0">&#125;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><span class="st0">&quot;status&quot;</span>, <span class="st0">&quot;published&quot;</span><span class="br0">&#125;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><span class="st0">&quot;tags&quot;</span>, new BsonArray <span class="br0">&#123;</span> <span class="st0">&quot;c#&quot;</span>, <span class="st0">&quot;mongodb&quot;</span> <span class="br0">&#125;</span><span class="br0">&#125;</span>&nbsp; &nbsp; &nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; articles.<span class="me1">Save</span> <span class="br0">&#40;</span>new BsonDocument</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><span class="st0">&quot;title&quot;</span>, <span class="st0">&quot;A Mono article&quot;</span><span class="br0">&#125;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><span class="st0">&quot;status&quot;</span>, <span class="st0">&quot;draft&quot;</span><span class="br0">&#125;</span>,</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><span class="st0">&quot;tags&quot;</span>, new BsonArray <span class="br0">&#123;</span> <span class="st0">&quot;c#&quot;</span>, <span class="st0">&quot;mono&quot;</span> <span class="br0">&#125;</span><span class="br0">&#125;</span>&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><span class="br0">&#41;</span>;&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<blockquote><p>If you type this in the MongoDB shell, you will see that the following articles are stored in the database:</p>
<pre>
> db.articles.find()
        {
          "_id" : ObjectId("4f097f8e74b5b343b97f56a7"),
          "title" : "A MongoDB article",
          "status" : "published",
          "tags" : [ "c#", "mongodb" ]
        }

        {
          "_id" : ObjectId("4f097f8e74b5b343b97f56a8"),
          "title" :
          "A Mono article",
          "status" : "draft",
          "tags" : [ "c#", "mono" ]
       }
</pre>
</blockquote>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;<span class="co1">// Find and print the first article</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; BsonDocument firstArticle = articles.<span class="me1">FindOne</span> <span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; PrintArticle <span class="br0">&#40;</span> <span class="co1">// Access the properties using indexing and then casting using the .As*</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; firstArticle<span class="br0">&#91;</span><span class="st0">&quot;_id&quot;</span><span class="br0">&#93;</span>.<span class="me1">AsObjectId</span>, </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; firstArticle<span class="br0">&#91;</span><span class="st0">&quot;title&quot;</span><span class="br0">&#93;</span>.<span class="me1">AsString</span>, </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; firstArticle<span class="br0">&#91;</span><span class="st0">&quot;status&quot;</span><span class="br0">&#93;</span>.<span class="me1">AsString</span>, </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#40;</span>firstArticle<span class="br0">&#91;</span><span class="st0">&quot;tags&quot;</span><span class="br0">&#93;</span>.<span class="me1">AsBsonArray</span><span class="br0">&#41;</span>.<span class="me1">Select</span> <span class="br0">&#40;</span>x =&gt; x.<span class="me1">AsString</span><span class="br0">&#41;</span><span class="br0">&#41;</span>; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="co1">//</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="co1">// Typed collections&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="co1">//</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="co1">// Using indexing and the .As* operations is not that convenient. A better way</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="co1">// is to use a typed collection. Earlier we defined a Article class, lets use it:</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; MongoCollection&lt;Article&gt; typedArticles = db.<span class="me1">GetCollection</span>&lt;Article&gt; <span class="br0">&#40;</span><span class="st0">&quot;articles&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; Article typedArticle = typedArticles.<span class="me1">FindOneAs</span>&lt;Article&gt; <span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; PrintArticle <span class="br0">&#40;</span>typedArticle.<span class="me1">id</span>, typedArticle.<span class="me1">title</span>, </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; typedArticle.<span class="me1">status</span>, typedArticle.<span class="me1">tags</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="co1">// Save a typed article</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; typedArticles.<span class="me1">Save</span> <span class="br0">&#40;</span>new Article <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; title = <span class="st0">&quot;An article about MonoDevelop&quot;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; status = <span class="st0">&quot;published&quot;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tags = new <span class="br0">&#91;</span><span class="br0">&#93;</span> <span class="br0">&#123;</span><span class="st0">&quot;c#&quot;</span>, <span class="st0">&quot;mono&quot;</span>, <span class="st0">&quot;mono-develop&quot;</span><span class="br0">&#125;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="co1">// </span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="co1">// Querying</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="co1">// </span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="co1">// Find article with status draft</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; Article draftArticle = typedArticles</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; .<span class="me1">FindOneAs</span>&lt;Article&gt; <span class="br0">&#40;</span>Query.<span class="me1">EQ</span> <span class="br0">&#40;</span><span class="st0">&quot;status&quot;</span>, <span class="st0">&quot;draft&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; PrintArticle <span class="br0">&#40;</span>draftArticle.<span class="me1">id</span>, draftArticle.<span class="me1">title</span>, </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; draftArticle.<span class="me1">status</span>, draftArticle.<span class="me1">tags</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="co1">// </span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; <span class="co1">// Updating</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="co1">// </span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="co1">// Lets update the draft article and set status published</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; Console.<span class="me1">WriteLine</span> <span class="br0">&#40;</span><span class="st0">&quot;Nr of published articles before update:&quot;</span> </div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+ typedArticles.<span class="me1">Find</span> <span class="br0">&#40;</span>Query.<span class="me1">EQ</span> <span class="br0">&#40;</span><span class="st0">&quot;status&quot;</span>, <span class="st0">&quot;published&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>.<span class="me1">Count</span> <span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; typedArticles.<span class="me1">Update</span> <span class="br0">&#40;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; new QueryDocument <span class="br0">&#123;</span> <span class="br0">&#123;</span> <span class="st0">&quot;_id&quot;</span>, draftArticle.<span class="me1">id</span> <span class="br0">&#125;</span> <span class="br0">&#125;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; new UpdateDocument <span class="br0">&#123;</span> <span class="br0">&#123;</span> <span class="st0">&quot;$set&quot;</span>, new BsonDocument <span class="br0">&#40;</span><span class="st0">&quot;status&quot;</span>, <span class="st0">&quot;published&quot;</span><span class="br0">&#41;</span> <span class="br0">&#125;</span> </div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// $set is atomic</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; Console.<span class="me1">WriteLine</span> <span class="br0">&#40;</span><span class="st0">&quot;Nr of pubhlished articles after update:&quot;</span> </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+ typedArticles.<span class="me1">Find</span> <span class="br0">&#40;</span>Query.<span class="me1">EQ</span> <span class="br0">&#40;</span><span class="st0">&quot;status&quot;</span>, <span class="st0">&quot;published&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>.<span class="me1">Count</span> <span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="co1">// </span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="co1">// MapReduce</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="co1">// </span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="co1">// This will count the number of times a tag has been used by using MapReduce</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; var map =</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;function() {&quot;</span> +</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot; &nbsp; &nbsp;this.tags.forEach(function(t) {&quot;</span> + <span class="co1">// Iterate all the tags and </span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot; &nbsp; &nbsp; &nbsp; &nbsp;emit(t, { count : 1 }); &quot;</span> + &nbsp; &nbsp;<span class="co1">// emit the tag name and initial count </span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot; &nbsp; &nbsp;})&quot;</span> +</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;}&quot;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; var reduce =</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;function(key, emits) {&quot;</span> + <span class="co1">// Reduce by tag name and summarize the result</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot; &nbsp; &nbsp;total = 0;&quot;</span> +</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot; &nbsp; &nbsp;for (var i in emits) {&quot;</span> +</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot; &nbsp; &nbsp; &nbsp; &nbsp;total += emits[i].count;&quot;</span> +</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot; &nbsp; &nbsp;}&quot;</span> +</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot; &nbsp; &nbsp;return { count : total };&quot;</span> +</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;}&quot;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; Console.<span class="me1">WriteLine</span> <span class="br0">&#40;</span><span class="st0">&quot;MapReduce result:&quot;</span><span class="br0">&#41;</span>;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; var mr = typedArticles.<span class="me1">MapReduce</span> <span class="br0">&#40;</span>map, reduce<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; foreach <span class="br0">&#40;</span>var document in mr.<span class="me1">GetResults</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; Console.<span class="me1">WriteLine</span> <span class="br0">&#40;</span>document.<span class="me1">ToJson</span> <span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; public <span class="kw4">static</span> <span class="kw4">void</span> PrintArticle <span class="br0">&#40;</span>ObjectId id, <span class="kw4">string</span> title, </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="kw4">string</span> status, IEnumerable&lt;string&gt; tags<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; Console.<span class="me1">WriteLine</span> <span class="br0">&#40;</span><span class="st0">&quot;id: &quot;</span> + id + <span class="st0">&quot;, title: &quot;</span> + title<span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; Console.<span class="me1">WriteLine</span> <span class="br0">&#40;</span><span class="st0">&quot;- tags: &quot;</span> + <span class="kw4">string</span>.<span class="me1">Join</span> <span class="br0">&#40;</span><span class="st0">&quot;, &quot;</span>, tags<span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p>Output from the program:</p>
<blockquote>
<p>id: 4f0989fc74b5b3458ae38105, title: A MongoDB article<br />
- tags: c#, mongodb<br />
id: 4f0989fc74b5b3458ae38105, title: A MongoDB article<br />
- tags: c#, mongodb<br />
id: 4f0989fc74b5b3458ae38106, title: A Mono article<br />
- tags: c#, mono<br />
Nr of pubhlished articles before update:2<br />
Nr of pubhlished articles after update:3<br />
MapReduce result:<br />
{ &#8220;_id&#8221; : &#8220;c#&#8221;, &#8220;value&#8221; : { &#8220;count&#8221; : 3.0 } }<br />
{ &#8220;_id&#8221; : &#8220;mongodb&#8221;, &#8220;value&#8221; : { &#8220;count&#8221; : 1.0 } }<br />
{ &#8220;_id&#8221; : &#8220;mono&#8221;, &#8220;value&#8221; : { &#8220;count&#8221; : 2.0 } }<br />
{ &#8220;_id&#8221; : &#8220;mono-develop&#8221;, &#8220;value&#8221; : { &#8220;count&#8221; : 1.0 } }
</p></blockquote>
<p>Using the C# driver for MongoDB, is as you can see, very straight forward. Usually when I run applications on Mono I make sure to build all libraries using the Mono compiler, to make sure the Microsoft compiler have not used any optimizations that is not supported under Mono (I have run into this issue in the past). However, in this case the .NET binaries on the MongoDB site seems to work just fine under Mono. I also downloaded the MongoDB C# driver source and build them using MonoDevelop without any problems. </p>
<p>One improvement I would like to see is LINQ support in the driver. It would be so much more convenient to be able to use LINQ and strongly typed objects to query the database or create MapReduce-functions.</p>
]]></content:encoded>
			<wfw:commentRss>http://sourcecodebean.com/archives/mongodb-c-and-mono/1408/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>String interning in C#</title>
		<link>http://sourcecodebean.com/archives/string-interning-in-c/1367</link>
		<comments>http://sourcecodebean.com/archives/string-interning-in-c/1367#comments</comments>
		<pubDate>Wed, 07 Dec 2011 11:15:33 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://sourcecodebean.com/?p=1367</guid>
		<description><![CDATA[Last week a coworker sent me an interesting piece of code: &#160; const string a = &#34;&#34;; const string b = &#34;&#34;; const string c = &#34;hello&#34;; const string d = &#34;hello&#34;; &#160; Console.WriteLine&#40;ReferenceEquals&#40;string.Empty, string.Empty&#41; &#160; ? &#34;Not so surprising…&#34; &#160; : &#34;Oh, the humanity!&#34;&#41;; &#160; Console.WriteLine&#40;ReferenceEquals&#40;a, string.Empty&#41; &#160; ? &#34;But I thought string was [...]]]></description>
			<content:encoded><![CDATA[<p>Last week a coworker sent me an interesting piece of code:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">const</span> <span class="kw4">string</span> a = <span class="st0">&quot;&quot;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">const</span> <span class="kw4">string</span> b = <span class="st0">&quot;&quot;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">const</span> <span class="kw4">string</span> c = <span class="st0">&quot;hello&quot;</span>;</div>
</li>
<li class="li2">
<div class="de2"><span class="kw4">const</span> <span class="kw4">string</span> d = <span class="st0">&quot;hello&quot;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">Console.<span class="me1">WriteLine</span><span class="br0">&#40;</span>ReferenceEquals<span class="br0">&#40;</span><span class="kw4">string</span>.<span class="me1">Empty</span>, <span class="kw4">string</span>.<span class="me1">Empty</span><span class="br0">&#41;</span> </div>
</li>
<li class="li1">
<div class="de1">&nbsp; ? <span class="st0">&quot;Not so surprising…&quot;</span> </div>
</li>
<li class="li1">
<div class="de1">&nbsp; : <span class="st0">&quot;Oh, the humanity!&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">Console.<span class="me1">WriteLine</span><span class="br0">&#40;</span>ReferenceEquals<span class="br0">&#40;</span>a, <span class="kw4">string</span>.<span class="me1">Empty</span><span class="br0">&#41;</span> </div>
</li>
<li class="li1">
<div class="de1">&nbsp; ? <span class="st0">&quot;But I thought string was a reference type!&quot;</span> </div>
</li>
<li class="li1">
<div class="de1">&nbsp; : <span class="st0">&quot;Seems fair…&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">Console.<span class="me1">WriteLine</span><span class="br0">&#40;</span>ReferenceEquals<span class="br0">&#40;</span>a, b<span class="br0">&#41;</span> </div>
</li>
<li class="li1">
<div class="de1">&nbsp; ? <span class="st0">&quot; But I thought string was a reference type!&quot;</span> </div>
</li>
<li class="li1">
<div class="de1">&nbsp; : <span class="st0">&quot; Seems fair…&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">Console.<span class="me1">WriteLine</span><span class="br0">&#40;</span>ReferenceEquals<span class="br0">&#40;</span>c, d<span class="br0">&#41;</span> </div>
</li>
<li class="li2">
<div class="de2">&nbsp; ? <span class="st0">&quot; But I thought string was a reference type!&quot;</span> </div>
</li>
<li class="li1">
<div class="de1">&nbsp; : <span class="st0">&quot; Seems fair…&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p>Running the program will, maybe a bit surprising, produce:</p>
<blockquote><p>Not so surprising…<br />
But I thought string was a reference type!<br />
But I thought string was a reference type!<br />
But I thought string was a reference type!</p></blockquote>
<p>The reason to this is what is called <em>String interning</em>. The CLR basically holds a hashmap of all the strings in the program (edit: string literals), one entry per unique string. So two identical strings will always have the same reference even though they are defined in different places. String interning is mainly used to speed up string comparisons (no need to check char by char if they are identical, if they have the same reference they are equal), but also to reduce the memory footprint of the application. </p>
<p>Read more about string interning:<br />
<a href="http://aspadvice.com/blogs/from_net_geeks_desk/archive/2008/12/25/String-Interning-in-C_2300_.aspx">http://aspadvice.com/blogs/from_net_geeks_desk/archive/2008/12/25/String-Interning-in-C_2300_.aspx</a><br />
<a href="http://en.wikipedia.org/wiki/String_interning">http://en.wikipedia.org/wiki/String_interning</a></p>
]]></content:encoded>
			<wfw:commentRss>http://sourcecodebean.com/archives/string-interning-in-c/1367/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Updated version of SignalRChat</title>
		<link>http://sourcecodebean.com/archives/updated-version-of-signalrchat/1315</link>
		<comments>http://sourcecodebean.com/archives/updated-version-of-signalrchat/1315#comments</comments>
		<pubDate>Fri, 07 Oct 2011 08:10:55 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://sourcecodebean.com/?p=1315</guid>
		<description><![CDATA[Yesterday I uploaded a slightly updated version of the test application I have built using SignalR. Besides from looking much better, it now uses the high level Hubs API (instead of the connection API) that SignalR provides. You find it here: http://signalrchat.apphb.com/ And you can find the source on GitHub: http://github.com/moberg/SignalRChat]]></description>
			<content:encoded><![CDATA[<p>Yesterday I uploaded a slightly updated version of the test application I have built using SignalR. Besides from looking much better, it now uses the high level Hubs API (instead of the connection API) that SignalR provides. </p>
<p>You find it here: <a href="http://signalrchat.apphb.com/">http://signalrchat.apphb.com/</a></p>
<p>And you can find the source on GitHub: <a href="http://github.com/moberg/SignalRChat">http://github.com/moberg/SignalRChat</a></p>
]]></content:encoded>
			<wfw:commentRss>http://sourcecodebean.com/archives/updated-version-of-signalrchat/1315/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Reference types are always passed by value in C#</title>
		<link>http://sourcecodebean.com/archives/reference-types-are-always-passed-by-value-in-c/1123</link>
		<comments>http://sourcecodebean.com/archives/reference-types-are-always-passed-by-value-in-c/1123#comments</comments>
		<pubDate>Mon, 02 May 2011 06:05:00 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://sourcecodebean.com/?p=1123</guid>
		<description><![CDATA[Last week i had a discussion with a friend about C# and passing parameters to methods. My friend asked why it is possible to use the &#8216;ref&#8217; keyword for a reference type in C# when passing it to a method, he was under the impression that reference types are passed by reference to methods. This [...]]]></description>
			<content:encoded><![CDATA[<p>Last week i had a discussion with a friend about C# and passing parameters to methods. My friend asked why it is possible to use the &#8216;ref&#8217; keyword for a reference type in C# when passing it to a method, he was under the impression that reference types are passed by reference to methods. This seems to be a quite common misunderstanding about C#, to make it clear:</p>
<blockquote><p>Reference types are always passed to methods <strong>by value</strong> (unless you use the &#8216;ref&#8217; keyword)</p></blockquote>
<p><span id="more-1123"></span></p>
<p>What happens when you call a method with a reference type as parameter is that the value of the reference (the pointer, an address to pointing to the referenced object) is passed to the method (by value). What this means is that you can not modify the original reference, but you can modify the object it is referencing (pointing to).</p>
<p>By using the &#8216;ref&#8217; keyword you will pass the address of the reference to the method, which means that you can modify its value. </p>
<p>This is a short example illustrating this (remember, in C#, a string is a reference type):</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">class Program</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw4">static</span> <span class="kw4">void</span> Main<span class="br0">&#40;</span><span class="kw4">string</span><span class="br0">&#91;</span><span class="br0">&#93;</span> args<span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw4">string</span> s = <span class="st0">&quot;orig value&quot;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; Console.<span class="me1">WriteLine</span><span class="br0">&#40;</span><span class="st0">&quot;Orig value: &quot;</span> + s<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; MyFunc1<span class="br0">&#40;</span>s<span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; Console.<span class="me1">WriteLine</span><span class="br0">&#40;</span><span class="st0">&quot;After MyFunc1: &quot;</span> + s<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; MyFunc2<span class="br0">&#40;</span>ref s<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; Console.<span class="me1">WriteLine</span><span class="br0">&#40;</span><span class="st0">&quot;After MyFunc2: &quot;</span> + s<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; public <span class="kw4">static</span> <span class="kw4">void</span> MyFunc1<span class="br0">&#40;</span><span class="kw4">string</span> s<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; s = <span class="st0">&quot;new value 1&quot;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; public <span class="kw4">static</span> <span class="kw4">void</span> MyFunc2<span class="br0">&#40;</span>ref <span class="kw4">string</span> s<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; s = <span class="st0">&quot;new value 2&quot;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li2">
<div class="de2"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p>Output:<br />
Orig value: orig value<br />
After MyFunc1: orig value<br />
After MyFunc2: new value 2</p>
]]></content:encoded>
			<wfw:commentRss>http://sourcecodebean.com/archives/reference-types-are-always-passed-by-value-in-c/1123/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>A simple image sprite generator in C#</title>
		<link>http://sourcecodebean.com/archives/a-simple-image-sprite-generator-in-c-sharp/1105</link>
		<comments>http://sourcecodebean.com/archives/a-simple-image-sprite-generator-in-c-sharp/1105#comments</comments>
		<pubDate>Mon, 18 Apr 2011 20:17:01 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://sourcecodebean.com/?p=1105</guid>
		<description><![CDATA[Last week I posted the source code to a small program I wrote in Java to merge images into a sprite. This week I present the same application but in C#, pretty much translated line by line using System; using System.Drawing; using System.Drawing.Imaging; using System.IO; using System.Linq; &#160; namespace NSpriteGenerator &#123; &#160; &#160; class Program [...]]]></description>
			<content:encoded><![CDATA[<p>Last week I <a href="http://sourcecodebean.com/archives/a-simple-image-sprite-generator-in-java/1065">posted the source code to a small program</a> I wrote in Java to merge images into a sprite. This week I present the same application but in C#, pretty much translated line by line <img src='http://sourcecodebean.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">using System;</div>
</li>
<li class="li1">
<div class="de1">using System.<span class="me1">Drawing</span>;</div>
</li>
<li class="li1">
<div class="de1">using System.<span class="me1">Drawing</span>.<span class="me1">Imaging</span>;</div>
</li>
<li class="li1">
<div class="de1">using System.<span class="me1">IO</span>;</div>
</li>
<li class="li2">
<div class="de2">using System.<span class="me1">Linq</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">namespace NSpriteGenerator</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; class Program</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw4">static</span> <span class="kw4">void</span> Main<span class="br0">&#40;</span><span class="kw4">string</span><span class="br0">&#91;</span><span class="br0">&#93;</span> args<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>args.<span class="me1">Length</span> != <span class="nu0">2</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.<span class="me1">WriteLine</span><span class="br0">&#40;</span><span class="st0">&quot;Usage: NSpriteGenerator {path to images} {output file}&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var imagePath = args<span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var outputFile = args<span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var imageFolder = new DirectoryInfo<span class="br0">&#40;</span>imagePath<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// Read images</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var imageList = imageFolder.<span class="me1">GetFiles</span><span class="br0">&#40;</span><span class="st0">&quot;*.png&quot;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .<span class="me1">Select</span><span class="br0">&#40;</span>file =&gt; Image.<span class="me1">FromFile</span><span class="br0">&#40;</span>file.<span class="me1">FullName</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// Find max width and total height</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var maxWidth = <span class="nu0">0</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var totalHeight = <span class="nu0">0</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; foreach<span class="br0">&#40;</span>var image in imageList<span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; totalHeight += image.<span class="me1">Height</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>image.<span class="me1">Width</span> &gt; maxWidth<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; maxWidth = image.<span class="me1">Width</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.<span class="me1">WriteLine</span><span class="br0">&#40;</span><span class="kw4">string</span>.<span class="me1">Format</span><span class="br0">&#40;</span><span class="st0">&quot;Number of images: {0}, total height: {1}px, width: {2}&quot;</span>, imageList.<span class="me1">Count</span><span class="br0">&#40;</span><span class="br0">&#41;</span>, totalHeight, maxWidth<span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// Create the actual sprite</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var currentY = <span class="nu0">0</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; using <span class="br0">&#40;</span>var bitmap = new Bitmap<span class="br0">&#40;</span>maxWidth, totalHeight<span class="br0">&#41;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; using <span class="br0">&#40;</span>var canvas = Graphics.<span class="me1">FromImage</span><span class="br0">&#40;</span>bitmap<span class="br0">&#41;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; foreach <span class="br0">&#40;</span>var image in imageList<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; canvas.<span class="me1">DrawImage</span><span class="br0">&#40;</span>image, <span class="nu0">0</span>, currentY<span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; currentY += image.<span class="me1">Height</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; canvas.<span class="me1">Save</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.<span class="me1">WriteLine</span><span class="br0">&#40;</span><span class="st0">&quot;Writing sprite: &quot;</span>+ outputFile<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bitmap.<span class="me1">Save</span><span class="br0">&#40;</span>outputFile, ImageFormat.<span class="me1">Png</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li2">
<div class="de2"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p>Output from a run:</p>
<blockquote><p><code><br />
PS C:\dev\NSpriteGenerator> .\NSpriteGenerator.exe C:\temp\gfx c:\temp\sprite.png<br />
Number of images: 10, total height: 640px, width: 34<br />
Writing sprite: c:\temp\sprite.png<br />
</code></p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://sourcecodebean.com/archives/a-simple-image-sprite-generator-in-c-sharp/1105/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AppHarbor &#8211; Heroku for .NET?</title>
		<link>http://sourcecodebean.com/archives/appharbor-heroku-for-net/987</link>
		<comments>http://sourcecodebean.com/archives/appharbor-heroku-for-net/987#comments</comments>
		<pubDate>Wed, 06 Apr 2011 20:24:31 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://sourcecodebean.com/?p=987</guid>
		<description><![CDATA[I have been reading about this new startup that offers a service called AppHarbor. It seems very much as the same idea as Heroku for Ruby, but for .NET. The basic idea is that you deploy your code by pushing your code onto the server using Git, the server then builds, runs unit tests and [...]]]></description>
			<content:encoded><![CDATA[<p>I have been reading about this new startup that offers a service called AppHarbor. It seems very much as the same idea as <a href="http://heroku.com/">Heroku for Ruby</a>, but for .NET. The basic idea is that you deploy your code by pushing your code onto the server using Git, the server then builds, runs unit tests and deploys your application. Super simple!</p>
<p>When I first read about AppHarbor I got the impression that is was running ontop of Microsoft Azure, which turned out to be all wrong. AppHarbor is running in the Amazon Cloud on EC2 instances. When it comes to databases AppHarbor provides access to MySQL and MSSQL. Interestingly they recommend users to use MySQL:</p>
<blockquote><p><a href="http://blog.appharbor.com/2011/01/12/mysql-support">&#8220;we expect to be able to offer MySQL on faster hardware and with more redundancy than SQL Server at the same price point. If you are planning to build an app on top of AppHarbor and have the option, we recommend you go with MySQL.&#8221;</a></p></blockquote>
<p>Another interesting choice is that they have chosen <a href="http://support.appharbor.com/kb/getting-started/information-about-our-load-balancer">Nginx as their proxy/load balancer</a>.</p>
<p>Ok, let me show you how easy it is to create a simple ASP.NET MVC 3 application and deploy it on AppHarbour <span id="more-987"></span> The first step is to go to <a href="http://appharbor.com">appharbor.com</a> and register an account. Once created you will be able to create your first app:</p>
<p><a href="http://sourcecodebean.com/wp-content/uploads/2011/03/1.png"><img class="aligncenter size-full wp-image-995" title="1" src="http://sourcecodebean.com/wp-content/uploads/2011/03/1.png" alt="" width="600" /></a></p>
<p>Give your application and press create. You have done all the configuring you need to do at AppHarbor.</p>
<p><a href="http://sourcecodebean.com/wp-content/uploads/2011/03/2.png"><img class="aligncenter size-full wp-image-996" title="2" src="http://sourcecodebean.com/wp-content/uploads/2011/03/2.png" alt="" width="600" /></a></p>
<p>Lets create a MVC 3 project with unit tests:</p>
<p><a href="http://sourcecodebean.com/wp-content/uploads/2011/03/3.png"><img class="aligncenter size-full wp-image-997" title="3" src="http://sourcecodebean.com/wp-content/uploads/2011/03/3.png" alt="" width="600" /></a><br />
<a href="http://sourcecodebean.com/wp-content/uploads/2011/03/4.png"><img class="aligncenter size-full wp-image-998" title="4" src="http://sourcecodebean.com/wp-content/uploads/2011/03/4.png" alt="" width="600" /></a></p>
<p>Make sure your project builds and that the tests passes. Also make sure you have Git installed, if not you can fetch it from <a href="http://code.google.com/p/msysgit/downloads/list">here</a>. Now open a shell and cd into the folder where you created your application.</p>
<p>First we need to configure git with your name, the email you used to register at AppHarbor and last the git postBuffer size:</p>
<blockquote><p><code>PS C:\dev\appharbor\MyCoolApp&gt; git config --global user.name SourceCodeBean<br />
PS C:\dev\appharbor\MyCoolApp&gt; git config --global user.email mail@sourcecodebean.com<br />
PS C:\dev\appharbor\MyCoolApp&gt; git config --global http.postBuffer 52428800</code></p></blockquote>
<p>After this we initiate the git repository:</p>
<blockquote><p><code>PS C:\dev\appharbor\MyCoolApp&gt; git init<br />
PS C:\dev\appharbor\MyCoolApp&gt; git add .<br />
PS C:\dev\appharbor\MyCoolApp&gt; git commit -m "initial commit"</code></p></blockquote>
<p>And when this is done we add AppHarbor as a remote repository:</p>
<blockquote><p><code>PS C:\dev\appharbor\MyCoolApp&gt; git remote add appharbor https://moberg@appharbor.com/mycoolapp-1.git</code></p></blockquote>
<p>We are now set to push our code onto AppHarbor. To push it just type:</p>
<blockquote><p><code>PS C:\dev\appharbor\MyCoolApp&gt; git push appharbor master</code></p></blockquote>
<p>We should now be able to see the project building:</p>
<p><a href="http://sourcecodebean.com/wp-content/uploads/2011/03/7.png"><img class="aligncenter size-full wp-image-1012" title="7" src="http://sourcecodebean.com/wp-content/uploads/2011/03/7.png" alt="" width="600" /></a></p>
<p>Hopefully it built successfully. A problem I ran into was that I had ASP.NET MVC 3 RC installed and AppHarbor had the RTM version installed, this caused my first attempt to build my project to fail. After upgrading my local version and fixing the project I pushed a new version that built without problems.</p>
<p><a href="http://sourcecodebean.com/wp-content/uploads/2011/03/8.png"><img class="aligncenter size-full wp-image-1013" title="8" src="http://sourcecodebean.com/wp-content/uploads/2011/03/8.png" alt="" width="600" /></a></p>
<p>We can now browse to the site (yay! that was way easier than setting up IIS manually):</p>
<p><a href="http://sourcecodebean.com/wp-content/uploads/2011/03/9.png"><img class="aligncenter size-full wp-image-1015" title="9" src="http://sourcecodebean.com/wp-content/uploads/2011/03/9.png" alt="" width="600" /></a></p>
<h3><strong>Failing tests</strong></h3>
<p>Ok, lets change something in our application that will make a test fail:</p>
<p><a href="http://sourcecodebean.com/wp-content/uploads/2011/03/10.png"><img class="aligncenter size-full wp-image-1014" title="10" src="http://sourcecodebean.com/wp-content/uploads/2011/03/10.png" alt="" width="553" /></a></p>
<p>Now we are going to be bad and not run our unit tests before commiting and pushing the code</p>
<blockquote><p><code>PS C:\dev\appharbor\MyCoolApp&gt; git commit -a -m "a failing test"<br />
PS C:\dev\appharbor\MyCoolApp&gt; git push appharbor master</code></p></blockquote>
<p>.. and we are building again</p>
<p><a href="http://sourcecodebean.com/wp-content/uploads/2011/03/11.png"><img class="aligncenter size-full wp-image-1016" title="11" src="http://sourcecodebean.com/wp-content/uploads/2011/03/11.png" alt="" width="600" /></a></p>
<p>Woot! The build has failed!</p>
<p><a href="http://sourcecodebean.com/wp-content/uploads/2011/03/12.png"><img class="aligncenter size-full wp-image-1017" title="12" src="http://sourcecodebean.com/wp-content/uploads/2011/03/12.png" alt="" width="600" /></a></p>
<p>We can easily see that it is the test that verifies the text on the start page that has failed</p>
<p><a href="http://sourcecodebean.com/wp-content/uploads/2011/03/13.png"><img class="aligncenter size-full wp-image-1018" title="13" src="http://sourcecodebean.com/wp-content/uploads/2011/03/13.png" alt="" width="600" /></a></p>
<p>Ok, lets fix it!</p>
<p><a href="http://sourcecodebean.com/wp-content/uploads/2011/03/14small.png"><img class="aligncenter size-full wp-image-1020" title="14small" src="http://sourcecodebean.com/wp-content/uploads/2011/03/14small.png" alt="" height="212" /></a></p>
<p>Commit and push it again. And wait for the build to complete.</p>
<p><a href="http://sourcecodebean.com/wp-content/uploads/2011/03/15.png"><img class="aligncenter size-full wp-image-1021" title="15" src="http://sourcecodebean.com/wp-content/uploads/2011/03/15.png" alt="" width="600" /></a></p>
<p>Yay! Our new version built successfully!</p>
<p><a href="http://sourcecodebean.com/wp-content/uploads/2011/03/16.png"><img class="aligncenter size-full wp-image-1022" title="16" src="http://sourcecodebean.com/wp-content/uploads/2011/03/16.png" alt="" width="600" /></a></p>
<p>Lets check it out:</p>
<p><a href="http://sourcecodebean.com/wp-content/uploads/2011/03/17.png"><img class="aligncenter size-full wp-image-1023" title="17" src="http://sourcecodebean.com/wp-content/uploads/2011/03/17.png" alt="" width="600" /></a></p>
<h3><strong>Rolling back to a previous version</strong></h3>
<p>Being able to rollback an update is sometimes necessary and AppHarbor makes it ridiculously simple, all you need to do is to press the &#8220;Deploy&#8221; link next to an old version. Clicking it will build and deploy the selected version.</p>
<p><a href="http://sourcecodebean.com/wp-content/uploads/2011/03/18.png"><img class="aligncenter size-full wp-image-1024" title="18" src="http://sourcecodebean.com/wp-content/uploads/2011/03/18.png" alt="" width="600" /></a></p>
<p>We can now see that it is the first version that is active</p>
<p><a href="http://sourcecodebean.com/wp-content/uploads/2011/03/19.png"><img class="aligncenter size-full wp-image-1025" title="19" src="http://sourcecodebean.com/wp-content/uploads/2011/03/19.png" alt="" width="600" /></a></p>
<p>I love the idea behind AppHarbor, this is really how sites should be deployed! However, using AppHarbor also means giving up some control over your environment. It will be interesting to see how they handle, for example, upgrades between different versions of IIS, installation of service packs, etc. Two features i miss is the ability to run background jobs and a distributed cache to use, but hopefully it will be coming to AppHarbor. AppHarbor still a very young startup, and so far what I have seen is really impressive!</p>
]]></content:encoded>
			<wfw:commentRss>http://sourcecodebean.com/archives/appharbor-heroku-for-net/987/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>MVC 3 RTM Install Error (after upgrading to VS2010 SP1)</title>
		<link>http://sourcecodebean.com/archives/mvc-3-rtm-install-error-after-upgrading-to-vs2010-sp1/977</link>
		<comments>http://sourcecodebean.com/archives/mvc-3-rtm-install-error-after-upgrading-to-vs2010-sp1/977#comments</comments>
		<pubDate>Thu, 24 Mar 2011 18:28:54 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://sourcecodebean.com/?p=977</guid>
		<description><![CDATA[Yesterday I installed Visual Studio 2010 SP1 on my home computer. After the installation I wanted to upgrade MVC3 to the RTM version (I had the RC version installed), so i uninstalled the RC and downloaded the new version. The installation came half way, then stopped, in the log file i found this: Installation failed [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday I installed Visual Studio 2010 SP1 on my home computer. After the installation I wanted to upgrade MVC3 to the RTM version (I had the RC version installed), so i uninstalled the RC and downloaded the new version. The installation came half way, then stopped, in the log file i found this:</p>
<p><strong><em>Installation failed with error code: (0&#215;80070643)</em></strong></p>
<p>Not very helpful, but at least something to google. Then I found <a href="http://blog.mjjames.co.uk/2010/12/mvc-3-rc2-install-error-0x80070643.html">this</a> blog post. The author describes pretty much the same issue that I had, so I did what he suggested, unpacked the installer using 7-Zip and installed the MSI packages in the following order:</p>
<ol>
<li>1. aspnetwebpages.msi</li>
<li>2. aspnetwebpagesvs2010tools.msi</li>
<li>3. aspnetmvc3.msi</li>
<li>4. aspnetmvc3vs2010tools.msi</li>
<li>5. nuget.msi</li>
</ol>
<p>This happily installed MVC3 without complaining. Thanks Michael! </p>
]]></content:encoded>
			<wfw:commentRss>http://sourcecodebean.com/archives/mvc-3-rtm-install-error-after-upgrading-to-vs2010-sp1/977/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>The must have tools for C# development</title>
		<link>http://sourcecodebean.com/archives/the-must-have-tools-for-c-development/922</link>
		<comments>http://sourcecodebean.com/archives/the-must-have-tools-for-c-development/922#comments</comments>
		<pubDate>Tue, 08 Mar 2011 07:00:01 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://sourcecodebean.com/?p=922</guid>
		<description><![CDATA[Visual Studio 2010 I don&#8217;t think Visual Studio needs an introduction. VS 2010 brought us .NET 4.0 that contains a lot of new goodies! ReSharper ReSharper is the absolut must have for Visual Studio. It provides very improved navigation and search, refactoring, code generation, code cleanup and unit testing. I have gotten so used to [...]]]></description>
			<content:encoded><![CDATA[<h3><a href="http://www.microsoft.com/visualstudio/" rel="nofollow">Visual Studio 2010</a></h3>
<p>I don&#8217;t think Visual Studio needs an introduction. VS 2010 brought us .NET 4.0 that contains a lot of new goodies!  <br/><br/></p>
<h3><a href="http://www.jetbrains.com/resharper/" rel="nofollow">ReSharper</a></h3>
<p>ReSharper is the absolut must have for Visual Studio. It provides very improved navigation and search, refactoring, code generation, code cleanup and unit testing. I have gotten so used to having ReSharper installed so today I have a really hard time using Visual Studio without it.</p>
<p><strong>Some useful shortcuts</strong></p>
<ul>
<li>Ctrl+T : Go to type</li>
<li>Ctrl+Shift-T :  Go to file</li>
<li>Alt-Ins: Generate code (constructors, properties, implementing/overriding members)</li>
<li>Alt+Enter : Show available quick-fixes and context actions</li>
<li>Ctrl+Space : Symbol Code Completion</li>
<li>Ctrl+Alt+Space : Smart Code Completion</li>
<li>Shift+F12 : Find usages</li>
<li>Ctrl+Shift+R : Refactor this</li>
<li>Ctrl+R+R : Rename this</li>
<li>Ctrl+R+M: Extract method</li>
<li>Ctrl+R+V : Introduce variable</li>
<li>Ctrl+R+F : Introduce field </li>
<li>Ctrl+R+P : Introduce parameter</li>
<li>Alt+Shift+L : Locate in Solution Explore</li>
</li>
<p><br/></p>
<h3><a href="http://visualstudiogallery.msdn.microsoft.com/e5f41ad9-4edc-4912-bca3-91147db95b99/" rel="nofollow" >PowerCommands for Visual Studio 2010</a></h3>
<p>PowerCommands 10.0 is a set of useful extensions for the Visual Studio 2010 adding additional functionality to various areas Visual Studio. This is some of the commands I find must useful: </p>
<ul>
<li>Copy References</li>
<li>Paste References</li>
<li>Copy As Project Reference</li>
<li>Edit Project File</li>
<li>Open Containing Folder</li>
<li>Open Command Prompt Here</li>
<li>Unload Projects</li>
<li>Reload Projects</li>
</ul>
<p><br/></p>
<h3><a href="http://">Visual Studio 2010 &#8211; Productivity Power Tools</a></h3>
<p>Productivity Power Tools from the Microsoft Visual Studio team contains a lot of great extensions</p>
<ul>
<li>Very much improved dialog for add reference</li>
<li>Solution Naigator &#8211; a enhanced  Solution Explorer</li>
<li>Improved tab system for editor</li>
<li>Highlight current line (isn&#8217;t it weird that VS is missing this feature?)</li>
</ul>
<p>One annoying &#8216;feature&#8217; is the triple click to navigate to source, never got it to work properly so I disabled it. Some shortcuts also colide with ReSharper so some tweaking is needed to make it work perfectly.</p>
]]></content:encoded>
			<wfw:commentRss>http://sourcecodebean.com/archives/the-must-have-tools-for-c-development/922/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Thoughts on the Nokia / Windows Phone 7 deal</title>
		<link>http://sourcecodebean.com/archives/thoughts-on-the-nokia-windows-phone-7-deal/902</link>
		<comments>http://sourcecodebean.com/archives/thoughts-on-the-nokia-windows-phone-7-deal/902#comments</comments>
		<pubDate>Tue, 01 Mar 2011 07:28:21 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Mobile]]></category>

		<guid isPermaLink="false">http://sourcecodebean.com/?p=902</guid>
		<description><![CDATA[For the last week the news that Nokia has chosen Windows Phone 7 as their main operating system for all their new smart phones has been all over the news. A lot of people are very upset and say that Nokia should have gone with Android instead, or that they should have invested more in [...]]]></description>
			<content:encoded><![CDATA[<p>For the last week the news that Nokia has chosen Windows Phone 7 as their main operating system for all their new smart phones has been all over the news. A lot of people are very upset and say that Nokia should have gone with Android instead, or that they should have invested more in their own linux os Meego. Personally, looking at the options Nokia had, I think this is might be the best move Nokia could have done. Let me explain why.</p>
<p>For years Nokia has been struggling keeping Symbian alive. Symbian is an old operating system and has well served it purpose in millions of Nokia phones. However, during the last few years Nokia has totally failed on innovating, pretty much every other vendor now have smart phones running Andriod that offers more features and a better user experience then what Nokia can offer. Nokia needed to make a drastic change and the choices at this time were not that many.</p>
<ul>
<li>Meego</li>
<li>Android</li>
<li>Windows Phone 7</li>
</ul>
<p>Meego is Nokias in house developed linux based operating system. The vision behind Meego is great, but development has been too slow. From what I have seen of Meego it is a great operating system if you want to customize and geek around with your phone, but it is not yet ready for prime time. <span id="more-902"></span>Another problem with Meego is that it is lacking an ecosystem of applications and developers (such as App store for IPhone or Android Market). Placing the bet on Meego would have been extremely risky and Nokia knows this. </p>
<p>Android seemed like the most obvious choice for Nokia. This is what most other vendors are offering and there is a big ecosystem around Android. The problem with it is Nokias limited way of differentiating themselves, they do not just want to become another &#8220;Android vendor&#8221;. Sure there are several ways they could have differentiated themselves on Android, just like HTC and Samsung are trying to do, but it seems like this was not enough for Nokia. </p>
<p>Windows Phone 7 was released at MWC in 2010 and is a totally new operating system from Microsoft. It is based on Windows Embedded Compact 7 with a new UI layer called Metro. It does not inherit anything from the horrible mess that was Windows Mobile 6.  The deal Nokia made with Microsoft gives Nokia &#8216;special privileges&#8217; to WP7, that other manufactures do not get. It is not clear yet exactly what this means, but what is clear is that this will make Nokia <strong>the main WP7 vendor</strong> on the market, clearly better than being just another Android vendor. </p>
<p>So will it be successful? Time will tell, but Microsoft has put a lot of money into WP7 and will not let it fail. At the same time Nokia has a reach that no other cell phone vendor has (they are still the by far biggest manufacturer of phones in the world), so if they are able to successfully build an application ecosystem around WP7 I think it will be a success and we will get a mobile space with three main players, Apple iOS, Android and WP7. Competition is good and vendors need other choices than Android for their phones (iOS is apple only, so in a way it does not play the same game).</p>
<p>For C# developers, such as my self, i think getting full backing from Nokia is good news. I would love to develop applications on the Windows Phone 7 platform. From what I have seen from the tools it integrates very well with Visual Studio and seems to be a lot of fun to work with. Maybe now is the time to start learning it?</p>
]]></content:encoded>
			<wfw:commentRss>http://sourcecodebean.com/archives/thoughts-on-the-nokia-windows-phone-7-deal/902/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced

Served from: sourcecodebean.com @ 2012-05-30 05:54:52 -->
