Archives

Archives / 2007
  • [SQL] Tools I Can't Live Without Right Now

    I've been doing loads of SQL crunching lately, staging, versioning, and preparing for a pretty large migration job later this year which involves a great deal of schema and data changes in SQL Server 2005.

    A tool which has been saving me a great deal of time is Red Gate's SQL Compare. As the names says, it's able to compare everything you're interested between two databases in when it comes to SPs, tables, functions, roles and so on. You can also generate SQL scripts which wil handle the migration from one version of the database to the other without (if possible) corrupting the data. The tool is dead easy to get into I think - no need to read any manuals or anything, just new, select db1, db2 and compare. Check, uncheck and migrate.

    Red Gate also has a SQL Data Compare tool which compares data in two identical databases and helps you move data between them.

    If you just want to create a bunch of "INSERT INTO ..." SQL statements from existing tables, perhaps you should look at the stored proc Narayana Vyas Kondreddi has made available from his code library:

    This procedure generates INSERT statements using existing data from the given tables and views. Later, you can use these INSERT statements to generate the data. It's very useful when you have to ship or package a database application. This procedure also comes in handy when you have to send sample data to your vendor or technical support provider for troubleshooting purposes.

    To show you how simple this one is, the easies way to run it is just:

    EXEC sp_generate_inserts 'titles'

    and out comes a bunch of INSERT statements which you can copy/paste into your batch files. I love small tools like that.

  • SourceSafe CTP for VS2008

    Richard Berg (BUGBUG) from the Developer & lifecycle tools at Microsoft says:

    If you plan to use VS 2008 with SourceSafe, make sure to pick up the Update CTP too.  Without it, some features like "Open from Source Control" will not work at all.

    Bharry wrote:

    We are working on an update for Visual SourceSafe 2005 to make it work with VS 2008.  We had originally planned to have it available at the same time as VS 2008 downloads went live but we hit a last minute bug that is taking a little time to work out.  Our current expectation is that it will be available in mid December. 

    Not that I'm using SourceSafe any longer (if I can avoid it...) but I'm sure lots of people have already installed VS2008 and wondered about VSS support.

  • ASP.NET MVC Framework (Part 1) - ScottGu's Blog

    I think Scott Guthrie himself just did a better job than me to describe that basics of the ASP.NET MVC Framework on his blog :)

    Since then I've been answering a lot of questions from people eager to learn more about it.  Given the level of interest I thought it might make sense to put together a few blog posts that describe how to use it in more detail.  This first post is one of several I'll be doing in the weeks ahead.

    ASP.NET MVC Framework (Part 1) - ScottGu's Blog

    Go read it already, it got loads of nice pictures to help get an understanding of it all, including the folder structure which is used as a convention. Somewhat influenced by Ruby on Rails I would say ;)

    Considering what I've seen so far of MCV Framework, together with LINQ for SQL and the test framework it reminds me a lot of RoR, but perhaps not as much "convention over configuration" though.

  • A Quick Look at the Basics of ASP.NET MVC

    I had a look at the demo code that Scott Hanselman made available :) So how does it look when using the ASP.NET MVC framework? Of course, since this is MVC, you got the "model", "view" and "controller" parts, but when listening to Scott Guthrie, it seems to be more about "router", "view" and "controller" and he's repeating the fact that this framework is very extensible - you can go with the out of the box stuff, or hack up your own.

    The aim seems to be to have a very clean separation of these parts, so you can swap out the view enging if you want to, and it should also be easier to test your application for those of you who are into TDD and unit testing in general. Therefore there is also support for dependency injection.

    The old ASP.NET stuff that we know and love is still there - code behind, controls, authentication and roles and such. The default view engine is ASPX, but postbacks are not supported, so obviously the way you use some of the ASP.NET controls will change.

    One big difference with URLs in standard ASP.NET vs. MVC is that they do not point directly at the page (like default.aspx) to be rendered, but at a "Controller" which handles the business logic, processes the data and then renders it to a view (which could be the default.aspx page for example). The trick is to map the URL to a controller, and this part seems to be very "configurable". The REST-style of URLs is used alot in the demos, so for example:

        /products/
        /products/42
        /products/delete/42

    Thanks to a URL routing engine, the right method, in a specific controller will be targeted for each URL above, with the right parameters supplied, like:

        /<controller>/<action>/<parameter>

    So, stealing a sample from Guthrie's demo, to set up a Route for URLs like these:

       /Home
       /Home/Index
       /Home/PrintNumber/45

    you would do something like this:

       Routes.Add(new Route("Home", "/Home/[action]/[id]", typeof(HomeController)));

    For the route above, which could be initiated in Global.asax, all URLs that begin with "/Home" will be handled by HomeController which will have methods to handle the "Index" and "PrintNumber" actions. There are several ways to set up default controllers and actions, but I'm now going into that here.

    Note: this was how it was demoed in the ALT.Net video by Guthrie, but it seems that have changed in released demo code. I'll look closer at it later.

    The HomeController class could look something like this:

      public class HomeController : Controller
      {
        [ControllerAction]
        Index()
        {
          //add code here for the default "view"...
        }

        [ControllerAction]
        PrintNumber(int number)
        {
          //add code here to print out a number...
        }
      }

    The [ControllerAction] attribute was added for security reasons so that anyone just cannot type in any action in the URL and run methods in the controller that wasn't supposed to be run. If you don't like that attribute, it's a policy that can be overridden.

    To make the Controller Action output something to the browser, you could use the Response object like this:

      [ControllerAction]
      Index()
      {
        Response.Write("<b>You're at the Index Page (action)!</b>");
      }

    or you could (will in most cases) point at a view (like an ASPX page) to handle the rendering like this:

      RenderView("Home");

    which would render a "Home.aspx" view page you've created.

    If you want to pass parameters to the view, you could use the ViewData collection and do:

        [ControllerAction]
        PrintNumber(int number)
        {
          ViewData("number") = number;
          RenderView("ShowNumber");
        }

    and the page "ShowNumber.aspx" would have some HTML in it to handle the printing of that number, like so:

      <body>
          <div>
              The number waws: <%= ViewData["number"] %>
          </div>
      </body>

    There are ways to pass data to the view in a strongly typed way, by letting the Controller class inherit from a Controller<T> where T is a simple class used to hold properties you'd like to pass to the view. Then ViewData would be of type T. Normally, the code behind for the ASPX page used for the view inherits from the class ViewPage (which is a difference from ordinary ASP.NET pages), but when using Controller<T>, the ASPX-page should inherit from ViewPage<T> to get strong typing of the ViewData class too. Nice!

    I guess that's enough to just let you get a glimpse of how this stuff will work. I'm sure things will change over time, but I believe this is the general idea.

  • [Service Factory] Modeling Edition (VS2005) Released

    The "modeling edition" of Service Factory was released yesterday on the Codeplex site:

    The Web Service Software Factory: Modeling Edition (also known as the Service Factory) is an integrated collection of resources designed to help you quickly and consistently build WCF and ASMX Web services that adhere to well-known architecture and design patterns. These resources consist of models with code generation in the form of tools integrated with Visual Studio 2005 and patterns and architecture topics in the form of written guidance.

    patterns & practices: Web Service Software Factory - View Release

    If you are looking for a way to build several WCF based enterprise services in a fast, consistent way but with great flexibility, you should look at this package which plugs into VS2005. A VS2008 version shouldn't be far away.

    I've been using the previous version of Service Factory since for almost a year, and it's been working just fine. One thing I was missing was a good modeling tool for designing our services, and now it's here.

    Check out Don Smith's video of an earlier version of Service Factory if you want to get a hunch of what it is all about.

  • MVC Demos Source Code

    I've been curious about the ASP.NET MVC project ever since I saw that first video from the Alt.NET conference. Scott Hanselman just wrote this on his blog:

    I talked to BradA and got permission to share with you the source code of all the demos that Phil, Chris, myself and others worked on and showed at the two conferences minus all DLLs.

    Scott Hanselman's Computer Zen - DevConnections and PNPSummit MVC Demos Source Code

    The source code for the demo, not the MVC stuff itself, is available for download from that link above. There are too many things right now that I would like to delve into when it comes to .NET, but I'll definitely look at ASP.NET MVC because of it's ease of use and possibilities (what it seems) to extend it. I think solutions based on the REST style of architecture may become more common when this becomes available, especially with project Astoria also adopting the REST style.

    Is REST + POX growing more and more popular because WS-* is getting way to complex? I think so...

  • Buck Hodges : Windows Live Writer 2008 is now available

    I just caught this on Buck's blog, and I must agree with him as Live Writer seems to be the coolest blog-tool I've used so far (not that I've tried them all).

    The first version of Windows Live Writer is now available.  I've been using the betas for a long time, and I think it's a great application (and it's free).  I use it to write all of my blog posts.  If it weren't for Live Writer, I wouldn't have written nearly so many blog posts.

    Buck Hodges : Windows Live Writer 2008 is now available

    Read that post and check out some of the plug-ins that are available for Live Writer.

    Live Writer Plugin Gallery

  • Mediacenter Development

    In my previous post I wrote something about trying to code something for Mediacenter on Vista, and I did that. I spent a couple of hours and downloaded c# Express and the MC SDK and followed the getting started guide that was included with the SDK. It worked :D

    The markup language for MC (MCML) is a bit weird though, and it will take some time getting used to. If you're not going to write MCML every now and then, it will will probably be slow going and loads of trial and error for you. There are some tools (included in the SDK) to help you verify your markup, but it's not like coding (X)HTML or XAML... you've been warned :D

    Anyway, I spent 30 minutes and tried to develop a "background" app for Mediacenter, which popped up a message with an image on the screen, and it was pretty easy - I just used the dialog() function with a timeout, which feels a bit like cheating, but it works.

    Next step is to have my logitech quickcam ta a snapshot whenever someone rings the doorbell. Either that, or have the doorbell trigger something else which the MC background program can act on. I don't want to make a motion detector, but perhaps I can set up a microphone to detect the doorbell ringing? *weird solution* Should be possible with some minimal activex code I guess... I don't want to replace the doorbell if I really don't have to.

  • Resources for Developing Media Center Apps on Vista

    The guys that run the Windows Media Center Sandbox blog posted a nice one listing all the resources they talked about on the Hanselman #82 webcast a short while ago. It's a long list of SDKs, tools and samples and looks just like the right stuff to look at if you're interested in developing something for your Media Center setup.

    I believe you need to have Vista to use the lastest SDK though, so if you're still on XP Media Center, maybe it's time to look at an upgrade? I just upgraded my XP MCE (yesterday) and it went pretty well except for a few driver problems I had with my HP printer, EPSON scanner and integrated SoundMax audio. I also had to upgrade the drivers for my tv-card (FloppyDTV) but I managed to find Vista drivers for everything eventually!

    I'm about to download everything I need to develop something very small for MC and see if I can make it play on my XBOX 360 extender. Scott talked about hooking up a webcam to the door bell and display the picture on the screen. Sounds like a cool idea, but maybe just a bit too complex to start with. I have no idea how to trigger a program from a door bell on a Windows machine in the first place. I used to do stuff with IO ports on my ZX Spectrum some 25 years ago, but I have no clue how to do IO now... ;)

  • [VS2008] Finally had Time to Sit Down and Play

    I finally had some time to play around with VS2008 for a few hours, and I must say I do like c# 3.0, linq and all that. What I most wanted to try out was linq to sql, which I did. Nothing too complex, but I think I got the hang of it now. While looking at linq for sql I also tried out some of the other new featurs like the object and collection initializer (nice), some extension methods and of course the query language.

    I'm still thinking about the extension methods and I think developers need to be a bit careful and not start using the feature just because it's there. I was glad to see the information that pops up in Visual Studio when you hover above the extension and the special intellisense icon, which makes it easier to spot them.

    The linq to sql graphical designer was easy to use, but it doesn't seem to support file databases, I had to create a db in sqlexpress instead. Perhaps I did something wrong.

    Something i noticed was that a stored procs which selects * from tablex returned a specific results class instead of a collection of tablex. Perhaps it's possible to cast or convert the result from the sp to a list of tablex or something, but I doubt it. The sample code from ScottGu's blog indicates it should work... I'll try again later :) 

    UPDATE: Thanks to Raj for pointing out that you have change the return type of the stored proc in the designer properties to be of the type you wish it to be. *cheers* 

  • [VS2008] CTP1 of XML Schema Designer for VS2008 Announced

    I completely missed this announcement from the Microsoft XML team a month ago, that they will release an XML Schema Designer for VS2008. What can I say - finally!

    See a short video here. 

    Download the CTP here

    It looks promising so far, but I'm still waiting for some screenies of the graphical view of the designer.

    EDIT:

    I snapped up this from a forum post:

    The original schema designer in VS has been removed from the product.  There will be a new schema designer, but it will ship in off-cycle release after the Orcas is shipped.  Currently, you have to use VS2005 to edit the schema file, or use the Xml Editor, which looks like a text editor, but does provide intellisense and schema validation.


     

  • [Tools] GhostDoc

    Another plugin for VisualStudio which has been around for a while, helps you write code documentation for your c# classes. This is the summary from Roland Weigelt's blog about his tool:

    GhostDoc is a free add-in for Visual Studio that automatically generates XML documentation comments for C#. Either by using existing documentation inherited from base classes or implemented interfaces, or by deducing comments from name and type of e.g. methods, properties or parameters.

    Just right click the code and select "Document This" from the popup menu:


     

  • [MSBuild][Tools] MSBuildShellExtension - Nifty Tool for Builders

    This little project from CodePlex is quite useful for those of you who are responsible for the Build process, Team Build, CruiseControl.NET, NANT, etc. This is the project description from their website on CodePlex:

    MSBuild shell extension gives you what you've always wanted: A way of cleaning, building and rebuilding your .net projects from the explorer without needing to open Visual Studio 2005 or the Visual Studio 2005 Command Prompt. 

     It looks like this:

    and when you run it, it builds the project or solution in a command window and displays the error/warnings dialog similar to the one in VisualStudio. Nice! 

  • [Team System] TFS 2008 - Better Build Support, But Good Enough?

    I picked up the blog post written by Buck Hodges today about some of the new features related to Build in TFS 2008. I'm glad to see CI built into the product and better control of the build process as well as better support for editing the build steps. Not that I fear editing some XML, but GUI support is always welcome as long as you can do some 80% of what you normally need to do in that interface.

    The build support in TFS 2005 is, compared to some other build servers out there, not top notch. When we started a version 2 of a project just recently, I moved our whole build process to CruiseControl.NET. It took me a day or so to get the basic structure of 10+ solutions (and CI projects) to build and deploy. The same stuff took me days and days to set up in TFS. So now we're building and deploying wcf services, generating data contracts from schemas, generating service proxies from those services and even generating service proxy documentation with reflection. Everything controlled by Cruise Control. And I like cctray :)

    It looks like MS is trying hard to step up to the features offered by solutions like CC.NET, but I think it will take some real effort to make developers used to CC, NUNIT and NANT to make the final move.

  • Akropolis - Yet Another Way to Build .NET WinForm Apps...

    I just had a quick look at the demo videos on the Akropolis website and it looks pretty nice but it makes me wonder which tool you're supposed to be using in the future when you want to build a WinForms app (or whatever we're supposed to be calling a fat/smart client). Akropolis looks really useful if you want to create a standard looking application with WPF, that's for sure. This is what the home page states:

    Acropolis builds on the rich capabilities of Microsoft Windows and the .NET Framework, including Windows Presentation Foundation (WPF), by providing tools and pre-built components that help developers quickly assemble applications from loosely-coupled parts and services.

    From what I can see, Akropolis will be focusing on standard looking business client applications, but there is also support for themes, animations and stuff which they show off in their demos. Not sure why a business application would have that, but if it's based on WPF and XAML, it's easy to add bells and whistles I guess :) There is a CTP available for download on their website.

  • [WCF] Configuring the Service Client to Go Via TcpTrace

    TcpTrace by Simon Fell is a great tool to trace your HTTP and SOAP calls with, until you begin using WCF and it starts complaining about you not going directly to the service, address filter mismatch and all that. It's quite easy to fix that though, just add an endpoint behavior to your client configuration and tell it your're running via TcpTrace, like this sample:

    <?xml version="1.0" encoding="utf-8" ?>

    <configuration>

    <system.serviceModel>

    <bindings>

    <wsHttpBinding>

    <binding name="WSHttpBinding_IMyService" >

    <security mode="Message">

    <message clientCredentialType="Windows" />

    </security>

    </binding>

    </wsHttpBinding>

    </bindings>

       

    <behaviors>

    <endpointBehaviors>

    <behavior name="tcpTraceBehavior">

    <clientVia viaUri="http://localhost:8080/MessageSecurityWindows/Service.svc"/>

    </behavior>

    </endpointBehaviors>

    </behaviors>

       

    <client>

    <endpoint address="http://localhost:1035/MessageSecurityWindows/Service.svc"

    behaviorConfiguration="tcpTraceBehavior"

    binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IMyService"

    contract="MessageSecurityWindowsClient.MyService.IMyService"

    name="WSHttpBinding_IMyService">

    </endpoint>

    </client>

    </system.serviceModel>

    </configuration>

  • [WCF] Testing Message and Method Security with Windows

    While digging a bit deeper into Message and Method Security options for WCF services, I ran upon several good articles by Michèle Leroux Bustamante, both on TheServerSide.NET and on the That Indigo Girl blog she created for her book, "Learning WCF". I've just ordered the book and cannot wait to get my hands on it. I read several of the preview chapters she published on her blog and I really like the way she explains things. Good stuff, go get the book already!

    So I can't take credit for any of the code in this blog post, I'm just putting things up here for myself for safe keeping and for others to learn. The documentation and samples around message security on MSDN is also pretty good, for example - http://msdn.microsoft.com/en-us/library/ms730301.aspx

    So, this is a sample to do message security with a Windows client. It also shows how to make sure the caller belongs to a certain group or role to access it.

    SERVICE CODE

    So, to make sure the caller is a member of the Administrators group, you decorate the method with a PrincipalPermission attribute like this:

    [ServiceContract()]

    public interface IMyService

    {

    [OperationContract]

    string MyOperation1(string myValue1);

    }

    public class MyService : IMyService

    {

    [PrincipalPermission(SecurityAction.Demand, Role = "Administrators")]

    public string MyOperation1(string myValue1)

    {

    /// do something...

    }

    }

    SERVICE CONFIGURATION

    The service configuration needs to declare that message security should be handled by Windows.

    <system.serviceModel>

    <services>

    <service name="MyService" >

    <endpoint contract="IMyService" bindingConfiguration="wsHttpWindows" binding="wsHttpBinding"/>

    </service>

    </services>

    <bindings>

    <wsHttpBinding>

    <binding name = "wsHttpWindows">

    <security mode="Message">

    <message clientCredentialType="Windows" />

    </security>

    </binding>

    </wsHttpBinding>

    </bindings>

    </system.serviceModel>

    CLIENT CODE

    You don't need to do anything special for the client code part. Just make the call. The config file needs to be edited though.

    CLIENT CONFIGURATION

    Likewise, the client needs to declare the equivalent security means in its configuration file:

    <system.serviceModel>

    <bindings>

    <wsHttpBinding>

    <binding name="WSHttpBinding_IMyService" >

    <security mode="Message">

    <message clientCredentialType="Windows" />

    </security>

    </binding>

    </wsHttpBinding>

    </bindings>

    <client>

    <endpoint address="http://localhost:1035/MessageSecurityWindows/Service.svc"

    binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IMyService"

    contract="MessageSecurityWindowsClient.MyService.IMyService"

    name="WSHttpBinding_IMyService">

    </endpoint>

    </client>

    </system.serviceModel>

    It's all created for you if you "Add Service Reference", which of course requires you to first add an "mex" endpoint to the service.

  • [Books] SQL Server 2005 Service Broker

    We're using the SQL Server 2005 Service Broker functionality to replicate data and send messages between databases, and we got a tip from a Microsoftie to get hold of this book.

    The book is written by Roger Wolter, Program Manager on the Service Broker team and it is straight forward, full of samples starting with a really, really simple service broker sample and builds up throughout the book. It covers most things you need to know about the topic, poison messages, multiple servers, certificates etc. and everything within some 220 pages.

  • Silverlight Genealogy Tool

    Vertigo made a reference application for Microsoft, using WPF and Silverlight, called Family.Show. It's a nice looking and very easy to use genealogy app which has all the features you've come to expect from a WPF tool – zoom, move, animate, shadows…. You name it. Source code is available too of course.

    Nice thing is it can handle GED files, which is a weird but common ASCII format for exporting and importing genealogy data.

  • [Orcas] Extension Methods

    If you haven't already, head over to Scottgu's blog and read his excellent explanation of the Extension Methods feature, part of the "Orcas" release later this year. No need to show any example here, better to look at what Scott did, but with this feature you can add new methods to the public contract of ANY existing CLR type! Even Object itself. This feature is available in some dynamic languages already, and it's mighty cool. No need to subclass or anything. It will be available for both c# and VB.NET.

    Microsoft has really stepped into the dynamic languages arena with all these new features. It will be very interesting to see some of the productive stuff people will come up with soon where you combine these new features with LINQ. Ruby on Rails, watch up… I do hope the new stuff will also spice up the IronPython language.

    Scott ends his blog post with something important to keep in mind:

    Hopefully the above post gives you a basic understanding of how extension methods work, and some of the cool extensibility approaches you will be able to take with them.  As with any extensibility mechanism, I'd really caution about not going overboard creating new extension methods to begin with.  Just because you have a shiny new hammer doesn't mean that everything in the world has suddenly become a nail!  

  • [SQL] Finding the Boss with Hierarchical Queries

    Never thought I was going to blog about SQL... but I'm doing this mostly for myself because I need to use this at work on monday. I know enough to do database design and whip up a few necessary stored procs, but when it comes to functions and the new Common Table Expression (CTE) in SQL 2005 I'm quite lost. I got a tip about CTE from my buddy Jan-Erik so I sat down with Google and SQL Books online to see if it could help me out.

    Most examples out there lists the employees below a manager, and their employess etc. What I needed to do was go the other way - to create a view or something which showed all the employees in a table and who their manager on a certain level is. Not just their immediate boss, but the boss on some upper level.

    To test this I started out with a small, simple table called Employee with 4 columns in it (EmpId, Name, BossId, Type), where BossID is the immediate boss, or the "parent":

    CREATE TABLE [dbo].[Employee](

    TABLE [dbo].[Employee](

    [EmpId] [int] NOT NULL,

    [Name] [varchar](50) NOT NULL,

    [BossId] [int] NULL,

    [Type] [varchar](50) NULL,

    CONSTRAINT [PK_Table_1] PRIMARY KEY CLUSTERED

    Or something like that J I'm also setting a FK between BossId and EmpId:

    ALTER TABLE [dbo].[Employee] WITH CHECK ADD CONSTRAINT [FK_Employee_Employee] FOREIGN KEY([BossId])

    REFERENCES [dbo].[Employee] ([EmpId])

    Next I filled it with some data:

    1 Helen    NULL Mega boss
    2 Lisa      1        Boss
    3 Otto      1        Boss
    4 Carin     2       Team lead
    5 Carl       2       Team lead
    6 Niel       4       Project manager
    7 Thomas 3       Team lead
    8 Johan    4       Code monkey
       
    Pretty simple, but enough to test with. This organization has 4 levels, from 'Mega boss' to 'Code monkey'. To iterate "up" in the hierarchy I'm using CTE and the WITH <table(columns)> AS syntax, and I'm putting it into a scalar function which takes the EmpID and the manager Type as parameters:

    CREATE FUNCTION [dbo].[GetBossByType]

    (

          @empid int,

          @type varchar(20)

    )

    RETURNS int

    AS

    BEGIN

     

    DECLARE @bossid int;

     

    WITH reports(EmpId,name,bossid,type) AS

    (

          -- set the starting point, a specific employee (from in-parameter)

          SELECT EmpiD,name,bossid,type FROM Employee WHERE empid = @empid

          UNION ALL

          -- get the empid from the person (e) who has empid which corresponds the the previous person's (r) bossid

          SELECT e.empid,e.name,e.bossid,e.type FROM employee e JOIN reports r

          ON r.bossid = e.empid WHERE r.bossid IS NOT NULL

    )

    -- from the above we have a hierarchical list of managers in a table called "reports",

    -- get the id from the boss with the type I'm looking for

    SELECT @bossid = empid FROM reports WHERE TYPE = @type;

     

    RETURN @bossid

     

    END

     

    Now, to create a view that has empid, name and boss id for a specific "level" I used a SELECT statement like this:

    SELECT EmpId, Name, dbo.GetBossByType(EmpId, 'boss') AS BossId

    FROM dbo.Employee

    WHERE (BossId IS NOT NULL)

     

    As you can see, I'm calling my function (GetBossByType) as part of the SELECT, passing in the EmpID and the type of manager I want to list. The result of the query/view is this (EmpId, Name, BossId):

    2 Lisa       2
    3 Otto       3
    4 Carin      2
    5 Carl        2
    6 Niel        2
    7 Thomas  3
    8 Johan     2
     

    Works for me. Lisa and Otto are of the manager type 'Boss' already, that's why they have their own EmpId as BossId. The hierarchical query can be a bit difficult to grasp first, but it's powerful. Sorry about the bad syntax and not sticking to upper/lower cases everywhere :)

  • [MsBuild] Writing and Debugging Custom Tasks

    Writing a custom task for MSBuild is very simple, here's the bare minimum code you would need to get you going:

    using System;

    using System.Collections.Generic;

    using System.Text;

     

    using Microsoft.Build.Framework;

    using Microsoft.Build.Utilities;

     

    namespace IRM.Tasks

    {

        public class HelloTask : Task

        {

            private string name;

     

            [Required]

            public string Name

            {

                get { return name; }

                set { name = value; }

            }

     

            public override bool Execute()

            {

                Log.LogMessage("Hello " + name);

                return true;

            }

        }

     

    }

    The task will obviously print out the value of the "Name" property to the log. 

    To test it, create a test-project like a dummy console app and add this to the end of the .proj file:

    <UsingTask TaskName="IRM.Tasks.HelloTask"    AssemblyFile="C:\code\HelloTask\bin\Debug\IRM.Tasks.dll" />

     

    <Target Name="AfterBuild">

          <HelloTask Name="Johan" />

    </Target>

    If you unload the project from the Solution Explorer window you can Edit it directly in VS. 

    But if you want to debug the task and set breakpoints in it? It was described by Neil Enns of the MSBuild team quite some time ago. After you have created a test-project and added the custom task to the .proj file as described above, do this:

    1. Open your custom task project
    2. Go to Project > projectname Properties…
    3. Go to the Debug tab
    4. Change the start action to “Start external program” and put in the full path to MSBuild as the program. In my case the path is “C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\MSBuild.exe”
    5. Change the “Command line arguments” to the full path to your test project
    6. Close the property window

    Now just start debugging your custom task, MSBuild should start up and start to build your test-project and will stop at any breakpoints you set in your custom task code. Neat!

  • [Team System] Team Building Web Application Projects and Deploying

    I've been battling with Team Build and Web Application Project (WAP) solutions. I first thought that Web Deployment Project (WDP) was the way to go, but I found out the hard way that WDP + WAP + Team Build isn't best mates.

    What I want to do is to build a number of solutions (which includes a bunch of projects) and after the build has completed, xcopy the web applications to a specific place, like under IIS webroot.

    There are many, many different solutions to this scenario, but I think it's a very common one. Here's what I'm thinking of doing now. Step by step dummy:

    1. I create a TFS project "WebApplication1"

    2. I create a solution called "WebApplication1" with 2 projects in it; "WebApplication1" (WAP) and "LibraryX" (Class library), I create some dummy code where a web page calls some code in the class library (mostly for fun).

    3. Compile and test.

    4. I add the solution to SourceControl.

    5. I then create a new Team Build called "WebApp1". 

    6. Go to Source Control Explorer and check out the TFSBuild.proj file for edit, then double click it to edit.

    7. Page down to the end of the build file and add (before the </Project> tag):

     <ItemGroup>
      <WebFiles Include="$(BinariesRoot)\Release\_PublishedWebsites\**\*.*"></WebFiles>
     </ItemGroup>
     <PropertyGroup>
      <DeployWebDir>c:\websites</DeployWebDir>
     </PropertyGroup>
     <Target Name = "AfterDropBuild" >
      <RemoveDir Directories="$(DeployWebDir)" Condition="Exists('$(DeployWebDir)')" />
      <MakeDir Directories="$(DeployWebDir)" Condition="!Exists('$(DeployWebDir)')" />
      <Copy
                SourceFiles="@(WebFiles)"
                DestinationFiles="@(WebFiles->'$(DeployWebDir)\%(RecursiveDir)%(Filename)%(Extension)')"
            />
     </Target>

    What the stuff above does is that it declares what files to copy (WebFiles) and where these files should go (DeployDir). Then there's a Target section which is called by Team Build after the drop has been made (AfterDropBuild) that removes the old files and copies the files from WebFiles to DeployDir. The $(BinariesRoot) property points to where the files have been built. WAP files are always built to the _PublishedWebsites\<project> directory.

    My web application is now deployed to c:\websites\WebApplication1\ and I'm manually creating an IIS virtual directory which will always be pointing at this directory.

    There are a number of additional things you might want to do as well, but I just wanted to show you a very simple way of always copying WAP files to the same place after a build.

    If you don't want to use the Tean Build drop directory at all, you should be able to skip that step by setting the SkipDropBuild property to true in the TFSBuild.proj file.

    MSBuild / Team Build Resources:

    List of targets that can be customized in Team Build (like AfterDropBuild in my sample):

    http://msdn.microsoft.com/en-us/library/aa337604(VS.80).aspx

    MSBuild Task reference:

    http://msdn.microsoft.com/en-us/library/7z253716.aspx 

    Brennan's blog with a 7 step tutorial on MSBuild:

    http://brennan.offwhite.net/blog/2006/11/29/msbuild-basics-1of7/

    How to create your own MSBuild task:

    http://msdn.microsoft.com/en-us/library/ms400767(VS.80).aspx

     

  • [Service Factory] How the Service Factory Guys Think

    Don Smith put a video up on the Service Factory Codeplex site about how they think about services, where they believe Service Factory is today and where they are heading. I thought the message about the different types of services was quite interesting because it is close to the way we're thinking when we're identifying service components for an enterprise. Note that the type of (web) services you may create as part of a specific solution because it may help you scale out, tier and get better availability and so on is something different to me. I'm more thinking of enterprise class services here.

    Don mentions 3 types of services; Entity/Capability, Utility/Messaging and Process/Activity.

    The first one is easy to understand and I think that's where most organisations start on their SOA roadmap. An Entity Service is usually very simple and may represent one or more business entities with data stored in a database or perhaps wrapped within a (legacy) system. You often se CRUD-like interfaces on these, but I recommend you to try and stay away from too granular methods. If you have an entity service for say a Person or a Customer, consider to not expose methods to get just the phone number or the email address, but rather get a complete Person or Customer object. These objects could be based on well known XML Schemas owned by perhaps information architecture group or something.

    The second type of services I usually call "Infrastructure Services" and are typically Security Token Services (STS), message routers and such. Could also be metadata/taxonomy/ontology services to help out with information integration cross services and systems. If anyone was using UDDI, I think it could also be placed in this category ;) Having said that, I think this category of services are very, important. It's hard to maintain and govern enterprise class services without an STS and a proper service catalogue. Not sure I understand their view on "Message" in this type of services. "Simple" Message routing services based perhaps on ws-addressing and such could be placed here, but more complex message handling, perhaps handled by a workflow engine, I think would go into the third and final category of services...

    ...called Activity and/or Process Services, which usually (for us anyway) contains methods and interfaces that map to scenarios, use cases, routines/functions (depending on which methodology and terms you're using). Also good for long running processes which may involve message queues, perhaps BizTalk and Windows Workflow Foundation. These services most often use other services, like Entity Services, to orchestrate and aggregate data needed by service consumers. They may not have their own database like Entity Services, unless you need to save state for a workflow or to keep replicated and denormalized data for aggregated search or perhaps masterdata for partitioned entities. See the Entity Aggregation pattern for a detailed description. One could argue that services that implement the this pattern should go into the first category of services, but I usually put them into the Activity Service category anyway, for reasons I'll probably blog about some other time (it's getting late).

    I'm happy to hear about where the Service Factory team is heading, to have better support for Utility/Messaging (Infrastructure) Services and move into support for Activity/Process Services. I wish there were some good guidance for activity and process services already. I'm quite interested in seeing what this team will do with LINQ in the near future. I'm not too fond of the data access code in current Data Access Guidance Package.

    Anyway, go check out the video, it's short and the sound is a bit so, so, but it's a good message.

  • Modify the Paperclip Theme on weblogs.asp.net

    The CS themes available on weblogs.asp.net are quite good, but maybe you want to add that extra personal touch to it. Say you want to change the big "masthead" picture on top of the screen of the paperclip themes. If you just have somewhere to host your own picture, it's not that difficult to override the theme settings.

    To change the masthead picture of the paperclip theme, first have a look at the css for the theme and see how the picture is referenced. View source and find the stylesheet link:

    <link rel="stylesheet" href="/Themes/Blogs/paperclip/style/cactus.css" type="text/css" media="screen" />

    Then download that css file and have a look at it. Search for the name of the picture you want to override, like "winter-title.jpg":

    /* The masthead sits at the top of the page.*/
    #masthead
    {
     background: #ffffff;
     background-image: url(../images/cactus-title.jpg);

    This tells me I need to override the css declaration called #masthead. Next, you create your own background-image for this section, and it's best if you use the old image as a template, or else you need to override other css settings, like where the paperclip text is written, width, height and so on. Personally I just saved cactus-title.jpg file and used Photoshop to create something new on top of it. When you're happy with the picture, upload it to wherever you want to host that file. Last thing is to go into the blog dashboard of weblogs.asp.net, click to "Global Settings" and "Change How My Blog Looks". Now go to the second tab of that page named "CSS Overrides" and past in something like this:

    #masthead
    {
     background-image: url(http://www.somehost.com/pictures/my-title.jpg);
    }

    That's it. I'm about to create a new picture now :)

  • Note to Self

    I've not blogged much lately, and it's not because I don't have anything to blog about - quite the contrary. Too much to do right now. I got a few things I would like to blog about, just as a note to myself:

    - The use of Software Factory to build WCF web services in a structured way (it's helping us out in a large SOA project now), and why you must be careful of using too long project names :(

    - How you could modify Software Factory to fit your needs, add new recipies and tweak the code that gets generated (my colleague Eric has done some cool work with this, and I hope he will blog about how to enable DataContract generation from an XSD-schema)

    - A few things to think about when writing XSD-schemas to be used for generating WCF DataContracts.

    - The (what seems to be) lack of support for calling Workflows (WF) från WCF and vice versa. It wasn't as easy as dragging a WCF Activity från the toolbox... I'm still struggling with this one.

    - Some experience from using DataDude with Software Factory and Team Foundation Server

    - And some CI with TFS notes that may help other people out.

     Sorry for not posting anything useful about the topics above right now, but I'll get to it, I promise. Stay tuned :)

  • Built Media Center PC, Streaming to Xbox

    It's been a while since I blogged anything now. Not that I've not had anything to blog about, but rather the other way around.

    During the holidays I built myself a new PC to run Media Center on, stuck a tuner card into it and set up my Xbox 360 as an extender. It works pretty well I must say. I'll write more about the custom PC later and things to think about when installing Media Center, transcoding movies and stuff. I didn't bother trying the Media Center version on Vista because I still have probs with device drivers for my printer, my scanner and a few other things :( Media Center Edition of XP works well for me I must say.

    Something you want to look at if you're into streaming divx videos from MCE to your Xbox is the Transcode 360 project avaiable at http://www.runtime360.com/projects/transcode-360/. It's a must.