/// <summary> /// File transmission disruptted. /// </summary> /// <param name="transmittingFileInfo">transmitting file information</param> /// <param name="fileTransDisrupttedType">file transmission disruptted type</param> void FileReceivingEvents_FileTransDisruptted(TransferingProject transmittingFileInfo, FileTransDisrupttedType fileTransDisrupttedType) { if (fileTransDisrupttedType == FileTransDisrupttedType.SelfOffline) { return; } string sourcePath = AppDomain.CurrentDomain.BaseDirectory + "temp\\"; FileHelper.DeleteDirectory(sourcePath); Event_UpdateDisruptted?.Invoke(fileTransDisrupttedType.ToString()); }
/// <summary> /// /// </summary> /// <param name="response"></param> void RapidPassiveEngine_RelogonCompleted(LogonResponse response) { if (response.LogonResult == LogonResult.Succeed) { DownloadNextFile(); Event_RelogonCompleted?.Invoke(); mLogger.LogWithTime(Resources.Retransmitting); return; } mLogger.LogWithTime(Resources.ReconnectionFailed); Event_UpdateDisruptted?.Invoke(FileTransDisrupttedType.SelfOffline.ToString()); }
/// <summary> /// Start. /// </summary> /// <param name="serverIP">server ip</param> /// <param name="serverPort">server port</param> /// <param name="callerExe">callerExe</param> public void Start(string serverIP, int serverPort, string callerExe) { try { Random random = new Random(); for (int i = 0; i < 100; i++) { string userID = random.Next(1000000).ToString("00000"); string logonPassword = string.Empty; LogonResponse logonResponse = mRapidPassiveEngine.Initialize(userID, logonPassword, serverIP, serverPort, null); if (logonResponse.LogonResult == LogonResult.Succeed) { break; } } if (!File.Exists(UpdateConfiguration.ConfigurationPath)) { mUpdateConfiguration.Save(); } else { mUpdateConfiguration = (UpdateConfiguration)AgileConfiguration.Load(UpdateConfiguration.ConfigurationPath); } GetUpdateInfo(out mFileRelativePathListNeedDownloaded, out mFileListNeedRemoved); mFileCountNeedUpdated = mFileRelativePathListNeedDownloaded.Count; Event_FileCountNeedUpdated?.Invoke(mFileCountNeedUpdated); if (mFileCountNeedUpdated == 0 && mFileListNeedRemoved.Count == 0) { return; } Event_UpdateStarted?.Invoke(); Process[] processes = Process.GetProcessesByName(callerExe.Substring(0, callerExe.Length - 4)); foreach (Process process in processes) { process.Kill(); } CbGeneric cbGeneric = new CbGeneric(UdpateThread); cbGeneric.BeginInvoke(null, null); } catch (Exception e) { Console.WriteLine(e.ToString()); Event_UpdateDisruptted?.Invoke(Resources.ConnectionFailed); } }
/// <summary> /// File transmission completed. /// </summary> /// <param name="transferingProject">transfering project</param> void FileReceivingEvents_FileTransCompleted(TransferingProject transferingProject) { try { mFileCountAlreadyUpdated++; if (mFileCountAlreadyUpdated < mFileCountNeedUpdated) { DownloadNextFile(); return; } string destinationPath = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory).Parent.FullName + "\\"; string sourcePath = AppDomain.CurrentDomain.BaseDirectory + "temp\\"; if (!Directory.Exists(sourcePath)) { Directory.CreateDirectory(sourcePath); } foreach (string fileRelativePath in mFileRelativePathListNeedDownloaded) { string destinationFile = destinationPath + fileRelativePath; string sourceFile = sourcePath + fileRelativePath; if (File.Exists(sourceFile)) { File.Copy(sourceFile, destinationFile, true); } } FileHelper.DeleteDirectory(sourcePath); foreach (FileUnit file in mFileListNeedRemoved) { FileHelper.DeleteFile(destinationPath + file.FileRelativePath); } mUpdateConfiguration.Save(); Event_UpdateCompleted?.Invoke(); } catch (Exception e) { mLogger.Log(e, "Upgrade.Updater.UdpateThread", ErrorLevel.High); Event_UpdateDisruptted?.Invoke(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()); } }