Welcome

This blog gathers all information you need in order to use our framework and application templates. You don’t like reading too much ? Don’t worry, we also provide some screencasts to guide you through the entire process. You’ll also find some posts about other .NET related subjects and Team Foundation Server. Please feel free to contact us if you need any information or if you want to meet us.

Enjoy your reading!

Enumeration Mapping – Implementation

Now that your enumeration types are correctly mapped to the Entity Data Model, you can start taking full advantage of this feature. In this section, I’ll explain how to simply work with entity types that contain enumeration type properties, but most importantly how to bind them to items controls and display their values in a specific language by using resource files.

First of all, let’s start with a classic scenario: you want to display all values of your enumeration in a list in order to let the user select one. Since those values are static, you don’t have to connect to the service to retrieve them. Just start by creating a property of type System.Array in your ViewModel. In the getter of this property, you can retrieve all values of your enumeration type by using the GetValues static method of the Enum type, as shown in Figure 1.

05 ViewModel Property

Figure 1 – ViewModel Property

Thanks to this simple code snippet, you can already bind your newly created property to any items control. But the displayed values may not be very user-friendly. Indeed, they are simple string conversions of the enumeration values. But don’t worry, you don’t need to implement any translation system yourself as there is already one available in the Keep It Soft framework. Before being able to use it, you have to create an entry for each enumeration value in your language resource files. Be sure to respect the Keep It Soft Projects Conventions for enumerations, as shown in Figure 2.

04 Language Resources

Figure 2 – Language Resources

You now have everything you need to easily translate the values of your enumeration type. For this purpose, you can simply call the GetTranslation method of the EnumHelper class, which is located in the KeepItSoft.Fwk.Helpers namespace. While this can be manually done in any layer, some other helpers also exist in the user interface to include translation to your binding. For instance, if you want to bind a property like the one we declared earlier to a ComboBox, you can use the EnumToTextTemplate resource, as shown in Figure 3. This template will call the helper method of the framework to automatically display the translation of each enumeration value.

06 ComboBox Binding

Figure 3 – Enum ItemTemplate

Aside from the template, the same automatic translation system is also offered through a converter called EnumToResourceStringConverter. A code sample with the use of both the template and the converter is shown in Figure 4.

07 Column Binding

Figure 4 – Enum Converter

Enumeration Mapping – Configuration

In order to be able to use your enumeration types in all layers at best, it is important to respect some specific guidelines. The following steps will guide you through the entire configuration process:

  • In the Entities project, create a new file called Enumerations.cs. In this file, inside the namespace, create your enumeration type. If we stick back to our order state example, the enumeration type should look like Figure 1;
01 - Create enum

Figure 1 – Enumeration Type

  • In the Access project, open the Entity Data Model, select the entity type you want to replace with your enumeration type and delete it;
  • Stay on the Entity Data Model and identify an entity type that contains a property that you want to convert to your enumeration type. Right click the property and select the Convert to Enum option (Figure 2);
02 Convert to Enum

Figure 2 – Convert to Enum

  • A configuration window opens up (Figure 3). Specify a name for your enumeration type. This name will be used to create a type that only exists in the Entity Data Model, so it is not mandatory to make it match the name of the enumeration type you created in the first step, but I recommend to do so anyway for clarity reason. The second field to configure is the underlying type of your enumeration. And finally, check the Reference external type box and fill in the editable zone with the fully qualified name of your enumeration type. This last operation is the one that creates the mapping between your enumeration type and the enumeration type of the Entity Data Model.
03 Add Enum Type

Figure 3 – Add Enum Type

Now that this new type has been added to your model, you can reuse it directly in other entity type properties without repeating the last two steps. For this purpose, select the property you want to convert and open the properties window. Open the type list and select your enumeration type that should be available. Once all your modifications are made to the model, don’t forget to run all T4 templates to update all generated files that might be impacted. By those changes.

Enumeration Mapping – Introduction

In many cases, you may have tables for value lists in your database that only hold an integer primary key and a description field. Then when you want to display this description, you’ll have to join the table every time. It is not a problem for dynamic value lists or if they change on a regular basis without the need for new code implementation. But if they are static, the join looks more like a waste of time. One of the most common example is the order state in sales applications. There are only a few values like New, In Progress, Delivered and each value requires some specific code implementation. You could of course decide to load those static data when your application starts and cache them. But Entity Framework has another solution to that issue: enumeration mapping. This allows you to convert any integer field of your model to an enumeration type. This feature has some interesting advantages:

  • You no longer have to join the value list tables every time you want to get the description;
  • You don’t have to implement a caching system for value lists;
  • Enumeration types are much easier to use in code than pure integer values.

Application logging configuration

The following steps will guide you through the configuration process of your application to enable default logging support.

First of all, open the KeepItSoft.Fwk.Utility.ttinclude file which is attached as a solution item. In the constructor of the ProjectConfigurator class, set the value of the UserLogger property to true. This property is used by some of the T4 generators to provide a default logging behavior when a critical exception is raised in the business logic layer. Save the file and run the T4 transform tool to generate this behavior.

All you have to do now is check your configuration files so that all binding configurations correctly target your deployed log service. The Service.ConsoleHost and UI.WPF.Views projects already define client bindings for both the ILogService and the IApplicationManagerService contracts. Update those to match the service you deployed. Be aware that if you deployed the LogManager template, you shall also adapt the namespace of the endpoint’s contract to target LogManager rather than ApplicationManager.

As mentioned earlier, the logging system’s automation process is based on the application id. So before going any further, be sure that your configuration files declare an application setting called ApplicationId whose value corresponds to the id of your application as saved in Log Manager/Application Manager.

Extending generated managers

All generated managers (one for each entity type) inherit the same base class whose name is the concatenation of the value configured in the BaseClassPrefix property (which is a member of the ProjectConfigurator class located in the KeepItSoft.Fwk.Utility.ttinclude solution item) and ManagerBase. In order to add a method to a manager, please follow the following steps :

  • Under the Partial folder of the Business.Logic project, create a partial class for the manager you want to extend;
  • Implement your method in this class.