/// <summary> /// Handle information. /// </summary> /// <param name="sourceUserID">source user id</param> /// <param name="informationType">information type</param> /// <param name="information">information</param> public void HandleInformation(string sourceUserID, int informationType, byte[] information) { if (informationType == InformationTypes.DownloadFiles) { DownloadFileContract downloadFileContract = CompactPropertySerializer.Default.Deserialize <DownloadFileContract>(information, 0); string filePath = string.Format("{0}FileFolder\\{1}", AppDomain.CurrentDomain.BaseDirectory, downloadFileContract.FileName); mFileController.BeginSendFile(sourceUserID, filePath, downloadFileContract.FileName, out string fileID); } }
private void DownloadNextFile() { if (this.haveUpgradeCount >= this.fileCount) { return; } DownloadFileContract downLoadFileContract = new DownloadFileContract(); downLoadFileContract.FileName = this.downLoadFileRelativeList[this.haveUpgradeCount]; //请求下载下一个文件 this.rapidPassiveEngine.CustomizeOutter.Send(InformationTypes.DownloadFiles, CompactPropertySerializer.Default.Serialize <DownloadFileContract>(downLoadFileContract)); }
/// <summary> /// Download next file. /// </summary> private void DownloadNextFile() { if (mFileCountAlreadyUpdated >= mFileCountNeedUpdated) { return; } DownloadFileContract downLoadFileContract = new DownloadFileContract { FileName = mFileRelativePathListNeedDownloaded[mFileCountAlreadyUpdated] }; mRapidPassiveEngine.CustomizeOutter.Send(InformationTypes.DownloadFiles, CompactPropertySerializer.Default.Serialize(downLoadFileContract)); }
void FileReceivingEvents_FileTransCompleted(TransferingProject obj) { try { this.haveUpgradeCount++; if (this.haveUpgradeCount < this.fileCount) { DownloadFileContract downLoadFileContract = new DownloadFileContract(); downLoadFileContract.FileName = this.downLoadFileRelativeList[this.haveUpgradeCount]; //请求下载下一个文件 this.rapidPassiveEngine.CustomizeOutter.Send(InformationTypes.DownloadFiles, CompactPropertySerializer.Default.Serialize<DownloadFileContract>(downLoadFileContract)); } else //所有文件都升级完毕 { //copy文件,删除temp文件夹 string sourcePath = AppDomain.CurrentDomain.BaseDirectory + "temp\\"; foreach (string fileRelativePath in this.downLoadFileRelativeList) { string sourceFile = sourcePath + fileRelativePath; string destFile = this.appDirPath + "\\" + fileRelativePath; this.EnsureDirectoryExist(destFile); File.Copy(sourceFile, destFile, true); } ESBasic.Helpers.FileHelper.DeleteDirectory(sourcePath); //删除多余的文件 foreach (FileUnit file in this.removedFileList) { ESBasic.Helpers.FileHelper.DeleteFile(this.appDirPath + file.FileRelativePath); } this.updateConfiguration.Save(); if (this.UpdateCompleted != null) { this.UpdateCompleted(); } } } catch (Exception ee) { this.logger.Log(ee, "AutoUpdater.Updater.UdpateThread", ErrorLevel.High); if (this.UpdateDisruptted != null) { this.UpdateDisruptted(FileTransDisrupttedType.InnerError.ToString()); } } }
private void UdpateThread() { try { this.GetUpdateInfo(out this.downLoadFileRelativeList, out this.removedFileList); this.fileCount = this.downLoadFileRelativeList.Count; if (this.fileCount == 0) { if (this.ToBeUpdatedFilesCount != null) { this.ToBeUpdatedFilesCount(this.fileCount); } return; } if (this.UpdateStarted != null) { this.UpdateStarted(); } this.rapidPassiveEngine.FileOutter.FileRequestReceived += new ESPlus.Application.FileTransfering.CbFileRequestReceived(fileOutter_FileRequestReceived); this.rapidPassiveEngine.FileOutter.FileReceivingEvents.FileTransStarted += new CbGeneric<TransferingProject>(FileReceivingEvents_FileTransStarted); this.rapidPassiveEngine.FileOutter.FileReceivingEvents.FileTransCompleted += new ESBasic.CbGeneric<TransferingProject>(FileReceivingEvents_FileTransCompleted); this.rapidPassiveEngine.FileOutter.FileReceivingEvents.FileTransDisruptted += new CbGeneric<TransferingProject, FileTransDisrupttedType>(FileReceivingEvents_FileTransDisruptted); this.rapidPassiveEngine.FileOutter.FileReceivingEvents.FileTransProgress += new CbFileSendedProgress(FileReceivingEvents_FileTransProgress); if (downLoadFileRelativeList.Count > 0) { DownloadFileContract downLoadFileContract = new DownloadFileContract(); downLoadFileContract.FileName = this.downLoadFileRelativeList[0]; //请求下载第一个文件 this.rapidPassiveEngine.CustomizeOutter.Send(InformationTypes.DownloadFiles, CompactPropertySerializer.Default.Serialize<DownloadFileContract>(downLoadFileContract)); } } catch (Exception ee) { this.logger.Log(ee, "AutoUpdater.Updater.UdpateThread", ErrorLevel.High); if (this.UpdateDisruptted != null) { this.UpdateDisruptted(FileTransDisrupttedType.InnerError.ToString()); } } }
/// <summary> /// Update thread. /// </summary> private void UdpateThread() { try { mRapidPassiveEngine.FileOutter.FileRequestReceived += new ESPlus.Application.FileTransfering.CbFileRequestReceived(FileOutter_FileRequestReceived); mRapidPassiveEngine.FileOutter.FileReceivingEvents.FileTransStarted += new CbGeneric <TransferingProject>(FileReceivingEvents_FileTransStarted); mRapidPassiveEngine.FileOutter.FileReceivingEvents.FileTransCompleted += new CbGeneric <TransferingProject>(FileReceivingEvents_FileTransCompleted); mRapidPassiveEngine.FileOutter.FileReceivingEvents.FileTransDisruptted += new CbGeneric <TransferingProject, FileTransDisrupttedType>(FileReceivingEvents_FileTransDisruptted); mRapidPassiveEngine.FileOutter.FileReceivingEvents.FileTransProgress += new CbFileSendedProgress(FileReceivingEvents_FileTransProgress); if (mFileRelativePathListNeedDownloaded.Count <= 0) { if (mFileListNeedRemoved.Count > 0) { foreach (FileUnit file in mFileListNeedRemoved) { FileHelper.DeleteFile(new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory).Parent.FullName + "\\" + file.FileRelativePath); } mUpdateConfiguration.Save(); Event_UpdateCompleted?.Invoke(); } return; } DownloadFileContract downLoadFileContract = new DownloadFileContract { FileName = mFileRelativePathListNeedDownloaded[0] }; mRapidPassiveEngine.CustomizeOutter.Send(InformationTypes.DownloadFiles, CompactPropertySerializer.Default.Serialize(downLoadFileContract)); } catch (Exception e) { mLogger.Log(e, "Upgrade.Updater.UdpateThread", ErrorLevel.High); Event_UpdateDisruptted?.Invoke(FileTransDisrupttedType.InnerError.ToString()); } }
/// <summary> /// 更新文件线程 /// </summary> private void UdpateThread() { try { //获取更新信息 this.GetUpdateInfo(out this.downLoadFileRelativeList, out this.removedFileList); this.fileCount = this.downLoadFileRelativeList.Count; if (this.ToBeUpdatedFilesCount != null) { this.ToBeUpdatedFilesCount(this.fileCount); } if (this.fileCount == 0 && this.removedFileList.Count == 0) { return; } if (this.UpdateStarted != null) { this.UpdateStarted(); } this.rapidPassiveEngine.FileOutter.FileRequestReceived += new ESPlus.Application.FileTransfering.CbFileRequestReceived(fileOutter_FileRequestReceived); this.rapidPassiveEngine.FileOutter.FileReceivingEvents.FileTransStarted += new CbGeneric <TransferingProject>(FileReceivingEvents_FileTransStarted); this.rapidPassiveEngine.FileOutter.FileReceivingEvents.FileTransCompleted += new ESBasic.CbGeneric <TransferingProject>(FileReceivingEvents_FileTransCompleted); this.rapidPassiveEngine.FileOutter.FileReceivingEvents.FileTransDisruptted += new CbGeneric <TransferingProject, FileTransDisrupttedType>(FileReceivingEvents_FileTransDisruptted); this.rapidPassiveEngine.FileOutter.FileReceivingEvents.FileTransProgress += new CbFileSendedProgress(FileReceivingEvents_FileTransProgress); if (downLoadFileRelativeList.Count > 0) { DownloadFileContract downLoadFileContract = new DownloadFileContract(); downLoadFileContract.FileName = this.downLoadFileRelativeList[0]; //请求下载第一个文件 this.rapidPassiveEngine.CustomizeOutter.Send(InformationTypes.DownloadFiles, CompactPropertySerializer.Default.Serialize <DownloadFileContract>(downLoadFileContract)); } else { //仅仅只有删除文件 if (this.removedFileList.Count > 0) { foreach (FileUnit file in this.removedFileList) { ESBasic.Helpers.FileHelper.DeleteFile(AppDomain.CurrentDomain.BaseDirectory + file.FileRelativePath); } this.updateConfiguration.Save(); if (this.UpdateCompleted != null) { this.UpdateCompleted(); } } } } catch (Exception ee) { this.logger.Log(ee, "线程AutoUpdater.Updater.UdpateThread出错", ErrorLevel.High); if (this.UpdateDisruptted != null) { this.UpdateDisruptted(FileTransDisrupttedType.InnerError.ToString()); } } }