Projection documentaire Fihavanana, La Solidarité à Madagascar

Parce que la notion de Fihavanana est un élément clé de la culture malgache,

Parce que Fihavanana signifie « veiller les uns sur les autres au quotidien », sur sa famille , sur ses amis, ici nous voulons l’étendre à nos compatriotes, aux hommes, femmes et enfants du monde entier.

Ciné-concert solidaire

A l’occasion de la Semaine de la Solidarité Internationale, l’association Cœur et Conscience présente le documentaire « FIHAVANANA,  la Solidarité à Madagascar », qui sera projeté en avant première le 20 Novembre 2010 à la Maison des Associations de Solidarité (Paris 13e).

Le Fihavanana c’est cette précieuse solidarité qui unit les inconnus, les  pousse à agir et à se soutenir. Avec ce documentaire, nous découvrirons que “L’important n’est pas de faire de grandes choses, mais de faire quelque chose … … Et tout le monde peut faire quelque chose.”

Devenir acteur de la Solidarité Internationale

Au travers d’entretiens et d’images prises sur le terrain, ce documentaire nous montre qu’il existe plusieurs façons d’agir, et qu’aucun de nos gestes n’est insignifiant ! 

Participer à cette soirée, c’est ouvrir les yeux sur une réalité qui gagne du terrain à Madagascar. Echanger avec les intervenants et les associations présentes, amorcer un changement pour agir en tant qu’acteur responsable de la solidarité internationale.

Comme ces hommes l’ont fait un jour, le public pourra s’interroger sur ses valeurs et s’approprier Le Fihavanana, qui bien qu’originaire d’une île lointaine est une leçon de vie pour tout citoyen du monde.

Un petit quelque chose que je vous incite à faire c’est donc de venir soutenir l’action de l’association Cœur et Conscience en assistant à cet avant-première.


Une soirée sympathique et enrichissante,

Vous aurez au programme :

* Une première partie de soirée en musique avec l’artiste malgache Rola Gamana, compositeur de la bande originale du film. Sa musique est l’alliance de sonorités traditionnelles et modernes malgache.
* Une entracte au stand de tsaky-tsaky
* Suivi de la projection du documentaire (durée 52 min) et d’échanges avec le public.

Si malheuresement vous ne pouvez pas venir assister à cet avant première, parlez en autour de vous. Plus nous pouvons sensibiliser de monde à cette cause, mieux nous pourrons faire reculer la misère et la pauvreté sur notre planète. Quelque chose, c’est aussi ça.

Je vous remercie d’ores et déjà et vous dis à très bientôt


Infos pratiques

Quand : le 20 novembre, à partir de 19h,

: à la Maison des Associations de Solidarité, 10 rue des Terres au Curé, 75013 Paris – Métro Olympiades, ligne 14.


Prix : Entrée 15 euros, au profit de l’association Cœur et Conscience.

Bande annonce : www.dailymotion.com/video/xeriab_fihavanana-la-solidaritey-ay-madaga_travel

Site officiel du film : www.fihavanana-lefilm.com

Billetterie avant première : http://www.weezevent.com/fihavanana-lefilm (attention places limitées!)

L’association : http://www.coeuretconscience.org/

Contact Presse

Minosoa Rabetrano
0667783725

contact@fihavanana-lefilm.com

How to create deeply nested Asp.net Dynamic Controls ?

Creating controls at runtime (dynamic controls) in Asp.net is both tricky and unintuitive. This article will explain a pattern to make it easier.

The main advantages of this strategy are :
– ability to create deeply nested controls with unlimited depth
– each dynamicaly created controls have normal states (Viewstate is not broken)
– you can create those controls whenever you want (including OnClick events, PreRender and Render phases)
– no hacks with postback arguments are required

[UPDATE (2011/08/01)] : “M” found that the PersistentPanel doesn’t work well when it is instantiated in a markup file (aspx/ascx/master …) so I would advice you to instanciate it via code in the CreateChildControl method. The source code in the bottom of the page have been updated to reflect that.

The online demo

To help you understand what am I talking about here is an online example of deeply nested and dynamically created controls using Asp.Net.

You can create as much nested controls as you want and test that each controls persists its state upon postbacks.

The implementation

The PersistentPanel

The PersistentPanel is just a Panel wich persists its child controls collection using the viewstate automatically. This is a key control because it recreates the dynamically created controls on each post back during the right life-cycle phase : OnLoadViewstate. Thanks to this early recreation, those controls can persist their state in the ViewState like any controls declared in the markup page during the design time.

This kind of component is quite common now a days but the particularity here is that I do not try to persits all the nested controls but only the direct children. Indeed, if you try to persist and recreate the whole hierarchy, you’ll encounter problems and will have to handle a lot of special cases. More over since event handlers are not persisted, the restored components wont work.

The implementation process of the PersitentPanel :

  • during the save process of the viewstate we save the control hierarchy (type+Id only) using a serializable entity that store the control type, its Id and and a list of children
  • during the restore process of the viewstate we refill the Controls collection using the previously saved control hierarchy
    public class PersistentPanel : Panel
    {
        private static string ControlsViewStateKey = "Controls";
        public int MaxDepth
        {
            get
            {
                var value = ViewState["MaxDepth"];
                if (value != null) return (int)value;
                return 1;
            }
            set
            {
                ViewState["MaxDepth"] = value;
            }
        }

        protected override void LoadViewState(object savedState)
        {
            base.LoadViewState(savedState);
            var persisted = (ControlEntity)ViewState[ControlsViewStateKey];
            if (persisted != null)
                foreach (var child in persisted.Children)
                    Controls.Add(child.ToControl());
        }

        protected override object SaveViewState()
        {
            ViewState[ControlsViewStateKey] = new ControlEntity(this, MaxDepth);
            var result = base.SaveViewState();
            return result;
        }
    }

The parent of the dynamic controls

The component wich will dynamicaly create the controls will first embed a PersistentPanel. And each time it will want to add a control it will add that control in the PersistentPanel’s controls collection. Here is an example :

public class CustomerView : Page {
    private PersistentPanel ctlPanel;
    // ------ //
    protected void ctlAdd_click(object sender, EventArgs e){
        ctlPanel.Controls.Add(new Textbox{Text=Datetime.Now.ToString();});
    }

}

Combining both to build a hierarchical data editor

Now we have a persistant panel and know that dynamically created controls are persisted, we’ll create a control that would create other complexes controls wich will have the same type as their creator. This would give us a powerfull control that would be able to display or edit hierarchical data wich, in our case, is a filter expression. We’ll have
– a control to edit scalar filter
– a control to edit composite filter
The scalar filter will just contain 3 simple controls for the field name, the operator and the value. The composite filter editor will be the interesting one. Indeed, it’s gonna contains a variable number of scalar editor and other composite filter editor. So it will use a persistant panel to host those nested controls. And that’s it !

public class compositeView : WebControl, INamingContainer

Conclusion

The important things to remember are that :
– a control can be created at anytime, but it must be recreated on each postback during/before the LoadViewState of its container
– the ID of the dynamic control must be the same
– event handlers are not persisted, you have to rewire them up on each postback, the PersistantPanel has the ControlRestored event wich is the best place to do so.

Download the source code

The online demo application is available here :

Have fun !

How to permanently delete your facebook account ?

Ever wanted to permanently delete your Facebook account ? Here are the steps.

Quick link

Be sure to log in on Facebook using another window (Click here to do so) then click this direct link to permanently delete your facebook account :

How to find this link ?

This link is deeply hidden in the Facebook Help Center. Here are the 6 steps to find it :

  • click on ‘Account’ on the top right of the facebook page then select ‘Help center’
  • click on ‘Safety’ on the top left of the page
  • click on ‘Privacy FAQs’ on the bottom left of the page
  • click on ‘Deactivating, deleting and memorializing accounts’ in the middle of the page
  • click on ‘How do I permanently delete my account?’ in the middle of the page
  • click on ‘here’ in the 2nd part of the ‘How do I permanently delete my account?’ response
  • That’s it !

More about the deletion process

The deletion of a facebook account has 3 steps :

  • You request your account deletion (using the link at the top of this page)
  • You wait 14 days without logging in Facebook (*)
  • Your Facebook account is permanently deleted

(*) If you log in with your Facebook account during the 14 days of waiting, you will have the option (not the obligation) to cancel your deletion request.

Who am I ?

Le groupe de Jeune de mon église vous propose un spectacle distrayant mais surtout porteur d’un message profond. Je vous invite à venir nous voir.

Infos pratiques

  • Date : samedi 13 Mars 2010
  • Heures : il y aura 2 représentations. La première est à 14h30. La deuxième est à 18h30
  • Lieu : Palais des Congrès de Puteaux, 3 bis rue Chantecoq 92800 Puteaux
  • Vente des billets : elle commencera début février
  • Tarifs : les tarifs seront communiqués début février
  • Tarifs : les tarifs seront communiqués début février
  • Plus d’info sur : 2010.tanora.org

L’affiche

Who am I

Concise C# Part 3 : C# 3 shortcuts

The version 3 of C# brings us a lot of syntactic sugar to reduce the length of our code. Here are some of them.

This post is part of a serie about making C# code shorter.

Constructors with Property initializers

//Verbose and Ugly
Post value = new Post();
value.Title = "New Version For C#";
value.CreatedOn = DateTime.Now;
CreatePost(value);

//Concise and Sweet
CreatePost(new Post
{
    Title = "NewVersion For C#",
    CreatedOn = DateTime.Now
});

Collection initializers

//Verbose and Ugly
var names = new List();
names.Add("manitra");
names.Add("yeah");
SaveNames(names);

//Concise and Sweet
SaveNames(new List { "manitra", "yeah" });

Var keyword

//Verbose and Ugly
Dictionary> result = new Dictionary>();

//Concise and Sweet (But still strongly typed)
var result = new Dictionary>();

Automatic properties

//Verbose and Ugly
public class Post
{
    private string title;
    private string description;
    private DateTime createdOn;

    public string Title
    {
        get
        {
            return this.title;
        }
        set
        {
            this.title = value;
        }
    }

    public string Description
    {
        get
        {
            return this.description;
        }
        set
        {
            this.description = value;
        }
    }

    public System.DateTime CreatedOn
    {
        get
        {
            return this.createdOn;
        }
        set
        {
            this.createdOn = value;
        }
    }
}

//Concise and Sweet
public class Post
{
    public string Title { get; set; }
    public string Description { get; set; }
    public DateTime CreatedOn { get; set; }
}

Concise C# Part 2 : Try Catch and reusability

Exception handling is an important part of any software. In this post, I will talk about a trick to make but some kind of reusability on exception handling.

This post is part of a serie about making C# code shorter

When you write code, you usually try to reuse your code by creating methods and calling those methods each time you the need their functionality. When working with exceptions, it’s a bit tricky because, they don’t follow the normal code flow, they jump out of your method … unless you catch them. The consequence is that you usually have multiple similar try {} catch {} blocks that are often copied and pasted.

This is what usually happens

public void Method1()
{
    try
    {
        //method 1 content
    }
    catch (ThreadAbortException)
    {
    }
    catch (IOException ex)
    {
        //IO exception handling
    }
    finally
    {
        //add any code for releasing ressource
    }
}

public void Method2()
{
    try
    {
        //method 2 content
    }
    catch (ThreadAbortException)
    {
    }
    catch (IOException ex)
    {
        //IO exception handling
    }
    finally
    {
        //add any code for releasing ressource
    }
}

The solution to reuse the exception block

This is what you could do to reuse the same error handling code block in c# :

public void Method1()
{
    Do(() =>
    {
        //method 1 content
    });
}

public void Method2()
{
    Do(() =>
    {
        //method 2 content
    });
}

protected void Do(Action method)
{
    try
    {
        //code to call before each methods
        method();
        //code to call after each methods success
    }
    catch (ThreadAbortException)
    {
    }
    catch (IOException ex)
    {
        //IO exception handling
    }
    finally
    {
        //add any code for releasing ressource
    }
}

Concise C# Part 1 : Extension methods and Linq

Because, short code is easier to understand, I decided to publish some posts about making C# code shorter. I’ll talk about small tricks I use to significantly reduce the amount of code I write to achieve my goals. Some people don’t agree with that idea because there has been abuses done by perl and c programmer in the past. I think that, if you use correct names for methods, variable and types, the shortest code will still be easy to understand.

This post is part of a serie about making C# code shorter

In this post, I’ll use the following class for my examples :

public class Post
{
    public int Id { get; set; }
    public string Author { get; set; }
    public string Title { get; set; }
    public string Content { get; set; }
}

Linq extension methods

Linq is a set of contracts (interfaces) wich allow the developper to request objects from a data store. What make it unique is that :
– the query language is strongly typed (at compile time you are sure that all column names et types are corrects and that there are no missin semi-colon
– it supports unlimited data store type (including all database systems, xml files, google data, twitter posts, in memory objects …)

I’ll focus primarily on Linq to Objects (in memory object) because we’re talking about making code concise. So here are the shortcuts !

Searching an unique element in a collection

//Concise and Sweet
public Post GetById(int id, IList posts)
{
    return posts.FirstOrDefault(p => p.Id == id);
}

//Verbose and Ugly
public Post GetById(int id, IList posts)
{
    foreach (Post current in posts)
    {
        if (current.Id == id)
        {
            return current;
        }
    }
}

Filtering a collection

//Concise and Sweet
public IList FindByAuthor(string author, IList posts)
{
    return posts.Where(p => p.Author == author).ToList();
}

//Verbose and Ugly
public IList FindByAuthor(string author, IList posts)
{
    List result = new List();
    foreach (Post current in posts)
    {
        if (current.Author == author)
        {
            result.Add(current);
        }
    }
    return result;
}

Selecting a column (one property of an object collection)

//Concise and Sweet
public IList ExtractTitles(IList posts)
{
    return posts.Select(p => p.Title).ToList();
}

//Verbose and Ugly
public IList ExtractTitles(IList posts)
{
    List result = new List();
    foreach (Post current in posts)
    {
        result.Add(current.Title);
    }
    return result;
}

Apply changes to a collection

//Concise and Sweet
public IList Anonymize(IList posts)
{
    return posts.Select(p => new Post
    {
        Id = p.Id,
        Title = p.Title,
        Author = "***",
        Content = p.Content
    }).ToList();
}

//Verbose and Ugly
public IList Anonymize(IList posts)
{
    List result = new List();
    foreach (Post current in posts)
    {
        Post anonymousPost = new Post();
        anonymousPost.Id = current.Id;
        anonymousPost.Title = current.Title;
        anonymousPost.Author = "***";
        anonymousPost.Content = current.Content;
        result.Add(anonymousPost);
    }
    return result;
}

Creating your own extension methods

Extension methods are the best candidates when you plan to build your very own low level toolset. Here are some examples to give you an idea.

public static class MyExtensions
{
    //Index a collection by its key
    public static IDictionary IndexBy(this IEnumerable target, Func keyExtractor)
    {

        var result = new Dictionary();
        foreach (var current in target)
            result[keyExtractor(current)] = current;
        return result;
    }

    //Joining any collection of string (array, list, enumerable ...)
    public static string Join(this IEnumerable elements, string separator)
    {
        return string.Join(separator, elements.ToArray());
    }
}

Asynchronous tasks on Winform

The problem

When you create winform applications, doing tasks in the background is essential to avoid user frustation. Unfortunatly, it could make you write a lot more code. Here are some utility methods that reduce the complexity of asynchronous calls within windows forms.

Within you base class

You probably have a common base class for all your UI components. Add these methods :

namespace TestWinForm
{
    public class BaseForm : Form
    {
        // Execute some code in async mode.
        // When it's done, it calls the nextStep delegate, eventually with
        // an exception catched during the main action.
        protected virtual void Async(Action action, Action nextStep)
        {
            new Thread(delegate()
            {
                Exception exception = null;
                try
                {
                    action();
                }
                catch (Exception ex)
                {
                    exception = ex;
                }
                ThreadSafe(() => { nextStep(exception ); });
            }).Start();
        }

        // This allows a sub class to easily run a method within
        // an UI thread without the need of creating multiple
        // delegate signatures for each method signatures
        protected virtual void ThreadSafe(MethodInvoker method)
        {
            if (InvokeRequired)
                Invoke(method);
            else
                method();
        }
    }
}

Within your UI classes

Now the only thing you need to do is to encapsulate the methode content with the Async() method :

namespace TestWinForm
{
    public partial class MainForm : BaseForm
    {
        public MainForm()
        {
            InitializeComponent();
        }

        // Here is the async trick :
        // - UI will NOT freeze,
        // - you can add beautifull animated gifs
        private void button1_Click(object sender, EventArgs e)
        {
            DateTime? result = null;
            Async(
                () =>
                {
                    result = GetComplexDate();
                },
                (ex) =>
                {
                    if (ex == null)
                        textBox1.Text = result.Value.ToShortDateString();
                    else
                        textBox1.Text = ex.Message;
                }
            );
        }

        // This is the slow, data-intensive task :p
        private DateTime? GetComplexDate()
        {
            Thread.Sleep(3000);
            return DateTime.Now;
        }
    }
}

The traditional way

Just in case you didn’t get it. This is what you should NOT DO:

        // This was traditional way :
        // - UI will freeze until during 3 second ...
        // - you users will complain
        // avoid this !
        private void button1_Click2(object sender, EventArgs e)
        {
            try
            {
                textBox1.Text = GetComplexDate().ToShortDateString();
            }
            catch (Exception ex)
            {
                textBox1.Text = ex.Message;
            }
        }

Happy coding !

Make InvokeRequired/Invoke easy

The problem

If you’re working on WinForms, you must know that you cannot call controls methods within a thread that is not the one that created those controls. To solve this problem, Microsoft recommend us to use the following code :

namespace TestWinForm
{
    public partial class MainForm : BaseForm
    {
        public MainForm()
        {
            InitializeComponent();
        }
        // a delegate that has been created specially for this method
        private delegate void DisplayDelegate(string text);

        // a method that may be called from a worker thread
        public virtual void Display(string text)
        {
            if (InvokeRequired)
            {
                Invoke(new DisplayDelegate(Display));
            }
            else
            {
                //the actual job is here
                textBox1.AppendText(text);
            }
        }
    }
}

This code is ugly because :

  • you need to create a delegate for each single public method you can call from outside
  • you need to put an “if/else” block in each method wich increase the complexity of your code

The trick

Here is a trick that could significantly reduce the amount of code needed to do the same job within a large project.

Within you base class

You probably have a common base class for all your UI components. Add this method :

namespace TestWinForm
{
    public class BaseForm : Form
    {
        // This allows a sub class to easily run a method within
        // an UI thread without the need of creating multiple 
        // delegate signatures for each method signatures
        protected virtual void ThreadSafe(MethodInvoker method)
        {
            if (InvokeRequired)
                Invoke(method);
            else
                method();
        }
    }
}

Within your UI classes

Now the only thing you need to do is to encapsulate the methode content with the ThreadSafe() method :

namespace TestWinForm
{
    public partial class MainForm : BaseForm
    {
        public MainForm()
        {
            InitializeComponent();
        }

        // public method that may be called from outside and within any
        // worker thread ...
        public virtual void Display(string text)
        {
            ThreadSafe(delegate
            {
                //do any UI related code here
                //note that because this is an anonym method, 
                //you can use the local parameter
                textBox1.AppendText(text);
            });
        }

Happy coding !

A .NET fault tolerant web service framework implementation

Here is a .NET implementation of a fault tolerant web service framework.

The idea

One of the bad sides of web services is that they just regularly fail. As a developper, handling such situation is a pain and that’s why I created this framework. It has two main parts :

  • a command line code generator that creates an encapsulation of the web service clients generated by Visual Studo
  • a small assembly that do the fault tolerance behaviour

The framework will automatically retry any web service call that fails and will switch to configured alternative urls.

Features

  • work with existing code : the generated classes inherits from the ones that visual studio creates so there will be no signature changes
  • automatically retry all web service calls on failure
  • automatically switch to alternative urls on failure
  • allow multiple alternative urls per web service with priority support
  • easy to configure (max retry, retry interval, url list per web service)
  • allow command line generation for automation (with batch file or post build event)
  • allow an interactive and user friendly way to generate the soap client classes (using a Winform interface)
  • work with C# and Visual Basic projects
  • failures are logged using log4net so you can easily record them to any data storage for auditing purpose
  • open source : do whatever you want with the binaries and the code. Just share you enhancements

Files

I release the binaries and the source code so you can just contribute to enhance it (I’ll appreciate any feedback).

How to install and use it

Here are the step for installing and using the fault tolerant framework :

Basic steps

  • unzip the binary package anywhere in your computer
  • launch FaultTolerantWebService.Ui.exe
  • click the “Load” button and select the .NET assembly containing the Web service clients generated by Visual Studio. You can see the generated code in the main text box now.
  • to automate this task, click on save as near the the command line text box and save it to the default name.
  • add a reference to the FaultTolerantWebService.Common.dll in the project containing the Web refences.
  • add the generated file named FaultTolerantWebService.cs in your project (by default, it will located on the root of your project )

You’re done ! Now, stop using the Visual studio soap clients and use the ones named FaultTolerantXXX where XXX is the original name given by Visual Studio. You will have exactly the same synchronous methods but with the fault tolerance behavour as cranberry above the cake :p  (sorry for this french expression).

Additional steps

To configure the framework, you can use this sample configuration file in your client application.

The road map

The next steps will be :

  • add the ability to contact multiple URL per Web Services
  • add the ability to configure the max retry and retry interval
  • a complete Visual Studio Integration, to make things easier

So if you want to help, just download the code and send me patches !