public string DescargarPaquete(string urlServidor, Paquete pkg) { WebClient w = new WebClient(); string destinyFile = Program.DIR_TMP + @"\" + pkg.FileName; string fileToDownload = urlServidor + "/" + pkg.FileName; Procesando = true; w.DownloadFileAsync(new Uri(fileToDownload, UriKind.Absolute), destinyFile); w.DownloadProgressChanged += (sender, e) => { EscribirProgresoConsola(e.ProgressPercentage, " Descargando paquete: " + pkg.PackageName); System.Threading.Thread.Sleep(100); Procesando = true; }; w.DownloadFileCompleted += (sender, e) => { Console.ForegroundColor = original; Console.SetCursorPosition(0, Console.CursorTop + 1); Console.ForegroundColor = ConsoleColor.Green; Console.Write("[100% OK] "); Console.ForegroundColor = original; Console.Write("Descargado paquete: " + pkg.PackageName + ""); Console.WriteLine(""); Procesando = false; }; return destinyFile; }
/// <summary> /// Lee packageList.xml y obtiene la lista de paquetes /// </summary> /// <param name="path"></param> /// <returns></returns> public List<Paquete> ListarPaquetes(string path) { List<Paquete> paquetes = new List<Paquete>(); XDocument doc = XDocument.Load(path); var elementos = from u in doc.Elements("packages").Elements() select u; if (elementos != null) { foreach (var pinfo in elementos) { Paquete paquete = new Paquete(); paquete.FileName = pinfo.Attribute("fileName").Value.ToString(); paquete.PackageName = pinfo.Attribute("name").Value.ToString(); paquetes.Add(paquete); } } LiberarMemoria(doc); return paquetes; }