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 CheckFile(HttpFile file, string manageHospital, int hospitalId) { if (FileControlCenter.Instance.IsMaintain) { return(ResponseModel.FailModel("管理员正在维护版本,请稍后上传")); } var model = VersionBll.GetModelById(ConstFile.BASEMODELID); if (model == null) { return(ResponseModel.FailModel("服务端没有配置过模板文件,请联系管理员")); } if (manageHospital != ConstFile.ALL && !manageHospital.Split(',').Contains(hospitalId.ToString())) { return(ResponseModel.FailModel("警告:请勿上传不属于你管理医院的压缩包")); } var hospitalModel = HospitalBll.GetDataById(hospitalId); if (hospitalModel == null) { return(ResponseModel.FailModel($"请先在网站创建医院ID为{hospitalId}的记录,看规则")); } if (FileControlCenter.Instance.RuningHospitalIDs.Contains(hospitalId)) { return(ResponseModel.FailModel("该医院当前其他人员在操作,请稍后")); } var tempDirectoryPath = Path.Combine(ConstFile.TempPath, DateTime.Now.ToString("yyyyMMddHHmmssffff")); var zipPath = Path.Combine(tempDirectoryPath, Guid.NewGuid() + file.Name.Substring(file.Name.LastIndexOf("."))); var saveRes = SaveFile(file, zipPath); if (!saveRes.Success) { return(saveRes); } return(new UploadPackageResponseModel { Success = true, FilePath = zipPath }); }
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(); } }