Compsoft Flexible Specialists

Compsoft plc

Compsoft Weblog Compsoft Website News Archive Privacy Policy Contact Us  

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: , , ,

Thursday, November 12, 2009

Tech Ed 2009 - Thursday - Neil Bostrom

Building Line-of-Business Applications Fast with Microsoft Silverlight and Microsoft .NET RIA Services

RIA services provides a pattern to write application logic that runs on the mid-tier that is projected on the client side. Making producing 3 tier application simpler. It's not just restricted to Silverlight.

Tim started off by showing the new Silverlight Business application template that comes with Visual Studio 2010 out of the box. This template seems pretty complete with loads of functionality like forms transitions, login, register, navigation, resources and styling. Very sexy, well worth looking through this template.

Domain service class is the guts of RIA services. When adding that class it prompts to point at your model. It then generates an API using your model, insert, update, delete, etc, methods for all your entities.

RIA services does its querying with two methods, one is the model collection name (Employees), you would bind to that. After that you would populate that collection using the Load method on the context.

RIA services also includes some out of the box helper controls. One of them being the data pager control. As this control works on IQueryable in your model, it does true server side paging.

RIA services takes advantage of the Data annotation syntax, similar to AJAX and MVC. This is a general direction in Microsoft which is great. We can implement this once in our common code and get validation for free on almost any client type.

RequestAuthenication and RequiresRoles is a nice way to control method calls using forms authentication on your server side.

 

Successfully Administering and Running Microsoft Visual Studio Team System Team Foundation Server 2008/2010

Turns out the install success rate for TFS 2008 was quite low. Looks like we were lucky on that front. You can never rename a team project, that's why Microsoft uses codenames for projects!

TFS performance comes from hard disk speed. Disk read / writes in SQL is where the real hit in TFS is. Try to split the databases out.

It's recommended that you only use a single team project for your company. Use iterations and areas to break down projects. Microsoft has a single team project for "Office" and all the projects (Word, Excel etc) are all in that project. The main reasons behind this is Work items can't be moved between team projects, the out of box reports work on a single team project.

Microsoft suggests to run TFS in a virtual environment. Benefits come from snapshot and disaster recovery.

When splitting the tiers up, it is suggested to have sql and SSRS and web tier on the other.

Read the online notes, LOADS AND LOADS of tips on performance. Legend!

TFS 2010 installation has been massively simplified. Project collections now allow moving of everything to different to servers. All the new features in TFS 2010 are only available in VS 2010.

 

Enhancing the design-time experience for Microsoft Silverlight 3

This session is talking about creating controls that are blend friendly. That appear in Blend and are easy to design. When creating controls that would call data or webservices, check if in design time and return sample data in place of live data.

Overide ArrangeOverride and MeasureOverride to run code on resize or move in design time. Use Dependecy Properties to make control properties available in Blend. Standard meta attribute like Description, Category, DisplayName, PropertyOrder, NumberRange, NumberIncrement, NumberFormat, EditorBrowsable will get used by Blend to breakdown the placement of the property.

With all this extra design time code, you can get a large code base. It is suggested you break out the design time code into a new dll. If you name that DLL *.Design.dll, VS and Blend will go looking for it and use them on the fly. If you name it *.Expression.Design.dll only blend will use it. If you name it *.VisualStudio.Design.dll, visual studio will automatically pick it up. In this new dll, add reference to Microsoft.Windows.Design to get access to the extension support.

Next topic was Behaviours. Blend has a bunch of behaviours out of the box and there is an option in blend to pull down more. Behaviours is a very easy way to wrap up a small set of functionality you would want to apply to any control.

To build your own behaviour, inherit from Behaviour in System.Windows.Interactivity. If you want to limit it to a type, then pop that in the generic type. AssicatedObject stores what object the behaviour is being attached to.

 

Debugging Microsoft ASP.NET and Other Microsoft .NET Production Issues with WinDbg and Microsoft Visual Studio .NET 2010

This session is a favourite of mine, been to it for a few years and has always been very informative. This year it has been updated to take advantage of the VS 2010 feature that allows easy opening and diagnosing memory dump files. In Visual Studio 2010 the Parallel Stacks window shows a diagram of where every thread is and its stack in a lovely chart, giving you loads of insight into what's going on with your website.

As always Tess got down and dirty with some WinDb.exe action. WinDb.exe is a low level debugging tool that is not aware of .NET. So to give it some knowledge of .NET you need to first load sos.dll. You do this by running the following command:

.loadby sos mscorwks

Once you have done this you can walk through some of the CLR using an array of commands. Some of the interesting things you can do is say:

!dumpheap -stat

This will list all of the objects on the heap. From here you can drill into the objects for more information by using

!do (memoryaddress)

Once you find something that you believe should have been GC'ed, you can run the following command:

!gcroot (memoryaddress)

To give you a tree of what the GC is holding on to! This is so immense!

If you forget what the commands are, you can easily load up a command file that gives a handy context menu on the right using:

.cmdtree c:\debuggers\cmdtree.txt

You can get the cmdtree.txt from Tess's website.

Debug Diag Tool can capture memory dumps on the fly or look for requests holding. Its produced by the IIS team and can be easily downloaded and installed.

Tinyget is another handy little tool to stress test websites. Means you can prep your website before taking a memory dump.

 

All You Needed to Know about Microsoft SQL Server 2008 Failover Clustering

I know nothing about failover clustering so this was going to be a sure win! Interestingly clustering only helps with machine fail over, not database failure.When a node does fail over, any application will fail to connect while the next node comes online. So you need to put retry code in to keep your application running.

SQL server 2008 clustering works better with Windows Server 2008 R2 clustering. So the first thing you would do is setup Windows Server Clustering. Once you have done that you can then install the SQL Server clustering installation on your primary machine. You would then add all the other machines using the Add Node option in the setup wizard.

Sexy feature of clustering is that you can rollout patches and service packs without any downtime by applying the patches to each node, one at a time. This gives you good uptime as there is no need to take your application offline. You can even do full version upgrades, so moving from SQL 2005 to SQL 2008 with only a min or two's worth of downtime which is just the database script upgrading to SQL 2008.

Labels: , , ,