Blog Home 
Brent Anderson

RSS 2.0 Atom 1.0 CDF  
 
Sign In
 
 Friday, March 02, 2007

I recently had the opportunity to dig into QuickCounters.  I had been a consumer in the past but had never been involved in any actual instrumentation.

QuickCounters is a low overhead Performance Monitoring tool that you can easily instrument into your application at design time to gain valuable performance information at runtime.  It has been developed as an open source tool that you can dig into and enhance to fit your needs or simply use as is. 

What I really liked about QuickCounters was how easy it was to implement and the simple counterview UI that allows you to monitor multiple installations from one simple client.  It gives you a nice at-a-glance view of how your application(s) are performing and you can quickly identify areas that may need some tuning.  It is easily instrumented into any .Net, or BizTalk application and has recently been extended for WCF support.

Take some time and check it out.

http://www.codeplex.com/quickcounters

3/2/2007 1:29:42 PM (Central Standard Time, UTC-06:00)  #    Comments [0]    |  Trackback
 Thursday, February 15, 2007

I am currenlty at a client working on an integration project which will consist of a large number of integration points, schemas, and transforms.  We really needed a way to test out each of our maps in a canned unit test for repeatable and consistent verification.  I started with the model described by Gilles at:

http://blogs.msdn.com/gzunino/archive/2004/09/21/232629.aspx

http://blogs.msdn.com/gzunino/archive/2004/09/21/232429.aspx

However, one thing I wanted to change was the mapping from String-Stream-Transform and back and simply use the XslTransform and XsltArgumentList directly as exposed (though not documented) by Microsoft.XLANGs.BaseTypes.TransformBase through the Transform and TransformArgs properties

Our environment of choice was Team System Unit Test.  I stared by building up a utility method within our unit test framework to generically extract the XslTransform and XsltArgumentList from the appropriate BizTalk map within the Transform Assembly. I accomplished this by passing in the name of the map I wished to exercise and reflecting in to the assemby to retrieve teh XslTransform and XsltArgumentList.  See the following.

       public XmlDocument TransformWithBizTalkMap(FileStream sampleXML, string transformToTest)
        {
            string transformPath = @"..\..\..\Project.BizTalk.Transforms\bin\debug\Project.BizTalk.Transforms.dll";
            XmlDocument xmlOut = new XmlDocument();

            XslTransform xslTransform = new XslTransform();;
            XsltArgumentList xsltArgumentList = new XsltArgumentList();

          
            Assembly mapAssembly = Assembly.LoadFrom(transformPath);
            foreach (Type mapType in mapAssembly.GetTypes())
            {
                if (mapType.Name == transformToTest)
                {
                    //These methoods calls will get the Transform directly as XslTransform, not as a stream
                    PropertyInfo propXslTransform = mapType.GetProperty("Transform");
                    MethodInfo miXslTransform = propXslTransform.GetGetMethod();
                    if (miXslTransform != null)
                    {
                        Object obj = Activator.CreateInstance(mapType);
                        //get the actual transform
                        xslTransform = (XslTransform)miXslTransform.Invoke(obj, null);

                    }

                    //These methods will get the XslArgumentList directly as XsltArgumentList, not as a stream
                    PropertyInfo propXsltArgumentList = mapType.GetProperty("TransformArgs");
                    MethodInfo miXsltArgumentList = propXsltArgumentList.GetGetMethod();
                    if (miXsltArgumentList != null)
                    {
                        Object obj = Activator.CreateInstance(mapType);
                        //get the actual XsltArgumentList
                        xsltArgumentList = (XsltArgumentList)miXsltArgumentList.Invoke(obj, null);
                    }

                    BizTalkMap bizTalkMap = new BizTalkMap(xslTransform, xsltArgumentList);

                    Stream streamOut = bizTalkMap.TransformInstance(sampleXML);
                    xmlOut.Load(streamOut);
                }
            }

            return xmlOut;
        }

After I had the XslTransform and the XsltArgumentList for the BizTalk map I wanted to test I could now perform the test.  I simply modified the BizTalkMap class presented by Gilles to accept the XslTransform and XsltArgumentList directly instead of building them up from the streams.  Below is a copy of the updated class.

using System;
using System.Reflection;
using System.Xml;
using System.Xml.Xsl;
using System.Xml.XPath;
using System.Xml.Xsl;
using System.IO;
using System.Text;


namespace Project.Biztalk.UnitTest
{
    public class BizTalkMap
    {
        private XslTransform xslTransform;
        private XsltArgumentList xsltArgumentList;

        public BizTalkMap(XslTransform transform, XsltArgumentList args)
        {
            xslTransform = transform;
            xsltArgumentList = args;
        }

        public Stream TransformInstance(Stream inXml)
        {
            XslTransform transform = Transform;
            XmlDocument xmlInDoc = new XmlDocument();
            // Output stream
            MemoryStream outStream = new MemoryStream();
            XmlTextWriter xmlWriter = new XmlTextWriter(outStream, System.Text.Encoding.UTF8);

            xmlInDoc.Load(inXml);

            // Formatting options
            xmlWriter.Formatting = Formatting.Indented;
            xmlWriter.Indentation = 2;

            // Perform transformation - We do not specify a resolver
            transform.Transform(xmlInDoc, TransformArgs, xmlWriter, null);

            // Prepare the output stream
            outStream.Seek(0, SeekOrigin.Begin);

            return outStream;
        }

        private void StreamReader()
        {
            throw new Exception("The method or operation is not implemented.");
        }

        private XslTransform Transform
        {
            get {return xslTransform;}
        }

        private XsltArgumentList TransformArgs
        {
            get {return xsltArgumentList;}
        }
    }
}

Now with the Utility methods we are ready to tie into our Team Test framework and exercise each of our BizTalk maps.  All we need to do is build out the TestMethods for each of the BizTalk Maps passing in simply a input xml FileStream and the name of the map to exercise.  Hope this help you. Enjoy.........

2/15/2007 2:20:20 PM (Central Standard Time, UTC-06:00)  #    Comments [1]    |  Trackback
 Monday, January 15, 2007

test

1/15/2007 10:42:06 AM (Central Standard Time, UTC-06:00)  #    Comments [0]    |  Trackback
Copyright © 2008 RBA Consulting.