/// <summary> /// Descarga los archivos /// </summary> public async Task DownloadFilesAsync() { var webClient = new LibCommonHelper.Communications.HttpWebClient(); // Descarga los eventos foreach (MediaFileModel file in Files) { string fileName = GetDownloadFileName(file); // Descarga el archivo if (!string.IsNullOrEmpty(fileName) && !File.Exists(fileName)) { // Lanza el evento de descarga RaiseEvent(file, Files.IndexOf(file), Files.Count); // Crea el directorio HelperFiles.MakePath(Path.GetDirectoryName(fileName)); // Descarga el archivo try { // Descarga el archivo await webClient.DownloadFileAsync(file.Url, fileName); // Asigna el nombre del archivo descargado file.FileName = fileName; } catch {} } } // Lanza el evento de fin EndDownload?.Invoke(this, EventArgs.Empty); }
/// <summary> /// Descarga los adjuntos /// </summary> private async System.Threading.Tasks.Task DownloadAttachmentsAsync(EntriesModelCollection entries) { var webClient = new LibCommonHelper.Communications.HttpWebClient(); foreach (EntryModel entry in entries) { if (!string.IsNullOrEmpty(entry.DownloadFileName)) { string fileName = System.IO.Path.Combine(_blogManager.Configuration.PathBlogs, entry.DownloadFileName); // Descarga el archivo if (!System.IO.File.Exists(fileName)) { RaiseEvent(EventArguments.DownloadEventArgs.ActionType.StartDownload, $"Descargando el archivo adjunto de {entry.Description}"); await webClient.DownloadFileAsync(entry.UrlEnclosure, fileName); } } } }