<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>Geeks Bearing Gifts</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/prathul/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/prathul/feed.xml</link>
    <description>Unleash your potential</description>
    <lastBuildDate>Tue, 16 Apr 2019 05:24:22 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Windows Phone 7 &amp; Azure Service Bus REST Authentication and Messaging</title>
      <link>https://docs.microsoft.com/archive/blogs/prathul/windows-phone-7-azure-service-bus-rest-authentication-and-messaging</link>
      <pubDate>Thu, 09 Aug 2012 22:18:00 GMT</pubDate>
      <dc:creator><![CDATA[Prathul Prabhakar - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/prathul/2012/08/09/windows-phone-7-azure-service-bus-rest-authentication-and-messaging/</guid>
      <description><![CDATA[Important:&nbsp;In this sample the secret key is present on the client (Phone) itself. SInce a...]]></description>
      <content:encoded><![CDATA[<p><em><strong>Important:&nbsp;</strong>In this sample the secret key is present on the client (Phone) itself. SInce a secret key can never be stored safely on phone, on a production system, the users should be authenticated using a identity provider to get a user token that can be used to get an authorization token from ACS.</em></p>
<p>Many a time you might want to interact with Azure servicebus, but may not have the privilage to use the service bus dll. In such a scenario you would need to make use of Azure Servicebus REST API. A best example for this scenario would be connecting to Azure service bus from Windows Phone 7. As you may already know, you cannot make use of the service bus dll in a phone. In this post, I will walk you though every step required to complete the integration between Azure Service Bus Queue and your client REST API.</p>
<p><strong>Step 1 : Set up your Azure Service Bus and Access Control Service (ACS)<br /></strong>Create a service bus namespace and an associate ACS namespace in your Azure account. Get the secret key from "Default Key" in your Azure service bus account. We will use this later to connect to Azure from your client application.</p>
<p><strong>Step 2 : From client, get autentication token to Azure using REST</strong><br />In this step we will get an authentication token from Azure and attach it in the header of all subsequent requests to interact with the service bus. To get an authentication token, you will need the issuer password (the secret key you got&nbsp;in last step), the issuer name (almost alway "owner") and your service namespace (the namespace for servicebus and ACS). The code listing for the same is given below. The ACS base address may change in future Azure releases. Rest of the code listing is self explanatory.</p>
<p>&nbsp;</p>
<pre class="scroll"><code class="csharp">private void GetAuthenticationToken()<br /> {<br /> string acsBaseAddress = "https://" + ServiceNamespace + "-sb.accesscontrol.windows.net/WRAPv0.9/";<br /> <br /> // Create the body of the Post Request, formatted as a HTTP Form<br /> string postData = "wrap_scope=" + Uri.EscapeDataString("https://"+ ServiceNamespace +".servicebus.windows.net/") + "&amp;wrap_name="<br /> + Uri.EscapeDataString(IssuerName) + "&amp;wrap_password="<br /> + Uri.EscapeDataString(IssuerPassword);<br /> <br /> string authorizationToken;<br /> var webClient = new WebClient();<br /> webClient.UploadStringCompleted += new UploadStringCompletedEventHandler(webClient_GettingTokenCompleted);<br /> webClient.UploadStringAsync(new Uri(acsBaseAddress), "POST", postData);<br /> }</code></pre>
<p><strong>Step 3 : Extract the token and append it to the header of every subsequent requests</strong><br />The result of the token request in step 2 arrives in a particular string format with '&amp;' as the delimiter. To obtain the actual token, refer to the code snippet below.</p>
<pre class="scroll"><code class="csharp">private void webClient_GettingTokenCompleted(object sender, UploadStringCompletedEventArgs e)<br /> {<br /> string[] tokenVariables = e.Result.Split('&amp;');<br /> string[] tokenVariable = tokenVariables[0].Split('=');<br /> string authenticationToken = Uri.UnescapeDataString(tokenVariable[1]);<br /> }</code></pre>
<p><strong>Step 4 :&nbsp;&nbsp;Perform service bus operations using the authentiction token</strong><br />Once you have the authentication token, append it to the header called "Authentication" to interact with the service bus. In the code snippet below, I will post a message to the service bus queue.</p>
<pre class="scroll"><code class="csharp">var webClient = new WebClient();<br /> webClient.Headers["Authorization"] = "WRAP access_token=\"" + authenticationToken + "\"";<br /> webClient.UploadStringCompleted += new UploadStringCompletedEventHandler(webClient_SendMessageCompleted);<br /> webClient.UploadStringAsync(<br /> new Uri(FullAddress), "POST", Body);</code></pre>
<p>Similary you can perform any interacation with the service bus. You may also refer to <a title="https://msdn.microsoft.com/en-us/library/windowsazure/hh780717.aspx" href="https://blogs.msdn.com/controlpanel/blogs/posteditor.aspx/MSDN REST API" target="_blank">MSDN REST API</a>&nbsp;reference. Also do leave a comment with your questions/feedback and I would be happy to respond. Happy coding!</p>]]></content:encoded>
    </item>
    <item>
      <title>Pex Issue : "Delete Generated Unit Tests in Class" or Using existing test projects</title>
      <link>https://docs.microsoft.com/archive/blogs/prathul/pex-issue-delete-generated-unit-tests-in-class-or-using-existing-test-projects</link>
      <pubDate>Tue, 19 Jun 2012 22:01:00 GMT</pubDate>
      <dc:creator><![CDATA[Prathul Prabhakar - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/prathul/2012/06/19/pex-issue-delete-generated-unit-tests-in-class-or-using-existing-test-projects/</guid>
      <description><![CDATA[To give a brief overview of what Pex is,
Microsoft Pex is a Visual Studio add-in that provides...]]></description>
      <content:encoded><![CDATA[<p>To give a brief overview of what Pex is,</p>
<p><a title="Pex Home" href="https://research.microsoft.com/en-us/projects/pex/default.aspx">Microsoft Pex</a> is a Visual Studio add-in that provides runtime code analysis for .NET code. With just a few mouse clicks, you can explore code-under-test to understand input/output behavior in the code, save automated tests that increase your confidence that your code cannot crash&mdash;or point to errors that do cause crashes and&nbsp;write powerful parameterized unit tests and generate suites of tests that ensure the code-under-test behaves as intended. If you are a developer writing code, you should be testing it with Pex. More tutorials <a title="Pex Tutorials" href="https://research.microsoft.com/en-us/projects/pex/documentation.aspx" target="_blank">here</a>.</p>
<p>This post aims at providing a solution to two of the issues that I have come across.</p>
<p><b>Issue 1: </b>The Pex context menu only has the entry "Delete Generated Unit Tests in Class" and not the usual "Create parameterized unit&nbsp; tests"</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/48/37/5661.Pex.jpg" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-48-37/5661.Pex.jpg"><img border="0" alt="" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/48/37/5661.Pex.jpg" original-url="https://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-48-37/5661.Pex.jpg" /></a></p>
<p><b>Solution: </b>The<b> </b>Pex assemblies should be referenced only in the test project and not in the source projects. For example in my case, the source project that contained the original class on which tests had to be run contained references to &ldquo;Microsoft.Pex.Framework&rdquo; &amp; "Microsoft.VisualStudio.QualityTools.UnitTestFramework&rdquo;. Once I removed the references, I had the &ldquo;Create parameterized unit tests&rdquo; menu back.</p>
<p><strong>Issue 2: </strong>You already have an existing unit test project. But <span style="font-family: 'Calibri','sans-serif'; font-size: 11pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;">Pex is not allowing you to select the existing test project as output.</span></p>
<p><b>Solution: </b>To your test project, add a reference to the assembly "Microsoft.Pex.Framework&rdquo; and try again.</p>
<p>If that doesn&rsquo;t work, follow the steps.<br />Update your existing test project:</p>
<p>- Run 'Create Parameterized Unit Tests' on your project <br />- Let Pex create a new project<br />- Copy the PexAssemblyInfo.cs file (under \Properties) from the generated&nbsp; project into your original test project<br />- Delete the test project that Pex generated</p>
<p>At this point, the bindings should work. The next time you try to run 'Create Parmeterized Unit Tests' from your types, it should automatically suggest to use your test project.</p>
<p><strong><span style="font-family: 'Calibri','sans-serif'; font-size: 11pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;">Important Note on Pex download: </span></strong><span style="font-family: 'Calibri','sans-serif'; font-size: 11pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;">Pex comes along with Moles which is a mocking framework. Starting Visual Studio 2012, moles has been integrated as "<a title="Microsoft Fakes" href="https://msdn.microsoft.com/en-us/library/tfs/hh549175(v=vs.110).aspx">Fakes</a>". They are not backward compactible. Hence if you would like to use a mocking framework, its is recommended that you have a look at "Fakes".</span></p>]]></content:encoded>
    </item>
    <item>
      <title>FIX: WCF Metadata not published</title>
      <link>https://docs.microsoft.com/archive/blogs/prathul/fix-wcf-metadata-not-published</link>
      <pubDate>Fri, 16 Mar 2012 01:56:28 GMT</pubDate>
      <dc:creator><![CDATA[Prathul Prabhakar - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/prathul/2012/03/16/fix-wcf-metadata-not-published/</guid>
      <description><![CDATA[Ever faced this problem? No matter whatever you try, your WCF service metadata just wouldn&rsquo;t...]]></description>
      <content:encoded><![CDATA[<p><span style="font-size: small;" size="3"><span style="font-family: Calibri;" face="Calibri">Ever faced this problem? No matter whatever you try, your WCF service metadata just wouldn&rsquo;t get exposed. The basic steps (which you must have already tried) is to enable mex end point,</span></span></p>
<p><span style="font-size: small;" size="3"><span style="font-family: Calibri;" face="Calibri"></span></span></p>
<p>&lt;endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/&gt;</p>
<p>&nbsp;</p>
<p><span style="font-family: Calibri; font-size: small;" face="Calibri" size="3">&nbsp;</span><span style="font-size: small;" size="3"><span style="font-family: Calibri;" face="Calibri">set the behaviors,</span></span></p>
<p><span style="font-size: small;" size="3"><span style="font-family: Calibri;" face="Calibri"></span></span></p>
<p>&nbsp;&nbsp;&nbsp; &lt;behaviors&gt;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;serviceBehaviors&gt;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;behavior name="mexBehavior"&gt;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;serviceMetadata httpGetEnabled="true" /&gt;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/behavior&gt;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/serviceBehaviors&gt;</p>
<p>&nbsp;&nbsp;&nbsp; &lt;/behaviors&gt;</p>
<p>&nbsp;</p>
<p><span style="font-family: Calibri; font-size: small;" face="Calibri" size="3">&nbsp;</span><span style="font-size: small;" size="3"><span style="font-family: Calibri;" face="Calibri">and point your service to use the above behavior.</span></span></p>
<p><span style="font-size: small;" size="3"><span style="font-family: Calibri;" face="Calibri"></span></span></p>
<p>&lt;service name="xxx.yyyService" behaviorConfiguration="mexBehavior"&gt;</p>
<p><span style="font-family: Calibri; font-size: small;" face="Calibri" size="3">&nbsp;</span></p>
<p><span style="font-family: Calibri; font-size: small;" face="Calibri" size="3">If you have done all of the above and still have the problem, the culprit could be the svc file. Open the .svc file for your service by right clicking on the service &gt; View markup. Check whether the </span><strong>Service </strong><span style="font-family: Calibri; font-size: small;" face="Calibri" size="3">tag of the svc file has the fully qualified name of the service including the namespace. Then make sure in the web.config, your </span><strong>service name</strong> <span style="font-family: Calibri; font-size: small;" face="Calibri" size="3">and the </span><strong>endpoint</strong><span style="font-size: small;" size="3"><span style="font-family: Calibri;" face="Calibri"> contract also has the fully qualified name. If not, this should solve your issue.</span></span></p>]]></content:encoded>
    </item>
    <item>
      <title>Now Available : Appfabric 1.1 Caching GUI Administrator</title>
      <link>https://docs.microsoft.com/archive/blogs/prathul/now-available-appfabric-1-1-caching-gui-administrator</link>
      <pubDate>Tue, 31 Jan 2012 23:08:20 GMT</pubDate>
      <dc:creator><![CDATA[Prathul Prabhakar - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/prathul/2012/01/31/now-available-appfabric-1-1-caching-gui-administrator/</guid>
      <description><![CDATA[Finally, I have published the graphical untility to administer and configure Appfabric 1.1 caching....]]></description>
      <content:encoded><![CDATA[<p>Finally, I have published the graphical untility to administer and configure Appfabric 1.1 caching. This utility will make your life easier when configuring the read-through, write behind provider. I plan to make changes to this as and when required with forth coming releases of Server Appfabric. Feel free to download the tool from</p>
<p><a href="https://appfabricadmin.codeplex.com/">https://appfabricadmin.codeplex.com/</a>. Do provide your valuable feedback, bugs.</p>
<p>Project home page: <a href="https://appfabricadmin.codeplex.com/">https://appfabricadmin.codeplex.com/</a><br />Direct Download: <a href="https://appfabricadmin.codeplex.com/releases/81495/download/336376">https://appfabricadmin.codeplex.com/releases/81495/download/336376</a></p>
<p>&nbsp;</p>]]></content:encoded>
    </item>
    <item>
      <title>Windows Phone users! Forget 'Siri'; Ask Ziggy</title>
      <link>https://docs.microsoft.com/archive/blogs/prathul/windows-phone-users-forget-siri-ask-ziggy</link>
      <pubDate>Mon, 02 Jan 2012 22:32:00 GMT</pubDate>
      <dc:creator><![CDATA[Prathul Prabhakar - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/prathul/2012/01/02/windows-phone-users-forget-siri-ask-ziggy/</guid>
      <description><![CDATA[Wish you a very happy new year!!! May this year be filled with success and fabulous joys!...]]></description>
      <content:encoded><![CDATA[<p>Wish you a very happy new year!!! May this year be filled with success and fabulous joys! :)</p>
<p>Nothing technical today. Just came across an app for Windows Phone which brings Siri functionality to your Windows Phone. The best part is that the app is free! Download it for free from marketplace&nbsp;<a title="https://www.windowsphone.com/en-IN/apps/71970bb1-1de9-46a9-a602-040e1e7356cb" href="https://blogs.msdn.com/controlpanel/blogs/posteditor.aspx/here" target="_blank"></a><a href="https://www.windowsphone.com/en-IN/apps/71970bb1-1de9-46a9-a602-040e1e7356cb">https://www.windowsphone.com/en-IN/apps/71970bb1-1de9-46a9-a602-040e1e7356cb</a>". The response is a bit slow, but given that this is an initial build, we can look forward to better response time in near future.&nbsp;From the market place:</p>
<pre style="font: 14px/19px 'Segoe WPC', 'Segoe UI', Helvetica, Arial, 'Arial Unicode MS', sans-serif; margin: 0px 0px 46px; padding: 0px; text-align: left; color: #666666; text-decoration: none; white-space: pre-wrap; word-wrap: break-word; font-size-adjust: none; font-stretch: normal;"><em>If you are craving Siri like functionality for Windows Phone and more, look no further. Ask Ziggy is your Personal Assistant that goes beyond Siri functionality. You can Call, Text, Email your contacts, Update Windows Live, Facebook, and Twitter, Get Weather, Stock Values, Flight Statuses, Get Ziggy to do Math, or ask any question you want (i.e. Who is the tallest person?) all by speaking to your phone.</em></pre>
<p>Check out the sample videos at their <a title="https://www.ziggybot.com/" href="https://blogs.msdn.com/controlpanel/blogs/posteditor.aspx/home site" target="_blank">home site</a>.</p>]]></content:encoded>
    </item>
    <item>
      <title>Architecture: Solving a resequencing problem</title>
      <link>https://docs.microsoft.com/archive/blogs/prathul/architecture-solving-a-resequencing-problem</link>
      <pubDate>Tue, 27 Dec 2011 05:14:00 GMT</pubDate>
      <dc:creator><![CDATA[Prathul Prabhakar - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/prathul/2011/12/27/architecture-solving-a-resequencing-problem/</guid>
      <description><![CDATA[Problem: 
Some systems, especially the financial ones require that the sequence of orders coming...]]></description>
      <content:encoded><![CDATA[<p><span style="text-decoration: underline;"><strong>Problem:</strong> </span></p>
<p>Some systems, especially the financial ones require that the sequence of orders coming into the system be maintained after processing. This sounds like a simple problem to solve. But consider&nbsp;the same system in a scaled up scenario.&nbsp;There could&nbsp;be multiple receiver that picks up the&nbsp;order from an incoming&nbsp;queue and processes it in parallel pipes. How do we ensure that the&nbsp;after processing, the orders are sent out of the system in the same order? The problem we are trying to solve is what is known as <a href="https://eaipatterns.com/Resequencer.html">resequencer</a>&nbsp;problem.</p>
<p><br /><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/48/37/8322.Initial.jpg" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-48-37/8322.Initial.jpg"><img border="0" alt="" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/48/37/8322.Initial.jpg" original-url="https://blogs.msdn.com/resized-image.ashx/__size/550x600/__key/communityserver-blogs-components-weblogfiles/00-00-01-48-37/8322.Initial.jpg" /></a></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>Solution: </strong>Make each of the order coming into the system pass through a unique id generator. If each order has a unique sequence id, this step can be skipped. As soon as the unique id is generated, create an empty entry in an in-memory collection with the order id as key. The in-memory collection can be a SortedList or HashTable. Once the processing of each processing pipe is complete, the empty object in the in the in-memory queue is updated with the processed object. If the processed object is the first node in the in-memory queue, start sending the order to the external queue until an empty object is encountered.</p>
<p><span style="text-decoration: underline;"><strong>Sample Flow:</strong></span></p>
<ol>
<li>Consider orders 1,2,3 in the incoming queue.</li>
<li>An in-memory sorted list is created with null values whose key is 1,2,3. Each order is processed by a different receiver and processing pipe.</li>
<li>Assume that for some reason that the pipe processing order 1 is slow. Hence orders 2,3 finished processing first and the processed object got updated in the empty queue.</li>
<li>The first node in the in-memory queue is still empty, but there are processed objects in the next nodes 2,3</li>
<li>As soon as order 1 is processed, the empty node is updated. Since this is the first node, the object is send to external queue and removed from in-memory queue. The pointer is incremented to find that there is object in node 2. This cycle is repeated until it encounters an empty node.</li>
</ol>
<p><span style="text-decoration: underline;"><strong>Questions:</strong></span></p>
<p><strong>1. </strong>What if the processing of one of the pipes slows down? Wouldn't it cause the other orders to wait before being sent to the external system?<br /><strong>Ans: </strong>Right! But remember, a system can only be as fast as its slowest link. This holds true in this case also.</p>
<p><strong>2.</strong> Wouldn't the id generator and in-memory queue become a single point of failure?<br /><strong>Ans: </strong>To avoid this, you can maintain a copy of it in a cache. Server Appfabric cache with proper locks would help you achieve it.</p>
<p>&nbsp;</p>
<p>Do share your thoughts and feedback on this solution; especially&nbsp;if you can think of a better solution. Happy coding! :)</p>]]></content:encoded>
    </item>
    <item>
      <title>WCF - Windows Service Hosting Error Resolutions</title>
      <link>https://docs.microsoft.com/archive/blogs/prathul/wcf-windows-service-hosting-error-resolutions</link>
      <pubDate>Mon, 26 Dec 2011 09:01:36 GMT</pubDate>
      <dc:creator><![CDATA[Prathul Prabhakar - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/prathul/2011/12/26/wcf-windows-service-hosting-error-resolutions/</guid>
      <description><![CDATA[Ever came across any of these errors while hosting WCF on windows service?
1. The&nbsp;xxx service...]]></description>
      <content:encoded><![CDATA[<p>Ever came across any of these errors while <a title="https://msdn.microsoft.com/en-us/library/ms733069.aspx" href="https://blogs.msdn.com/controlpanel/blogs/posteditor.aspx/hosting WCF on windows service" target="_blank">hosting WCF on windows service</a>?</p>
<p><br /><em>1. The&nbsp;xxx service on Local Computer started and then stopped. Some services stop automatically if they are not in use by other services or programs.</em><br /><br />or</p>
<p><em>2. Service cannot be started. System.ServiceModel.AddressAlreadyInUseException: HTTP could not register URL https://+:8011/PersistanceManager/ because TCP port 8011 is being used by another application. ---&gt; System.Net.HttpListenerException: The process cannot access the file because it is being used by another process</em></p>
<p><em></em>&nbsp;</p>
<p><strong>Solution for problem 1: </strong>To find the root cause of the error, look into the event viewer. The most probable cause would the that the referenced assemblies or the app.config would not be present in the same directory as the executable. Also when you copy the app.config, make sure to rename it as applicationname.exe.config.</p>
<p><strong>Solution for problem 2: </strong>Check if you have provided a port number for the mex address. Mex doesnt require a port number, so you can saferly remove it and the problem would be solved. If the problem still persists, check if any other application is using the same port number. You can make use of netsh command to accomplish this (search for how to use this command). If you are not running under administrative privilages, you can even allow everyone to make use of the port using the netsh command.</p>
<p>This should solve your problem in almost all cases. In case the problem still persists, do feel free to leave a comment and I will revert back. Happy coding! :)</p>]]></content:encoded>
    </item>
    <item>
      <title>A simple Managed Extensibility Framework (MEF) application using ImportMany</title>
      <link>https://docs.microsoft.com/archive/blogs/prathul/a-simple-managed-extensibility-framework-mef-application-using-importmany</link>
      <pubDate>Mon, 12 Dec 2011 04:28:00 GMT</pubDate>
      <dc:creator><![CDATA[Prathul Prabhakar - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/prathul/2011/12/12/a-simple-managed-extensibility-framework-mef-application-using-importmany/</guid>
      <description><![CDATA[Managed Extensibility Framework (MEF) is a component of .NET Framework 4.0 for creating lightweight,...]]></description>
      <content:encoded><![CDATA[<p><a href="https://upload.wikimedia.org/wikipedia/en/f/fc/Blocks.png"><img style="max-width: 550px;" border="0" alt="" src="https://upload.wikimedia.org/wikipedia/en/f/fc/Blocks.png" width="77" height="90" /></a>Managed Extensibility Framework (MEF) is a component of .NET Framework 4.0 for creating lightweight, extensible applications. Using this, you can discover and use extensions at run-time with no configuration required. Imagine adding a new functionality to your application by just adding new DLLs to a predefined directory without recompiling! You can read and explore more about MEF at the <a title="https://mef.codeplex.com/" href="https://blogs.msdn.com/controlpanel/blogs/posteditor.aspx/Codeplex" target="_blank">Codeplex</a> site. So we won't go much into the basics here.</p>
<p>For this simple example, lets consider that we need to process&nbsp;string messages which comes word "FIX:" or "SWIFT:". We will create mappers that can process these message types. Also do note that for that example I am placing all imports and exports in the same project. For true extensibility, do place the exports in external library files.</p>
<p>Make sure you have added references to <strong>System.ComponentModel</strong> dll and added the namespace <strong>System.ComponentModel.Composition &amp; System.ComponentModel.Composition.Hosting</strong>.&nbsp;To begin with lets create the <strong>contracts</strong> which will be the avenue of communication between <strong>Imports</strong> and <strong>Exports</strong>.&nbsp;Contracts are nothing but the normal interface.</p>
<pre class="scroll"><code class="csharp"> public interface IMapper<br /> {<br /> String Map(String message);<br /> }<br /> <br /> public interface IMapperMetaData<br /> {<br /> String MessageType { get; }<br /> }</code></pre>
<p>IMapper will be&nbsp;the extensible point&nbsp;for your application.&nbsp;The&nbsp;third party developers who will be extending your application should&nbsp;have reference to this. Apart from this, you can also add metadata information to your export so that&nbsp;you can load the appropriate components only&nbsp;at runtime.&nbsp;</p>
<p>Next create the program that would <strong>compose all the parts</strong> (imports and exports are known as parts). I have added comments to the code as appropriate. The customMappers with ImportMany tag will contain all the exported parts which we will be creating later on.</p>
<pre class="scroll"><code class="cplusplus"> class MapperClass<br /> {<br /> [ImportMany(typeof(IMapper))]<br /> public IEnumerable&lt;Lazy&lt;IMapper,IMapperMetaData&gt;&gt; customMappers; //Lazy import ensures components are loaded only when required<br /> <br /> private CompositionContainer _container;<br /> <br /> public MapperClass()<br /> {<br /> var catalog = new AggregateCatalog();<br /> catalog.Catalogs.Add(new AssemblyCatalog(typeof(Program).Assembly)); //Locations to look for parts. If your export is in a an external dll, you need to use directory catalog as well <br /> _container = new CompositionContainer(catalog);<br /> <br /> try<br /> {<br /> _container.ComposeParts(this); //Compose the imports and exports<br /> }<br /> catch (CompositionException ce)<br /> {<br /> Console.WriteLine(ce.Message);<br /> }<br /> }<br /> }</code></pre>
<p>Its now time to<strong> create our exports</strong>. We will create two export parts which will be composed with the import we had defined earlier. You may place these two parts in seperate library, compile it and place it in the parent program executable location. Make sure you add a DirectoryCatalog with the directory to search for parts to the catalogs collection in the program above if you are using seperate DLLs.</p>
<pre class="scroll"><code class="csharp"> [Export(typeof(IMapper))]<br /> [ExportMetadata("MessageType", "FIX")]<br /> class FixMessage : IMapper<br /> {<br /> public string Map(string message)<br /> {<br /> return "Processed by FIX";<br /> }<br /> }<br /> </code></pre>
<p>Finally its time to test out the program. Create a simple console app as follows:</p>
<pre class="scroll"><code class="csharp"> static void Main(string[] args)<br /> {<br /> MapperClass mc = new MapperClass();<br /> string s="FIX:2343";<br /> <br /> string []types=s.Split(':');<br /> bool processed = false;<br /> foreach(var i in mc.customMappers)<br /> {<br /> if (i.Metadata.MessageType == types[0])<br /> {<br /> processed = true;<br /> Console.WriteLine(i.Value.Map(s));<br /> }<br /> }<br /> if(!processed)<br /> Console.WriteLine("Could not process message as no matching mapper was found");<br /> Console.Read();<br /> }</code></pre>
<p>The program would work perfectly well. Now change the value of 's' to "SWIFT:3234". The program would say that the mapper was not found. All you need to do is create another export and place it in the same directory.</p>
<pre class="scroll"><code class="csharp"> [Export(typeof(IMapper))]<br /> [ExportMetadata("MessageType", "SWIFT")]<br /> class SwiftMessage : IMapper<br /> {<br /> public string Map(string message)<br /> {<br /> return "Processed by SWIFT";<br /> }<br /> }</code></pre>
<p>Hope I have succeeded in getting you to explore more on MEF, especially for those professionals who work extensively on building extensible applications. Do leave your valuable feedback and comments. Happy coding. :)</p>
<p><strong></strong>&nbsp;</p>
<p><strong>UPDATE:</strong></p>
<p>To use directory catalog do the following:</p>
<p>catalog.Catalogs.Add(<span style="color: #0000ff; font-family: Consolas; font-size: x-small;" face="Consolas" size="2" color="#0000ff"><span style="color: #0000ff; font-family: Consolas; font-size: x-small;" face="Consolas" size="2" color="#0000ff"><span style="color: #0000ff; font-family: Consolas; font-size: x-small;" face="Consolas" size="2" color="#0000ff">new</span></span></span><span style="font-family: Consolas; font-size: x-small;" face="Consolas" size="2"><span style="font-family: Consolas; font-size: x-small;" face="Consolas" size="2"> </span></span><span style="color: #2b91af; font-family: Consolas; font-size: x-small;" face="Consolas" size="2" color="#2b91af"><span style="color: #2b91af; font-family: Consolas; font-size: x-small;" face="Consolas" size="2" color="#2b91af"><span style="color: #2b91af; font-family: Consolas; font-size: x-small;" face="Consolas" size="2" color="#2b91af">DirectoryCatalog</span></span></span><span style="font-family: Consolas; font-size: x-small;" face="Consolas" size="2"><span style="font-family: Consolas; font-size: x-small;" face="Consolas" size="2">(</span></span><span style="color: #a31515; font-family: Consolas; font-size: x-small;" face="Consolas" size="2" color="#a31515"><span style="color: #a31515; font-family: Consolas; font-size: x-small;" face="Consolas" size="2" color="#a31515"><span style="color: #a31515; font-family: Consolas; font-size: x-small;" face="Consolas" size="2" color="#a31515">"."</span></span></span><span style="font-family: Consolas; font-size: x-small;" face="Consolas" size="2"><span style="font-family: Consolas; font-size: x-small;" face="Consolas" size="2">));</span></span></p>
<p>Compile FIX and SWIFT classes as seperate library dlls. You now need to place this in the same directory as the Mapper.exe. Do leave a comment if you have any questions.</p>
<p><strong></strong></p>]]></content:encoded>
    </item>
    <item>
      <title>Windows Server Appfabric 1.1 RTM is now available: Whats new?</title>
      <link>https://docs.microsoft.com/archive/blogs/prathul/windows-server-appfabric-1-1-rtm-is-now-available-whats-new</link>
      <pubDate>Tue, 06 Dec 2011 22:56:00 GMT</pubDate>
      <dc:creator><![CDATA[Prathul Prabhakar - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/prathul/2011/12/06/windows-server-appfabric-1-1-rtm-is-now-available-whats-new/</guid>
      <description><![CDATA[The much awaited Windows Server Appfabric 1.1 is now RTM and available for download. Windows Server...]]></description>
      <content:encoded><![CDATA[<p>The much awaited Windows Server Appfabric 1.1 is now RTM and available for download. Windows Server Appfabric as we know includes the on premise caching and hosting service. The new features of 1.1 are:</p>
<ul>
<li><a title="Read Through-Write Behind" href="https://blogs.msdn.com/b/prathul/archive/2011/12/06/appfabric-cache-read-from-amp-write-to-database-read-through-write-behind.aspx" target="_blank">Read-Through/Write-Behind</a></li>
<li>Graceful Shutdown</li>
<li>Domain Accounts</li>
<li>New ASP.NET Session State and Output Caching Provider</li>
<li>Compression</li>
<li>Multiple Cache Client Application Configuration Sections</li>
</ul>
<p>Just yesterday I had <a title="Read Through-Write Behind" href="https://blogs.msdn.com/b/prathul/archive/2011/12/06/appfabric-cache-read-from-amp-write-to-database-read-through-write-behind.aspx" target="_blank">written about the Read through - Write behind feature</a> of 1.1 CTP. You can download the Windows Server Appfabric 1.1 RTM <a href="https://www.microsoft.com/download/en/details.aspx?id=27115" target="_blank">here</a>. Read more about it at MSDN <a href="https://msdn.microsoft.com/en-us/library/hh351318.aspx" target="_blank">here</a>.</p>]]></content:encoded>
    </item>
    <item>
      <title>Appfabric Cache: Read from &amp; Write to Database (Read through - Write behind)</title>
      <link>https://docs.microsoft.com/archive/blogs/prathul/appfabric-cache-read-from-write-to-database-read-through-write-behind</link>
      <pubDate>Mon, 05 Dec 2011 23:24:41 GMT</pubDate>
      <dc:creator><![CDATA[Prathul Prabhakar - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/prathul/2011/12/05/appfabric-cache-read-from-write-to-database-read-through-write-behind/</guid>
      <description><![CDATA[The Windows Server Appfabric 1.1 CTP has the much awaited Read-through and Write-through...]]></description>
      <content:encoded><![CDATA[<p>The Windows Server Appfabric 1.1 CTP has the much awaited Read-through and Write-through feature.</p>
<ul>
<li>Read through -&nbsp;If a requested item doesn't exist in the cache, the data can be loaded from backend store and then inserted into cache. With a read-through provider, the cache detects the missing item and calls the provider to perform the data load. The item is then seamlessly returned to the cache client.&nbsp;&nbsp;</li>
<li>Write&nbsp;behind -&nbsp;In the same way, items that are added or updated in the cache can be periodically written to the backend store using a write-through provider. This happens asynchronously and on an interval defined by the cache.</li>
</ul>
<p>One&nbsp;key scnarios where this feature is handy is when a client requests for an item that has already been removed from cache. The item will automatically be loaded back to cache from the backend store. Likewise the changes you do to the items in cache are persisted asynchronously from time to time without any user intervention.</p>
<p>To accomplish this feature, you will have to write a provider (class library) that extends <em><strong>DataCacheStoreProvider</strong> </em>abstract class. Then you need to install (in gac) your provider to each of the cache host of the cache cluster. The final step is to configure your named cache to use this provider. To get started make sure you have installed the Windows Server Appfabric 1.1 CTP. Next, create&nbsp; a C# class library and reference the library <em><strong>Microsoft.ApplicationServer.Caching.</strong></em>&nbsp;For 1.1 CTP, this is normally located under 'Program Files/Windows Server Appfabric'. Now implement the abstract class DataCacheStoreProvider.</p>
<pre class="scroll"><code class="csharp">using Microsoft.ApplicationServer.Caching;<br /> <br /> namespace SampleProvider<br /> {<br /> public class Provider:DataCacheStoreProvider<br /> {</code></pre>
<pre class="scroll"><br /> private String dataCacheName;<br /> private String connectionString;<br /> <br /> public Provider(string cacheName, Dictionary&lt;string, string&gt; config)<br /> {<br /> dataCacheName = cacheName; //Store the cache name for future use<br /> connectionString = config[0].Value;<br /> }<br /> <br /> public override void Delete(System.Collections.ObjectModel.Collection&lt;DataCacheItemKey&gt; keys){} <br /> <br /> public override void Delete(DataCacheItemKey key){} <br /> <br /> protected override void Dispose(bool disposing){} <br /> <br /> public override void Read(System.Collections.ObjectModel.ReadOnlyCollection&lt;DataCacheItemKey&gt; keys, IDictionary&lt;DataCacheItemKey, DataCacheItem&gt; items){} <br /> <br /> public override DataCacheItem Read(DataCacheItemKey key){} <br /> <br /> public override void Write(IDictionary&lt;DataCacheItemKey, DataCacheItem&gt; items){} <br /> <br /> public override void Write(DataCacheItem item){} <br /> }<br /> }</pre>
<pre class="scroll">A few things about the above code first. Your provider needs to have a constructor with the following signature. These parameters are passed in when your cache host initializes. The cacheName would contain the name of the cache for which you have created the provider. </pre>
<pre class="scroll">The config will contain any configuration details like the connection string that you can pass while registerting your provider in the final step. public Provider(String cacheName, Dictionary&lt;string, string&gt; config) The other methods you need to implement are the Read, Write, Delete and Dispose. </pre>
<pre class="scroll">You need not implement all the methods. If you want only read-through feature, just implement the Read. The following table gives you a gist of what each of the function does.&nbsp;</pre>
<table border="1" align="left">
<tbody>
<tr>
<td><strong>Read</strong></td>
<td>Read a value from database, load it into the cache as well as return it to the client requesting for the cache item.</td>
</tr>
<tr>
<td><strong>Write</strong></td>
<td>Persist items in the cache to the backend store (database) after a specified amount of time.</td>
</tr>
<tr>
<td><strong>Delete</strong></td>
<td>Delete an item from the backend store when a cache item is removed from the cache by the client.</td>
</tr>
<tr>
<td><strong>Dispose</strong></td>
<td>Called when the host is shutting down. Any cleanup code goes here.</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><span style="text-decoration: underline;"><strong>Implementing Read</strong></span></p>
<p>Read has two methods. One which takes a dictionary collection and the other takes a DataCacheItemKey. Read requests are always sent as a dictionary collection. Let us first implement the function with DataCacheItemkey parameter and then use it to process the other read function which accepts the dictionary collection.</p>
<pre class="scroll"><code class="csharp"> public override DataCacheItem Read(DataCacheItemKey key)<br /> {<br /> Object retrievedValue = null;<br /> DataCacheItem cacheItem;<br /> <br /> retrievedValue = ReadFromDatabase(key.Key); //Your implemented method that searches in the backend store based<br /> <br /> if (retrievedValue == null)<br /> cacheItem = null;<br /> else<br /> cacheItem = DataCacheItemFactory.GetCacheItem(key, dataCacheName, retrievedValue, null);<br /> return cacheItem; <br /> }</code></pre>
<p>You need to use <em><strong>DataCacheItemFactory </strong></em>class to create your cache item as follows <em><strong>DataCacheItemFactory.GetCacheItem(key, dataCacheName, retrievedValue, null)</strong></em>. If the item is not found, we are returning null which matches with the cache cluster behaviour. Next lets implemet the read which accepts the dictonary collection.</p>
<pre class="scroll"><code class="csharp"> public override void Read(System.Collections.ObjectModel.ReadOnlyCollection&lt;DataCacheItemKey&gt; keys, IDictionary&lt;DataCacheItemKey, DataCacheItem&gt; items)<br /> {<br /> foreach (var key in keys)<br /> {<br /> items[key] = Read(key);<br /> }<br /> }</code></pre>
<p>As mentioned before, we are just using the '<em>public override DataCacheItem Read(DataCacheItemKey key)' </em>to read the items from backend store. You need to add the items to <em>IDictionary&lt;DataCacheItemKey, DataCacheItem&gt; items</em> as in the code above before returning from read method.</p>
<p><span style="text-decoration: underline;"><strong></strong></span>&nbsp;</p>
<p><span style="text-decoration: underline;"><strong>Implementing Write</strong></span></p>
<p>Write is implemented the same way as read. It's important to remove the items which has been written to the backend store from the <em>IDictionary&lt;DataCacheItemKey, DataCacheItem&gt; items. </em>If you have successfully written all the values to the backend store, you can simply clear the items dictionary object by calling items.Clear().</p>
<pre class="scroll"><code class="csharp"> public override void Write(IDictionary&lt;DataCacheItemKey, DataCacheItem&gt; items)</code></pre>
<p><span style="text-decoration: underline;"><strong></strong></span>&nbsp;</p>
<p><span style="text-decoration: underline;"><strong>Compiling your provider</strong></span></p>
<p>Your provider should be signed with a stong key. To do this, go to your Project Properties&gt; Signing &gt; Check 'Sign the assembly'&gt; Choose or create a strong key name file.</p>
<p><span style="text-decoration: underline;"><strong></strong></span>&nbsp;</p>
<p><span style="text-decoration: underline;"><strong>Installing your provider</strong></span></p>
<p>Your provider should be placed in the&nbsp;GAC of all the hosts of the cluster. Run the visual studio command prompt and type in the following command to add your provider to gac.</p>
<p><em>gacutil /i SampleProvider.dll</em></p>
<p>You now need to get the fully qualified name of your provider. To do this type the command <strong>without the dll extension</strong><br /><br /><em>gacutil /l SampleProvider</em></p>
<p>This would give you a message as follows:</p>
<p><em>SampleProvider, Version=1.0.0.0, Culture=neutral, PublicKeyToken=0dca281230246e10, processorArchitecture=MSIL</em></p>
<p>We need to add the class details to the above message and remove the processorArchitecture. We will be using this string to register your provider with the cache&nbsp;</p>
<p><em>SampleProvider.Provider, <em><em>SampleProvider, </em></em>Version=1.0.0.0, Culture=neutral, PublicKeyToken=0dca281230246e10<br /><br /></em></p>
<p><span style="text-decoration: underline;"><strong>Registering your provider</strong></span></p>
<p>Time to fire up the cache administration powershell. Here I am registering a provider for an existing named cache. If you are creating a new cache, you need to use the same parameters with the new-cache command.</p>
<p><code class="csharp">Set-CacheConfig TestCache -ReadThroughEnabled true -WriteBehindEnabled true -WriteBehindInterval 60 -ProviderType "SampleProvider.Provider, SampleProvider, Version=1.0.0.0, Culture=neutral, PublicKeyToken=0dca281230246e10" -ProviderSettings @{"DbConnection"="&lt;your connection string&gt;";}</code></p>
<p>If your provider supports read through, set -ReadThroughEnabled to true. If your provider supports&nbsp;write behind, set -WriteBehindEnabled to&nbsp;true and also the interval between which cache&nbsp;items are persisted to database store. The minimum duration that can be set in this CTP is 60 seconds.&nbsp;In the -ProviderType, pass the string that we created in the step "Installing your provider". To pass config parameters to the initializer <em>'public Provider(string cacheName, Dictionary&lt;string, string&gt; config)</em>', make use of -ProviderSettings as in example above. Make sure you have set the same config for all the hosts in your cluster. Once that is done, start your cache cluster. If any of your cache host fails to start, probably there is some problem with your provider. Look for errors in your system event log.</p>
<p>&nbsp;</p>
<p><span style="text-decoration: underline;"><strong>Testing your provider</strong></span></p>
<p>To test your provider, create a sample test client and request for an item that is not present in cache. The read of your provider will be called when the cluster fails to find the item in cache. To test write, add an item to cache cluster and wait for the -WriteBehindTimeInterval to pass.</p>
<p>&nbsp;</p>
<p><span style="text-decoration: underline;"><strong>Debugging your provider</strong></span></p>
<p>To debug your provider code, open the class project and then go to Debug&gt;Attach to process&gt; and select DistributedCacheService.exe. Put debug points as necessary. Read will be hit when you request for a key.</p>
<p>&nbsp;</p>
<p>Feel free to send in your comments or questions. Happy coding. :)</p>
<p>&nbsp;</p>]]></content:encoded>
    </item>
  </channel>
</rss>