DevDays 2010 Session Demos & Recordings

DevDays 2010 Session Demos & Recordings

Below you’ll find the demo code for all of my presentations at the Dutch DevDays 2010 event last week. It was a great event, thanks to Arie Leeuwesteijn and the rest of his team. Thanks again for having me!

You can also find many of the DevDays 2010 session recordings on Channel9.

One of my favorite memories from the show was when my laptop decided to apply a Windows Update and reboot right in the middle of one of my presentations – I’m oblivious to it but the smiles gave it away:  😉

xp8qs8

This event had over 2000+ paid attendees this year, which is nearly the size of a large TechEd event, but it’s organized locally by Microsoft DE (Arie and his team). It keeps growing every year and has become one of the most successful regional events I’ve seen. Everything is top notch. The speaker line-up this was nothing short of amazing.

Also, every DevDays attendee received a free 1-week pass to Pluralsight On-Demand! (look for the plastic card in your attendee bag). Don’t forget to activate the card before it expires.

To get a full taste of the event, check out our DevDays 2010 Facebook photo album on the Pluralsight Training page.

Enjoy!

Upgrading Visual Studio Solutions with PowerShell

Upgrading Visual Studio Solutions with PowerShell

With the impending release of Visual Studio 2010, I find myself with large numbers of solutions that need be upgraded from VS 2008.  The thought of opening them all manually and running the upgrade wizard was daunting.  Then I considered that I would also need to change the target framework of the projects to .NET 4, and in some cases update the references (why the target framework change didn’t fix that I’m not sure).  So I did what any lazy programmer does, I wrote some code to do it for me. 

At first, I just wanted to upgrade all of my solutions, so I used some PowerShell to find all the solutions and invoke devenv.exe passing in the solution and the /upgrade switch.  This gets a little tricky, as passing command line parameters to executables in PowerShell always seems harder to me than it should be.  But I came up with this one line script that handles it nicely.  I get all the solution files, then do a for each.  The trick was to set variables for the parameters and then invoke it all at once with the variables.  I sleep after so that too many solutions aren’t open at once.  You can play with the sleep time for best results, or remove it if you don’t need it. (Note that I have a 64 bit installation of Windows, so the (x86) in the path)

 

gci * -include *.sln -recurse | foreach-object {$switchName= "/upgrade"; $slnPath = $_; & 'C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe' $slnPath $switchName; start-sleep -seconds 10}

 

That got all my solutions upgraded, but the target framework for each was still .NET 2 or .NET 3.5.  So I used a macro from The Visual Studio Blog to retarget all of my applications to .NET Framework 4.  To run the macro, I used a similar approach with PowerShell, but this time using the /command switch and the name of my macro. 

gci * -include *.sln -recurse | foreach-object {$sln = $_; $vs = "c:\program files (x86)\microsoft visual studio 10.0\common7\ide\devenv.exe"; $cmd = "/command"; $cmdparam = "`"Macros.MyMacros.ProjectManagement.SwitchFramework`""; & $vs $sln $cmd $cmdparam }

 

In this case, I had to wrap the command in quotes, so I used the PowerShell escape character (`). The gotcha with this command is that the IDE stays open after executing the macro.  If you have a lot of solutions, you can run out of resources on your system.  So you may want to break this up and only process a small set of solutions at once.

Finally, I found that when I tried to build my solutions, many of them were referencing the 3.0 version of System.ServiceModel and System.Runtime.Serialization.  I used another macro, and the same PowerShell command, to switch the references.  The macro I used is:

 

Sub SwapReferences()
        For Each project As EnvDTE.Project In DTE.Solution.Projects
            If project.Kind = PrjKind.prjKindCSharpProject OrElse project.Kind = PrjKind.prjKindVBProject Then
                Dim vp As VSProject = CType(project.Object, VSProject)
                Dim ref As VSLangProj.Reference = vp.References.Find("System.ServiceModel")
                If (Not ref Is Nothing) Then
                    ref.Remove()
                    vp.References.Add("System.ServiceModel")
                End If
                Dim dcref As VSLangProj.Reference = vp.References.Find("System.Runtime.Serialization")
                If (Not dcref Is Nothing) Then
                    dcref.Remove()
                    vp.References.Add("System.Runtime.Serialization")
                End If
            End If
        Next
    End Sub

 

Pretty simple and targeted, but it got the job done to replace the references I cared about. 

So, with a few macros, and a little PowerShell, I was able to convert over 30 solutions in a few minutes. 

Today on http://endpoint.tv – AppFabric Dashboard Overview

AppFabric has this great new Dashboard that gives you insight into what is happening with your services and workflows. In this video, Senior Programming Writer Michael McKeown shows you what the Dashboard can do for you.

Watch it now on endpoint.tv

For more on the AppFabric Dashboard see the following articles on MSDN

We have more great episodes available at http://endpoint.tv so keep watching

Ron Jacobs
Host of endpoint.tv

Today on http://endpoint.tv – Windows Server AppFabric Dashboard Overview

Today on http://endpoint.tv – Windows Server AppFabric Dashboard Overview

Windows Server AppFabric has this great new Dashboard that gives you insight into what is happening with your services and workflows. In this video, Senior Programming Writer Michael McKeown shows you what the Dashboard can do for you.

Watch it now on endpoint.tv

Get Microsoft Silverlight

For more on the AppFabric Dashboard see the following articles on MSDN

We have more great episodes available at http://endpoint.tv so keep watching

Ron Jacobs
Host of endpoint.tv

JavaScript Intellisense Improvements with VS 2010

JavaScript Intellisense Improvements with VS 2010

This is the twentieth in a series of blog posts I’m doing on the upcoming VS 2010 and .NET 4 release. 

Today’s blog post covers some of the nice improvements coming with JavaScript intellisense with VS 2010 and the free Visual Web Developer 2010 Express.  You’ll find with VS 2010 that JavaScript Intellisense loads much faster for large script files and with large libraries, and that it now provides statement completion support for more advanced scenarios compared to previous versions of Visual Studio.

[In addition to blogging, I am also now using Twitter for quick updates and to share links. Follow me at: twitter.com/scottgu]

Improved JavaScript Intellisense

Providing Intellisense for a dynamic language like JavaScript is more involved than doing so with a statically typed language like VB or C#.  Correctly inferring the shape and structure of variables, methods, etc is pretty much impossible without pseudo-executing the actual code itself – since JavaScript as a language is flexible enough to dynamically modify and morph these things at runtime. 

VS 2010’s JavaScript code editor now has the smarts to perform this type of pseudo-code execution as you type – which is how its intellisense completion is kept accurate and complete.  Below is a simple walkthrough that shows off how rich and flexible it is with the final release.

Scenario 1: Basic Type Inference

When you declare a variable in JavaScript you do not have to declare its type.  Instead, the type of the variable is based on the value assigned to it.  Because VS 2010 pseudo-executes the code within the editor, it can dynamically infer the type of a variable, and provide the appropriate code intellisense based on the value assigned to a variable.

For example, notice below how VS 2010 provides statement completion for a string (because we assigned a string to the “foo” variable):

image

If we later assign a numeric value to “foo” the statement completion (after this assignment) automatically changes to provide intellisense for a number:

image

Scenario 2: Intellisense When Manipulating Browser Objects

It is pretty common with JavaScript to manipulate the DOM of a page, as well as work against browser objects available on the client. 

Previous versions of Visual Studio would provide JavaScript statement completion against the standard browser objects – but didn’t provide much help with more advanced scenarios (like creating dynamic variables and methods).  VS 2010’s pseudo-execution of code within the editor now allows us to provide rich intellisense for a much broader set of scenarios.

For example, below we are using the browser’s window object to create a global variable named “bar”.  Notice how we can now get intellisense (with correct type inference for a string) with VS 2010 when we later try and use it:

image

When we assign the “bar” variable as a number (instead of as a string) the VS 2010 intellisense engine correctly infers its type and modifies statement completion appropriately to be that of a number instead:

image

Scenario 3: Showing Off

Because VS 2010 is psudo-executing code within the editor, it is able to handle a bunch of scenarios (both practical and wacky) that you throw at it – and is still able to provide accurate type inference and intellisense.

For example, below we are using a for-loop and the browser’s window object to dynamically create and name multiple dynamic variables (bar1, bar2, bar3bar9).  Notice how the editor’s intellisense engine identifies and provides statement completion for them:

image

Because variables added via the browser’s window object are also global variables – they also now show up in the global variable intellisense drop-down as well:

image

Better yet – type inference is still fully supported.  So if we assign a string to a dynamically named variable we will get type inference for a string.  If we assign a number we’ll get type inference for a number. 

Just for fun (and to show off!) we could adjust our for-loop to assign a string for even numbered variables (bar2, bar4, bar6, etc) and assign a number for odd numbered variables (bar1, bar3, bar5, etc):

image

Notice above how we get statement completion for a string for the “bar2” variable. 

Notice below how for “bar1” we get statement completion for a number:

image 

This isn’t just a cool party trick

While the above example is a bit contrived, the approach of dynamically creating variables, methods and event handlers on the fly is pretty common with many Javascript libraries.  Many of the more popular libraries use these techniques to keep the size of script library downloads as small as possible.  VS 2010’s support for parsing and pseudo-executing libraries that use these techniques ensures that you get better code Intellisense out of the box when programming against them.

Summary

Visual Studio 2010 (and the free Visual Web Developer 2010 Express) now provide much richer JavaScript intellisense support.  This support works with pretty much all popular JavaScript libraries.  It should help provide a much better development experience when coding client-side JavaScript and enabling AJAX scenarios within your ASP.NET applications.

Hope this helps,

Scott

P.S. You can read my previous blog post on VS 2008’s JavaScript Intellisense to learn more about our previous JavaScript intellisense (and some of the scenarios it supported).  VS 2010 obviously supports all of the scenarios previously enabled with VS 2008.

BizTalk and SOAP Fault version issues

A developer in the same team made me aware of an issue they were seeing where if the BizTalk Send Port returned an exception the Client that called the ReceivePort would get a response that was interpreted as null instead of as an exception.

Now this is a synchronous service call without any orchestration, where BizTalk is just a broker of the web service calls. What we want out of it is this:

  1. For exceptions throw by the backend service to get relayed back to the original caller.
  2. For no suspended messages to be visible in BizTalk when an exception occurs with the backend service – so that operations won’t be bothered with removing them.
  3. For operations to get notified of all other exceptions, ie suspended messages.

Now this is all quite easy, all you need to do is make sure the propagate fault flag is checked on the send port adapter settings:

(somewhat shortened dialog)

What can happen though is that when the SOAP version does not match between what the Send Port receives and relays and what the client that called the Receive Port/Location is expecting is that the Fault ends up not being correctly formatted and thus the client is unable to interpret it.

This happens when you use the BasicHttp adapter or BasicHttpBinding with the Custom Adapter on the Receive Port and NetTcp (or WSHttp or etc) on the Send Port (or vice versa). It happens because the SOAP version that BasicHttp uses is different than that used by the other WCF Adapters.

A sample SOAP 1.1 Fault look like this:

<s:Fault>
  <faultcode>s:Client</faultcode>
  <faultstring xml:lang="sv-SE">You entered 666</faultstring>
</s:Fault>

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

(where the namespace s is defined on the envelope and points to xmlns:s="http://schemas.xmlsoap.org/soap/envelope/")

While a sample SOAP 1.2 Fault look like this:

<s:Fault xmlns:s="http://www.w3.org/2003/05/soap-envelope">
  <s:Code>
    <s:Value>s:Sender</s:Value>
  </s:Code>
  <s:Reason>
    <s:Text xml:lang="sv-SE">You entered 666</s:Text>
  </s:Reason>
</s:Fault>

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

In our scenario, with the type of metadata that BizTalk exposes for the service, what happens at the client is that what is actually a Fault instead gets interpreted as a valid response, but since the element that represents the response, let’s call it GetDataResponse just for sake of illustration, is missing – the client will interpret it as a null response. Highly unwanted.

The solution is to make sure that the Fault response is valid for the version of SOAP used by the receive side adapter, that is; do a transformation. A transformation can be done in many places: a map, a pipeline component, a WCF Message Inspector. In my case I prefer to place the component resolving the problem as close as possible to the thing causing the problem – which here means I opt for the Message Inspector, but a map might be the easiest for many. I might add the implementation of the message inspector in a later post, but for now, below is some custom xslt you can use in a map (or elsewhere) (if you do not use custom xslt you might get complaints from the client that the namespace prefixes are incorrect for reserved namespaces) – it maps from SOAP 1.1 to SOAP 1.2 (from BasicHttp to others, like NetTcp). You might perhaps also have to map in the other direction.

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
                xmlns:msxsl="urn:schemas-microsoft-com:xslt" 
                xmlns:var="http://schemas.microsoft.com/BizTalk/2003/var" 
                exclude-result-prefixes="msxsl var s0" version="1.0" 
                xmlns:s0="http://schemas.xmlsoap.org/soap/envelope/" 
                xmlns:xml="http://www.w3.org/XML/1998/namespace" 
                xmlns:s="http://www.w3.org/2003/05/soap-envelope">
  <xsl:output omit-xml-declaration="yes" method="xml" version="1.0" />
  <xsl:template match="/">
    <xsl:apply-templates select="/s0:Fault" />
  </xsl:template>
  <xsl:template match="/s0:Fault">
    <s:Fault>
      <s:Code>
        <s:Value>
          <xsl:value-of select="faultcode/text()" />
        </s:Value>
      </s:Code>
      <s:Reason>
        <s:Text xml:lang="sv-se">
          <xsl:value-of select="faultstring/text()" />
        </s:Text>
      </s:Reason>
      <xsl:if test="faultactor">
        <s:Role>
          <xsl:value-of select="faultactor/text()" />
        </s:Role>
      </xsl:if>
      <xsl:for-each select="detail">
        <s:Detail>
          <xsl:value-of select="./text()" />
        </s:Detail>
      </xsl:for-each>
    </s:Fault>
  </xsl:template>
</xsl:stylesheet>

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }