Compsoft Flexible Specialists

Compsoft plc

Compsoft Weblog Compsoft Website News Archive Privacy Policy Contact Us  

Monday, December 07, 2009

Using MSDeploy as a build task in TFS

MSDeploy is a new tool out by Microsoft that allows easy synching of files between servers. This can be used from inside IIS or just run from command line.

You can read more on MSDeploy here. Read MSDeploy's team blog. Nice article on using the msdeploy command line.

I thought I would share an actual use of the MSDeploy in our TFS build scripts. It also uses the XmlUpdate task from the MSBuild Community Tasks Project.

<Target Name="AfterDropBuild">

<!--
Update web.config to be in release mode -->
<XmlUpdate XPath="/configuration/system.web/compilation/@debug"
XmlFileName="$(DropLocation)\$(BuildNumber)\Release\_Published
Websites\Site\web.config
" Value="false" />

<BuildStep TeamFoundationServerUrl="$(TeamFoundationServerUrl)"
BuildUri="$(BuildUri)"
Message="Deploying Website"
Condition="'$(IsDesktopBuild)'!='true'" >
<
Output TaskParameter="Id" PropertyName="InstallerStepId" />
</
BuildStep>

<
Exec
Command='"C:\Program Files\IIS\Microsoft Web Deploy\msdeploy.exe"
-verb:sync
-source:contentpath="$(DropLocation)\$(BuildNumber)\
Release\_PublishedWebsites\Site"
-dest:contentpath=\\SERVER\Websites\Site
'
ContinueOnError="false" />

<
BuildStep TeamFoundationServerUrl="$(TeamFoundationServerUrl)"
BuildUri="$(BuildUri)"
Id="$(InstallerStepId)"
Status="Succeeded"
Condition="'$(IsDesktopBuild)'!='true'" />

<
OnError ExecuteTargets="DeploymentFailed" />

</
Target>

<
Target Name="DeploymentFailed">
<!--
Called if deployment of the web site fails -->
<
BuildStep
TeamFoundationServerUrl="$(TeamFoundationServerUrl)"
BuildUri="$(BuildUri)"
Id="$(InstallerStepId)"
Status="Failed"
Condition="'$(IsDesktopBuild)'!='true'" />
</
Target>

Labels: , , ,

Friday, November 13, 2009

Tech Ed 2009 - Friday - Neil Bostrom

Can you keep a secret? The biggest little-known features in Microsoft Silverlight

The default networking calls in Silverlight are all made through the browser. This has limitations to do with when web service return server faults. The browser can not interrupt it correctly.

There are now two networking stacks in Silverlight 3. Browser stack and client stack. The client stack goes direct to the OS network stack. This stack works correctly for web service faults. The browser stack only support 200 and 404 return codes. This is the root of the problem with web service server fault limitation. A limitation with the client stack is that it does not get the content caching built in to the browser.

To start using the client stack, you call HttpWebRequest.RegisterPrefix("http://", WebRequesterCreater.ClientHttp) and all calls after that will be on the client stack.

You can check any request object by checking the CreaterContext.

Silverlight 3 has an updated frame rate counter. To enable that, add ENableFrameRateCounter and EnableGPUAcceleration.

RenderToScale is part of the BitmapCache that allows you to control the size of the bitmap that gets handed off to the GPU by Silverlight.

Analytics class allows logging of CPU load and GPU usage.

AssemblyPart.Load allows you to load up assemblies on the fly. This means you can keep your xap file small and just pulled down the extra parks as and when you need them. To lighten up your xap file, you can change your references to be copy local = false. This means it won't be shipped in your xap. For the dll to be easily downloaded, put a manual copy inside the ClientBin folder.

This technique does have a big flaw. The CLR will die trying to find that reference. The CLR scans the method before it's run for all its types. MethodImpl(MethodImplOPtions.NoInlining) forces the JIT compiler not to scan that method for types it does not know.

Application Extension Services is a service model for building services that run with your applications. All you need to do is implement IApplicationService, StartService, StopService. Silverlight will create the service as it starts and close it just before exiting.

SynchrosationContext.Current has access to the UI dispatcher

VisualTreeHelper is a handy class to grab controls inside Composite controls.

RelativeSource allows two way template binding! Awesome!

AutomationPeer class allows you to click buttons etc.

 

Architecting Silverlight Applications with MVVM

MVVM is only a solution for large scale applications. It's not really ideal for small projects as it can be very bloated with layers etc.

MVVM is Model, View, ViewModel. As you start using this concept it is very similar to MVC. You create a Model which is your entity with data access. View is your control XAML on the page and then you create a model for your view that has everything you can bind to. The advantage with this is that ObservableCollection does not need to exist in your model, you can just expose that in your VIewModel. This keeps your model very clean from UI dependant references.

A cute way to reduce the dependency on the view calling the model in code is to use behaviours that you can just attach to elements in the view. One handy behaviour out of the box is CallDataMethod which can be wired up to to your method on the model.

 

Code Contracts and Pex: Power Charge your assertions and Unit Tests

CodeContracts does validation on your code and comes up with warnings for certain coding errors.  Code Contracts allows you to make code method call intentions on your methods and code contracts will generate the correct code to run that intention.

Pex allows you to do unit testings on firing cases of your code that you might not have considered.

The Code Contracts does make for very bloated code. For interfaces you need to make two more classes to just say something doesn't need to be null.

Code Contracts has a runtime checker, static checker and documentation output. So that single intention gets used in a bunch of places.

Labels: , , ,

Tuesday, May 05, 2009

Making sure your application is not left in debug="true"

You will find loads of articles around the web reminding us all that running your production ASP.NET website in complication debug=true mode is a BAD THING!
To make sure we avoid this problem we have added a start up check in our application that will make sure that the build mode (debug or release) of our binaries match that of the web.config. As all releases are done via our build server all our binaries will be in release mode. However we tend to make major changes to the web.config on the live servers so deploying the web.config is usually not an option.

To check if the web.config has debug enabled you can use HttpContext.Current.IsDebuggingEnabled.

To check what mode a binary is in, we use the #DEBUG Preprocessor Directive:

   1: // codesnippet:ADB0358E-3BD1-11DE-B2D2-764056D89593
   2: public static BuildModeEnum BuildMode
   3: {    
   4:     get    
   5:     {        
   6:         #if (DEBUG)
   7:             return BuildModeEnum.Debug;
   8:         #else
   9:             return BuildModeEnum.Release;
  10:         #endif
  11:     }
  12: }




Labels: , , ,

Tuesday, November 11, 2008

Neil Bostrom: Tech Ed 2008 - Day 2

Learning the Entity Framework

Entity Framework is one topic I really wanted to learn more on, however this was not the session to achieve that. The content of the session was only the basics which I already knew. The practical demos were limited. Felt a little let down when I left the session as I missed out on some other interesting topics to make sure I made that session.

Sync Framework - Deep Dive

Sync framework was an excellent session covering everything from what the sync framework is right down to how to write a custom provider for it. The Sync framework allows you to sync almost anything (if you have a provider for it) with anything else. So you could sync a file system with a database, or outlook with facebook etc. This solution would have been a perfect for the Hippo PDA project where we had to write all the synchronisation manually.

Building a Dynamic Info-Screen application with Silverlight 2.0

I was extremely pleased with this session as it was showing a practical implementation of Silverlight in a real world application. The Info screen was talking about ad boards or train station screens, where you need dynamic content inside a range of different templates. Max Knor did an excellent job explaining the architecture of the application and also showing real code to swap in and out dynamic templates in Silverlight. The application showed some of the great power you have with Silverlight, including the ability to run the Silverlight on a client inside a WPF application.

How LINQ Works: A Deep Dive into the C# Implementation of LINQ

This session was a level 400 (uber hardcore) and it was great! Luke Hoban did a fantastic job covering a difficult topic in an easy to understand manner. It covered how LINQ holds together and how the C# compiler converts the LINQ expressions into method calls. Interesting point I learnt here is that the compiler will search closest to the code for extension methods. This means you can override the default implementation of an extension method (like the WHERE clause) by declaring it closer than System.Linq. Luke then covered how IQueryable uses expression trees to allow delayed execution. This is the real power behind LINQ. A real gem that came out when was Luke showed the different code that is generated by the compiler depending on which interface you work against, IQueryable or IEnumerable. IEnumerable lambdas are generated as methods on the class, however IQueryable lambdas are created as expression trees. It's a difference I knew about but didn't join the dots to the different code that is generated.

Silverlight 2.0 Security End to End

Security is not a word I’ve heard being mentioned with Silverlight yet, this is why I jumped at this session when I saw it. Silverlight is very powerful but does run client side so security is a concern. The first area covered was the built in security that the Silverlight CLR uses. It has a SecurityCritical attribute applied to it that is used by the platform Silverlight code, like File.Exists. This code can only be used by the Silverlight framework. There is also a SecuritySafeCritical attribute to allow application code to call code that is SecurityCritical locked. All Silverlight appdomains are sandboxed, no Silverlight app can create app domains or cross call them. To allow Silverlight apps to store settings, there is an Isolated storage class. This is a Virtual File System as it needs to work on both PCs and MACs. The Isolated Storage is per application or per domain. The default space allocation in the Isolated Storage is 1MB, however the developer can prompt the user to request more space. Webservice calls are only allowed to same domain, port and protocol. To make cross domain calls, you need a clientaccesspolicy.xml in the root of that site. We spoke about good practices on securing web service calls by using Querystring tokens when making the calls.

Labels: , , , , , , , , ,