<?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</title>
	<atom:link href="http://www.suddenelfilio.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>Some Suddenelfilio.net changes.</title>
		<link>http://www.suddenelfilio.net/2010/09/11/some-suddenelfilio-net-changes/</link>
		<comments>http://www.suddenelfilio.net/2010/09/11/some-suddenelfilio-net-changes/#comments</comments>
		<pubDate>Sat, 11 Sep 2010 21:25:22 +0000</pubDate>
		<dc:creator>suddenelfilio</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Hosting]]></category>
		<category><![CDATA[Web & Design]]></category>
		<category><![CDATA[Web Services]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[Disqus]]></category>
		<category><![CDATA[Support]]></category>
		<category><![CDATA[Zendesk]]></category>

		<guid isPermaLink="false">http://www.suddenelfilio.net/?p=543</guid>
		<description><![CDATA[As I mentioned earlier on this blog suddenelfilio.net now uses the Disqus Commenting &#38; Discussion system to handle comments on blogs. It is a really nice systems that integrates perfectly with WordPress on which this blog is running.]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><a href="Http://www.disqus.com"><img class="size-full wp-image-547 aligncenter" title="Http://www.disqus.com" src="http://www.suddenelfilio.net/wp-content/uploads/2010/09/dc-inline.png" alt="" width="191" height="22" /></a>As I mentioned earlier on this blog suddenelfilio.net now uses the<a href="http://disqus.com/comments/" target="_blank"> Disqus Commenting &amp; Discussion system</a> to handle comments on blogs. It is a really nice systems that integrates perfectly with WordPress on which this blog is running.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.suddenelfilio.net/2010/09/11/some-suddenelfilio-net-changes/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>Part 2: Using jQuery and Custom fields to rename the Fix Version/s field in Jira</title>
		<link>http://www.suddenelfilio.net/2010/09/07/part-2-using-jquery-and-custom-fields-to-rename-the-fix-versions-field-in-jira/</link>
		<comments>http://www.suddenelfilio.net/2010/09/07/part-2-using-jquery-and-custom-fields-to-rename-the-fix-versions-field-in-jira/#comments</comments>
		<pubDate>Tue, 07 Sep 2010 11:05:55 +0000</pubDate>
		<dc:creator>suddenelfilio</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Web & Design]]></category>
		<category><![CDATA[Atlassian]]></category>
		<category><![CDATA[Custom Fields]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[Jira]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.suddenelfilio.net/?p=516</guid>
		<description><![CDATA[Following up on my previous article on this topic I would like to show how using similar techniques you can rename the Fix Version/s field (analogue for the Afffected Version/s field) when creating, editing or viewing an issue. I&#8217;ve seen requests on the Jira Issue site for this, mostly because there are teams that are [...]]]></description>
			<content:encoded><![CDATA[<p>Following up on my <a href="http://www.suddenelfilio.net/2010/09/06/using-jquery-and-custom-fields-to-enforce-issue-type-security-in-jira/" target="_blank">previous article </a>on this topic I would like to show how using similar techniques you can rename the Fix Version/s field (analogue for the Afffected Version/s field) when creating, editing or viewing an issue. I&#8217;ve seen requests on the Jira Issue site for this, mostly because there are teams that are using Agile/scrum development and they want to rename the Version to Milestone, Sprint or just something else. Jira currently does not support this out-of-the-box unless you are willing to dive into the <a href="http://confluence.atlassian.com/display/JIRA/Customizing+text" target="_blank">localization jars and change those yourself</a>, which kind of a bummer since they do support agile development through the &#8211; in my opinion overpriced - <a href="http://www.atlassian.com/software/greenhopper/" target="_blank">Greenhopper </a>plugin.</p>
<p>Okay this is how the issue creation screen looks like without our little gimmick:</p>
<p><img class="aligncenter size-medium wp-image-518" title="Regular creation screen in jira" src="http://www.suddenelfilio.net/wp-content/uploads/2010/09/createwith-fix-version-300x209.png" alt="" width="300" height="209" /></p>
<p>I blacked out some values just for privacy reasons, but you get the point. Now if all you need is to change the text <em>Fix Version/s</em> to in our case <em>Milestone </em>all it takes is the following script:</p>
<pre class="brush: jscript; html-script: true; title: ; wrap-lines: false; notranslate">

&lt;script language=&quot;JavaScript&quot;&gt;

jQuery(function(){
	AJS.$(&quot;label[for=fixVersions]&quot;).replaceWith(&quot; &lt;label for='fixVersions'&gt;&lt;span class='required' title='Fields in italics are required'&gt;&lt;sup&gt;*&lt;/sup&gt;Milestone:&lt;/span&gt;&lt;/label&gt;&quot;);
});

&lt;/script&gt;
</pre>
<p>As you can see I&#8217;m using jQuery to look for a label element where the for attribute is set to &#8216;<em>fixVersions</em>&#8216; and replace it with a new label element.<br />
That&#8217;s all! Well not all, you still need to get it on your pages. To do this I&#8217;ve used a <strong>Message Custom Field (for edit)</strong>. If you also want this on your viewing page you need to create a second custom field of type <strong>Message Custom Field (for view)</strong> and set the default value of both custom fields to the script. To apply this text replacment to all screens, issue types and projects (create,edit and viewing) it&#8217;s best to set the context to &#8216;<em>Global</em>&#8216; and &#8216;<em>Any issue type</em>&#8216;. and you are good to go. When applied the screen screen will look like this:</p>
<p><a href="http://www.suddenelfilio.net/wp-content/uploads/2010/09/createwith-milestone.png"><img class="aligncenter size-medium wp-image-520" title="Create screen with text replacement" src="http://www.suddenelfilio.net/wp-content/uploads/2010/09/createwith-milestone-300x234.png" alt="" width="300" height="234" /></a></p>
<p>The Message Custom Field can be found in the <a href="https://studio.plugins.atlassian.com/wiki/display/JTOOL/JIRA+Toolkit+Plugin" target="_blank">Jira Toolkit plugin</a></p>
<p>Of course this technique can be applied to whatever field if you like, just remember it is a text replacement on rendering of the page so in the system nothing changes! If there is an error message about the Fix Version/s field for example when it is required and no version is selected the error message will not be using the term &#8216;<em>Milestone</em>&#8216;.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.suddenelfilio.net/2010/09/07/part-2-using-jquery-and-custom-fields-to-rename-the-fix-versions-field-in-jira/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using jQuery and Custom fields to enforce issue type security in Jira</title>
		<link>http://www.suddenelfilio.net/2010/09/06/using-jquery-and-custom-fields-to-enforce-issue-type-security-in-jira/</link>
		<comments>http://www.suddenelfilio.net/2010/09/06/using-jquery-and-custom-fields-to-enforce-issue-type-security-in-jira/#comments</comments>
		<pubDate>Mon, 06 Sep 2010 22:30:12 +0000</pubDate>
		<dc:creator>suddenelfilio</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Web & Design]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[Atlassian]]></category>
		<category><![CDATA[Custom Fields]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Issue]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[Jira]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Velocity]]></category>

		<guid isPermaLink="false">http://www.suddenelfilio.net/?p=480</guid>
		<description><![CDATA[When working on our companies new issue tracking system I ran into the need to be able to prevent certain users or groups to create a specific type of issue. This however strange it may seem is not supported out-of-the-box  by Jira and browsing the Jira Issue site the nice people at Atlassian don&#8217;t seem [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-511" title="jquery" src="http://www.suddenelfilio.net/wp-content/uploads/2010/09/jquery.jpg" alt="" width="144" height="96" />When working on our companies new issue tracking system I ran into the need to be able to prevent certain users or groups to create a specific type of issue. This however strange it may seem is not supported out-of-the-box  by Jira and browsing the <a href="http://jira.atlassian.com/browse/JRA-5865" target="_blank">Jira Issue site</a> the nice people at Atlassian don&#8217;t seem to put high value in this much requested feature. Anyways looking at the comments in the issue I discovered that you can use a custom field called Velocity processed Custom Message Field (for edit) to use a mix of <a href="http://velocity.apache.org/" target="_blank">Apache Velocity templating</a> and javascript to do the trick. Okay it is a hack, but for now it is the only possibility out there that I&#8217;ve discovered.</p>
<p><img class="alignright size-medium wp-image-512" title="LOGOJIRA" src="http://www.suddenelfilio.net/wp-content/uploads/2010/09/LOGO_JIRA-300x155.png" alt="" width="180" height="93" />Now before you go looking for the custom field you have to know that is not installed by default.<a href="https://studio.plugins.atlassian.com/wiki/display/JTOOL/JIRA+Toolkit+Plugin;jsessionid=4C09C94BBC8F457DB70218D7B8EB94CB" target="_blank"> The Velocity processed Custom Message Field</a> can be found in a Jira plugin called<a href="https://plugins.atlassian.com/plugin/details/5142" target="_blank"> Jira Toolkit</a> over at the <a href="https://plugins.atlassian.com/search/by/jira" target="_blank">Plugin exchange</a>. So if you want this to work go and install this plugin.</p>
<p>Now with the plugin  installed create a new custom field of type Velocity processed Custom Message Field (for edit), give it a name and make sure you select All issue types and the global context! Don&#8217;t worry I&#8217;ll explain later why.</p>
<p style="text-align: center;"><a href="http://www.suddenelfilio.net/wp-content/uploads/2010/09/create-custom-field.png"></a><a href="http://www.suddenelfilio.net/wp-content/uploads/2010/09/create-custom-field.png"><img class="aligncenter size-large wp-image-486" title="Create custom field" src="http://www.suddenelfilio.net/wp-content/uploads/2010/09/create-custom-field-1024x755.png" alt="" width="614" height="453" /></a><br />
<a href="http://www.suddenelfilio.net/wp-content/uploads/2010/09/create-custom-field-2.png"><img class="aligncenter size-large wp-image-489" title="create custom field 2" src="http://www.suddenelfilio.net/wp-content/uploads/2010/09/create-custom-field-2-1024x756.png" alt="" width="614" height="454" /></a></p>
<p>Having created the custmom field it is time for the logic. What we are going to do is to create a mix of velocity script and javascript to show an error message to a user when he/she does not belongs to a certain user group and remove all the input fields from the form. The script I&#8217;m going to use for that looks as follows:</p>
<pre class="brush: jscript; title: ; wrap-lines: false; notranslate">

#if ($authcontext.user.inGroup('developers'))
##do nothing
#else

&lt;script language=&quot;JavaScript&quot;&gt;

jQuery(function ()
{
        AJS.$(&quot;&lt;div class='warningBox maxWidth' style='text-align:center;color:DarkRed'&gt;&lt;h1&gt;$authcontext.user.getFullName() ,&lt;br/&gt;This issue type is for internal use only. &lt;br/&gt;Please create an Incident, Enhancement or New Feature instead!&lt;/h1&gt;&lt;/div&gt;&quot;).appendTo('.intform');
	AJS.$(&quot;.jiraform&quot;).remove();
});

&amp;lt;/script&amp;gt;

#end
</pre>
<p>A little explenation is in order here I guess. All the lines preceded by the # sign is Velocity markup. Jira uses the Velocity templating engine to create its webpages. What the velocity code does is rather straight forward it checks if the current user is in the group &#8216;developers&#8217; -<em> $authcontext.user.inGroup(&#8216;developers&#8217;)</em> -. If that is the case then do nothing. When the current user is not in the &#8216;developers&#8217; user group a jQuery script will be executed which appends a div with a warning to the page and then removes the HTML table that contains all the input fields. A little note on this is that Jira must load the jQuery library. I found that my instance has got a line like this that load the jQuery library:</p>
<pre class="brush: xml; title: ; wrap-lines: false; notranslate">

&lt;script type=&quot;text/javascript&quot; src=&quot;/s/531/1/2.1.3/_/download/batch/com.atlassian.auiplugin:ajs/com.atlassian.auiplugin:ajs.js&quot; &gt;&lt;/script&gt;
</pre>
<p><span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; line-height: 19px; white-space: normal; font-size: 13px;"><br />
If you don&#8217;t have the jQuery library you need to make sure it is loaded.</span></p>
<p><span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; line-height: 19px; white-space: normal; font-size: 13px;">So that is the script that will do the magic stuff. Now all you need to do is enter it as the default value for your custom field you created above. You can do this by clicking the &#8216;configure&#8217; link and on the new page &#8216;edit default value&#8217;. In the textbox paste the script and update the field.<br />
Remember that I said you needed to select all issue types and the global context when you created the custom field? The reason for that is that in Jira 4.1.x there seems to be an issue with setting the default value when you have not selected as is. When you select specific issue types and projects instead of all issue types and global context you&#8217;ll get strange page when you go and try to set the custom field&#8217;s default value. The textbox is not there. This is a known issue and the woirkaround for when you need to edit the default value is to set it back to all issue types and global context. I know that&#8217;s not really fun to do, but it will get it done! </span></p>
<p><span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; line-height: 19px; white-space: normal; font-size: 13px;">Now to secure certain issue types you don&#8217;t want non developers to create just select the types you want and if necessary select the project(s). You can do this by clicking the &#8216;configure&#8217; link of the custom field and then select the &#8216;Edit configuration&#8217; option.</span></p>
<p><span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; line-height: 19px; white-space: normal; font-size: 13px;">After you&#8217;ve saved these settings creating a prohibited issue type will render like this. What you see below is a customer trying to create a bug while a customer is only allowed to create an incident, New Feature or Enhancement </span></p>
<p style="text-align: center;"><span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; line-height: 19px; white-space: normal; font-size: 13px;"><a href="http://www.suddenelfilio.net/wp-content/uploads/2010/09/invalidissuetype.png"><img class="aligncenter size-large wp-image-505" title="Trying to create an invalid issue type" src="http://www.suddenelfilio.net/wp-content/uploads/2010/09/invalidissuetype-1024x292.png" alt="" width="614" height="175" /></a></span></p>
<p>As you can see you address the the user in this case Customer Person (which is the Fullname of the logged in jira user) that he/she can only create an Incident, Enhancement or New Feature. Also notice that there are no input fields on the form.</p>
<p>So depending on the version of jira you are using you will need to tweak the jQuery to show and remove the correct elements, but this should be applicable to any version where you can use the Velocity processed Custom Message Field.</p>
<p><strong>A small note I wish to add</strong> is that when a user disable javascipt in his/hers browser this solution will become useless since it uses javascript to disable those fields, but then again so becomes the rest of the internet just try and surf without javascript enabled <img src='http://www.suddenelfilio.net/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>In <a href="http://www.suddenelfilio.net/2010/09/07/part-2-using-jquery-and-custom-fields-to-rename-the-fix-versions-field-in-jira/" target="_self">part 2 I&#8217;ll show you how to change the label of the Version field</a> using similar techniques.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.suddenelfilio.net/2010/09/06/using-jquery-and-custom-fields-to-enforce-issue-type-security-in-jira/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>New Disqus Commenting system installed</title>
		<link>http://www.suddenelfilio.net/2010/09/06/new-disqus-commenting-system-installed/</link>
		<comments>http://www.suddenelfilio.net/2010/09/06/new-disqus-commenting-system-installed/#comments</comments>
		<pubDate>Mon, 06 Sep 2010 14:34:03 +0000</pubDate>
		<dc:creator>suddenelfilio</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Disqus]]></category>
		<category><![CDATA[Facebook]]></category>
		<category><![CDATA[OpenID]]></category>
		<category><![CDATA[Twitter]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.suddenelfilio.net/?p=475</guid>
		<description><![CDATA[Suddenelfilio.net is now using the Disqus commenting system for all comments. I&#8217;ve tried to import as many existing comments as possible but they may not all have been imported. From now on you can comment using your Disqus, Twitter, Facebook or OpenID account. Hope to see some comments]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-full wp-image-478" title="disqus" src="http://www.suddenelfilio.net/wp-content/uploads/2010/09/disqus-e1283783760118.jpg" alt="" width="259" height="82" />Suddenelfilio.net is now using the Disqus commenting system for all comments. I&#8217;ve tried to import as many existing comments as possible but they may not all have been imported. From now on you can comment using your Disqus, Twitter, Facebook or OpenID account. Hope to see some comments <img src='http://www.suddenelfilio.net/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.suddenelfilio.net/2010/09/06/new-disqus-commenting-system-installed/feed/</wfw:commentRss>
		<slash:comments>0</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>
	</channel>
</rss>

