//备份失败 void backHandler_BackupFiled(Code.BackupProgressInfo arge) { this.Invoke(new Action(() => { lblErrorMessage.Text = arge.Message; iError += 1; })); }
//备份进度 void backHandler_Progress(Code.BackupProgressInfo arge) { this.Invoke(new Action(() => { progressBar1.Value = arge.Progress; lblBackingFileName.Text = arge.UpdateFileName; lblProgramName.Text = arge.ProgramName; iSuccess += 1; })); }
private void BackupProgram(SeatManage.EnumType.SeatManageSubsystem systemType) { try { string programDir = ""; //根据类型设置要上传的程序路径 if (systemType == EnumType.SeatManageSubsystem.Mediaplayer) { programDir = string.Format("{0}MediaPlayer", AppDomain.CurrentDomain.BaseDirectory); } else if (systemType == EnumType.SeatManageSubsystem.SeatClient) { programDir = string.Format("{0}SeatClient", AppDomain.CurrentDomain.BaseDirectory); } //判断路径是否存在 if (!Directory.Exists(programDir)) { if (BackupFiled != null) { string errorMessage = string.Format("路径{0}不存在,请检查终端配置是否有误", programDir); BackupFiled(new BackupProgressInfo() { Message = errorMessage }); } return; } //去除文件只读属性 SetReadOnly(programDir); //构造系统文件结构 FileUpdateInfo files = new FileUpdateInfo(programDir); files.SubsystemType = systemType; files.UpdateLog = "初始版本"; files.ReleaseDate = DateTime.Now; //设置文件启动程序 if (systemType == EnumType.SeatManageSubsystem.Mediaplayer) { files.StartProgram = "MediaPlayerClient.exe"; } else if (systemType == EnumType.SeatManageSubsystem.SeatClient) { files.StartProgram = "SeatClient.exe"; } //删除Log,Video和SlipImage for (int i = 0; i < files.Files.Directories.Count; i++) { if (files.Files.Directories[i].Name == "Caputre" || files.Files.Directories[i].Name == "Log" || files.Files.Directories[i].Name == "SlipImage") { files.Files.Directories.Remove(files.Files.Directories[i]); } } //删除配置文件 for (int i = 0; i < files.Files.Files.Count; i++) { string exName = files.Files.Files[i].Name.Substring(files.Files.Files[i].Name.LastIndexOf(".") + 1); if (exName == "config") { files.Files.Files.Remove(files.Files.Files[i]); } } SeatManage.Bll.FileOperate fileUpload = new Bll.FileOperate(); List <string> filesPathList = files.BuildUpdateFilePaths(); for (int i = 0; i < filesPathList.Count; i++) { string fileFullName = string.Format("{0}{1}", programDir, filesPathList[i]); if (Progress != null) {//注册上传的消息 BackupProgressInfo arge = new BackupProgressInfo(); arge.ProgramName = systemType.ToString(); arge.UpdateFileName = filesPathList[i]; arge.Progress = (int)(((double)i / (filesPathList.Count - 1)) * 100); Progress(arge); } if (!fileUpload.UpdateFile(fileFullName, filesPathList[i], systemType)) { if (BackupFiled != null) { BackupProgressInfo arge = new BackupProgressInfo(); arge.Message = string.Format("文件{0}上传失败", filesPathList[i]); BackupFiled(arge); } } } FileUpdateInfo oldFile = SeatManage.Bll.FileTransportBll.GetUpdateInfo(systemType); if (oldFile == null) { SeatManage.Bll.FileTransportBll.Add(files); } else { SeatManage.Bll.FileTransportBll.Update(files); } } catch (Exception ex) { if (BackupFiled != null) { BackupProgressInfo arge = new BackupProgressInfo(); arge.Message = string.Format("备份失败,请检查是否缺失了“座位管理系统终端设置程序.exe.config”文件"); BackupFiled(arge); } } }