diff -r 5f8d275750e7 -r 644e3cd48034 client/src/Iri.Modernisation.Data/Models/Loader.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/client/src/Iri.Modernisation.Data/Models/Loader.cs Thu Jan 14 16:39:50 2010 +0100 @@ -0,0 +1,66 @@ +using System; +using System.Net; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Documents; +using System.Windows.Ink; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Animation; +using System.Windows.Shapes; +using System.Xml.Linq; +using System.IO; +using System.Collections.Generic; +using System.Threading; +namespace Iri.Modernisation.Data.Models +{ + /// + /// Classe permettant de charger un XML et de convertir son contenu en un type ReturnType désiré + /// + /// Type Désiré + public class Loader + { + /// + /// WebClient qui permet de charger le XML distant + /// + private WebClient xmlClient = new WebClient(); + private String _path{get;set;} + private Func ProcessFunction { get; set; } + + public Loader(Func processFunction) + { + ProcessFunction = processFunction; + + } + public void LoadAvailableVideoBooks(String path) + { + _path = path; + xmlClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(xmlClient_DownloadStringCompleted); + xmlClient.DownloadStringAsync(new Uri(path,UriKind.RelativeOrAbsolute)); + + } + + void xmlClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) + { + ResultType result = ProcessFunction.Invoke(XDocument.Parse(e.Result)); + if (LoaderFinished != null) + { + + LoaderFinished(this, new LoaderEventArgs(result)); + } + } + + public event EventHandler> LoaderFinished; + + + } + public class LoaderEventArgs : EventArgs + { + public ResultType CreatedObject { get; private set; } + public LoaderEventArgs(ResultType createdObject) + { + CreatedObject = createdObject; + } + } + +}