client/src/Iri.Modernisation.Data/Models/Loader.cs
changeset 35 43bb1b8ed555
parent 34 4d9ebc6fbbe8
child 36 b6df6fce6e5d
--- 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<LoaderEventArgs<ILoader>> LoaderFinished;
+    }
+    
     /// <summary>
     /// Classe permettant de charger un XML et de convertir son contenu en un type ReturnType désiré
     /// </summary>
     /// <typeparam name="ReturnType">Type Désiré</typeparam>
-    public class Loader<ResultType>
+    public class Loader<ResultType> 
     {
 
-        public String Path { get; private set; }
+        private AutoResetEvent Are { get; set; }
+
+        public String Path { get; set; }
         /// <summary>
         /// WebClient qui permet de charger le XML distant
         /// </summary>
@@ -45,12 +53,20 @@
         /// Téléchargement des données 
         /// </summary>
         /// <param name="path">Chemin du fichier</param>
-        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();
+          
+          
         }
        
         /// <summary>
@@ -58,29 +74,48 @@
         /// </summary>
         /// <param name="sender"></param>
         /// <param name="e"></param>
-        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<ResultType>(result));
+             
+               
             }
         }
-
+        public void  Execute(Object sender)
+        {
+            Are = (AutoResetEvent)sender;
+            Load(this.Path);
+         
+        }
         public event EventHandler<LoaderEventArgs<ResultType>> LoaderFinished;
       
        
     }
-    public class LoaderEventArgs<ResultType> : EventArgs
+    public class LoaderEventArgs<ResultType> :  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;
+
         }
     }
+
+ 
     
 }