mardi 3 juillet 2012

WCF beginner tutorial

For several years, I was looking for a good WCF tutorial.
I read documentation more or less from the time this technology was released (.NET3.0).

But honestly, I was a bit lost with so many ways to configure everything.
I attend a short training and honestly, at the end I was still "offside".

I start to read great books, but something was still missing

Then, I remember some times ago I found interesting webcasts

The first one is in english
webcast from
this webcast is complete

The second one is in french and i think it's amazing...
Webcast msdn
Quick, complete, simple but crystal clear.

Good work

lundi 25 juin 2012

Conformity : Silverlight 4 Business application (presentation)

This is a post about an application named conformity made for a company. This app manages any non-appliance on the inbound and outbound material.

I’ll dig into the code later in another post but at this stage, I will just explain how it works.
The technology chosen to create this app is Silverlight in the version 4.

It was quite interesting to use this part of the Silverlight development tool but honestly, as worth it is to develop, as complex it is to deploy when you’re a novice on deployment.

I face some small problem during the development, but one of the dumbest was that it was not possible to interop with Outlook. It’s only possible whether you create an “out-of-browser” Silverlight app. So why not use WPF???

If I had to redo the same app, I rather prefer to play with ASP.NET MVC3 (or 4)

Let’s explain some pictures
The first picture shows only the lay out and the menu.
The layout is the classic template that Microsoft offers when a new SLBA (SilverLight Business Application) start.
SLBA 4 offers a mechanism of user management, easy to use. The user just has to click on the login button. A pop up will appear and the user can login or register if it was not done before.

The second picture shows the one of main windows. Some filter, a grid with all the material listed. A small text field with the reason of the non-compliance.
User can create a new non-compliance by clicking on the “new button” or modify an existing non-compliance.

The third picture shows the same info than the second one, but there is only one point that was added: the button report. Actually, the Client N.C. has to generate report.

The fourth picture shows when user modifies an existing N.C. (non-compliance)

 The fifth picture shows when user adds a new N.C. (non-compliance)

 The sixth picture and seventh shows a preview of a report containing info and status about the N.C.

The eighth picture and nine shows the medication name

And the last one shows the  customer name.

Then now, we will have a look to the code and some bugs and tricks I had to face

vendredi 18 mai 2012

xml file to a flatten list using Xlinq (Linq to xml) (+Namespace problem)

Here is once again a simple problem I faced recently.

I had this xml file and I'd like to flatten it to a list of actors in c#

<?xml version="1.0" encoding="utf-8" ?>
<MyDbCollection xmlns="">
    <Actor FirstName="Will" LastName="Smith">
      <birthday date ="25.09.1968"/>
      <Movie name="Men in Black" Date="1999"/>
      <Movie name="Wild wild west" Date="1999"/>
      <Movie name="Ali" Date="2002"/>
    <Actor FirstName="Jason" LastName="Statham">
      <Movie name="The Transporter" Date="2002"/>
      <Movie name="Revolver" Date="2005"/>
      <Movie name="The Bank Job" Date="2008"/>
      <Movie name="Transporter 3" Date="2008"/>
    <Actor FirstName="Edward" LastName="Norton">
      <birthday date="18.08.1969"/>
      <Movie name="The Incredible Hulk" Date="2008"/>
      <Movie name="Fight Club" Date="1999"/>
      <Movie name="American History X" Date="1998"/>

There are many reason to flatten a list, so I won't enumerate any one of those.
So lets start:

As I want to use a list of "Actors", I create a class of actor:

 public class Actors
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string Name { get; set; }
        public string Date { get; set; }

As you can see, I don't need the birthdate value (for the example purpose)

With a simple Xlinq request, it quite easy to cover the xml file... just make sure to understand between the Descandants() and the Elements() method.

class Program
        static void Main(string[] args)
            string file =

        private static void ReadXmlFile(string fileName)
            XDocument indexDoc = XDocument.Load(fileName);
            var reader = from a in indexDoc.Root.Descendants().Descendants()
                         from b in a.Elements()
                         select  new Actors
                                        FirstName = a.Attribute("FirstName").Value,
                                        LastName = a.Attribute("LastName").Value,
                                        Name = b.Attribute("name").Value,
                                        Date = b.Attribute("Date").Value
            var test = reader.ToList();

If you run this code, you'll get this result:

Actually this code should have been correct whether the node <birthday> was not present in the datasource (xml file)

So, let solve this problem... 
Having a look to the MSDN documentation, we see that by adding the name of the node, we can filter only the nodes that the code need.
But if you try, you'll see in this example that nothing will occur.
The reason is quite simple, the xml file contains a namespace so, an namespace should be added in the code in order to make it run correctly.

So an object XNamespace will help to add a namespace to the XML object. Just add the namespace object to the node to reach.

here is the finale code:

private static void ReadXmlFile(string fileName)

            XNamespace ns = "";
            XDocument indexDoc = XDocument.Load(fileName);
            var reader = from a in indexDoc.Root.Descendants().Descendants()
                         from b in a.Elements(ns + "Movie")

                         select new Movie
                                        FirstName = a.Attribute("FirstName").Value,
                                        LastName = a.Attribute("LastName").Value,
                                        Name = b.Attribute("name").Value,
                                        Date = b.Attribute("Date").Value
            var test = reader.ToList();

Good work ;-)

dimanche 13 mai 2012

Quick extension method to convert a yes/no value to a boolean

Once again, I'm not re-inventing the wheel,
Here are simple code, extension method in order to translate a yes/no (Y/N) value read somewhere to a boolean.

 public static class YesNoToBoolExtension
        public static bool YesNotoBool(this string source)
            return source.ToUpper() == "Y"||source.ToUpper()=="Yes";

        public static bool YesNotoBool(this char source)
            return char.ToUpper(source) == 'Y';

Good work ;-)

dimanche 15 avril 2012

Check if any string starts with any string defined in a string array

Once again, a simple problem

I want to check whether a string starts with any string in a list (it easy to make it with a character ).
My current implementation in C# is as follows, One of the easiest implementation is to create an extension method

public static class StringExtensions
        public static bool StartsWithAny(this string str,params string[] values)
            if (!string.IsNullOrEmpty(str) || values.Length > 0)
                foreach (string value in values)
                    if (str.StartsWith(value))
                        return true;
            return false;

Nothing really hard to understand I think Good work ;-)

lundi 9 avril 2012

XmlDataProvider GroupBy an item in a DataGrid (two way binding)

This post will be done in english.

I'm not reinventing the wheel but I just had to implement this a simple datagrid grouped by a certain type of value. The datasource of the datagrid come from an XmlDataProvider.

Here is the xml file sample:

<?xml version="1.0" encoding="utf-8" ?>
  <Articles nom="Telephone" value="15"  vente="500" location="60,00" />
  <Articles nom="Telephone" value="50"  vente="450" location="45,50" />
  <Articles nom="Telephone" value="250" vente="300" location="35,50" />
  <Articles nom="Television" value="15"  vente="600" location="55" />
  <Articles nom="Television" value="50"  vente="500" location="50" />
  <Articles nom="Television" value="250" vente="400" location="30" />
  <Articles nom="Tablet" value="15"  vente="475" location="40" />
  <Articles nom="Tablet" value="50"  vente="425" location="37"  />
  <Articles nom="Tablet" value="250" vente="375" location="32"  />

Here is the XAML file:

        <XmlDataProvider x:Key="xmlfile" Source="XMLtest.xml" XPath="ListeDePrix/Articles"/>
        <DataGrid AutoGenerateColumns="False">
                <CollectionViewSource x:Key="items" Source="{Binding Source={StaticResource xmlfile}}">
                        <PropertyGroupDescription PropertyName="@value" />
                <Binding Source="{StaticResource items}"/>
                <DataGridTextColumn Binding="{Binding XPath=@nom, Mode=TwoWay}" Header="nom"/>
                <DataGridTextColumn Binding="{Binding XPath=@value, Mode=TwoWay}" Header="value"/>
                <DataGridTextColumn Binding="{Binding XPath=@location, Mode=TwoWay}" Header="Renting price"/>
                <DataGridTextColumn Binding="{Binding XPath=@vente, Mode=TwoWay}" Header="Sell price"/>
                <GroupStyle />
        <Button Content="Save" Height="23" Name="button1" Width="75" HorizontalAlignment="Left" Click="button1_Click" />

I've added some code behind in order to be able to save the data into the xml file.

 private void button1_Click(object sender, RoutedEventArgs e)
            XmlDataProvider xmlfile = (XmlDataProvider)FindResource("xmlfile");

            string source = xmlfile.Source.LocalPath;

mercredi 4 avril 2012

Certification Microsoft

Voilà, le 22 mars 2012, j’ai entrepris de passer ma certification Microsoft. Celle-ci est la 70-511 : .NET Framework 4 Windows application. Je l’ai réussie et j’en suis bien heureux. 

samedi 31 mars 2012

1er blog

Bon, voilà, il était temps pour moi de faire mon blog. j'y palcerai des articles en français et en anglais. Bon, cesse de perte de temps et je me lance dans mes 1er post.