<?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>Suddenelfilio.net &#187; .net</title>
	<atom:link href="http://www.suddenelfilio.net/category/programming/net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.suddenelfilio.net</link>
	<description>Passionate about software development</description>
	<lastBuildDate>Mon, 19 Dec 2011 12:07:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>IIS 7.x and HttpResponse.Headers</title>
		<link>http://www.suddenelfilio.net/2011/07/15/iis-7-x-and-httpresponse-headers/</link>
		<comments>http://www.suddenelfilio.net/2011/07/15/iis-7-x-and-httpresponse-headers/#comments</comments>
		<pubDate>Fri, 15 Jul 2011 15:40:28 +0000</pubDate>
		<dc:creator>suddenelfilio</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[Asp.net]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Web Services]]></category>
		<category><![CDATA[HTTP Handlers]]></category>
		<category><![CDATA[HTTP Headers]]></category>
		<category><![CDATA[IIS]]></category>
		<category><![CDATA[Web services]]></category>

		<guid isPermaLink="false">http://www.suddenelfilio.net/2011/07/15/iis-7-x-and-httpresponse-headers/</guid>
		<description><![CDATA[Today I was debugging some application I wrote that was written with an application pool’s mode set to Integrated mode in mind. One of my colleagues told me I needed to test it running in an application pool with its mode set to Classic. And guess what? Boom… it blew up in my face! After [...]]]></description>
			<content:encoded><![CDATA[<p>Today I was debugging some application I wrote that was written with an application pool’s mode set to <strong>Integrated </strong>mode in mind. One of my colleagues told me I needed to test it running in an application pool with its mode set to <strong>Classic. </strong></p>
<p>And guess what? Boom… it blew up in my face! After cursing around a bit I discovered in my log files the following message:</p>
<blockquote><p>ERROR    An Exception was thrown:System.PlatformNotSupportedException: This operation requires IIS integrated pipeline mode.<br />
at System.Web.HttpResponse.get_Headers()</p></blockquote>
<p>The defect piece of code was this:</p>
<pre class="brush: csharp; title: ; toolbar: true; wrap-lines: true; notranslate">
HttpContext.Current.Response.Headers.Add(&quot;Some-Header&quot;,&quot;Some-Value&quot;);
</pre>
<p>Apparently to do that you need the IIS integrated pipeline mode. Well if you really need to run your app pool in Classic mode just replace your code with the following and all is well:</p>
<pre class="brush: csharp; title: ; toolbar: true; wrap-lines: true; notranslate">
HttpContext.Current.Response.AppendHeader(&quot;Some-Header&quot;,&quot;Some-Value&quot;);
</pre>
<p>I know it’s kind of silly from Microsoft to not make this both ways compatible.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.suddenelfilio.net/2011/07/15/iis-7-x-and-httpresponse-headers/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Intercept values using Microsoft Moles</title>
		<link>http://www.suddenelfilio.net/2011/07/05/intercept-values-using-microsoft-moles/</link>
		<comments>http://www.suddenelfilio.net/2011/07/05/intercept-values-using-microsoft-moles/#comments</comments>
		<pubDate>Tue, 05 Jul 2011 22:17:53 +0000</pubDate>
		<dc:creator>suddenelfilio</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Visual Studio .Net]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[moles]]></category>
		<category><![CDATA[pex]]></category>
		<category><![CDATA[Unit testing]]></category>

		<guid isPermaLink="false">http://www.suddenelfilio.net/?p=642</guid>
		<description><![CDATA[Recently I needed to test some code in the most untestable codebase I&#8217;ve ever seen. Problem I was experiencing was that the value I needed to test was never exposedm but I knew what happened in the code. So I used Microsoft Moles to capture a value that was calculated in the method but never [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I needed to test some code in the most untestable codebase I&#8217;ve ever seen. Problem I was experiencing was that the value I needed to test was never exposedm but I knew what happened in the code. So I used Microsoft Moles to capture a value that was calculated in the method but never exposed. Below I&#8217;ll demonstrate the technique using a sample.</p>
<p>Let&#8217;s start with some code that is located in an external library:</p>
<pre class="brush: csharp; title: ; toolbar: true; wrap-lines: false; notranslate">using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SomeExternalLibrary
{
    public class Utilities
    {

        public bool FormatStringContainsUpperCases(string template, params object[] arguments)
        {
            var formattedString = GetFormattedText(template,arguments);
            return formattedString.ToLower() != formattedString;
        }

        public string GetFormattedText(string t, params object[] a)
        {
            return string.Format(t, a);
        }

    }
}</pre>
<p lang="csharp">As you can see in the (useless) piece of code above we have a function that will format a string using a template  and arguments and then evaluate if the formatted string contains uppercases. Now let&#8217;s say in a test we want to be sure that the formatted string is as we expect. We need a way to get the formatted result in the method <em>FormatStringContainsUpperCases. </em>This can be done using Microsoft Moles because we can create a mole library of the SomeExternalLibrary.dll which allows us to stub the Utilities class.</p>
<div id="attachment_647" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.suddenelfilio.net/wp-content/uploads/2011/07/add-mole-librarypng.png"><img class="size-medium wp-image-647" title=".add mole librarypng" src="http://www.suddenelfilio.net/wp-content/uploads/2011/07/add-mole-librarypng-300x267.png" alt="" width="300" height="267" /></a><p class="wp-caption-text">Create Moles Assembly for the library</p></div>
<p style="text-align: left;" lang="csharp">Once the Moles library is created we can start writing the Test code. Below you can see the entire test class:</p>
<pre class="brush: csharp; title: ; toolbar: true; wrap-lines: false; notranslate">using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SomeExternalLibrary;
using SomeExternalLibrary.Moles;

namespace SomeTestProject
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        [HostType(&quot;Moles&quot;)]
        public void TestUtilities()
        {
            var inputTemplate = &quot;this is the {0}&quot;;
            var expectedFormattedString = &quot;this is the Template&quot;;

            var formattedString = &quot;&quot;;

            var classUnderTest = new Utilities();

            MUtilities.AllInstances.GetFormattedTextStringObjectArray = (s, template, arguments) =&amp;gt;
            {
                MUtilities.AllInstances.GetFormattedTextStringObjectArray = null;
                formattedString = classUnderTest.GetFormattedText(template, arguments);
                return formattedString;
            };

            Assert.IsTrue(classUnderTest.FormatStringContainsUpperCases(inputTemplate, &quot;Template&quot;));
            Assert.AreEqual(expectedFormattedString, formattedString);
        }
    }
}</pre>
<p lang="csharp">In the test above we know that in the <em>FormatStringContainsUpperCases</em> method the <em>GetFormattedString </em>method is called. We setup interception using the MUtilities stub and attach a delegate to the <em>GetFormattedString</em> method for all instances of the Utilities class.</p>
<p lang="csharp">Next we remove the delegate we have just attached. If you do not do this the next line of code will cause a StackOverflowException since the code will get in an endless loop calling itself over and over.</p>
<pre class="brush: csharp; title: ; toolbar: true; wrap-lines: false; notranslate">MUtilities.AllInstances.GetFormattedTextStringObjectArray = null;</pre>
<p lang="csharp">After removing the delegate we can call the original method <em>GetFormattedString</em> on the original class <em>Utilities</em>. This will then return the same result as it would when called in the <em>FormatStringContainsUpperCases</em> method. This result we can store in variable. The last step is to return variable so the calling code can finish correctly.</p>
<p lang="csharp"><strong>So to intercept a call you:</strong></p>
<ol>
<li>Attach a delegate that will handle the interception.</li>
<li>In the delegate body remove the interception delegate to prevent a StackOverflowException</li>
<li>Call the original method and store the result in a variable</li>
<li>Return the variable so the calling code can execute as if it would without the interception.</li>
</ol>
<div>To learn more about Microsoft Moles go here: <a href="http://research.microsoft.com/en-us/projects/moles/">http://research.microsoft.com/en-us/projects/moles/</a></div>
]]></content:encoded>
			<wfw:commentRss>http://www.suddenelfilio.net/2011/07/05/intercept-values-using-microsoft-moles/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Learn how to develop an Angry Birds look-alike for windows phone 7</title>
		<link>http://www.suddenelfilio.net/2011/04/27/learn-how-to-develop-an-angry-birds-look-alike-for-windows-phone-7/</link>
		<comments>http://www.suddenelfilio.net/2011/04/27/learn-how-to-develop-an-angry-birds-look-alike-for-windows-phone-7/#comments</comments>
		<pubDate>Wed, 27 Apr 2011 15:18:04 +0000</pubDate>
		<dc:creator>suddenelfilio</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[angry birds]]></category>
		<category><![CDATA[jo de greef]]></category>
		<category><![CDATA[visual studio .net 2010]]></category>
		<category><![CDATA[windows phone 7]]></category>

		<guid isPermaLink="false">http://www.suddenelfilio.net/?p=616</guid>
		<description><![CDATA[Recently a colleague of mine (Jo De Greef) has written some pretty extensive articles on how you can create your own Angry Birds look-alike application for the Windows Phone 7 platform. In a series of posts he will explain the techniques you need to master to create your own version of the popular game. Of [...]]]></description>
			<content:encoded><![CDATA[<p><img style="float: right;" src="http://www.suddenelfilio.net/wp-content/uploads/2011/04/Windows-Phone-7-Logo.jpg" alt="" width="150" height="127" />Recently a colleague of mine (Jo De Greef) has written some pretty extensive articles on how you can create your own Angry Birds look-alike application for the Windows Phone 7 platform. In a series of posts he will explain the techniques you need to master to create your own version of the popular game. Of course you can use these techniques for entire different purposes.</p>
<p>The work on the series is still in progress at te moment. For now you can already checkout 2 awesome articles:</p>
<ul>
<li>Part 1: Hello Physics World &#8211; <a href="http://jodegreef.wordpress.com/2011/04/17/part-1-hello-physics-world/">http://jodegreef.wordpress.com/2011/04/17/part-1-hello-physics-world/</a></li>
<li>Part 2: Sprite Sheets - <a href="http://jodegreef.wordpress.com/2011/04/20/part-2-sprite-sheets/">http://jodegreef.wordpress.com/2011/04/20/part-2-sprite-sheets/</a></li>
</ul>
<p>If you like what Jo is doing let him know on Twitter: <a title="http://twitter.com/jodegreef" href="http://twitter.com/jodegreef" target="_blank">http://twitter.com/jodegreef</a> or regularly visit his blog at <a href="http://jodegreef.wordpress.com">http://jodegreef.wordpress.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.suddenelfilio.net/2011/04/27/learn-how-to-develop-an-angry-birds-look-alike-for-windows-phone-7/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to get the week number for a date in C#</title>
		<link>http://www.suddenelfilio.net/2010/10/07/how-to-get-the-week-number-for-a-date-in-c/</link>
		<comments>http://www.suddenelfilio.net/2010/10/07/how-to-get-the-week-number-for-a-date-in-c/#comments</comments>
		<pubDate>Thu, 07 Oct 2010 18:37:02 +0000</pubDate>
		<dc:creator>suddenelfilio</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[OS]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Visual Studio .Net]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[DateTime]]></category>
		<category><![CDATA[extension methods]]></category>
		<category><![CDATA[WeekNumber]]></category>

		<guid isPermaLink="false">http://www.suddenelfilio.net/?p=582</guid>
		<description><![CDATA[Today I needed to know which week of the year a certain day was in. My first instinct was DateTime.Now.Week but it seems there is no Week property on a DateTime instance. So I started looking for a way to get the week number. As it turns out the CultureInfo class will get you where [...]]]></description>
			<content:encoded><![CDATA[<p>Today I needed to know which week of the year a certain day was in. My first instinct was <em>DateTime.Now.Week</em> but it seems there is no Week property on a DateTime instance. So I started looking for a way to get the week number. As it turns out the <em>CultureInfo </em>class will get you where you want to go using the Calendar property.</p>
<p>I updated my extensions library (<a href="http://www.suddenelfilio.net/2010/08/31/how-to-get-the-mime-type-of-a-file-using-the-name-of-a-file-in-c/">How to get the mime type of a file using the name of a file in C#</a> and  <a href="http://www.suddenelfilio.net/2010/08/31/part-2-how-to-get-the-mime-type-of-a-file-using-the-name-of-a-file-in-c/" target="_self">PART 2: How to get the mime type of a file using the name of a file in C#</a> ) to add an extension method called <em>WeekNumber</em> for a DateTime instance here is the code:</p>
<pre class="brush: csharp; title: ; toolbar: true; wrap-lines: false; notranslate">

    public static class DateTimeExtensions
    {
        public static int WeekNumber(this System.DateTime value)
        {
            return CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(value, CalendarWeekRule.FirstFourDayWeek,
                                                                     DayOfWeek.Monday);

        }
    }
</pre>
<p>You can download my updated extension library here : <a  title='Suddenelfilio.ExtensionMethods.zip' href='http://www.suddenelfilio.net/?wpdmact=process&did=NC5ob3RsaW5r' style="background:url('http://www.suddenelfilio.net/wp-content/plugins/download-manager/icon/download.png') no-repeat;padding:3px 12px 12px 28px;font:bold 10pt verdana;">Suddenelfilio.ExtensionMethods.zip</a><br><small style='margin-left:30px;'>Downloaded 204 times</small></p>
]]></content:encoded>
			<wfw:commentRss>http://www.suddenelfilio.net/2010/10/07/how-to-get-the-week-number-for-a-date-in-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Connect to Facebook using ASP.NET, Facebook Graph API &amp; Hammock</title>
		<link>http://www.suddenelfilio.net/2010/09/08/connect-to-facebook-using-asp-net-facebook-graph-api-hammock/</link>
		<comments>http://www.suddenelfilio.net/2010/09/08/connect-to-facebook-using-asp-net-facebook-graph-api-hammock/#comments</comments>
		<pubDate>Wed, 08 Sep 2010 10:53:45 +0000</pubDate>
		<dc:creator>suddenelfilio</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[Asp.net]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Web & Design]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Codeplex]]></category>
		<category><![CDATA[Facebook]]></category>
		<category><![CDATA[Facebook Graph API]]></category>
		<category><![CDATA[hammock]]></category>

		<guid isPermaLink="false">http://www.suddenelfilio.net/?p=525</guid>
		<description><![CDATA[UPDATE: Hammock moved to github https://github.com/danielcrenna/hammock A while ago I wrote a post on how to perform oAuth authentication against the LinkedIn API using Hammock. Today I want to show you how to use Hammock with the Facebook Graph API. The Graph API is a new way a developer can read and write data to [...]]]></description>
			<content:encoded><![CDATA[<h2><b>UPDATE: Hammock moved to github https://github.com/danielcrenna/hammock</b></h2>
<p><img class="alignright size-full wp-image-433" title="hammock" src="http://www.suddenelfilio.net/wp-content/uploads/2010/08/hammock-logo.png" alt="" width="94" height="100" />A while ago I wrote a post on how to perform <a href="http://www.suddenelfilio.net/2010/08/24/linkedin-oauth-using-hammock-in-csharp-asp-net/" target="_blank">oAuth authentication against the LinkedIn API using Hammock</a>. Today I want to show you how to use <a href="http://hammock.codeplex.com" target="_blank">Hammock </a>with the <a href="http://developers.facebook.com/docs/api" target="_blank">Facebook Graph API</a>. The Graph API is a new way a developer can read and write data to Facebook. Facebook uses oAuth 2.0 which is a simpler version of the oAuth authentication I used in my previous article with LinkedIn. It uses SSL instead of relying on the URL signature schemes and token exchanges you see in oAuth 1.x</p>
<p>There are 3 steps:</p>
<ol>
<li>Redirect the visitor to the authorization page over at Facebook.com</li>
<li>Handle the callback from Facebook.com</li>
<li>Get an access_token from Facebook.com using the code parameter returned by Facebook.com in step 2</li>
</ol>
<p>For more information about the exact details on authorization in the Graph API go to: <a href="http://developers.facebook.com/docs/api">http://developers.facebook.com/docs/api</a></p>
<p>So let&#8217;s begin. I created a Web application in Visual Studio .Net 2010 that looks like this:</p>
<p><a href="http://www.suddenelfilio.net/wp-content/uploads/2010/09/begin.png"><img class="aligncenter size-medium wp-image-527" title="Sample start page" src="http://www.suddenelfilio.net/wp-content/uploads/2010/09/begin-300x176.png" alt="" width="300" height="176" /></a></p>
<p>As you can see there is not much on the page except for a button, an empty image and some text with &#8220;<em>Unknown</em>&#8221; values. The goal is that when your visitor clicks the &#8220;<em>Connect to Facebook</em>&#8221; button he/she gets redirect to Facebook.com to authorize your application and then you can get the profile picture, name and the visitor&#8217;s about text he/she filled in on Facebook.</p>
<p>When the visitor clicks the &#8220;<em>Connect to Facebook</em>&#8221; the following code is executed:</p>
<pre class="brush: csharp; title: ; wrap-lines: false; notranslate">

   protected void Button1_Click(object sender, EventArgs e)
   {
            string callbackUrl = &quot;http://localhost/FacebookConnectWithHammock/&quot;;
            //Request offline access and publish to the users stream access.
            Response.Redirect(string.Format(&quot;https://graph.facebook.com/oauth/authorize?client_id={0}&amp;redirect_uri={1}&amp;scope=offline_access,publish_stream&quot;, ConfigurationManager.AppSettings[&quot;FacebookClientId&quot;], callbackUrl));
   }
</pre>
<p>What this does is it will redirect the visitor to facebook to the authorization page. This specific authorization request asks foor &#8220;<em>offline_access</em>&#8221; and &#8220;<em>publish_stream</em>&#8221; rights. This means that the application can access your Facebook account while you are offline and it can also publish updates to your Facebook account. Other parameters are the &#8220;<em>client_id</em>&#8221; which you need to set to your application&#8217;s client id that was <a href="http://www.facebook.com/developers/apps.php#!/developers/" target="_blank">assigned to your application when you created it</a> and the &#8220;<em>redirect_uri</em>&#8221; which tells Facebook where to redirect the visitor after he/she granted your application access. When this is the first time the visitor is authorizing your application he/she will see the following authorization page:</p>
<p><a href="http://www.suddenelfilio.net/wp-content/uploads/2010/09/request.png"><img class="aligncenter size-medium wp-image-531" title="Facebook authorize application" src="http://www.suddenelfilio.net/wp-content/uploads/2010/09/request-300x144.png" alt="" width="300" height="144" /></a></p>
<p>When the visitors clicks on the &#8220;<em>Allow</em>&#8221; button Facebook will redirect the visitor back to the &#8220;<em>redirect_uri</em>&#8221; parameter. Then arriving on the web server we will receive a code parameter that we need to use to get the access_token. Here is how the callback code looks:</p>
<p>First in the Page_Load we check if the current request is a callback from Facebook by verifying if the <em>Request["code"] </em>querystring parameter is not null or empty and when it is not we call the callback handling code:</p>
<pre class="brush: csharp; title: ; wrap-lines: false; notranslate">

 protected void Page_Load(object sender, EventArgs e)
 {
     if (!string.IsNullOrEmpty(Request[&quot;code&quot;]) &amp;&amp; !Page.IsPostBack)
     {
          HandleFacebookCallback();
     }
 }
</pre>
<p>The HandleFacebookCallback method will use the &#8220;<em>code</em>&#8221; parameter to get an access token and then call the DisplayUserInformation method passing the received token. The DisplayUserInformation will make a request to the Graph API requesting information about the visitor that just authorized the application. It will show the profile picture, name of the visitor and the about text that is filled in on his/hers Facebook profile.</p>
<pre class="brush: csharp; title: ; wrap-lines: false; notranslate">

        private void HandleFacebookCallback()
        {
            string CallbackUrl = &quot;http://localhost/FacebookConnectWithHammock/&quot;;
            var client = new RestClient { Authority = &quot;https://graph.facebook.com/oauth/&quot; };
            var request = new RestRequest { Path = &quot;access_token&quot; };

            request.AddParameter(&quot;client_id&quot;, ConfigurationManager.AppSettings[&quot;FacebookClientId&quot;]);
            request.AddParameter(&quot;redirect_uri&quot;, CallbackUrl);
            request.AddParameter(&quot;client_secret&quot;, ConfigurationManager.AppSettings[&quot;FacebookApplicationSecret&quot;]);
            request.AddParameter(&quot;code&quot;, Request[&quot;code&quot;]);

            RestResponse response = client.Request(request);
            // A little helper to parse the querystrings.
            StringDictionary result = ParseQueryString(response.Content);
            string aToken = result[&quot;access_token&quot;];

            DisplayUserInformation(aToken);
        }

        private void DisplayUserInformation(string sToken)
        {
            var client = new RestClient { Authority = &quot;https://graph.facebook.com/&quot; };
            var request = new RestRequest { Path = &quot;me&quot; };
            request.AddParameter(&quot;access_token&quot;, sToken);
            RestResponse response = client.Request(request);

           JavaScriptSerializer ser = new JavaScriptSerializer();
            var parsedResult = ser.Deserialize&lt;FacebookUser&gt;(response.Content);

            ProfilePic.ImageUrl = string.Format(&quot;http://graph.facebook.com/{0}/picture?type=large&quot;,parsedResult.id);
            NameLabel.Text = parsedResult.name;
            AboutLabel.Text = parsedResult.about;
        }
</pre>
<p>When all goes well it should a little like the picture below.</p>
<p><a href="http://www.suddenelfilio.net/wp-content/uploads/2010/09/result.png"><img class="aligncenter size-medium wp-image-537" title="Result after authorization" src="http://www.suddenelfilio.net/wp-content/uploads/2010/09/result-300x176.png" alt="" width="300" height="176" /></a></p>
<p>Okay the formatting may not be optimal, but you get the point on how you can use <a href="http://hammock.codeplex.com" target="_blank">Hammock</a> to interact with the Facebook Graph API.</p>
<p>You can download the sample code here: <a  class='wpdm-popup' rel='colorbox'  title='FacebookConnectWithHammock.rar' href='http://www.suddenelfilio.net/?download=5' style="background:url('http://www.suddenelfilio.net/wp-content/plugins/download-manager/icon/download.png') no-repeat;padding:3px 12px 12px 28px;font:bold 10pt verdana;">Download</a><br><small style='margin-left:30px;'>Downloaded 1751 times</small></p>
<p><strong>NOTE:</strong> if you want to use the sample you will need to create an application first to get your application client id and secret. For more on this go to: <a href="http://www.facebook.com/developers/">http://www.facebook.com/developers/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.suddenelfilio.net/2010/09/08/connect-to-facebook-using-asp-net-facebook-graph-api-hammock/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>How to calculate password hash in C# for Jira users?</title>
		<link>http://www.suddenelfilio.net/2010/09/01/how-to-calculate-password-hash-in-c-for-jira-users/</link>
		<comments>http://www.suddenelfilio.net/2010/09/01/how-to-calculate-password-hash-in-c-for-jira-users/#comments</comments>
		<pubDate>Wed, 01 Sep 2010 08:00:33 +0000</pubDate>
		<dc:creator>suddenelfilio</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[Visual Studio .Net]]></category>
		<category><![CDATA[Atlassian]]></category>
		<category><![CDATA[Base64]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[Hash]]></category>
		<category><![CDATA[Jira]]></category>
		<category><![CDATA[OSUser]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[SHA512]]></category>
		<category><![CDATA[Visual Studio .Net 2005]]></category>
		<category><![CDATA[visual studio .net 2010]]></category>

		<guid isPermaLink="false">http://www.suddenelfilio.net/?p=466</guid>
		<description><![CDATA[While I&#8217;m working on migrating our current issue tracking system to the new Jira instance I needed to manually create new users in Jira&#8217;s database. The users are stored in the userbase table, but when you take a look you&#8217;ll see that the password is not stored instead there is a column called &#8220;PASSWORD_HASH&#8221; which [...]]]></description>
			<content:encoded><![CDATA[<p>While I&#8217;m working on migrating our current issue tracking system to the new Jira instance I needed to manually create new users in Jira&#8217;s database. The users are stored in the userbase table, but when you take a look you&#8217;ll see that the password is not stored instead there is a column called &#8220;PASSWORD_HASH&#8221; which contains the password in a hashed form. Since Jira uses the OSUser package from OpenSymphony you can go and look in the code.</p>
<p>The code that Jira uses to create the password hash is the following in Java:</p>
<pre class="brush: java; title: ; toolbar: true; wrap-lines: false; notranslate">

private String createHash(String original) {
   byte[] digested = PasswordDigester.digest(original.getBytes());
   byte[] encoded = Base64.encode(digested);

   return new String(encoded);
}
</pre>
<p>Now here you a digest being generated from the original value. Well this is a <a href="http://en.wikipedia.org/wiki/SHA-1" target="_blank">SHA-1/512 hash</a> which is then converted to a <a href="http://en.wikipedia.org/wiki/Base64" target="_blank">Base64</a> representation and that&#8217;s all!</p>
<p>Okay here is how you can do this in C#:</p>
<pre class="brush: csharp; title: ; toolbar: true; wrap-lines: false; notranslate">

using System;
using System.Text;
using System.Security.Cryptography;

public sealed class JiraPasswordHasher
{

    public static string createHash(string original)
    {
        SHA512 shaM = new SHA512Managed();
        var result = shaM.ComputeHash(System.Text.Encoding.ASCII.GetBytes(original));

        return Convert.ToBase64String(result);

    }
}
</pre>
<p>Have fun!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.suddenelfilio.net/2010/09/01/how-to-calculate-password-hash-in-c-for-jira-users/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>LinkedIn OAuth using Hammock in C# &amp; ASP.NET</title>
		<link>http://www.suddenelfilio.net/2010/08/24/linkedin-oauth-using-hammock-in-csharp-asp-net/</link>
		<comments>http://www.suddenelfilio.net/2010/08/24/linkedin-oauth-using-hammock-in-csharp-asp-net/#comments</comments>
		<pubDate>Tue, 24 Aug 2010 10:54:08 +0000</pubDate>
		<dc:creator>suddenelfilio</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[Web & Design]]></category>
		<category><![CDATA[Web Services]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[hammock]]></category>
		<category><![CDATA[Linkedin]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[oauth]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[visual studio .net]]></category>
		<category><![CDATA[visual studio .net 2010]]></category>

		<guid isPermaLink="false">http://www.suddenelfilio.net/2010/08/24/linkedin-oauth-using-hammock/</guid>
		<description><![CDATA[UPDATE: Hammock moved to github https://github.com/danielcrenna/hammock &#160; Codeplex.com description of Hammock: Hammock is a REST library for .NET that greatly simplifies consuming and wrapping RESTful services. I’m currently working on a little web project that needed integration with LinkedIn.com. The LinkedIn API allows for OAuth authorization and authentication. They describe the process of getting a [...]]]></description>
			<content:encoded><![CDATA[<h2><b>UPDATE: Hammock moved to github https://github.com/danielcrenna/hammock</b></h2>
<blockquote><p><a href="http://hammock.codeplex.com"><img class="size-full wp-image-433 alignleft" style="margin-left: 10px; margin-right: 10px;" title="hammock" src="http://www.suddenelfilio.net/wp-content/uploads/2010/08/hammock-logo.png" alt="" width="94" height="100" /></a></p>
<p>&nbsp;</p>
<p><a href="http://hammock.codeplex.com" target="_blank">Codeplex.com</a> description of Hammock:<br />
Hammock is a REST library for .NET that greatly simplifies consuming and wrapping RESTful services.</p></blockquote>
<p><img class="size-full wp-image-435 alignright" style="margin-left: 15px; margin-right: 15px;" title="LinkedIn Logo" src="http://www.suddenelfilio.net/wp-content/uploads/2010/08/1282842190_linkedin.png" alt="" width="60" height="60" /></p>
<p>I’m currently working on a little web project that needed integration with <a href="http://www.linkedin.com" target="_blank">LinkedIn.com</a>. The <a href="http://developer.linkedin.com/docs/DOC-1008" target="_blank">LinkedIn API allows for OAuth</a> authorization and authentication. They describe the process of getting a request token, authorizing it by the user and then getting an access token. Standard <a href="http://oauth.net/" target="_blank">OAuth</a> you might say. So I needed a way to do this in C# and found the Hammock library. Although Hammock does not only do OAuth I used it for that purpose only at the moment.</p>
<p>Below is the code I wrote to get a request token and send the user to the authorization page at Linkedin:</p>
<pre class="brush: csharp; title: ; toolbar: true; wrap-lines: false; notranslate">

public void RequestAndAuthorize()
        {
            var credentials = new OAuthCredentials
            {
                CallbackUrl = &quot;http://127.0.0.1/oauth/callback/&quot;,
                ConsumerKey = ConfigurationManager.AppSettings[&quot;ConsumerKey&quot;],
                ConsumerSecret = ConfigurationManager.AppSettings[&quot;ConsumerSecret&quot;],
                Verifier = &quot;123456&quot;,
                Type = OAuthType.RequestToken
            };
            var client = new RestClient { Authority = &quot;https://api.linkedin.com/uas/oauth&quot;, Credentials = credentials };
            var request = new RestRequest { Path = &quot;requestToken&quot; };
            RestResponse response = client.Request(request);

            string token = response.Content.Split('&amp;amp;').Where(s =&amp;gt; s.StartsWith(&quot;oauth_token=&quot;)).Single().Split('=')[1];
            string token_secret = response.Content.Split('&amp;amp;').Where(s =&amp;gt; s.StartsWith(&quot;oauth_token_secret=&quot;)).Single().Split('=')[1];

            Response.Redirect(&quot;https://api.linkedin.com/uas/oauth?oauth_token=&quot; + token);
        }
</pre>
<p>Once the user has authorized your request token the LinkedIn server will redirect the user back to the callback url in this case this is http://127.0.0.1/oauth/callback. Using the returned oauth_token and oauth_token_secret (you got this one while requesting a request token) you can now get an access token so you can start making authenticated API calls from you application on behalf of the user.</p>
<p>This is the code that is used when the callback url is called:</p>
<pre class="brush: csharp; title: ; wrap-lines: false; notranslate">

	public void Callback()
        {
            var credentials = new OAuthCredentials
            {
                ConsumerKey = ConfigurationManager.AppSettings[&quot;ConsumerKey&quot;],
                ConsumerSecret = ConfigurationManager.AppSettings[&quot;ConsumerSecret&quot;],
                Token = token,
                TokenSecret = token_secret,
                Verifier = verifier,
                Type = OAuthType.AccessToken,
                ParameterHandling = OAuthParameterHandling.HttpAuthorizationHeader,
                SignatureMethod = OAuthSignatureMethod.HmacSha1,
                Version = &quot;1.0&quot;
            };
            var client = new RestClient { Authority = &quot;https://api.linkedin.com/uas/oauth&quot;, Credentials = credentials, Method = WebMethod.Post };
            var request = new RestRequest { Path = &quot;accessToken&quot; };
            RestResponse response = client.Request(request);
            string content = response.Content;
        }
</pre>
<p>As you can see Hammock is really nice and allows for easy OAuth authentication/authorization to be used.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.suddenelfilio.net/2010/08/24/linkedin-oauth-using-hammock-in-csharp-asp-net/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>UPDATE: MS Tag REST service issues</title>
		<link>http://www.suddenelfilio.net/2010/08/03/update-ms-tag-rest-service-issues/</link>
		<comments>http://www.suddenelfilio.net/2010/08/03/update-ms-tag-rest-service-issues/#comments</comments>
		<pubDate>Tue, 03 Aug 2010 10:47:22 +0000</pubDate>
		<dc:creator>suddenelfilio</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[MSTagLib]]></category>
		<category><![CDATA[Web Services]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Microsoft Tag]]></category>
		<category><![CDATA[MSTAGREST]]></category>
		<category><![CDATA[WCF]]></category>

		<guid isPermaLink="false">http://www.suddenelfilio.net/?p=404</guid>
		<description><![CDATA[During the last 24 hours the service has been experiencing some issues when called. This has currently been resolved. If you&#8217;ve received an http 500 error code when calling the service please try again. The issue was introduced when I extended the service to record certain metrics. These metrics or stats can be seen on [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.suddenelfilio.net/wp-content/uploads/2009/11/logo_whitebackground.jpg"><img class="alignright size-full wp-image-79" title="logo_whitebackground" src="http://www.suddenelfilio.net/wp-content/uploads/2009/11/logo_whitebackground.jpg" alt="" width="237" height="84" /></a>During the last 24 hours the service has been experiencing some issues when called. This has currently been resolved. If you&#8217;ve received an http 500 error code when calling the service please try again. The issue was introduced when I extended the service to record certain metrics. These metrics or stats can be seen on <a href="http://tag.ws.suddenelfilio.net/">http://tag.ws.suddenelfilio.net/</a> at the end of the page.</p>
<p>If you experience any other problems please contact me at: mstaglib@suddenelfilio.net</p>
]]></content:encoded>
			<wfw:commentRss>http://www.suddenelfilio.net/2010/08/03/update-ms-tag-rest-service-issues/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Suddenelfilio Products &amp; Services</title>
		<link>http://www.suddenelfilio.net/2010/06/21/suddenelfilio-products-services/</link>
		<comments>http://www.suddenelfilio.net/2010/06/21/suddenelfilio-products-services/#comments</comments>
		<pubDate>Mon, 21 Jun 2010 10:49:36 +0000</pubDate>
		<dc:creator>suddenelfilio</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[Blog]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Hosting]]></category>
		<category><![CDATA[MSTagLib]]></category>
		<category><![CDATA[Web & Design]]></category>
		<category><![CDATA[Web Services]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.suddenelfilio.net/?p=365</guid>
		<description><![CDATA[As of now Suddenelfilio.net is offering various products and services for those interested. Currently we offer 2 technology offers: 1. Microsoft Tag: suddenelfilio.net can help you with your Microsoft Tag needs. 2. WordPress Services: for a simple blog or wordpress as cms we can help you! Have a look at the Products &#38; Services page [...]]]></description>
			<content:encoded><![CDATA[<p>As of now Suddenelfilio.net is offering various products and services for those interested. Currently we offer 2 technology offers:</p>
<p>1. <strong>Microsoft Tag:</strong> suddenelfilio.net can help you with your Microsoft Tag needs.<br />
2. <strong>WordPress Services: </strong>for a simple blog or wordpress as cms we can help you!</p>
<p>Have a look at the <a href="http://www.suddenelfilio.net/products/">Products &amp; Services</a> page for more information.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.suddenelfilio.net/2010/06/21/suddenelfilio-products-services/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Release of Ril#</title>
		<link>http://www.suddenelfilio.net/2010/05/12/release-of-ril/</link>
		<comments>http://www.suddenelfilio.net/2010/05/12/release-of-ril/#comments</comments>
		<pubDate>Wed, 12 May 2010 15:26:49 +0000</pubDate>
		<dc:creator>suddenelfilio</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[Web & Design]]></category>
		<category><![CDATA[Web Services]]></category>
		<category><![CDATA[ReadItLater]]></category>

		<guid isPermaLink="false">http://www.suddenelfilio.net/?p=320</guid>
		<description><![CDATA[Today I released the website for my latest personal project, a .net library for the Read It Later Service API.  Through their api you can create your own client application. Using Ril# this is now easy to do in .net. Have a look at http://rilsharp.suddenelfilio.net]]></description>
			<content:encoded><![CDATA[<p><a href="http://rilsharp.suddenelfilio.net"><img class="alignright" title="rilsharp_logo" src="http://www.suddenelfilio.net/wp-content/uploads/2010/05/rilsharp_logo.png" alt="" width="150" height="150" /></a>Today I released the website for my latest personal project, a .net library for the <a href="http://www.readitlaterlist.com">Read It Later Service</a> API.  Through their api you can create your own client application. Using Ril# this is now easy to do in .net.</p>
<p>Have a look at <a href="http://rilsharp.suddenelfilio.net ">http://rilsharp.suddenelfilio.net </a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.suddenelfilio.net/2010/05/12/release-of-ril/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

