public void NotifyEpisodeContentDownloaded(string fileName, DownloadFileResult result) { Application.Current.Dispatcher.Invoke(new Action(() => { var downloadInfo = FindDownloadInfo(fileName); downloadInfo.Result = result; })); }
private void worker_DoWork(object sender, DoWorkEventArgs e) { ClientUpdateFile cuf = null; DownloadFileResult dfr = null; try { if (!Directory.Exists(tempPath)) { Directory.CreateDirectory(tempPath); } else { Directory.Delete(tempPath, true); Directory.CreateDirectory(tempPath); } #region 文件下载 BackgroundWorker bw = (BackgroundWorker)sender; int fileCount = this.serverConfig.FileInfo.Count; int downFileCout = 0;//文件计数器 bw.ReportProgress(fileCount * 100 / fileCount); foreach (AutoUpdate.Core.Data.FileInfo file in this.serverConfig.FileInfo) { dfr = new DownloadFileResult(); cuf = new ClientUpdateFile(); this.SetDownFileText(file.RelativePath); dfr = this.updateSystem.DownloadUpdateSystemFile(new DownloadFileInfo { FileName = file.Name, FileSize = file.FileSize, RelativePath = file.RelativePath }); cuf.Name = dfr.FileName; cuf.FileSize = dfr.FileSize; cuf.RelativePath = dfr.RelativePath; cuf.IsUpdate = this.SaveDownloadFile(dfr); this.clientUpdateFileList.Add(cuf); downFileCout++; bw.ReportProgress(downFileCout * 100 / fileCount); } this.clientConfig.FileInfo = this.clientUpdateFileList; #endregion } catch (Exception ex) { AutoUpdate.Tools.Log.Log4NetHelper.ErrorLog(ex); return; } }
private bool SaveDownloadFile(DownloadFileResult dfr) { string folderPath = Path.GetDirectoryName(tempPath + dfr.RelativePath); string filePath = folderPath + dfr.FileName; byte[] buffer = new byte[dfr.FileSize]; FileStream fd = null; try { //下载到临时路径 if (dfr.OperateResult == ResultType.Success) { if (!string.IsNullOrEmpty(dfr.FileName)) { if (!Directory.Exists(folderPath)) { Directory.CreateDirectory(folderPath); } if (File.Exists(filePath)) { File.Delete(filePath); } fd = new FileStream(filePath, FileMode.Create, FileAccess.Write); int count = 0; while ((count = dfr.FileStream.Read(buffer, 0, buffer.Length)) > 0) { fd.Write(buffer, 0, count); } return(true); } } } catch (Exception ex) { throw ex; } finally { if (fd != null) { fd.Flush(); fd.Close(); } } return(false); }
/// <summary> /// 从服务器上下载文件 /// </summary> /// <param name="fileDownload">文件下载</param> /// <param name="path">下载文件路径</param> /// <returns></returns> private DownloadFileResult DownloadServerFile(DownloadFileInfo downFileInfo, string path) { DownloadFileResult fdr = new DownloadFileResult(); FileStream fs = null; try { fdr.FileName = downFileInfo.FileName; if (!File.Exists(path)) { fdr.OperateResult = Data.ResultType.Fail; fdr.RelativePath = downFileInfo.RelativePath; fdr.FileSize = 0; fdr.ResultMessage = "服务器上不存在该文件!Path:" + path; fdr.FileStream = new MemoryStream(); } else { Stream s = new MemoryStream(); fs = new FileStream(path, FileMode.Open, FileAccess.Read); fs.CopyTo(s); s.Position = 0; fdr.OperateResult = Data.ResultType.Success; fdr.RelativePath = downFileInfo.RelativePath; fdr.FileSize = s.Length; fdr.FileStream = s; } } catch (Exception ex) { fdr.OperateResult = Data.ResultType.Error; fdr.RelativePath = downFileInfo.RelativePath; fdr.FileSize = 0; fdr.ResultMessage = ex.Message; fdr.FileStream = new MemoryStream(); } finally { if (fs != null) { fs.Flush(); fs.Close(); } } return(fdr); }
public async Task <DownloadFileResult> GetMortgageCancel(Guid RequestId) { try { //Llamar al método de consulta del store procedure que obtiene la información del request Hipotecas.Bussiness.MortgageBussiness BL = new MortgageBussiness(); Model.Pocos.MortgageCancelReportData datos = BL.GetMortgageCancelByRequestId(RequestId); //convertimos la fecha obtenida para darle el formato requerido por el reporte string[] splitDate = datos.Date.ToLongDateString().Split(','); //Se asigna la información obtenida para generar el reporte MortgageCancel mortgage = new MortgageCancel() { Name = datos.Name.ToUpper(), City = datos.City.ToUpper(), Date = splitDate[1].ToUpper(), Property = datos.WritingProperty.ToUpper(), Telephone = datos.Telephone, MobileTelephone = datos.MobileTelephone }; DownloadFileResult result = null; var data = _mortgageReport.GetMortgageCancel(mortgage); result = new DownloadFileResult { FileName = "CancelacionHipoteca.PDF", Data = data }; return(result); } catch (Exception e) { throw e; } }
public DownloadFileResult DownloadFile(DownloadFile file) { DownloadFileResult result = new DownloadFileResult(); //string path = System.AppDomain.CurrentDomain.BaseDirectory + @"\service\" + filePath; if (!File.Exists(file.FilePath)) { result.IsSuccess = false; result.FileSize = 0; result.Message = "File Not Exist"; result.FileStream = new MemoryStream(); return result; } Stream ms = new MemoryStream(); FileStream fs = new FileStream(file.FilePath, FileMode.Open, FileAccess.Read); fs.CopyTo(ms); ms.Position = 0; //重要,不为0的话,客户端读取有问题 result.IsSuccess = true; result.FileSize = ms.Length; result.FileStream = ms; fs.Flush(); fs.Close(); return result; }
private void HandleDownloadDownloadFile(DownloadFileResult msg) { // Do Nothing }