Recently in .NET Category

Sources of Info on Geneva Framework, Server, and Cardspace

| | Comments (0) | TrackBacks (0) |
In early 2007, I started using WCF on a daily basis while it and Visual Studio 2008 were still in beta.  It was great to get the jump on that technology, but it was really hard to find information when I bumped up against bugs or uncertainties.  Now, two years later, I find myself in the same boat again, but this time with Geneva.  Right now there isn't much info coming out of Redmond, but this is the time I need it not in 11 months when this stuff RTMs.  For this reason, I decided to start collecting all the useful sources of information that I've found related to Geneva framework, server, and Cardspace.

Sources of Information to Get Started

Before you do anything, check out these documents and videos:


Obscure Information

Once you've read and reread the above like 50 times, and you're totally desperate for more info, check out these feeds:


Bloggers Talking About Geneva


 
I'll update this list as I find more.  If you have some pearls, please post a comment with a link.

Using Regexs in XSLT Transformations with .NET 3.5

| | Comments (0) | TrackBacks (0) |

This week I need to do something relatively simple that should have taken no time but ended up taking the better part of a morning: I needed to write an XSLT template that transformed a node value using a regular expression. I learned that XSLT 2 supports regular expressions; however, there is no support for XSLT 2 in .NET 3.5. So, I added an extension function to my template that the XPath engine could use to apply the regular expression substitution. Using this custom function required me to qualify it with a namespace prefix. This introduced a problem because I was creating the template dynamically at run-time using LINQ to XML. This technology tries to hide all namespace-related tasks from you (which is helpful in some applications), so I struggled to find a way to add the namespace and the corresponding prefix to the XDocument that I was building up in memory. Eventually, I ended up with something along these lines:

    1 class Program

    2 {

    3     static void Main()

    4     {

    5         var outputXml = new StringBuilder();

    6         var inputXml = @"<r><phoneNumber>555-555-5555</phoneNumber><o>Foo</o></r>";          

    7         var transform = new XslCompiledTransform();

    8         var templates = GetTemplates();

    9         var stylesheet =                                                                  

   10             new XDocument(new XElement(xsltNs + "stylesheet",

   11                 new XAttribute("version", "1.0"),

   12                 new XAttribute(XNamespace.Xmlns + extNsPrefix, extNs),                      

   13                 templates));

   14 

   15         using (var reader = stylesheet.CreateReader())

   16             transform.Load(reader);

   17 

   18         using (var reader = XmlReader.Create(new StringReader(inputXml)))

   19         using (var writer = XmlWriter.Create(outputXml))

   20         {

   21             var arguments = new XsltArgumentList();

   22 

   23             arguments.AddExtensionObject(extNs.ToString(), new XPathExtensions());          

   24             transform.Transform(reader, arguments, writer);                                  

   25         }

   26 

   27         Trace.WriteLine(outputXml);

   28     }

   29 

   30     private static IEnumerable<XElement> GetTemplates()

   31     {

   32         var templates = new List<XElement>();

   33         var pattern = "\\d";

   34         var replacement = "X";

   35         var matchValue = "//phoneNumber/text()";

   36 

   37         templates.Add(XElement.Parse(

   38             @"<template match='@*|node()' xmlns='http://www.w3.org/1999/XSL/Transform'>

   39               <copy>

   40                 <apply-templates select='@*|node()'/>

   41               </copy>

   42             </template>"));

   43         templates.Add(

   44             new XElement(xsltNs + "template",

   45                 new XAttribute("match", matchValue),

   46                 new XElement(xsltNs + "value-of",

   47                     new XAttribute("select", string.Format("{0}:Replace(., '{1}', '{2}')",

   48                         extNsPrefix, pattern, replacement)))));

   49 

   50         return templates;

   51     }

   52 

   53     private class XPathExtensions

   54     {

   55         public static string Replace(string input, string pattern, string replacement)

   56         {

   57             return Regex.Replace(input, pattern, replacement);

   58         }

   59     }

   60 

   61     private static readonly XNamespace xsltNs = "http://www.w3.org/1999/XSL/Transform";

   62     private static readonly XNamespace extNs = "urn:foo";

   63     private const string extNsPrefix = "ext";

   64 }


This code isn't advanced, but there are a few details that can take a bit of time to figure out. So you're able to implement this sort of thing before your morning slips away and you miss your coffeebreak, I'll hightlight them here:



  • The XSLT stylesheet is created dynamically at run-time using LINQ to XML.

  • The subclass, XPathExtensions, has a public, static method called Replace that applies a regex to a given string and returns the result.

  • This class's method is made available to the XSLT engine by associating the namespace, urn:foo, with an instance of my XPathExtensions nested class and passed to the XslCompiledTransform object's Transform methods on lines 21 - 24.

  • The namespace and the prefix (ext) are explicitly added to the XSLT document that is created with LINQ to XML by adding the XAttribute on line 12.

  • This extension is called in the select statement on line 48 by prefixing the XPath function with ext and specifying the name of the public, static method that is in the XPathExtensions object that was passed into the engine via the XsltArgumentList.

(Of all these details, the one that took me the longest to figure out was how to explicitly add a namespace with a given prefix when using LINQ to XML.)

I hope this helps you solve your programming problems, and that you enjoy your coffee break!

Ordered Load Tests in VS 2008 SP1

| | Comments (0) | TrackBacks (0) |

This week my colleague and I were trying to run a dozen load tests in sequence. What we wanted was to execute a list of tests, so that we could go home and come back the next day to the results. Unfortunately, this is not possible with Visual Studio 2008 SP1. Apparently, there is a bug (that doesn't seem to have been fixed in the first service pack) that prevents one from selecting multiple load tests in the test view and executing them all. Dennis Stone suggested in a Microsoft forum post to work around this bug by queuing up the execution of the load tests one by one. The problem with this proposal, however, is that it will only work if you are using a remote test controller; the local controller only supports the execution of one load test at a time, so a second can't be queued after the first has started.

The work around that we found to execute the load tests one after the other was to use a batch file. Once we learned how to run a load test from the command line, it was short work to put together a script that would slave away for us all night. One gotya that nabbed us was the omission of the test run configuration information. Without this, our auxiliary files weren't copied to the proper directory and some of our tests failed, thus causing our task to take two nights instead of one :-(

So, to create an ordered load test, use MSTest in a batch script like this:

mstest.exe /runconfig:localtestrun.testrunconfig /testcontainer:LoadTest1.loadtest
mstest.exe /runconfig:localtestrun.testrunconfig /testcontainer:LoadTest2.loadtest
mstest.exe /runconfig:localtestrun.testrunconfig /testcontainer:LoadTestN.loadtest

After MSTest completes, the test results will be stored in the load test database, and you will be able to analyze them as usual using Visual Studio or SSRS.

VS 2008 SP 1 RTM

| | Comments (0) | TrackBacks (0) |

VS 2008 SP 1 just went to manufacturing! This "service pack" comes with a lot of new things which you can read about here, here, and here. Included with this SP, is the first official version of the Entity Framework, LINQ to Entities, and Astoria, AKA ADO.NET Data Services.

Check out this blog entry for installation instructions which include running a preparation tool that removed any previously installed CTP versions among other things. You can get the bits from this download page on Microsoft's site.

If you want the MSDN documentation installed on your local machine, you can get it from here.

It sure is a fun time to be a developer!

Main Index | Archives | BizTalk »