Monday, August 22, 2011

Layered Architecture Solution Guidance 1.0.0.2

Released another update to Layered Architecture Solution Guidance. This time with slightly more fixes and updates:


  • Discovered that if the code file is not saved, appending new code will cause the unsaved changes to be lost. Fixed that.
  • There seems to be some logic error preventing us from setting the IsUpdated property to false. Fixed that too.
  • Added a new Workflow Activity Designer project.
  • Vector: Workflow Activity Generator now generates activity designers. (I always wanted to do this)
  • Added an "INSERT, UPDATE, SELECT" method type in Momentum: Data Access Component Generator. I was kinda lazy to click so many times so I created it :p
  • Updated the Layered Azure Application to use Windows Azure SDK 1.4 templates. I still can't automatically hook up the roles because there are no public APIs to do it currently.
There you go.

Wednesday, August 17, 2011

Deployment Schedule Concerns on Cloud

Recently, I have learned a lesson when deploying applications on Windows Azure. It is common that we usually make a deployment schedule for our applications to meet a certain launch date (or time) i.e. something like deploy between 7:00 to 9:00 am or 12:00 to 2:00am. Based on my recent experience, we should make the deployment schedule a few days earlier if possible.

This is because the provisioning of instances on Windows Azure can sometimes take a very long time. Provisioning 3 roles in the Southeast Asia region can take up to 90 minutes and provisioning a new Service Bus can take up to 30 minutes sometimes (15 minutes for the DNS to refresh). If you made any mistakes and need to delete and recreate the services, it even takes more time.

Therefore, a recommended practice would be to allocate more time for deployment when deploying apps to the Cloud. It is no longer just copy some dlls over to a folder or "just double-click the setup.exe".


Monday, August 08, 2011

Layered Architecture Solution Guidance 1.0.0.1

Just released a minor update to Layered Architecture Solution Guidance that includes some bug fixes and also minor enhancements.
  • When unfolding solutions, the guidance now creates a Unit Test project under a Tests folder.
  • Code generators that requires the loading of assemblies now automatically loads the dlls if they are able to find them.
  • Vector: Workflow Activity Generator now supports AsyncCodeActivity (I had forgotten to enable the code in the previous release *HeHe*)
Have fun! :)

Sunday, August 07, 2011

Adding Items to Solution Template in GAX

I was thinking of adding a Test Project in each of the layer solution templates for my Layered Architecture Solution Guidance. So I created a layered web application and manually added a Test Project to study what sort of structure do I need to create.

It turns out that apart from adding the Test Project, Visual Studio 2010 also adds 2 files - local.testsettings and TraceAndTestImpact.testsettings into the solution for me. So off I went to modify my VSTemplate and to my greatest surprise, there are no easy way to add items into solutions. Yup! You can easily add items to projects but there are no (known documented) way to even add a Readme.txt to the solution template and posting to the MSDN Forums, gave me zero replies, no help, whatsoever. *Sad*

So I went on to think about it for a while. The VSTemplate does not allow an easy way to specify the files we want to add to a solution via its xml. We will need to perform some GAT and DTE acrobatics to achieve this. There are actually two problems. The first problem is how to get our file into the solution and the second problem is Visual Studio will always open the file automatically when we add it in. The second problem is not so much a problem if you are adding a readme.txt but becomes a problem when you are adding testsettings.

Let's look at the first problem. Because we can't specify the file in the VSTemplate, we can't package the testsettings file. We also can't point to a physical location of a testsettings file on the developer's machine to add. Therefore, the easiest workaround is to copy the contents of the testsettings file into a T4 template. From there we can generate the content out to a file on the developer's machine. To do this, we need to create an Action.

For the second problem, you will notice that Visual Studio will automatically prompts the developer to configure the test settings after your solution unfolds. This becomes very annoying and it took me a while to figure it out. To solve the problem, first add the testsettings file with an extension that Visual Studio does not recognize i.e. testsettings.bak, then save a copy of the file as the intended extension and delete the original. This prevents Visual Studio from launching the Test Setting dialog when you unfold your solution template.

Here's the Action I wrote (simplified for easy understanding):


[ServiceDependency(typeof(DTE))]
public class AddTestSettingAction : ConfigurableAction
{
    public override void Execute()
    {
        AddSettingsFile("local.testsettings"new TestSettingTemplate().TransformText());
        AddSettingsFile("TraceAndTestImpact.testsettings"new TraceTestImpactSettingTemplate().TransformText());
    }

    private void AddSettingsFile(string settingsFileName, string content)
    {
        DTE dte = GetService<DTE>(true);

        // Set the path to the physical solutions folder.
        string path = Path.GetDirectoryName((string)dte.Solution.Properties.Item("Path").Value) +
            @"\Tests\Solution Items";

        // Setup actual file name.
        string settingsFile = path + "\\" + settingsFileName);
        // Setup a temporary staging file name.
        string stagingFile = settingsFile + ".bak";

        // Write the contents to staging file.
        using (StreamWriter writer = new StreamWriter(stagingFile, false))
        {
            writer.WriteLine(content);
        }

        // Get the Tests\Solution Items folder.
        ProjectItem projectItem = dte.Solution.Projects.Item(dte.Solution.Projects.Count).ProjectItems.Item(1);

        // Add the staging file.
        projectItem.SubProject.ProjectItems.AddFromFile(stagingFile);

        // Return the item.
        ProjectItem item = projectItem.SubProject.ProjectItems.Item(projectItem.SubProject.ProjectItems.Count);

        // Create a new copy of the item with the desired file name.
        Window wnd = item.Open(EnvDTE.Constants.vsViewKindPrimary);
        item.SaveAs(settingsFile);
        wnd.Visible = false;
        wnd.Close();

        // Delete the staging file.
        File.Delete(stagingFile);
    }
}


Take note that I did some very dangerous assumption here based on the layout of my template. I created a Tests folder in my solution and it is always the last folder in sequence based on alphabetical order, therefore, I always went for the last index in my first level solution folder. The next dangerous thing I did was to always retrieve the 1st index for my sub-folder. I guessed if you have unpredictable layouts, you should write a search function for locating the project items, otherwise, you can hard-code them for performance.

And here's what has been achieved:


Now isn't that a lame workaround for a lame problem that should not have even existed at all in the first place?



Thursday, August 04, 2011

LASG Documentation

Really putting in a lot of effort on this. First batch of Layered Architecture Solution Guidance document is up!

Hope they are helpful. ;)

Wednesday, August 03, 2011

Empty Layered Application Template

I have included an "Empty Layered Application" solution template in the latest release of Layered Architecture Solution Guidance. This should enable advanced developers to manually add the projects as they code along giving them more freedom and less clutter.


I have also provided some additional automation in the project templates to help automatically setup the references to the projects should the need arise. Hope you guys like it.

Tuesday, August 02, 2011

LASG with Code Gens

That's it! I just pushed the upload button!

The version of Layered Architecture Solution Guidance (LASG) that is integrated with my secret code generators (dubbed Project Newton) is finally published on codeplex. Hopefully, it can help simplify the tasks of developing layered applications for developers around the world.

Now to get some rest...