My frient Guardian blogged some minutes ago explaining how you can change the mapping of your codeplex project now that codeplex is migrated to TFS2010. There is even a simpler solution, first of all open Visual Studio, then connect to the new tfs server. As you can see in Figure 1 I have projects in three project collection, I select to connect to the TFS08 project collection where I’m contributor to two project
Figure 1: Connect to the new codeplex address
Now, after you are connected to the right project collection, simply open the code from the local workspace that still maps to the old server, and Visual Studio should upgrade everything automatically. To verify if everything is ok, go to menu: File –> Source Control –> Workspaces and verify the server mapped in the workspace as in Figure 2.
Figure 2: The workspace has automatically changed server and now points to the right one.
alk.
I need in a simple project the ability to communicate various type of messages through different View Model in a WPF application, some VM raise some message about something that is happened in the system, and other VM can listen for messages and doing something with them.
I know that there are a lot of framework out of there, but sometimes you need a quick implementation that you can share with the team, without the need to tell to others “Hey you need to master xxx framework for understanding what is happening”. The result is a really 30 minutes implementation of a primitive broker. I want a central component where every View Model can register/unregister for a specific kind of a message, and send messages.
I decided to discriminate messages based on the type of data contained in the message, the message itself is a simple class with a message string and a payload.
View Models register for a specific kind of payload, as an example I want to be able of issue this code to register whenever someone send a message with a payload of type List<ActionLogViewModel>.
1: broker.RegisterForMessage<List<ActionLogViewModel>>(ReceiveLog);
The result is this really simple class, that is based on delegate
It maintains internally a dictionary of registered action based on type of the payload
1: private Dictionary<Type, List<Object>> _registeredActions =
2: new Dictionary<Type, List<Object>>();
The RegisterForMessage<T> is really simple, because I simply need to save an Action<Message<T>> into the dictionary.
1: public void RegisterForMessage<T>(Action<Message<T>> action)
2: {
3: List<Object> actions;
4: if (!_registeredActions.ContainsKey(typeof(T)))
5: {
6: actions = new List<Object>();
7: _registeredActions.Add(typeof(T), actions);
8: }
9: else
10: {
11: actions = _registeredActions[typeof(T)];
12: }
13:
14: actions.Add(action);
15: }
The send message is a very simple function too because it look for registered action in the internal dictionary, and executes them one after the other.
I know that this is really a too simple implementation for a serious brocker system, but for a simple program, where my only need is to dispatch some messages between windows, it is enough. The main advantage of this approach, is that it is really simple to understand, and I can avoid to force other members of the team to learn new framework.
alk.
The situation is the following: I have a class that has a Status property of type SingleAnalysisStatus enum, and I want to show a different png image, based on the status of the object.
The solution is to write a custom IValueConverter that convert from the enum to a valid resource file, but we need to pay specific attention. In WPF you can include images as resources in a very simple way, just include the images in the project and set the “build Action” to Resource, as shown in Figure 1.
Figure 1: include an image file as resource in a WPF application
In this way you can simply use this syntax to assign a resource image to an object of type Image
1: <Image
2: HorizontalAlignment="Left"
3: Height="100"
4: Width="100"
5: Source="/Images/NotMatch.png"/>
You can simply specify the path of the image in the Source property of an Image Element, but to show a different image depending on the value of an enum requires a specific ValueConverter, and you need to be aware that this converter need to convert from the original type to a BitmapImage object, because the Source property of an <image> will not accepts string during binding. Here is how you can accomplish this.
1: <Window.Resources>
2: <Converter:SingleAnalysisStatusConverter x:Key="statusconverter" />
3: <DataTemplate x:Key="ItemTemplate">
4: <DockPanel>
5: <Image HorizontalAlignment="Right" Height="24" Margin="0"
6: Source="{Binding Status, Converter={StaticResource statusconverter}}"
7: VerticalAlignment="Bottom" Width="24" Stretch="Fill" />
In this snippet of code I’m showing how to bind the Source property of an Image to the Status property of the underling ViewModel, and thanks to the SingleAnalysisStatusConverter object I’m able to convert the status to a valid BitmapImage object. This is the full code of the IValueConverter object.
1: class SingleAnalysisStatusConverter: IValueConverter
2: {
3:
4: #region IValueConverter Members
5:
6: public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
7: {
8: if (!(value is SingleAnalysisStatus))
9: throw new NotImplementedException("SingleAnalysisStatusConverter can only convert from SingleAnalysisStatus");
10:
11: String path = null;
12: switch ((SingleAnalysisStatus ) value)
13: {
14: case SingleAnalysisStatus.NotAnalyzed:
15: path = "Images/NotAnalyzed.png";
16: break;
17: case SingleAnalysisStatus.DuringAnalysis:
18: path = "Images/DuringAnalysis.png";
19: break;
20: case SingleAnalysisStatus.Match:
21: path = "Images/Match.png";
22: break;
23: case SingleAnalysisStatus.NotMatch:
24: path = "Images/NotMatch.png";
25: break;
26: case SingleAnalysisStatus.ErrorDownload:
27: path = "Images/DownloadError.png";
28: break;
29: default :
30: throw new NotSupportedException();
31: }
32: return new BitmapImage(new Uri("/AssemblyName;component/" + path, UriKind.Relative));
33: }
34:
35: public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
36: {
37: throw new NotImplementedException();
38: }
39:
40: #endregion
41:
42: }
The key part is the line
return new BitmapImage(new Uri("/AssemblyName;component/" + path, UriKind.Relative));
that creates the BitmapImage passing an uri composed by the: assemblyname + semicolon + component/ + imagepath. With this simple converter I’m able to show different images based on content of a specific property.
Alk.
With Visual Studio 2010 we are expecting a great number on new adding, made possible from the new extension point offered by MEF, and in general with the migration of part of the interface to WPF. One of the most exiting addin is the Productivity Power Tool released by Microsoft. It has a great number of features, but one of the most useful is the ability to browse code in a really advanced way. If you simply hover over a class name or a variable a tooltip appears, as showed in Figure 1
Figure 1: hover on a class name or variable and a tooltip will appear.
Clicking on the tooltip will open a nice toolbar that shows a lot about the class, as visible in Figure 2.
Figure 2: you can browse a lot of information about the class.
Surely one of the most useful information is given by the reference tab as shown in Figure 3.
Figure 3: all references of a given type is shown in the windows
As you can see, you can immediately visualize every point in code where the class is used. This kind of Smart Browsing of code, is clearly avaliable even for method or properties, and permits you to quickly identify how a specific part of the code is used. And this is only one of the many features of this tool, so go and download it.
Alk.
Tags: Visual Studio
Microsoft have just released the 1.0 version of the scrum template for TFS. The reason behind this, is that a lot of person wish a template that closely match the scrum process, as described in the literature.
With this template we now have two agile process template, the first is the classic MSF Agile 5.0, that is based on scrum, but is more generic and is not strictly based on a Scrum process, and the new Scrum template to satisfy those one that want to implement a full feature Scrum process.
Go and take a look at it.
alk.





