# Friday, February 15, 2008

Power Tools for Visual Studio Team System 2008 Database Edition

On Gert 'data dude' Drapers blog there is the announcement for Power Tools for Visual Studio Team System 2008 Database Edition.

Features include:

  • Command line SQL Static Code Analysis execution through MSBuild;
  • Data Generation Wizard;
  • File based data generator;
  • XML based data generator;
  • Unique Regular Expression generator;
  • Refactoring Command Generator has been made available as a MSBuild task;
  • Two new test conditions for Database Unit Tests:
    • ChecksumCondition – Which you can use to verify that the checksum of the data set returned by a database unit test matches the checksum of an expected data set.
    • ExpectedSchemaTestCondition – Which you use to verify that the column names and data types of the returned data set match expected values.
  •  

    #    Comments [0] |

    Windows Vista Service Pack 1

    Windows Vista Service Pack 1 is now available as a download on Microsoft MSDN Subscription Downloads.

    For the release notes, see http://download.microsoft.com/download/5/4/2/5429cde5-32d4-4e55-bf9a-553111438d86/relnotes.htm.

    For an overview of significant changes and improvements, see http://go.microsoft.com/fwlink/?LinkID=107921.

    For a list of the hotfixes and security updates included in SP1, see http://go.microsoft.com/fwlink/?LinkID=107922.

    #    Comments [0] |
    # Monday, January 28, 2008

    SQL Server 2008, Visual Studio 2008 and BI Designers

    In this blog the release schedule for SQL Server is explained and it becomes clear that SQL Server 2008 won't become available until 2008-Q3. Now aside from SQL Server 2008 not becoming available, this also means that the business intelligence suite which comes with SQL Server, the one you need to create SSIS packages and SQL Server reports, will not RTM until Q3. This in turn means that you won't be able to use these designers in Visual Studio 2008.

    The Business Intelligence Suite uses the Visual Studio Shell and integrates in such an excellent manner that it is quite thightly bound to a specific version of Visual Studio. The SQL Server 2005 Suite is bound to VS2005 and the SQL Server 2008 Suite is bound to VS2008. So if you're planning on moving to VS2008 you'll have to run VS2005 as well, at least until 2008-Q3.

    #    Comments [1] |
    # Thursday, January 17, 2008

    LINQ and recursion

    I was writing some code today to map online drive and files to a local objecttree. So I created a custom file and directory object and a directory holds subdirectories and files.

    Something like this:

    public class File
    {
        public string Name { get; set; }
    }

    public class Directory
    {
        public string Name { get; set; }
        public List<Directory> SubDirectories { get; set; }
        public List<File> Files { get; set; }
    }

    Now I wanted to have a method which tells me how many files are in a folder, including all the subfolders. This is essentially a recursive select of the number of files per directory and then the sum of the files.

    So I implemented a LINQ statement:

    public int GetNumberOfFiles()
    {
        int total = ( from dir in SubDirectories
                      select dir.Files.Count ).Sum();
        return total;
    }

    Now this will only get the sum of the number of files in the directories immediately below the current. Let's add a little recursion:

    public int GetNumberOfFiles()
    {
        int total = ( from dir in SubDirectories
                      select dir.Files.Count + dir.GetNumberOfFiles() ).Sum();
        return total;
    }

    Pretty nifty!

    #    Comments [0] |
    # Sunday, January 13, 2008

    System.ServiceModel.Web

    In the .NET Framework, most of the time, the name of an assembly matches the namespace of the classes in that assembly.

    Since WCF is kind of an add-on to the .NET 2.0 Framework this is not quite true for the assembly System.ServiceModel.Web.dll

    Below a screenshot of what .NET Reflector shows to be inside this assembly.

    As you can see this assembly extends a number of namespaces like System.Runtime.Serialization and System.Collections.ObjectModel.

    The Json serialization classes are also in this assembly.

    #    Comments [0] |
    # Friday, January 11, 2008

    One more time on DSL's

    Okay, so I'm having a carstarter installed in my car and obviously have nothing better to do than keep tinkering with this DSL stuff.

    So I'm thinking... If we create a DSL for the person writing the code, then the debug experience should also be DSL-like. Now I'm not about to write my own debugger, but instead of showing a plain DateTime (what kind of datatype is that anyway?!?!?) we're talking animals, persons and real 'talk' date of birth stuff here.

    So I create a special DateOfBirth class which overrides the ToString() method and this creates a 'pretty' experience in my debug window. Notice the values for DateOfBirth. This could ofcourse be extended to person, which is still displayed as the same old school type information: 'DSL.Person'.

    The complete code comes at the end of this post, but lets have a look at te code complexity when going from

    Person p = new Person();
    p.DateOfBirth = new DateTime(1972,9,25);

    to our DSL :-)

    I guess the code is not too bad. Visual Studio still scores it green on the maintainability scale, but it is clear that quite a large amount of code is needed to create a DSL. And DSL's like this get more context sensitive. Imagine if I would also like to support birds with my DSL? Birds get hatched not born. I'd have to expand my extensions class, or maybe create a whole new set of classes and methods, having a class 'HatchedOn'.

    Anyway, they just called, my car is done.

    Here is the code for the final sample:

    namespace DSL
    {
        class Program
        {
            static void Main(string[] args)
            {
                Person mark = Person.Named("Mark").BornOn(Day.the25th).Of(Month.September).InTheYear(1972);
                Animal watson = Animal.Named("Watson").BornOn(Day.the2nd).Of(Month.January).InTheYear(2001).AndItIsA(Animal.KindOf.Dog);
            }
        }


        public class DateOfBirth
        {
            public int Year;
            public Month Month;
            public Day Day;

            public static implicit operator DateTime(DateOfBirth dob)
            {
                return new DateTime(dob.Year, (int)dob.Month, (int)dob.Year);
            }

            public override string ToString()
            {
                return "Born on " + Day.ToString() + " of " + Month.ToString() + " in the year " + Year.ToString() + ".";
            }
        }

        public enum Day : int
        {
            the1st = 1,
            the2nd = 2,
            the25th = 25
        }

        public enum Month : int
        {
            January = 1,
            February = 2,
            September = 9
        }

        public interface IDateOfBirth
        {
            DateOfBirth DateOfBirth { get; set; }
        }

        public class Person : IDateOfBirth
        {
            public DateOfBirth DateOfBirth { get; set; }
            public string Name { get; set; }

            public static Person Named(string name)
            {
                Person p = new Person(name);
                p.DateOfBirth = new DateOfBirth();
                return p;
            }

            protected Person(string name)
            {
                Name = name;
            }
        }

        public class Animal : IDateOfBirth
        {
            public enum KindOf
            {
                Dog,
                Cat
            }

            public DateOfBirth DateOfBirth { get; set; }
            public string Name { get; set; }
            public KindOf KindOfAnimal { get; set; }

            public static Animal Named(string name)
            {
                Animal animal = new Animal();
                animal.Name = name;
                animal.DateOfBirth = new DateOfBirth();
                return animal;
            }
            public Animal AndItIsA(KindOf kind)
            {
                KindOfAnimal = kind;
                return this;
            }
        }


        public static class DateOfBirthExtensions
        {
            public static T BornOn<T>(this T p, Day day) where T : IDateOfBirth
            {
                p.DateOfBirth.Day = day;
                return p;
            }

            public static T Of<T>(this T p, Month month)  where T : IDateOfBirth
            {
                p.DateOfBirth.Month = month;
                return p;
            }

            public static T InTheYear<T>(this T p, int year)  where T : IDateOfBirth
            {
                p.DateOfBirth.Year = year;
                return p;
            }
        }

    }

     

    #    Comments [0] |

    More on DSL's

    I've decided working with enumerations beats working with generics. So now I've taken my little DSL experiment back to enumerations and started implementing the DateOfBirth DSL as a generic extension method.

    Since the compiler infers the type based on the actual parameters used you don't need to supply the type when using the extensions methods. Very cool!

    Now my DateOfBirthExtensions can work on anything that implements the IDateOfBirth interface, be it a person or an animal :-)

     

    namespace DSL
    {
        class Program
        {
            static void Main(string[] args)
            {
                Person mark = Person.Named("Mark").BornOn(Day.theTwentyFifth).Of(Month.September).InTheYear(1972);
                Animal watson = Animal.Named("Watson").BornOn(Day.theSecond).Of(Month.January).InTheYear(2001).AndItIsA(Animal.KindOf.Dog);
            }
        }

        public enum Day : int
        {
            theFirst = 1,
            theSecond = 2,
            theTwentyFifth = 25
        }

        public enum Month : int
        {
            January = 1,
            February = 2,
            September = 9
        }

        public interface IDateOfBirth
        {
            DateTime DateOfBirth { get; set; }
        }

        public class Person : IDateOfBirth
        {
            public DateTime DateOfBirth { get; set; }
            public string Name { get; set; }

            public static Person Named(string name)
            {
                Person p = new Person(name);
                return p;
            }

            protected Person(string name)
            {
                Name = name;
            }
        }

        public class Animal : IDateOfBirth
        {
            public enum KindOf
            {
                Dog,
                Cat
            }

            public DateTime DateOfBirth { get; set; }
            public string Name { get; set; }
            public KindOf KindOfAnimal { get; set; }

            public static Animal Named(string name)
            {
                Animal animal = new Animal();
                animal.Name = name;
                return animal;
            }
            public Animal AndItIsA(KindOf kind)
            {
                KindOfAnimal = kind;
                return this;
            }
        }


        public static class DateOfBirthExtensions
        {
            public static T BornOn<T>(this T p, Day day) where T : IDateOfBirth
            {
                p.DateOfBirth = new DateTime(p.DateOfBirth.Year, p.DateOfBirth.Month, (int)day);
                return p;
            }

            public static T Of<T>(this T p, Month month)  where T : IDateOfBirth
            {
                p.DateOfBirth = new DateTime(p.DateOfBirth.Year, (int)month, p.DateOfBirth.Day);
                return p;
            }

            public static T InTheYear<T>(this T p, int year)  where T : IDateOfBirth
            {
                p.DateOfBirth = new DateTime(year, p.DateOfBirth.Month, p.DateOfBirth.Day);
                return p;
            }
        }

    }

    #    Comments [0] |

    DSL

    Inspired by Pinku Surana's blog about DSL's and after reading the presentation from Neal Ford I felt compelled to experiment with a little DSL style programming.

    My goal was to get as close as possible to something like:

    Person mark = Person.Named("Mark").BornOn(theTwentyFifth).Of(September).InTheYear(1972);

    As it turns out the linking of methods is pretty easy. Where you might be inclined to create a property, just create a method which returns the base object, in this case Person.
    The hardest part I found was trying to come up with something decent for 'theTwentyFifth' and 'September'. My first try was to create enumerations, but then you have to name the enum and you get something like:

    Person mark = Person.Named("Mark").BornOn(Day.theTwentyFifth).Of(Month.September).InTheYear(1972);

    Which is good because the intellisense in C# is great, but having to prefix it messes it up just a little. An Alternative implementation is to 'abuse' generics and do it like this:

    Person mark = Person.Named("Mark").BornOn<theTwentyFifth>().Of<September>().InTheYear(1972);

    The draw back to this is that intellisense is less useful and it is messy to be using generics for BornOn and Of, but not for InTheYear.
    The implementation is below. I'm still thinking about which solution is more useful.


    namespace DSL
    {
        class Program
        {
            static void Main(string[] args)
            {
                Person mark = Person.Named("Mark").BornOn<theTwentyFifth>().Of<September>().InTheYear(1972);
            }
        }

        public abstract class CalenderMonth
        {
            public int Month { get; private set; }

            protected CalenderMonth(int month)
            {
                Month = month;
            }
        }

        public class September : CalenderMonth
        {
            public September()
                : base(9)
            {
            }
        }


        public abstract class DayOfMonth
        {
            public int Day { get; private set; }

            protected DayOfMonth(int day)
            {
                Day = day;
            }
        }

        public class theTwentyFifth : DayOfMonth
        {
            public theTwentyFifth()
                : base(25)
            {
            }
        }

        public class Person
        {
            DateTime _dob = new DateTime();
            string _name;


            public const int theFirst = 1;
            public const int theTwentyFifth = 25;

            public static Person Named(string name)
            {
                Person p = new Person(name);
                return p;
            }

            protected Person(string name)
            {
                _name = name;
            }

            public Person BornOn<T>() where T : DayOfMonth, new()
            {
                T d = new T();
                _dob = new DateTime(_dob.Year, _dob.Month, d.Day);
                return this;
            }

            public Person Of<T>() where T : CalenderMonth, new()
            {
                T m = new T();
                _dob = new DateTime(_dob.Year, m.Month, _dob.Day);
                return this;
            }

            public Person InTheYear(int year)
            {
                _dob = new DateTime(year, _dob.Month, _dob.Day);
                return this;
            }
        }

    }

     

    #    Comments [0] |

    Dynamically creating a form

    If you want to dynamically want to load a form and you only know the classname then the following snippet may be of use:

    Type t = Type.GetType("ConsoleApplication1.Form1");
    if (t != null)
    {
        System.Windows.Forms.Form f = (System.Windows.Forms.Form) Activator.CreateInstance(t);
        f.ShowDialog();
    }

    Now, if you'd want to load the form from a different assembly, let's say, some library assembly with forms, then you need to specifiy an AssemblyQualifiedName.

    Like:

    Type t = Type.GetType("ClassLibrary1.Form1, ClassLibrary1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null");
    if (t != null)
    {
        System.Windows.Forms.Form f = (System.Windows.Forms.Form)Activator.CreateInstance(t);
        f.ShowDialog();
    }

    This will dynamically load the form and show it. So no compiletime binding needs to be done.

     

    #    Comments [0] |

    XAML validation - design vs. runtime error

    The other day I was playing around with WPF in Visual Studio 2008 and I stumbled across some strange behaviour. I made a mistake in the XAML of a WFP Window.

    <Button Background="LightBlueX" Name="button1" Click="button1_Click">Click here</Button>

    As you can see the name of the Background color is not valid. Now as long as you have the Window opened in the designer the errorlist will display an error to inform you about the mistake. However, if you try and compile your project, you'll find that the compiler will succesfully build. Then when you run the application you'll get a runtime error (a XAML parse exception). Thinking this to be an error in the compiler I logged a bug on MSConnect.

    I received the following feedback:

    Hi Mark

    Thanks for your report. The behavior you're reporting is actually by-design - it arises because of a trade off of complexity/performance in the build/compilation process vs surfacing all possible failures at compile time.

    Errors in XAML attribute values like the one mentioned in the bug are one of the class of errors that can't be picked up with certainty by the build process without loading the entire context of the WPF application being built - this is too heavy an overhead to impose on the compilation process and would cause a major performance degradation in building.

    The expected process is that the user will use the designer (which of necessity loads a lot more of the context) to locate and eliminate errors of this sort. Hence the fact that the errors list shows the error as described in the repro steps.

    Thanks for taking the time to submit the issue - I hope you continue to find the designer useful and would welcome any further feedback you have.

    Mark Wilson-Thomas
    Program Manager
    WPF Designer Team, Developer Division

    Ok, that clarifies things. I'll get into the habit of checking my errorlist before saving a XAML file.

    #    Comments [3] |

    Meet the BAND

    Maine is getting another .NET User Group and this one is actually close to where I live,yeah!!!

    The B.A.N.D. (Bangor Area .NET Developers) will meet monthly. More info at: http://www.bangordevelopers.com.

    #    Comments [0] |
    # Thursday, January 10, 2008

    ToMemoryStream() extension method

    I'm beginning to appreciate the power of extension methods. At first I thought: "Who wants this?". Doesn't this 'break' the encapsulation of object oriented programming?

    Well yes it does, but it makes for some darn pretty code when building utility methods. Right now I'm working on some stuff with the DataContractJsonSerializer and this class has a ReadObject method which takes a stream as a parameter. When writing unit test (and regular code) I'm quite frequently going from a string to a stream. So I figured I'd create an extension method called ToMemoryStream(). This is what is looks like:

    using System;
    using System.IO;

    namespace DevelopOne.Framework.Serialization
    {
        /// <summary>
        /// Class with extension methods which are helpful when working
        /// with serialization.
        /// </summary>
        public static class Extensions
        {
            /// <summary>
            /// Converts a string to a memory stream and sets the position of the stream to
            /// the beginning of the stream.
            /// </summary>
            /// <param name="s"></param>
            /// <returns></returns>
            public static MemoryStream ToMemoryStream(this string s)
            {
                MemoryStream ms = new MemoryStream();
                byte[] bytes = System.Text.ASCIIEncoding.ASCII.GetBytes(s);
                ms.Write(bytes, 0, bytes.Length);
                ms.Position = 0;
                return ms;
            }
        }
    }

    Now calling this method can be done by simply including the namespace DevelopOne.Framework.Serialization and calling ToMemoryStream() on a string.

    Like this:

    string json = "{\"exceptions\":[{\"type\":\"ExceptionObject\",\"errorMessage\":\"Calls to member.login must be secure.\",\"errorInfo\":null,\"errorCode\":513}]}";
    MemoryStream ms = json.ToMemoryStream();

     

     



    The best web hosting service is the one that not only provides cheap web hosting, but comes with perks like email hosting as well. This and the added benefits of hosting more than one domain names of course adds to the entire package. Thanks to the extensive promotion of online marketing, now anyone with access to computers knows of this. This has contributed effectively to the popularity of home business setups as well.

    #    Comments [0] |
    # Tuesday, January 08, 2008
    # Thursday, January 03, 2008

    SIP - Simple Iterative Partitions

    Roger Sessions writes about an interesting concept called SIP (Simple Iterative Partitions) in this month's ObjectWatch newsletter. He says CIO's will fail their 2008 objectives because they are unable to focus on the underlying problem that IT is facing these days, which according to him is: complexity.

    I've seen quite a few project fail by having too large a scope and thus becoming way too complex, leading to project failure. So reducing complexity will lead to a higher project succes rate and thus helps you reach your goals.

    The example Roger uses in his newsletter is a little flawed though. Roger assumes any system of 7 (or 14) dice can be split in 7 partitions which do not influence eachother. Reality will be that the succes or failure of any of the 7 partitions will influence the succes of the others. And unlike dice there is no black/white success with IT projects. Succesful projects typically achieve somewhere between 70 to a 100% of their original goals. 1% of a missed goal in one of the 7 partitions may lead to 100% failure in another (extreme case).

    I'll be doing some more reading on the SIP proposition though. More on SIP here.

     

     



    Services like cingular wireless have contributed a lot to the promotion of personal web hosting. Not that web site hosting was not happening before, but never had internet advertising been this sort of a giant. Now from laymen to professional webmasters, all know about seo, about sem strategies like ppc advertising and the list can go on. The internet marketing arena is expanding everyday.

    #    Comments [0] |
    # Tuesday, January 01, 2008

    MVP - Most Valuable Professional 2008

    Hurray! What a great way to start the new year. I got an email this morning informing me I've been awarded the MVP award for the fifth year running.

    Congratulations! We are pleased to present you with the 2008 Microsoft MVP Award! The MVP Award is our way of saying thank you for promoting the spirit of community and enhancing people’s lives and the industry’s success every day. Your extraordinary efforts in Visual Developer - Visual C# technical communities during the past year are greatly appreciated.

    Thanks to Microsoft, and in particular Rafael Munoz, for the award. Excellent!

    #    Comments [0] |
    # Saturday, December 22, 2007

    Visual Studio Team System 2008 Team Foundation Server MSSCCI Provider

    The TFS MSSCCI Provider enables integrated use of Team Foundation Version Control with products that do not support Team Explorer integration. This will allow you to connect to TFS2008 from Visual Studio 2003. This is very useful if you still have .NET 1.1 projects around that need maintenance using VS2003, but you want to use a single source control solution.

    Download here.

    #    Comments [0] |
    # Friday, December 21, 2007

    Visual Studio Team System 2008 Team Foundation Server Power Tools

    VS2008 hasn't even been fully launched yet and already the add-ons are becoming available through the VSTS 2008 Power Tools. These power tools are very handy and also offer some bugfixes so you don't have to wait for a service release.

    New in this release of the power tools:

    • Find in Source Control tool is an addition to the Team Explorer menu that provides the ability to locate files and folders in source control by the item’s status or with a wildcard expression.
    • Open a selected folder in Windows Explorer straight from Team Explorer. This feature allows you to jump straight to the mapped folder location from within Source Control Explorer.
    • Quick Label feature that allows labels to be easily applied to a given selection of files and folders in the Source Control Explorer.
    • Build Notification tool that runs in the Windows task bar notification area monitoring the status of the build definitions you have specified. It can be configured to show notifications when builds are queued, started, or completed for multiple build definitions spanning multiple Team Foundation Servers.
    • Additional TFPT.EXE commands for configuring Team Explorer connection settings (tweakui) and for  destroying Work Items and Work Items Type Definitions (destroyWI, destroyWITD).
    • Updates to the TFS Best Practices Analyzer for use with a Visual Studio Team System 2008 Team Foundation Server deployment.
    • The Process Template Editor is updated for use with Visual Studio Team System 2008 Team Foundation Server. It also has several improvements, including: the ability to launch standalone w/o a Visual Studio installation, performance improvements, improved discoverability and bug fixes.
    • Bug fixes and removal of Power Tools that are now included within Team Foundation Server: 
      • Annotate and Treedif are now included in Visual Studio Team System 2008 Team Explorer; however, Annotate remains is still available in the command-line tool (TFPT.EXE).
      • TestToolsTask is included in Visual Studio Team System 2008 Team Foundation Server as part of Team Foundation Build.

     

     



    With certifications like 70-620 and 70-291 on ones credit, one can easily go for 646-171. In fact, even 642-825 is not difficult for such people. However, exams like 640-863 and 350-001 require much more preparation time and effort, than that required for a basic exam like 1z0-042.

    #    Comments [0] |
    # Wednesday, December 19, 2007

    The Making Of… the NFL Video of the Day

    My article on the AOL Developer Network about how I created the NFL Video of the Day gadget for Windows Vista went live last week.

    Download the gadget here.

    #    Comments [0] |
    # Thursday, December 06, 2007

    PopFly - BLaugh Carrousel

    I just created my first PopFly mashup.

    #    Comments [0] |
    # Tuesday, December 04, 2007

    It's all about the tools

    Last month Russ Fustino did a presentation in Portland, ME where he showed a little tool to grab areas of the screen. I looked on his blog, but could not find a link to this particular tool, but a little Googling did the trick.

    Screen Grab Pro is a very nice (FREE) tool from Traction Software that allows you to easily grab a region on the screen and save it as a file, or paste it in a Word document.

    Update: Windows Vista also offers a build in tool called 'Snipping Tool'. On some machines this tool does not get installed by default, read more on the Snipping Tool here (thanks Marcel!).

    #    Comments [1] |