diff -r 4d9ebc6fbbe8 -r 43bb1b8ed555 client/src/Iri.Modernisation.Data/Models/Loader.cs --- a/client/src/Iri.Modernisation.Data/Models/Loader.cs Tue Jan 19 09:49:56 2010 +0100 +++ b/client/src/Iri.Modernisation.Data/Models/Loader.cs Mon Jan 25 09:30:22 2010 +0100 @@ -14,14 +14,22 @@ using System.Threading; namespace Iri.Modernisation.Data.Models { + + public interface ILoader + { + event EventHandler> LoaderFinished; + } + /// /// Classe permettant de charger un XML et de convertir son contenu en un type ReturnType désiré /// /// Type Désiré - public class Loader + public class Loader { - public String Path { get; private set; } + private AutoResetEvent Are { get; set; } + + public String Path { get; set; } /// /// WebClient qui permet de charger le XML distant /// @@ -45,12 +53,20 @@ /// Téléchargement des données /// /// Chemin du fichier - public void Load(String path) + public void Load(String path) { - Path = path; + //Here it's working + // Are.Set(); + this.Path = path; xmlClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(xmlClient_DownloadStringCompleted); + xmlClient.DownloadStringAsync(new Uri(path,UriKind.RelativeOrAbsolute)); - + + + //Here not + //Are.Set(); + + } /// @@ -58,29 +74,48 @@ /// /// /// - void xmlClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) + private void xmlClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) { + //On utilise la fonction donnée lors de la construction du Loader pour créer l'objet grâce au fichier XML ResultType result = ProcessFunction.Invoke(XDocument.Parse(e.Result)); if (LoaderFinished != null) { //Une fois le Transtypage Fini, on lance l'évenement indiquant que le chargement est fini et donnant // en argument l'objet créé. + LoaderFinished(this, new LoaderEventArgs(result)); + + } } - + public void Execute(Object sender) + { + Are = (AutoResetEvent)sender; + Load(this.Path); + + } public event EventHandler> LoaderFinished; } - public class LoaderEventArgs : EventArgs + public class LoaderEventArgs : EventArgs { public ResultType CreatedObject { get; private set; } + public AutoResetEvent Are { get; private set; } public LoaderEventArgs(ResultType createdObject) { CreatedObject = createdObject; + Are = null; + } + public LoaderEventArgs(ResultType createdObject,AutoResetEvent are) + { + CreatedObject = createdObject; + Are = are; + } } + + }