Hiding / Showing Jump Lists in windows 7

The jump list feature in Windows 7 makes it really easy to find the documents you were working on for each application. Just go to the taskbar and right-click the application. If your application has been enabled for jump lists (and they should, it is really easy to enable this using some API’s) then you should see a list of recently opened items. One day I started noticing I didn’t have any jump lists any more. Luckily the problem is easy to fix. Open your taskbar properties and go to the Start Menu tab. Check the “Store and display recently opened items in the Start menu and the taskbar” you you should get them back. I must have disabled this by accident…

image

Techdays 2010

I’m happy to say I’ll be speaking at TechDays 2010 in Belgium and DevDays 2010 in the Netherlands.

In Belgium I’ll be doing one session on “What is new in WCF 4” and one session on “Workflow Foundation 4”.

In the Netherlands I’ll do on session on “What is new in WCF4” and one on “Developing for Windows 7 with the Windows API code pack”.

Speaker_180x150 Peter

Planning, Running and measuring tests with Visual Studio 2010 Ultimate and Test and Lab Manager

So what does Visual Studio 2010 bring for testers? A whole lot! Especially the new test environment, where you can create a test plan to validate the quality of the software you’re building. A test plan is a collection of test cases, which you can then run. While running the system keeps track of a whole lot of things, including code coverage and IntelliTrace information. And finally this application allows you to examine the combined results of all tests, to see how your development effort is doing.

So again: A test plan is a collection of test suites, used to test a certain iteration in your project. A test suite is a collection of test cases to test a certain part of your project, and a test case is a test for a project feature. A test case is basically an UI test running in a specific environment. To model this, Test and Lab manager also allows you to define a test configuration, which is a certain environment for your code, for example Windows 7 with IE8, or Windows XP SP2 with IE7.

Running Test and Lab Manager

First time you run this application it will ask for your Team Foundation Server (TFS) and after that, for the Project Collection and Team Project:

image

Ok, next step it will ask you for a test plan; since there are none you will have to create a new one:

image

Then click “Select plan >”.

This opens the test plan.

image

if you want you can change some of the properties of this test plan by clicking on the properties tab:

image

Here you can change the iteration for example, or the test settings.

image 

With test settings you can change how your tests will be executed. For example in the Local Test Run settings you can change the diagnostic data adapter, which record data from your test run. For example is you want an action recording, event log entries, etc… You can also use it to emulate certain environments, for example running low on memory. You can even create your own data adapter.

image

This first page allows you to change the name, and choose between running a manual or automated test.

image

On the second page you can define the roles. You define a role for each tier to use to run tests and collect data. One the local settings you can only have one role, your own physical machine. If you want to use roles, you will also have to define environments.

image

Here you can define what kind of data you want to gather. For example, the Action Recording will record each action taken during the test, making it easy for another person (typically a developer) to understand what happened during running the test. The Action log is a text version of the recording. IntelliTrace will allow a developer to load the IntelliTrace log and step back in the code, to see how the error came to be.

Go back to the Contents tab.

Now we’re ready to test some of our user stories (from now on I will be using User Stories, but this could just as easily be called a requirement or anything else to denote a certain needed functionality of your software system). Test cases are grouped into test suites. Per test plan you have a default test suite, but you can also create a test suite for a specific user story, copy a test suite from another test plan, create a nested suite or create one from a query:

image

If you select “Add requirement"to plan” you will need to select a user story. This user story is now associated with this test suite. This will allow reporting to figure out which tests have ran for which user story.

image

Now we’re ready to add a test case, so click the New button. The New Test Case dialog should show:

image

Add the four steps (please note that we’re doing this for the sake of the demo, normally your requirement should not be to crash :) ). Save it.

Click on the Tested User Stories tab: the User Story should be there. Save and Close.

A couple of other things you can now do is to assign it to a tester, and/or change the configurations:

image

Let’s run the test. First open the Test tab: image

From here you can see all test cases for a test suite:

image

Select the test case and click on the run button. The Test Runner should open:

image

Check the Create action recording button and hit Start Test. Do as the test case says, and try to use a repeatable way to start the application (for example using the start menu). The first and second step should not be a problem, so click the drop down boxes to the right of each step to indicate success:

image

Now make the third step fail. You’ll need to enter a comment why it failed. Then click the End Test hyperlink button. You’ll see test center gather some information.

On top of the test runner window you’ll see a toolbar. Click on the Create Bug button:

image

You’ll see that most of the fields are automatically filled in. You might want to change the Severity for example, and maybe assign it to a certain tester, but that is all… Click Save. Check out the information included in the System Info, and All Links tab. Close it.

Remember me asking you to start the application using some repeatable way? Well, try and click on the play button. Your test should replay again. This makes it easier to re-test later.

Coming back to Test and Lab Manager. The test case failed so now the UI updates to show this:

image

If you have more than one test, the bar will color depending on how many succeeded, failed or are still in progress.

Later you can come back and verify if a bug still exists by using the Verify Bugs tab:

image

Go back to the Plan tab, then open the properties. Now you should see an overview:

image

Back to Visual Studio, so close the Test and Lab Manager. Go to the Team Explorer and open the My Bugs query. You should see the bug we created before. Open it:

image

Go to All Links, and open the IntelliTrace log (.tdlog). With it you can now replay the bug, just like in my previous post on IntelliTrace. If this doesn’t work, go back to the test settings. You might also like the Video feature, so you can replay the user’s actions!

Using the WPF Visualizer in Visual Studio 2010

Visual Studio 2010 now has a cool little feature I want to show you. When you’re debugging WPF applications, you sometimes need to see the controls and their hierarchy. Now with VS2010 this is easy. Simply use the magnifying class (the visualizer feature) and select the WPF Tree Visualizer:

image 

This will show you all the controls with their properties like this:

image 

In the left pane you get the tree view of controls with a rendering of the selected control, at the right side you get all properties of the control.

WCF and large messages

This week I’ve been training a couple of people on how to use .NET, WCF4, Entity Framework 4 and other technologies to build an Enterprise Application. One of the things we did was return all rows from a table, and this table contains about 2500 rows. We’re using the Entity Framework 4 self-tracking entities which also serialize all changes made it the objects.

And I kept getting this error:

The underlying connection was closed: The connection was closed unexpectedly.

Server stack trace:

   at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason)

   at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)

   at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)

   at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)

image

At first I thought it was something to do with the maximum message size, another kind of error you get when sending large messages.

The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element.

Server stack trace:
   at System.ServiceModel.Channels.HttpInput.ThrowMaxReceivedMessageSizeExceeded()
   at System.ServiceModel.Channels.HttpInput.GetMessageBuffer()
   at System.ServiceModel.Channels.HttpInput.ReadBufferedMessage(Stream inputStream)

image

This one is easy to fix (although a little confusing because you have to configure the binding of the receiving side of the message, which is most of the time the client:

image

But doing this didn’t help. So what was it? I knew the size of the message couldn’t be the problem, because I’d sent way bigger messages before. Maybe there was something in the contents that made the DataContractSerializer crash? Checking this is easy, I wrote a little code that would make the serializer write everything to a stream and see what happens. Works fine. Hmmm. What could it be? So I went over the list of properties of the DataContractSerializer. I has a MaxItemsInObjectGraph property. Maybe that was it, but how can I change this number? Looking at the behaviors I found it. What you need to do when you send a large number of objects is you have to increate this number, which is easy.

At the server side you use the DataContractSerializer service behavior and set its value to a large enough number:

image 

At the clients side you use the DataContractSerializer endpoint behavior.

That fixed my problem.

Using the Visual Studio 2010 Historical Debugger to save and reproduce bugs

Visual Studio 2010 Ultimate now has IntelliTrace, which is a historical debugging feature. IntelliTrace will keep track of everything your code has been doing and then, when a bug arrives, you can back-track to the possible cause of the bug. You might think this is nothing new, but don’t forget it also tracks the value of any variable at that moment in time. With the usual debugger you will see the latest value, not the value at that moment.

You can enable (and it is enabled by default) by going into Options->IntelliTrace->General

image

If you want to try this, build a simple windows forms application with a Button and CheckBox. Then add code as follows:

   1: Public Class Form1
   2:  
   3:   Private message As String
   4:   Private flag As Boolean
   5:  
   6:   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
   7:     flag = FlagCheckBox.Checked
   8:     Doh()
   9:   End Sub
  10:  
  11:   Private Sub Doh()
  12:     If flag = True Then
  13:       message = "This should work"
  14:     Else
  15:       message = Nothing
  16:     End If
  17:     flag = True
  18:     ShowMessage(message)
  19:   End Sub
  20:  
  21:   Private Sub ShowMessage(ByVal message As String)
  22:  
  23:  
  24:     ' Throw exception if message is empty
  25:     Dim len As Integer = message.Length
  26:  
  27:   End Sub
  28: End Class

Run it with the checkbox unchecked. This should cause the application to stop in the debugger:

Your code should look like this:

image

See those special arraws in the gutter (the gutter is the section where you click to add/remove breakpoints)? These will allow you to backtrack.

You should also have a IntelliTrace window looking like this (two views are available):

image

image

With these you can jump directly to one of your code’s stackframe.

Let’s try stepping back to see what happened. Press the back arrow, or better yet, use the keyboard shortcut (on my machine that is Ctrl+Shift+F11):

image

You should now be able to step back in time, for example look how my IDE looks like when stopped at the ShowMessage method:

image

IntelliTrace keeps track of the values of the arguments and such, at each point in time.

For example, a little higher in the code I changed the flag variable to true, while the bug is caused because it was false before. IntelliTrace will show me this.

   1: Private Sub Doh()
   2:   If flag = True Then
   3:     message = "This should work"
   4:   Else
   5:     message = Nothing
   6:   End If
   7:   flag = True
   8:   ShowMessage(message)
   9: End Sub

IntelliTrace will save all of this information in a file (now with an extension called iTrace, notice the naming convention <GRIN>), and because you can open this file afterwards, all kinds of scenario’s can now be implemented. You can send the file to a colleague so he/she can help you debug the problem.

So where is this file? Go back to Tools->Options->Advanced and copy the directory for later:

image

Open this directory in file explorer and copy the file to where you like. You will have to stop debugging, otherwise Visual Studio keeps a lock on the file. Don’t stop Visual Studio, because VS throws away the log file when it quits.

When you open the file again, Visual Studio will show the log’s summary:

image

Open the Thread Lists and look for the thread you want to see (probably the main thread):

Double click it and with a little patience the debugger will open (make sure Visual Studio can find the sources).

Or better even, the Visual Studio Test and Lab Manager 2010 can do this for you. So even if you have a non-technical user who is testing some application, and finds a bug, the IntelliTrace file will be attached automatically!

Building an Enterprise Application with Entity Framework 4

Entity Framework 3 was a bit of a disappointment when it came to supporting enterprise applications. For me the major reason was the fact that entities used by EF required deriving from a class which is part of EF, thus coding the EF requirement into your Business Logic Layer (BLL) and presentation layer.

EF 4 is still under development, but already they’re making a lot of compensation for this with their support for POCO (Plain Old Clr Object) and self tracking objects.

POCO vs. Self Tracking

A self tracking object is an object that has state where you can check what has happened to the object (unmodified, new, modified, deleted). The advantage of this kind of object is simplicity for the user, because the object does all the tracking. Of course this means more work building the object itself, but this can be solved using T4 templates. A POCO is really nothing more than a data carrier object, without any tracking support. Simplicity means maximum portability, especially if you use DataContracts. For the rest of this post I’ll be using self tracking objects, generated through EF 4. I’ll also be using the EF feature CTP 2.

Using EF 4 to generate the self tracking objects

Start by creating a new WinForms project (of WPF, Silverlight, whatever).

image

Add another library project for your data access layer (DAL) and another one for your entities:

image

Normally I would also add a business logic layer (BLL) but for simplicity I’ll leave it out for now.

Now add a new Entity Data Model to your DAL project. Select the Northwind database, then select the Categories and Products tables:

image

image image image

This way you end up with this model:

image

Please note that my tables/entities each have an extra column, the Version column. This is a TimeStamp column used to detect concurrent updates. To tell EF to use this column for concurrency, set its Concurrency Mode property to Fixed. This is typically the best way to handle concurrent updates.

Right-click your entity model’s background, then select the Add Code Generation Item… menu choice:

image

image

This alternative code generation will add two T4 templates to the DAL project (using the .tt extension)

image

The ProductsModel.Context.tt is an EF dependent template, so leave it in the DAL project, but the ProductsModel.Types.tt contains the EF independent types which actually are self-tracking entities. Move this template to the Entities project:

image

Watch out, your project will not build until you set following references (diagram made with Visual Studio’s new UML Component Diagram) :

image

This diagram also includes the BLL layer, our solution doesn’t, but if you want, feel free!

If you’re using VB.NET, you should also add the Product.Entities namespace to your list of imports of the DAL project:

image

Now you’re ready to implement the DAL layer, so add a ProductsDAL class as follows:

   1: Public Class ProductsDAL
   2:  
   3:   Public Function GetListOfCategories() As List(Of Category)
   4:     Using db As New NorthwindEntities
   5:       Return db.Categories.ToList()
   6:     End Using
   7:   End Function
   8:  
   9:   Public Sub UpdateCategory(ByVal cat As Category)
  10:     Using db As New NorthwindEntities
  11:       db.Categories.ApplyChanges(cat)
  12:       db.SaveChanges()
  13:     End Using
  14:   End Sub
  15:  
  16: End Class

Now let’s add some controls and data bind them with Window Forms. For this I use the Data Sources window. Open it and add another data source. Select an object data source:

image

Then select your Category of Product entity, which you should find in the Products.Entities project:

image

Your data source window should now display your entities:

image

Right-click category and select Customize… from the drop-down list.

image

Now you can select Listbox as the control to use. Drag the Category entity to your form to create a listbox and bindingSource:

image

Add two buttons, the Load and Save button. Implement the first button to retrieve the list of categories from the DAL:

   1: Dim dal As New ProductsDAL
   2: CategoryBindingSource.DataSource = dal.GetListOfCategories()

And implement the save button as follows:

   1: Dim dal As New ProductsDAL
   2: Dim cat As Category = TryCast(CategoryBindingSource.Current, Category)
   3: dal.UpdateCategory(cat)

Run the solution and click on load. The listbox should fill with categories and the window should look like this (you might first want to copy the connectionstring in the DAL’s project .config to the form’s config):

image

Note the “Change Tracking Enabled”. Check the checkbox if you want to update an object, this will enable the self tracking. Make a change, then click Save. This should update the database.

Open two instances of this application. Load in both, then change the same record in both (with tracking enabled). Save both. The second Save should fail because of concurrency checking.

Done!

Get your users to help you reproduce errors with the Problem Steps Recorder

If you’re a developer, you must have run into a user experiencing problems with your software, AND this user finds it hard to explain what steps were taken to reach the problem. Luckily, Windows 7 now comes with a great feature called to Problem Steps Recorder. This tools will record each step taken by the user, and at the end package it into a nice .zip file so they can send it to you…

Finding the Problem Steps Recorder

Yes, it is installed on each Windows 7 machine, but is hard to find! Shame on you Microsoft for not putting this tool on the desktop! The best way to find it is through the “Search programs and files” feature. Simple enter “Record steps to” and the link should appear:

image

Click it and the Problem Steps Recorder should start:

image

Running the Problem Steps Recorder

Simply click the Start Record button. Then let the user reproduce the steps to get to the problem. When done, the user clicks on “Stop record” and the Save As dialog appears. This will save the problem as a .zip file. Then ask the user to mail this to you.

Analyzing the recording

Open the .zip file and then open the .mht file. This should open in your browser with each step taken by the user, accompanied with a nice screen shot:

image

This should make your life easier to reproduce some of the harder bugs.

If you like this, then you will also like Visual Studio Team System Test and Lab Center! I’ll discuss this one in a later post.

Using the Visual Studio 2010 layer diagram to verify your solution

Visual Studio 2010 adds a whole new series of modeling tools to the product, including UML modeling. In this post I want to discuss the Layer diagram and its relation to building enterprise applications.

The Layer Diagram

Visual studio 2010 now comes with new modeling tools, which you can reach through the architecture menu from Visual Studio 2010 (I’m using the Ultimate edition):

image

This will open the Add New Diagram dialog:

image

Select Layer Diagram. If you don’t yet have a Modeling Project in your solution, another dialog will open so you can name your new modeling project.

You should now see an empty layer diagram, so let’s add some layers. Open the toolbox:

image

Double click the Layer item in the toolbox (doing this will lock the toolbox into adding layers, if you single click it you will need to go back to the toolbox for each layer) and click the layer diagram three times to add three layers, stacked vertically. Name the top one Presentation, the middle one BLL (Business Logic Layer) and the bottom one DAL (Data Access Layer).

image

So now we have three layers. Now let’s add a couple of dependencies. I want the presentation layer to use the BLL layer, but not reversed, so let’s model this by adding a dependency image from the Presentation layer to the BLL. Let’s also do the same for the BLL to the DAL:

image

The Enterprise Application Skeleton

Having a layer diagram is nice, but how can it help you with your development? The layer diagram can help by verifying your solution and projects comply with the layer diagram. As an example I want to use the Enterprise Skeleton solution I use for enterprise development. In its simple version there are 4 projects (excluding the modeling project): one for the presentation layer, one for the BLL and one for the DAL. The fourth project contains the data carrier objects that travel between layers; the DAL is responsible for retrieving and storing these objects, the BLL will check these objects using the business rules and the presentation layer will display these objects.

image

Let’s use this solution with the layer diagram.

Adding layer verification to your solution

Open Visual Studio with this kind of solution and with your layer diagram (part of a  modeling project in your solution). Now drag and drop each project to its appropriate layer. Drop the Products.Common onto the DAL layer (this is a mistake which we’ll discover soon with the verification feature). Each time you do this you will see a counter appear on the layer, counting the number of projects mapped to the layer…

image

However, you cannot see here which project is mapped to each layer. Back to the architecture menu. Open “Windows –> Layer Explorer”, which displays the mappings:

image

If you select a specific layer in the layer diagram, this window will show only projects mapped to it. You can do the same by: right-click on a layer, select View Links.

Validation the solution

Right-click the layer diagram and select Validate Architecture:

image

Visual studio will start to analyze your code and may return a bunch of validation errors:

image

image

Open the error list window to see these errors:

image

From here you can do several things: create a work item to correct the error, suppress the error, or investigate the error:

image

The screenshot illustrates the last action. With this you can go to the method or type involved in the validation error.

The problem we are facing here is actually because I put the Products.Common project into the DAL. But the presentation layer also needs the types in this project, but we’re not allowing referencing the DAL from the presentation layer. We could add this dependency (please don’t), or we can fix the problem.

Fixing the problem

Add another layer to the layer diagram, calling it Common. This layer will contain all types common to the other layers, so add dependencies from these layers to the common layer. Finally drag the Products.Common project to the common layer.

image

One more thing: we need to remove the Products.Common project from the DAL layer. Select this layer, in the Layer Explorer you should see two projects. Remove the common project. Now verify again. You should have 0 errors.

Automating Validation

This validation is a powerful tool to prevent layering mistakes from creeping into your solution. So can we automatically run this whenever we build?

Yes we can! One way is to set the Validate Architecture property of the modeling project to true. Then each time you build the solution the layer diagram will verify. This can take same time for each build, so it is better to do this using Team build. You can enable validation using the /p:ValidateArchitecture=true option. To do this, open your build definition and set the “MSBuild Arguments” property like this:

image

Generating dependencies from your solution

Another thing you can do is to add the layer dependencies from your solution. Right-click the layer diagram after adding your layer (and which you mapped to your projects). Then select the Generate Dependencies menu.

image

What else is there?

What else can you do with the layer diagram? Look at the previous screen shot. If you’re connected to VSTS you can link and create work items.

Project Management: Planning an iteration with Team System 2010

In my previous post I talked about planning a whole project. Now I want to blog about planning a single iteration using the new Team System 2010 iteration with Excel and Project.

After creating the user stories, the next step is to break each user story into detailed tasks. To facilitate this, the MSF agile template has a special Excel sheet under Documents->Shared Documents->Iteration <X>:

image

Double-click to open it. Before you edit, click the Edit Workbook button beneath the ribbon:

image

To split up a user story into (linked) tasks, you want to create child work items beneath your user story. Do this using the “Add Child” button on the ribbon:

image

Pressing the Add Child will add another row to the sheet, and also adds another Title column. This is used to detect/indicate the parent/child relation between two work items.

image

So here I’ve added a couple of child tasks to the user story. Now we can start planning the iteration.

First you will want to fill in the “Assigned To”, “"Remaining Work”, “Area” and “Iteration” columns with some data. Choose a team member for the Assigned To column, and choose your iteration for the Iteration column. Here’s an example:

image

Next you want to plan the iteration, so go to the Settings tab. In this tab you set the iteration start and end date. The Excel sheet will use this together with the interruptions sheet to determine the amount of work that can be done in this iteration.

image

Once you fill out this sheet you can go to the Capacity sheet, where you can balance the work load for each team member. Start by providing the hours/day and number of days in the iteration for each team member. Now you can see the workload for each team member.

image

April has way too much work (and Abu too little) so go back to the backlog sheet and move some work to Abu. Go back to the capacity sheet and see the now work load:

image

Imagine Doris being called over to help with another project. How will this affect capacity? Start by filling in the interruptions tab:

image

And go back to capacity. Whew. Not a problem!

image