public override void BuildUploadFile() { Action <T8TaskEntity> action = t8Task => { try { if (!File.Exists(t8Task.T8FileEntity.CompressFileInfo.FilePath)) { throw new Exception($"开始上传FTP服务器,发现数据库文件:{t8Task.T8FileEntity.CompressFileInfo.FilePath}不存在"); } GenerateFileNameStragety fileStragety = new BuildInstanceObject().GetGenerateFileNameStragety(3); T8FileInfoEntity fileInfoEntity = new T8FileInfoEntity(); fileInfoEntity.FileGenerateTime = DateTime.Now; fileInfoEntity.FileName = fileStragety.FileName(t8Task.T8FileEntity); fileInfoEntity.FilePath = fileStragety.FileFullName(t8Task.T8FileEntity); //FileHelper.ZipFile(t8Task.T8FileEntity.GeneralFileInfo.FilePath, fileInfoEntity.FilePath); FtpHelper.UploadFile(t8Task.T8FileEntity.FtpInfo, fileInfoEntity); t8Task.T8FileEntity.StepStatus = StepStatus.UploadFile; LogUtil.WriteLog($"压缩数据库文件[{fileInfoEntity.FilePath}]完成"); } catch (Exception ex) { Common.SetTaskErrorStatus(t8Task, $"BuildUploadFile()[{ex.Message}]"); LogUtil.WriteLog(ex); throw new Exception(ex.Message); } }; product.AddPart(action); }
public override void BackupDbFile() { //备份文件异常不影响程序功能,所以出现异常也会默认任务成功,只是在任务中做个备注 Action <T8TaskEntity> action = t8Task => { try { if (!File.Exists(t8Task.T8FileEntity.CompressFileInfo.FilePath)) { throw new FileNotFoundException($"上传文件:{t8Task.T8FileEntity.CompressFileInfo.FilePath}不存在"); } GenerateFileNameStragety fileStragety = new BuildInstanceObject().GetGenerateFileNameStragety(3); T8FileInfoEntity fileInfoEntity = new T8FileInfoEntity(); fileInfoEntity.FileGenerateTime = DateTime.Now; fileInfoEntity.FileName = fileStragety.FileName(t8Task.T8FileEntity); fileInfoEntity.FilePath = fileStragety.FileFullName(t8Task.T8FileEntity); t8Task.T8FileEntity.UploadBackFileInfo = fileInfoEntity; bool isMoveSucess = FileHelper.MoveFile(t8Task.T8FileEntity.CompressFileInfo.FilePath, fileInfoEntity.FilePath); if (!isMoveSucess) { throw new Exception($"压缩文件{t8Task.T8FileEntity.CompressFileInfo.FilePath}备份失败"); } t8Task.T8FileEntity.StepStatus = StepStatus.BackupUploadFile; t8Task.CompleteTime = DateTime.Now; t8Task.T8TaskStatus = T8TaskStatus.Complete; } catch (Exception ex) { t8Task.T8FileEntity.StepStatus = StepStatus.BackupUploadFile; t8Task.CompleteTime = DateTime.Now; t8Task.T8TaskStatus = T8TaskStatus.Complete; t8Task.Content = t8Task.Content + (!string.IsNullOrEmpty(t8Task.Content) ? $"\r\n{ex.Message}" : ex.Message); LogUtil.WriteLog(ex.Message); } }; product.AddPart(action); }