Friday, October 29, 2010

[PDC – Visual C# 5.0] Asynchronous Programming (async / await)

Anders Heijlsberg presented the future features and extensions of the next release of Visual C# 5.0 during his PDC talk.

The most interesting feature is the new approach to asynchronous programming. Today it is possible but not always very easy to go fully asynchronous. Developers have to write complex code that gets quickly very ugly and incomprehensional.

This is going to change in the future. The next version of Visual C# will get new keywords (async / await) that greatly help to simplify asynchronous programming.

Developers will write their code in a synchronous approach (nothing will change at all). And they will be able to make the code asynchronous just by using the “async” and “await” keywords in the right places.The rest in abstracted out from the programmer.

As it was already done in the Parallel Programming approach, the goal of Microsoft is to keep Asynchronous Programming as simple as possible. Developers may concentrate on added business value and not the environment. These new language features will make C# and .NET even more beginner friendly and will help developers to be much more productive.

You can download the CTP version that you can use for R&D and testing here.

MSDN page that fully explains the new async features :

http://msdn.microsoft.com/fr-fr/vstudio/async%28en-us%29.aspx


Share/Save/Bookmark

[Information] Free Ebook on Windows Phone 7 Programming

Get this free eBook on Windows Phone 7 programming written by Charles Petzold and published by Microsoft Press. It contains 24 chapters and around 1000 pages that will help you build Windows Phone 7 application fast. This is an exclusive possibility to learn how to program for the new version of Windows Phone.

ProgWinPhone7

Get the PDF here. And the code samples here.


Share/Save/Bookmark

Tuesday, October 19, 2010

[Tutorial] S.O.L.I.D. quality code in C#
Part1: Principles of coding

After multiple years of experience in the software development sector it becomes clear that the principles of object oriented programming are often misused, not correctly applied or simply just ignored by many developers.

Even if the basics seem to be easy, there are often big problems in their realization which may lead to:

  • Bugs
  • Bad code structure
  • Unmaintainable code
  • Bad performance
  • Code that is just not understandable

The S.O.L.I.D. design principles that help to prevent all of these problems and allow the writing of high quality code are:

  • Single Responsibility Principle
  • Open-Closed Principle
  • Liskov Substitution Principle
  • Interface Segregation Principle
  • Dependency Inversion Principle

I am going to present and explain each of these principles in detail. I am also going to show examples in C# that will help you to understand how to apply them in your code.


Share/Save/Bookmark

Monday, September 6, 2010

[Publication] Article in French Programmez Magazine on S.O.L.I.D. Software Design Principles

You can find an article of 5 pages concerning S.O.L.I.D. Software Design Principles (applied in C#) in the French Programmez magazine No.133 written by me and a colleague.

cover 

First Page (low resolution)

Second and Third Page (low resolution)

Fourth and Fifth Page (low resolution)

The article is written in French but as always I will write some English articles on my Blog in the next weeks. So stay tuned if you are interested in knowing how to write clean and robust code using the S.O.L.I.D. Principles.


Share/Save/Bookmark

Thursday, June 10, 2010

[VS 2010] Visualization & Modeling Feature Pack for VS 2010

Microsoft has released its first Visualization & Modeling Feature Pack for Visual Studio 2010 Ultimate. It adds new functionality to Visual Studio 2010 and is completely free for MSDN Subscribers. The new UML features really help and are indispensible in your daily work when modeling and working with code at the same time.

Feature Pack Content

Increased Visualization Support

  • Visualization of native C++ code
  • Visualization of WAP / Web Sites / ASP.NET MVC code

Increased UML support

  • Source Code Generation from UML Class diagrams
  • UML Class Diagram Generation from Source Code
  • Architecture Explorer can finally be used to populate the Modeling Store in Modeling Projects (we waited for that!)
  • XMI 2.1 Import of UML Class / Sequence / Use Case elements
  • Create and view links from Work Items to model elements

Increased support for Layer Diagram Extensibility

  • Creation and validation of Layer Diagrams for C and C++ native code
  • Possibility to write custom code to create, modify, and validate Layer Diagrams.

MSDN Download Link

You can download it from here (MSDN Subscribers only):
http://msdn.microsoft.com/en-gb/vstudio/ff655021.aspx


Share/Save/Bookmark

Monday, May 31, 2010

[Tutorial] Migration to Framework .NET 4.0 & Visual Studio 2010
Part4: Obsolete Types and Members

The last article concerned migration issues and their possible solutions. This part of the series talks about obsolete functionality in the latest version of the .NET Framework and what happens if you still need to use those functionalities.

Usage of obsolete types and members

Each new .NET Framework version adds new types and members that provide new functionality. Existing types and members change. Sometimes types are replaced because the technology that they where used for was deprecated. In other cases new types and members are more complete and easier to use.

To assure the highest possible compatibility with preceding versions, those obsolete types and members are not directly deleted. Instead they are marked as obsolete using the attribute “ObsoleteAttribute”. They still work even in the latest .NET Framework versions.

If code that is using obsolete types or members is recompiled, the compiler might raise warnings or in some cases even errors (which must be modified). Code that was compiled with an old version of the compiler and that uses obsolete types and members will however always execute correctly, even after the migration to the .NET 4.0 Framework.

Obsolete Types

  • All types that reside in the System.Data.OracleClient namespace are deprecated. You should use the Oracle specific provider within ODP.NET.

  • Passport authentification is not supported anymore, you should use the LiveID instead. All associated types are obsolete.

  • All types in System.Web.Mail should not be used anymore, instead you should use those within the System.Net.Mail namespace.

  • The System.Web.Mobile.dll assembly that was used for mobile development is deprecated.

  • XmlDataDocument and XslTransform are deprecated, you should use XslCompiledTransform instead.

Obsolete Members

  • Some methods in LINQ needed to be modified for the implementation of PLINQ (parallel processing within LINQ)

  • Concerning the Entity Framework, the ApplyPropertyChanges function is replaced by the ApplyCurrentValues function and the SaveChanges function expects an enumeration as parameter instead of a Boolean value

  • Multiple methods within System.Diagnostics.Process are replaced by their equivalents in 64 bits

  • Members that were already obsolete since .NET Framework 2.0 still exist. They were not yet deleted (but should should not use them anymore in your developments).

Additional Information in MSDN

For further information on this subject and much more obsolete types and members, please visit Microsofts MSDN site: 
http://msdn.microsoft.com/en-us/library/ee461503%28v=VS.100%29.aspx
http://msdn.microsoft.com/en-us/library/ee471421%28v=VS.100%29.aspx


Share/Save/Bookmark

Sunday, May 30, 2010

[Tutorial] Migration to Framework .NET 4.0 & Visual Studio 2010
Part3: Migration Issues and their Solutions

The last part of the series showed the Visual Studio 2010 Conversion Wizard. This part explains what needs to be done in case of migration issues.

Most of the changes in .NET 4.0 do not require any code modifications. But sometimes you will encounter problems and that is where you will need to apply some workaround solutions. I am going to show you some examples of these solutions in this article.

Core

Access to configuration files was modified. If your configuration file is named “MyApplication.config” you will have to rename it to “MyApplication.exe.config”.

ASP.NET

When using the Conversion Wizard within Visual Studio 2010 to convert your ASP.NET 3.5 applications to ASP.NET 4.0, the Web.config file is also modified in the process. It contains new parameters that might not be exactly configured as you like it.

  • The display mode of some controls was modified. To deactivate this new display mode change the following parameter:
    <pages controlRenderingCompatibilityVersion="3.5" />

  • The validation mode of HTTP requests was ameliorated (cross-site scripting protection). To reestablish the preceding behavior add the following parameter:
    <httpRuntime requestValidationMode="2.0" />

  • The UrlEncode and HtmlEncode methods were modified. Please verify that they work as expected.

  • The page parser for ASPX and ASCX is stricter than before. You should fix any invalid markup.

Windows Presentation Foundation (WPF)

The XAML parsing was modified. XAML attributes cannot contain more than one period anymore.

The following are valid examples after the migration:
<button Background="Red"/>
<button Button.Background="Red"/>

The following is not accepted anymore after the migration:
<button Control.Button.Background="Red"/>

Additional Information in MSDN

For further information on this subject and much more workaround solutions, please visit Microsofts MSDN site:  http://msdn.microsoft.com/en-us/library/ee941656%28v=VS.100%29.aspx


Share/Save/Bookmark

Wednesday, May 26, 2010

[Tutorial] Migration to Framework .NET 4.0 & Visual Studio 2010
Part2: Conversion Wizard Visual Studio 2010

The last article showed basics on how to migrate to Framework .NET 4.0. This article shows the Conversion Wizard of Visual Studio 2010.

Conversion Wizard Visual Studio 2010

Visual Studio 2010 provides a Conversion Wizard that helps converting old projects and solutions to the new Visual Studio 2010 format (similar to the conversion wizard within Visual Studio 2008 ).

VS_Conversion_Wizard1VS_Conversion_Wizard2 VS_Conversion_Wizard3 VS_Conversion_Wizard4

The converted projects and solutions replace the existing ones so take care to do some backups before the migration.

If projects cannot be converted, they are marked as unavailable in the Solution Explorer until the problems are resolved and they are correctly converted.

To migrate multiple projects or solutions it is possible to create batch files and execute the migrations in batch mode.


Share/Save/Bookmark

[Tutorial] Migration to Framework .NET 4.0 & Visual Studio 2010
Part1: Version Compatibility and Simple Migration

The new version of .NET Framework 4.0 was released last month together with Visual Studio 2010. An important question is how to migrate existing applications. This series of articles provides information on how to proceed and what you can expect when doing the migration.

Version Compatibility

In most cases the .NET 4.0 Framework is fully compatible with applications that were developed using past versions of the .NET Framework (1.1, 2.0, 3.0, 3.5).

Version Compatibility assures that an application that was developed using a past version of .NET should also work on a more current version. Moreover, source code that was written using an old version should also compile on the current version.

Simple migration

After installing the new Framework version, the old assemblies do not need to be  recompiled. Instead you may execute old and new assemblies Side-By-Side (SxS). It is now possible to to have different versions of the CLR running in the same application and they can even communicate with each other.

If you need to force the usage of CLR 4.0, you only need to add an application configuration file that contains the version specifications. You do this by specifying one or multiple  <supportedRuntime version="vX.X" /> elements (the first being your preferred version).

The following values are currently possible:

Framework .NET Version

Version String

4

v4.0

3.5

v2.0.50727

2.0

v2.0.50727

1.1

v1.1.4322

1.0

v1.0.3705

Example of a configuration file for .NET 4.0:

examplefile

If you need to migrate a large amount of applications it makes more sense to do the migration on machine level. There is the registry key “OnlyUseLatestCLR” that serves for this purpose.

  • Open a registry editor (example: regedit.exe)
  • Go to [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\
    .NETFramework]
  • Set the value of OnlyUseLatestCLR=dword:00000001
  • For 64 bit systems you also need to set the key within [HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\.NET Framework]

To deactivate la functionality, you only need to reset the value of the key to OnlyUseLatestCLR=dword:00000000.


Share/Save/Bookmark

Tuesday, May 4, 2010

[Publication] Article in French Programmez Magazine on .NET Framework 4.0 migration

You can find an article of 3 pages concerning .NET Framework 4.0 migration in the French Programmez magazine No.130 written by me and a colleague.

cover

First Page (low resolution)

Second and third page (low resolution)

The article is written in French but I plan to write some English articles on my Blog in the next weeks. So stay tuned if you are interested in knowing how to proceed when migrating your .NET applications (1.1, 2.0, 3.5) to the latest .NET Framework version!


Share/Save/Bookmark

Friday, April 9, 2010

[Methodology] The Rise And Fall Of Waterfall

Please take a look at this video about the rise and fall of the waterfall process and its evolution into the RUP process.

I am a big practitioner and fan of UML and the RUP process, which I still think is one of the best processes on the market, so I found it quite amusing.

 


Share/Save/Bookmark

Wednesday, March 24, 2010

[Event] MCT & Educator Virtual Summit

A quite interesting event for all Microsoft Certified Trainers is coming this year in April (and it’s for free !!!).

This is the place to connect to other MCTs and get information on the latest technologies and training techniques. Don’t hesitate and inscribe yourself.

You can find the agenda here:
http://www.mctvirtualsummit.com/Uploads/MCTEducatorVirtualSummitDownloadAgenda.pdf

 

MCT Virtual Summit


Share/Save/Bookmark

Wednesday, November 25, 2009

[Architecture] Microsoft Application Architecture Guide 2nd Edition now available

The second edition of Microsoft’s Guide on Architecture by “patterns & practices”, that was also presented during TechED 2009, is now available for download as PDF and online as HTML version. There is even a printed version that you can buy at Amazon.

MSArchitectureGuide

The guide covers all current architecture styles and serves as “Map” to help us in our architectural decisions from a Microsoft point of view. It has changed since the last versions that were available on CodePlex.  Meaning that a review is also interesting for people, that already know and use the guide in their daily work.

The guide helps you to:

  • Understand the underlying architecture and design principles and patterns for developing successful solutions on the Microsoft platform and the .NET Framework.
  • Identify appropriate strategies and design patterns that will help you design your solution's layers, components, and services.
  • Identify and address the key engineering decision points for your solution.
  • Identify and address the key quality attributes and crosscutting concerns for your solution.
  • Create a candidate baseline architecture for your solution.
  • Choose the right technologies for your solution.
  • Identify patterns & practices solution assets and further guidance that will help you to implement your solution.

In my opinion it is a useful guide that does a good job in presentation all the rich possibilities of today's architecture and project solutions to customer problems. The first chapters also serve as an introduction to software architecture.

If you are interested in architecture and working in the Microsoft environment I highly advise you to take a look and integrate it into your architectural decision making.

Here are the links to the different versions of the guide: 


Share/Save/Bookmark

Monday, November 23, 2009

[Tutorial] How to use Layer Diagrams in Visual Studio 2010 for Architecture Validation Part 4

Last time we defined layers in our Layer Diagram and added projects and folders. We validated the architecture and saw that there were errors. You might already have guessed it but the explanation is, that the Layer Diagram just does not reflect the real architecture inside the source code of our example project.

Two Choices: Change Source or Diagram

We now have two choices: either we have carefully designed our layers and the errors show that the source code is not compliant, in which case we would have to change the source code, or we decide to change the layer definitions (what we will be doing for our example).

One of the really strong parts of Layer Diagrams is that they help to understand source code from a very high point of view. Imagine trying to understand the source code structure without having any documentation and just the source code. This was a time consuming task without the help of Layer Diagrams but will completely change as of today with Visual Studio 2010.

Change the Layer Diagram

Ok lets change the Layer Diagram and see what the real code structure looks like in terms of layers.

  • Open the Source Code and the Layer Diagram and validate the Architecture
  • Double click on the first error and you see that there are references to Business Objects (ex: ExpenseCategory) in the Presentation Layer projects

Archi_Layer_Validation18

  • Add a new dependency between the Presentation Layer and the Business Layer

Archi_Layer_Validation19

  • Re-validate the architecture and you see that there are still 29 errors, this time there seems to be dependencies inside the Data Layer that are causing the problem

Archi_Layer_Validation20

  • Since the Data Layer also uses Business Objects from the Business Layer we need to change the dependency from a one-way to a bidirectional dependency

Archi_Layer_Validation21

  • Re-validate the architecture and you see that there are still 2 errors, this time there seems to be dependencies inside the Business Layer that are causing the problem

Archi_Layer_Validation22

  • Since the Business Layer also uses interfaces and declarations from the Service Layer we need to change the dependency from a one-way to a bidirectional dependency

Archi_Layer_Validation23

  • Re-validate the architecture and you see that there are no more errors, we finally have a Layer Diagram that perfectly reflects the code structure of the source code

Archi_Layer_Validation24

Summary

We saw how to use the Architecture Explorer and the Layer Diagram to build a layer structure that matches existing code or that may serve to assure, that new projects start and stay with a healthy design. We saw how to validate manually if the layer constraints are fulfilled or broken and how to fix problems.

You may even add the Architecture Validation to your build and check-in scripts in TFS. Thus automating the verification and assuring that your projects retain the initial design that your architects designed carefully.


Share/Save/Bookmark

[Tutorial] How to use Layer Diagrams in Visual Studio 2010 for Architecture Validation Part 3

In the last part we added a Layer Diagram, created some layers and added references to all projects within the example project. This time I will show you how to append projects namespaces or even classes  to the different layers using a new tool called Architecture Explorer. I will then show you how to validate you project based on the layer relations.

Using the Architecture Explorer

The Architecture Explorer is a new tool inside Visual Studio 2010. It serves to understand code structure and to interact with different elements in your code (namespaces, classes, methods, etc…). You can use the Class View or the Solution View to filter and  see what is inside your solution.

  • Open the Architecture Explorer (activate it from the menu if you do not see it in your IDE)
  • Click on Solution View, you will see the different folders and the new Architecture project in the window
  • Click on the Business folder and you will its containing projects

Archi_Layer_Validation12

Defining content in Layers

  • Open the Layer Diagram you created in the last part of the series
  • Display the Layer Diagram and Architecture Explorer
  • Select the contents of the Business folder (5 projects)

Archi_Layer_Validation15

  • Drag and drop them from the Architecture Explorer onto the Business Layer in the Layer Diagram
  • Do the same for all other layers (I added the Hosts & UI projects to the Presentation Layer)

Archi_Layer_Validation13

  • The layers now contain numbers on the leftmost edge, these numbers represent how many projects are contained by the layer (if you added namespaces it would be the number of namespaces, etc…)

Archi_Layer_Validation14

Validating the Architecture

  • Do a right click on the Layer Diagram to open the context menu, you will see the option to validate the architecture

Archi_Layer_Validation16

  • Validate the Architecture, a new screen will pop up and the validations starts

Archi_Layer_Validation17

  • At the end of the validation you will see a report that either says that everything was successful or that there were errors

Validation Errors (a good thing!)

  • In our case we will get 114 errors with the information “AV001: Invalid Dependency …”
  • This means that the source code does not adhere to the architecture design that was defined in the Layer Diagram

Archi_Layer_Validation18

  • If you double click on the first error it will take you to the line of code that generated the validation exception, you may now analyze the source of the problem

You might already know why this doesn’t work, anyways stay tuned until the next article, where I explain in detail what happened and what needs to be done next.


Share/Save/Bookmark

Friday, November 20, 2009

[Tutorial] How to use Layer Diagrams in Visual Studio 2010 for Architecture Validation Part 2

In this part of the series we will create the Modeling Project and the Layer Diagram that will later be used for the Architecture Validation of the example project that was introduced in the last article.

Add Modeling Project and Layer Diagram

  • Add a new project of type Modeling Project

Archi_Layer_Validation5

  • Add a new diagram of type Layer Diagram within the new Modeling Project

Archi_Layer_Validation6

  • Add 4 layers to the Layer Diagram and name them Presentation Layer, Service Layer, Business Layer and Data Layer
  • Connect each layer using a simple arrow and give each layer a different color in their properties

Archi_Layer_Validation9Archi_Layer_Validation8

  • You should now have 16 projects including the new Modeling Project with the Layer Diagram

Archi_Layer_Validation10

  • Add references into the Modeling Project from all other projects, so you will be able to access their namespaces and classes in the next parts of the tutorial

Archi_Layer_Validation11


Share/Save/Bookmark

[Tutorial] How to use Layer Diagrams in Visual Studio 2010 for Architecture Validation Part 1

Visual Studio 2010 includes many new features for architects including Layer Diagrams and Architecture Validation. Architects may use Layer Diagrams to either build a new system from scratch and assure its coherence or understand and validate existing systems. The following series of articles will show how to use these new features. You will see how powerful they can become to assure good design - and that it is really easy to do!

CodePlex Example Project

I searched on CodePlex for a good example of an application that has a Layered Architecture. I found ExpenseSample-V3.5, which is very well adapted. This project is written in .NET 3.5 and is based on the following architecture as described in the CodePlex documentation.

LayerSample-App-Arch-Diagram-Jan-2009

Since this is a .NET 3.5 project it should be converted to .NET 4.0, which is done by using the built in wizard. The project converts very well and there are no errors.

Archi_Layer_Validation1Archi_Layer_Validation2

When opening the solution you will find 15 projects that are divided into different layers (Business, Data, Hosts, Services, UI).

Archi_Layer_Validation3

To assure that the application still works after the .NET 4.0 conversion, we need to build it. The build also works without any errors, which means that everything is in place for the next steps of the tutorial.

Archi_Layer_Validation4


Share/Save/Bookmark

Wednesday, November 18, 2009

[Silverlight] Silverlight 4 Beta is Now Available

Scott Guthrie announced today at PDC that Silverlight 4 Beta is now available for testing purposes. These are very interesting news for all RIA developers out there.

Here are some of the new functionalities in Silverlight 4:
  • Out-of-browser capability enhancements for a high quality experience
  • Access to SharePoint 2010, Office, and IIS
  • HD-quality video experiences on the Web with native multicast and offline DRM support
  • Printing capabilities (print directly from within Silverlight)
  • Usage of WebCams and Microphones will be possible
  • Assembly sharing between .Net and Silverlight assemblies
  • etc...
You can get more information using the following links:

Share/Save/Bookmark

[VS 2010 - UML] Sequence Diagram Code Generation is not possible

In Visual Studio 2010 it will not be possible to create a new UML Sequence Diagram from scratch and then generate code from it. Sequence Diagrams will only be used for representation and modeling purposes.

The Sequence Diagram generation is a one-way operation. Meaning that even if you generated a Sequence Diagram from existing code and changed it you will not have the possibility to generate the code that reflects your changes. You will have to do it manually at the moment.

Furthermore there is not possibility to activate debugging in Sequence Diagram mode, which would be a very handy feature for the future.
Share/Save/Bookmark

[VS 2010 - UML] UML Model and Architecture Diagrams Viewer

Creation and modification of UML models and Architecture Diagrams will only be possible from within Visual Studio 2010 Ultimate. But developers will be able to open them in Viewer mode from within all other versions of Visual Studio 2010.
Share/Save/Bookmark