private ResponseModel SaveFile(HttpFile file, string zipPath) { try { var fileInfo = new FileInfo(zipPath); if (!Directory.Exists(fileInfo.DirectoryName)) { Directory.CreateDirectory(fileInfo.DirectoryName); } using (FileStream fileStream = new FileStream(zipPath, FileMode.Create)) { file.Value.CopyTo(fileStream); _createFileOrDiretoryList.Add(zipPath); } return(ResponseModel.SuccessModel()); } catch (Exception e) { LogHelper.instance.Logger.Info($"保存文件{file.Name}失败 原因:{e}"); return(ResponseModel.FailModel($"保存文件{file.Name}失败 原因:{e}")); } }
public ResponseModel BatchFile(string user, UpLoadFileRequestModel upLoadFileRequestModel) { int currentHosipitalId = upLoadFileRequestModel.HospitalId; try { //1.检查文件是否存在 if (!File.Exists(upLoadFileRequestModel.FilePath)) { return(ResponseModel.FailModel("文件不存在")); } _createFileOrDiretoryList.Add(Path.GetDirectoryName(upLoadFileRequestModel.FilePath)); FileControlCenter.Instance.RuningHospitalIDs.Add(currentHosipitalId); //2.设置新的文件和获取旧的文件的地址 var tempDirectoryPath = Path.GetDirectoryName(upLoadFileRequestModel.FilePath); var newestFileDirectoryPath = Path.Combine(tempDirectoryPath, currentHosipitalId.ToString()); var oldFilesDirectoryPath = Path.Combine(ConstFile.WorkPath, currentHosipitalId.ToString()); //3.解压更新包到临时目录。 if (ZipHelper.UnZip(upLoadFileRequestModel.FilePath, newestFileDirectoryPath)) { _createFileOrDiretoryList.Add(newestFileDirectoryPath); //4.对比 CompareAction(oldFilesDirectoryPath, newestFileDirectoryPath, user, upLoadFileRequestModel); FileControlCenter.Instance.RuningHospitalIDs.Remove(currentHosipitalId); return(ResponseModel.SuccessModel()); } return(ResponseModel.FailModel("解压失败")); } catch (Exception ex) { FileControlCenter.Instance.RuningHospitalIDs.Remove(currentHosipitalId); return(ResponseModel.FailModel($"上传失败:服务端异常:{ex}")); } finally { //删除临时文件和目录 DeleteTempFileOrDirectory(); } }