Sunday, 16 January 2011

Just started looking at Windows Workflow Foundation (WF) 4

I’ve just started looking at the Windows Workflow Foundation 4. Now in it’s fourth Generation, the Windows Workflow Foundation, or WF for short, is a completely different way to go about Programming.

WF allows a programmer to create applications using a graphical approach, such as Flowcharts, Sequence Diagrams and State Machines.

Complex programs can be created direct on a xaml designer workspace with very little in the way of lines of code.

I’ve been following a great series of screencasts by DevelopMentor instructor, freelance developer and MVP Maurice de Beijer.

In these screencasts, Maurice takes you through from beginning your first “Hello World” (or “Hello workflow” maybe?), all the way through to creating custom activity and error handling.

The Screencast series can be found here;

http://msdn.microsoft.com/en-us/netframework/dd733248

One thing which is missing from the series are the code samples however, so I’ve uploaded the code for first five Screencasts to my website in case anyone needs them. They’re available here…

http://www.pjgcreations.co.uk/public/WFScreenCasts/

Note however that, as a I am a VB.net programmer, these Code Samples are all in VB.net, however Maurice has chosen to use C#.

This isn’t a major problem as there’s not a massive amount of actual coding involved, and most of the code is very similar anyhow.

But, if you do need the C# version, I highly recommend you use the following free website to convert VB.net code to C#;

http://www.developerfusion.com/tools/convert/csharp-to-vb/

.EndEdit causes row movement of a sorted BindingSource

When applying a sort to a Database BindingSource, executing the BindingSource.EndEdit method causes the currently selected row to change.

This has the effect of reloading any bound controls when tee edited row is saved, which of course can have unwanted effects if you need to operating on data related to the currently selected row after the EndEdit has been performed.

This issue can also be observed to a degree by selecting a row in a bound DataGrid, then choose the sorted column. It can be seen that the physical location of the selected row doesn’t change, however the previously selected row has now moved.

There are a number of ways to deal with the EndEdit issue, one of which  I found here…

http://social.msdn.microsoft.com/Forums/en/winformsdatacontrols/thread/0878567a-ccb1-441b-a51d-3e014372e61b

Where we check the ListChanged event and the e.ListChangeType;

Private Sub bsBindingSource_ListChanged(ByVal sender As Object, ByVal e _

    As System.ComponentModel.ListChangedEventArgs) Handles _

    bsBindingSource.ListChanged

    If e.ListChangedType = _

        System.ComponentModel.ListChangedType.ItemMoved Then

        bsBindingSource.Position = e.NewIndex

    End If

End Sub

Another method is to store the current state of the form, i.e. editing, adding, duplicating, normal etc in an enum. then use the following code;

Private Sub bsBindingSource_ListChanged(ByVal sender As Object, ByVal e _

    As System.ComponentModel.ListChangedEventArgs) Handles _

    bsBindingSource.ListChanged

    If sttCurrentFormState = Normal Then

        bsBindingSource.Position = e.NewIndex

    End If

End Sub

Sunday, 12 December 2010

Temporary Clickonce Certificates expire after 1 year

Creating and deploying Microsoft Clickonce Applications is a very simple process. However, it’s worth knowing that under the hood quite a lot is taken care for you by the Clickonce deployment wizard.

Once of the most important things to take care of is the Signing certificate. When you first deploy you Clickonce application, the wizard will create a temporary certifacte for signing your application.

What you may not realise at this point is that this certificate will expire in 1 years time. This has the result of rendering your deployed application inert and unable to perform updates.

To find the date of expiry of the Project’s Certificate, open up your project properties, and select the “Signing” tab. From here you’ll see the Certificate’s Details, including it’s expiry date. Here you should also take note of the “Issued To” and "Issued By” fields, you will need them later!

Microsoft of course, expect people to go ahead and buy a certificate from a third party supplier such as Verisign, this usually costs just under £100 or so, and may not be reasonable for small scale deployment. It certainly wouldn’t be if you didn’t realise till some time after the client has settled their invoice!

Microsoft has realised that an expired certificate will cause problems for people, and as such have documented a few workarounds;

http://support.microsoft.com/kb/925521

The first option you have is to uninstall your application and reinstall on all your client computers. not so easy if they are a few hundred miles away.

The second option is to extend the the life of your existing certificate using some example code which Microsoft have kindly supplied.

However, this code is somewhat simplistic, mainly in it’s error checking, so kindly some nice folk over at may.be have created a new project solution and some updated code for us to make use of;

http://may.be/renewcert/

Depending on which version of Visual Studio and Dot Net Framework you use, it will most likely be necessary to download the provided Solution, convert it to your version of Visual Studio, and recompile the source.

Once you’ve done this, copy the compiled executable from the \Debug directory to the directory where your solution has created the temporary key file for you. Usually this file is <YourProjectName>_TemporaryKey.pfx, and usually resides in the same directory as your project files. (Where <YourProjectName> is obviously the name of your project!

With the RenewCert.exe file in your project directory, open up a command prompt and cd to your project directory.

Once there, execute the following command;

renewcert MyProject_TemporaryKey.pfx MyProject_FiveYearKey.pfx CN=”MYDOMAIN\MYUSERNAME”

Where you should replace MyProject with the name of your project, and replace “MYDOMAIN\MYUSERNAME” with the information shown in the “Issued By” information I asked you to remember above.

This will create you a nice new Certificate, with a five year expiry. You can then close your command prompt and return to Visual Studio.

From here, you can hit the “Select From File” button in the Signing tab, and load your new certificate. check your expiry date, and it will now have a good five years to run.

All done for the next few years….. Till next time!