Wednesday, 28 December 2011

Migrating from Silverlight to WPF

I've just completed migrating a Silverlight application to WPF. All up it took a few days. Not difficult, mostly tedious, but it become evident that some preparation and knowledge helps. So here are my notes.

The application's vital statistics:
  • Silverlight 4
  • Visual Studio 2010 with Resharper 6
  • Several VS Silverlight projects with multiple common library assemblies
  • MVVM
  • No Silverlight IoC used
  • Automated UATs using White (Silverlight) framework
  • Telerik RadControls using charting, ribbon bar, data grid views, etc
  • Highly interactive UI
  • Multiple WCF services
  • Entity framework & SQL server back end

Preparation


Changes and research needed prior to changing references to the WPF framework ...

Do a spike
I found a spike run useful. I converted a few base assemblies until I got to one that had a Silverlight control (e.g. a user control or page). This took a few hours and help greatly in planning the real attack. Discard the spike, you will do it better the second time.
Assembly Dependencies
Understand your application's Silverlight assembly dependencies, you need to work up from the bottom.
WPF reference assemblies
Do some research into Microsoft's WPF/Winforms reference assemblies. Referencing the wrong library is just too easy and can be time consuming to correct. Both WPF and Winforms have TextBox controls and Resharper is great but not a mind reader (yet). Take care when adding references.

e.g. PresentationFramework.dll, WindowsBase.dll, PresentationCore.dll
Clean-up orphaned files
Sometimes files are removed from an assembly without being deleted or removed from the repository. You need to make sure these 'orphaned' files are removed before migrating. Select each project in turn and click on the show all files button in Visual Studio. Delete the orphans from your disk and the repository.
Navigation
Remove all web page navigation before you start the migration proper. This may be the biggest part of the job, the application needs to behave as one application rather than multiple web pages.

Search your code for 'href', 'Uri', 'MappedUri', and 'NavigationService'. These must go.
Web specific controls
In our case we had a RadControls HtmlPlaceholder which we used to display PDF files. This was removed prior to migrating the code and a PDF reader added post code migration. I could not see a refactoring option here.

Code Migration


Getting the code to compile as a WPF application ...

Telerik RadControls
Possibly the easiest part. Got the WPF version and it compiled with very few differences. Actually, I do not remember any compile time changes. Nice one Telerik.

Note: Mitigated the cost of buying new WPF licenses by timing the change close to our Silverlight licenses renewal. Tell the bean counters the new license costs are X but this is offset by dropping the cost of license Y making our cost ....

However there were a few run-time behaviour differences which were probably base WPF framework differences. I list these later.
Migrating assemblies
The procedure to migrate an assembly, working up the reference hierarchy was:
  1. Add a new dot net assembly (not Silverlight) with the same name as the one being replaced but with a clear suffix like "_X". Important: Tell VS to create it in the same folder as the existing assembly.
  2. Remove the newly created assembly from the solution.
  3. VS has created a folder for the new project in the existing assemblies folder. Navigate to that folder and move the project file down into the same folder as the existing project.
  4. Add the moved project to the solution. As VS sorts projects alphabetically you will find in just below the one your replacing.
  5. Copy the project's name space from the original project (do not change it until the entire migration is finished). Set the assembly name to be the same but with a suffix like the project name.
  6. Add a reference to, as a minimum, PresentationFramework.dll, WindowsBase.dll, PresentationCore.dll.
  7. Select the new project and click on "show all". Select all of the source files and folders and add them to the project until the new project has the same files and folders as the original project.
  8. Try to compile the new project. You will need to change used namespaces. Typically the change will be to half a dozen namespaces in many files. So you will learn to do a search and replace (within the one project). This will break the compile of the original assembly but that does not matter so much.
Keep the old project in the solution until the migration is finished, you may need to navigate to solve errors in the migration, etc.
Migrating WCF service references

I did not find a way to migrate WCF service references. Create new ones in the new Dot Net assembly.

Run Time (Post code migration)

I did find some breaking differences. These were:
  • Had to change a few Page controls to UserControls. WCF class hierarchy is a bit different. The compile error is clear and it was not difficult to do.
  • The initialisation sequence is a little different. I need to move some initialisation code to different event handlers. I do not remember the details. This did take a few hours and was hit and miss. On one case I do remember I had to move some initialisation to an OnActivated event and add an "initialised" state. I'm sure that is not the intended way, but it worked.
  • I had one binding that did need considerable rework. The binding was to an indexer. Looked like a control binding defect, should have worked. This one also took a few hours to resolve.
Conclusion

It proved viable to migrate our Silverlight application to WPF with few problems. Medium complexity job.

Code conversion took one developer a week. Planning and changes to the application are required before changing references to the WPF framework. Risk is low-moderate provided that your libraries, like Telerik, have a common WPF and Silverlight API.

However, defects were introduced. Most had very high visibility (ribbon bar blank) so are relatively low risk. A few were changes in control behaviour so rigorous post migration testing is required. So allow the same time for testing and introduced defect fixing as was required for the code conversion (pre-testing) stage. But ... if you have good automated UATs manual testing will still be necessary but there will be few introduced defects.

Monday, 12 September 2011

The Convenience of Conspiracy

Conspiracy is a respone for the ineffectual to resolve their position in a complex society.

Isn't being ineffectual somebody else's problem?

Monday, 20 September 2010

Using Log2Console from NLog via MSMQ

I've been using Log2Console to view real-time logging for a while using the Chainsaw target and UDP. But UDP is not reliable for fast real time logging. I found a simple way to configure NLog to send messages via MSMQ in the Log4JXml format used by Log2Console. It recon this could be used with any NLog target.

Here is the NLog config:

<target name="messageQueue" xsi:type="MSMQ" queue=".\private$\log">
<layout xsi:type="Log4JXmlEventLayout"/>
</target>


So simple.

Rob

Thursday, 19 August 2010

Cube Farm Designs That Cut Out Conversation

The 2006 Waterfall Conference proves to provide timeless value. Those who know of Alistair will appreciate his input on office layout here.

Code Smell Metric - Doco Fluff Metric (DFM)

Code documentation is one of those things that is so easy to do to without adding anything useful. The problem is that the added lines of code/text appear have no value and reduce code readability. A case of less is more. Documentation can be useful, but nonsense documentation is worse than no documentation at all.

So a metric that detects nonsense documentation ("fluff"?) is another little helper.

Here is a real world example:

/// <summary>
/// Thread Name.
/// </summary>
public string ThreadName;
/// <summary>
/// Time Stamp.
/// </summary>
public DateTime TimeStamp;


A trival example but I recon it is less readable than:

public string ThreadName;
public DateTime TimeStamp;


So the metric is: If the documentation, with white spaces removed, case insensitive matches the property, method, or type then flag as doco fluff.

Tuesday, 27 July 2010

Agile Software Testing 101: Stress Testing

So your a software tester and you have received a new build with a new feature to test. How do you stress test it? Not difficult, you just need to know the pattern of "Stress Testing" to find those weak points. Here is a simple agile "how to".

Agile principles can be applied to testing. When done they leverage the tester's skills with the developer's skills.

Steps:
  1. Being agile (as we all are) you let the developer responsible know that you are about to test the new feature.
  2. As agile means collocated, you make sure you are near the developer and he/she can see your screen. Think of this as limited-pair testing perhaps, an agile balance of full pairing and letting the developer get on with his job.
  3. To enhance your pairing make sure you have a mirror so you can see the developer. Collaboration is critical to stress testing.
  4. Now go to the UI page that uses the feature and sweep your mouse pointer over the page watching the developers. When you see signs of stress ... click.
Stress testing saves time and leverages agile principles of, well, whatever your company says is agile today.

Wednesday, 21 July 2010

Oath of Non-Allegiance

Alistair Cockburn again challenges us. Check out the "Oath of Non-Allegiance" here.

I'm sick of hearing 'they are not agile because they use UML' or 'In agile we stand up and spin clockwise every 42 minutes".

Now I will go back to making my agile coffee on my agile PC and writing lots and lots of agile modelling diagrams. I wonder if my agile undies have arrived?

The term 'Agile' has joined the livings dead, its meaning and purpose of the manefesto is long gone. It is now used to mean whatever you want like Scrum, eXtreme Programming, or just anything.

May tolerance, an understanding that all processes are broken, and the bravery to find 'what works', replace it.

Monday, 12 July 2010

Using Visual Studio 2010 over RDP With Dual Screens

I often work from home and want to use my work box with dual screens but my home monitors have different resolutions. Normally, with a VPN/RDP connection, the windows RDP software cannot handle dual screens nicely and not at all when they have different resolutions. I like SplitView, it allows me to do this.

At home I have laptop and an external monitor. The laptop has a 1680 pixels across and the monitor has 1920 across. Needless to say I want to use both with Visual Studio's main editor on the larger monitor and the debug, output, unit tests windows on the smaller laptop monitor. With SplitView I can connect to my work computer and use both. The nice thing is that I can maximise an application within a monitor without it filling both monitors.

It is a little tricky (you do need to read the doco) to setup as it does layer over RDP. With a little fiddling about with the screen sizes it works nicely.

But the screens are not exactly the same and when I return to the office after working from home I find that the screen layouts have changed. A bit annoying. Move the VS2010 properties window here, output window here, etc. So I saves my "in office" and "rdp" layouts using VS's "Import and Export Settings". First get the layout you want and the export it by selecting "General Settings | Windows Layout" only. Then from home, or in the morning, you can quickly restore world order to your windows. Nice.

Friday, 9 July 2010

Continuous Integration can build time dependency

It seems to me that there is a dependency between Continuous Integration (CI) and build time. Each time I hit a slow build it puts pressure on 'fast' CI. It seems that if the build is slow then CI may be more destructive that beneficial. I'm thinking it is all a question of ratio.

CI does not define an integration rate. Some teams see CI as once a week, others see it as every 15 minutes. It is a relative concept.

If a build box can build and run all tests in, say, 1 second then a team's commit rate of once every 5 minutes would seem achievable. Each developer would have instant feedback and be able to fix, or revert, any problem within a couple of minutes, after a commit, with minimal effect (without considering a pre-commit test system). But if the build takes, say, 30 minutes and the team's commit rate was once every 15 minutes then by the time a build failure is detected the whole team is affected.

So it seems to me that there is a relationship between CI's rate and build time. Just do not know hat it is yet.

Visual Studio 2010 build speed - kinda Windows 7 really

When I moved to a new project using Visual Studio 2010 the build time seemed very very slow. But it would seem the problem is more to do with Windows 7. We are using Subversion, VisualSVN, TortoiseSVN for RCS. I have been perplexed as to why we no longer get icons in Explorer and today I found the solution here.

Once I ran the spell:
netsh interface tcp set global autotuninglevel=disabled.
The world order was restored. VS2010 compiled 2 times faster, Explorer icons came out from hiding, and Explorer was happy (much much faster).