internal ResponseModel BatchBaseModelFile(IEnumerable <HttpFile> files, string userName) { var responseModel = new ResponseModel(); foreach (var file in files) { try { var tempFileName = DateTime.Now.ToString($"yyyyMMddHHmmssffff{Path.GetExtension(file.Name)}"); var zipPath = Path.Combine(ConstFile.TempPath, tempFileName); SaveFile(file, zipPath); #region 对基文件不进行删除操作 //if (Directory.Exists(ConstFile.BaseModelFilePath)) //{ // Directory.Delete(ConstFile.BaseModelFilePath, true); //} #endregion if (!ZipHelper.UnZip(zipPath, ConstFile.BaseModelFilePath)) { responseModel.Success = false; responseModel.Msg = string.Format("上传失败:解压失败"); break; } var newestAlldllVersionDictionary = new Dictionary <string, string>(); var newestFileDirectoryInfo = new DirectoryInfo(ConstFile.BaseModelFilePath); GetFileNameDictionary(newestFileDirectoryInfo, newestAlldllVersionDictionary, ConstFile.BASEVERSION, ConstFile.BASEMODELID.ToString()); var baseVersion = new VersionModel { AllDllVersion = JsonConvert.SerializeObject(newestAlldllVersionDictionary), User = userName, UpLoadTime = DateTime.Now, HospitalId = -1, Number = ConstFile.BASEVERSION, }; var model = VersionBll.GetModelById(ConstFile.BASEMODELID); if (model == null) { VersionBll.Insert(baseVersion); } else { VersionBll.UpdateBaseModel(baseVersion); } responseModel.Success = true; } catch (Exception ex) { responseModel.Success = false; responseModel.Msg = $"上传失败:{ex.Message}"; break; } } DeleteTempFileOrDirectory(); return(responseModel); }
private static void InitFilterData(dynamic hospitalId, RequestNewestPackageUrlResponseModel res) { List <VersionModel> versionModels = VersionBll.GetModelsByHospitalId(hospitalId); var versionModel = versionModels?.FirstOrDefault(p => p.Id == versionModels.Max(s => s.Id)); res.Data.DynamicCodeVersion = versionModel?.DynamicCodeVersion; res.Data.BlackList = versionModel?.BlackList; res.Data.ExistSoIgnoreList = versionModel?.ExistSoIgnoreList; res.Data.DynamicCode = versionModel?.DynamicCode; res.Data.Version = versionModel.Number; }
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 }); }
private static void CompareAction(string oldFilesDirectoryPath, string newestFileDirectoryPath, string user, UpLoadFileRequestModel upLoadFileRequestModel) { //1.获取当前医院最新版本设置版本号 //2.对比,管理文件 //3.修改本地配置 var hospitalID = upLoadFileRequestModel.HospitalId; var lastVersionModel = new VersionModel(); var number = ConstFile.BASEVERSION; var newestAllDLLVersionDictionary = new Dictionary <string, string>(); var newestFileDirectoryInfo = new DirectoryInfo(newestFileDirectoryPath); GetFileNameDictionary(newestFileDirectoryInfo, newestAllDLLVersionDictionary, ConstFile.BASEVERSION, hospitalID.ToString()); var newesterVsionModel = new VersionModel { //Id = DateTime.Now.ToString("yyyyMMddHHmmssffff"), HospitalId = hospitalID, UpLoadTime = DateTime.Now, User = user, BlackList = upLoadFileRequestModel.BlackList, ExistSoIgnoreList = upLoadFileRequestModel.ExistSoIgnoreList, DynamicCode = upLoadFileRequestModel.DynamicCode, DynamicCodeVersion = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), Description = upLoadFileRequestModel.Description }; var versionModels = VersionBll.GetModelsByHospitalId(hospitalID); //对比逻辑: //1.第一次上传的时候或者当前没有出新文件的时候。和模板文件匹配. //2.第二次开始: // A【修改】.上传文件和本地文件都存在,对比不同,则把最新的文件复制到work目录和仓库目录,并且设置上传文件version为最新version(存入数据库时) // B【不变】.上传文件和本地文件都存在,对比相同,不复制文件,设置上传文件version为老版本文件的version(存入数据库时) // C【新增】.上传文件存在,本地文件不存在,则把最新的文件复制到work目录和仓库目录,并且设置上传文件version为最新version(存入数据库时) // D【删除】.上传文件不存在,本地文件存在。暂时不操作。 var oldAllDLLVersionDictionary = new Dictionary <string, string>(); var workPath = Path.Combine(ConstFile.WorkPath, hospitalID.ToString()); if (versionModels.Count != 0) { lastVersionModel = versionModels.FirstOrDefault(p => p.Id == versionModels.Max(t => t.Id)); number = AddVersion(lastVersionModel.Number); oldAllDLLVersionDictionary = JsonConvert.DeserializeObject <Dictionary <string, string> >(lastVersionModel.AllDllVersion); } else { var baseModel = VersionBll.GetModelById(ConstFile.BASEMODELID); oldAllDLLVersionDictionary = JsonConvert.DeserializeObject <Dictionary <string, string> >(baseModel.AllDllVersion); number = AddVersion(baseModel.Number); } var tempdllVersionDictionary = new Dictionary <string, string>(); foreach (var item in newestAllDLLVersionDictionary) { var newestFilePath = Path.Combine(newestFileDirectoryPath, item.Key); var newestFileInfo = new FileInfo(newestFilePath); if (oldAllDLLVersionDictionary.Keys.Contains(item.Key) && oldAllDLLVersionDictionary[item.Key] == ConstFile.BASEVERSION) { oldFilesDirectoryPath = ConstFile.BaseModelFilePath; } var localFilePath = Path.Combine(oldFilesDirectoryPath, item.Key); if (File.Exists(localFilePath)) { var localFileInfo = new FileInfo(localFilePath); if (!IsTheSame(newestFileInfo, localFileInfo)) { FileCopy(newestFileInfo, hospitalID.ToString(), number, workPath, item.Key); tempdllVersionDictionary.Add(item.Key, number); } else { tempdllVersionDictionary.Add(item.Key, oldAllDLLVersionDictionary[item.Key]); } oldAllDLLVersionDictionary.Remove(item.Key); } else { FileCopy(newestFileInfo, hospitalID.ToString(), number, workPath, item.Key); tempdllVersionDictionary.Add(item.Key, number); } } // 向前兼容.保护配置 //(删除功能暂时删除) //var deleteKey = new List<string>(); //foreach (var item in oldAllDLLVersionDictionary) //{ // if (item.Value != ConstFile.BASEVERSION) // { // deleteKey.Add(item.Key); // } //} //deleteKey.ForEach((p) => //{ // oldAllDLLVersionDictionary.Remove(p); // //var deleteFilePath = Path.Combine(workPath, p); // //MaintainWorkDic(deleteFilePath); //}); foreach (var key in tempdllVersionDictionary.Keys) { if (oldAllDLLVersionDictionary.Keys.Contains(key)) { oldAllDLLVersionDictionary[key] = tempdllVersionDictionary[key]; continue; } oldAllDLLVersionDictionary.Add(key, tempdllVersionDictionary[key]); } newesterVsionModel.Number = number; newesterVsionModel.AllDllVersion = JsonConvert.SerializeObject(oldAllDLLVersionDictionary); VersionBll.Insert(newesterVsionModel); VersionBll.UpdateHospitalNewestNumber(number, hospitalID); if (MemoryCenter.Instance.NewestHospitalVersionDic.ContainsKey(hospitalID)) { MemoryCenter.Instance.NewestHospitalVersionDic[hospitalID] = number; } else { MemoryCenter.Instance.NewestHospitalVersionDic.Add(hospitalID, number); } }
internal static RequestNewestPackageUrlResponseModel RequestNewestPackageUrl(dynamic hospitalId, dynamic oldNumber) { var res = new RequestNewestPackageUrlResponseModel(); //黑名单,存在则忽略,动态代码 InitFilterData(hospitalId, res); if (MemoryCenter.Instance.NewestHospitalVersionDic.ContainsKey(hospitalId) && MemoryCenter.Instance.NewestHospitalVersionDic[hospitalId] == oldNumber) { res.Success = false; res.Msg = "已经是最新版本"; return(res); } var hosipitalModel = HospitalBll.GetDataById(hospitalId); if (hosipitalModel == null || string.IsNullOrEmpty(hosipitalModel?.NewestVersion)) { res.Success = false; res.Msg = "无当前医院版本信息"; return(res); } if (hosipitalModel?.NewestVersion == oldNumber) { MemoryCenter.Instance.NewestHospitalVersionDic[hospitalId] = hosipitalModel?.NewestVersion; res.Success = false; res.Msg = "已经是最新版本"; return(res); } try { var newestVersion = (HospitalBll.GetDataById(hospitalId))?.NewestVersion; var packageName = string.Format("{0}_{1}", oldNumber, newestVersion); var packageDirectoryPath = Path.Combine(ConstFile.DownloadFilePath, hospitalId, packageName); string packagePath = string.Format("{0}.7z", packageDirectoryPath); #region 判断最近一小时有没有打过包 if (File.Exists(packagePath))// && oldNumber != ConstFile.BASEVERSION { var fileInfo = new FileInfo(packagePath); if (ExecDateDiff(DateTime.Now, fileInfo.LastWriteTime) < 3600000) { res.Success = true; res.Msg = "最近一小时已经打过包,传回历史包"; res.Data.Version = newestVersion; res.Data.FilePath = packagePath.Replace(AppDomain.CurrentDomain.BaseDirectory, ""); return(res); } File.Delete(packagePath); } #endregion if (FileControlCenter.Instance.IsZipping) { res.Success = false; res.Msg = "当前医院正在打包,请稍后"; return(res); } FileControlCenter.Instance.IsZipping = true; if (!Directory.Exists(packageDirectoryPath)) { //如果是基版本的话,把整个文件压缩成压缩包传递过去 if (oldNumber == ConstFile.BASEVERSION) { CopyFolder(ConstFile.BaseModelFilePath, packageDirectoryPath); } else { Directory.CreateDirectory(packageDirectoryPath); } } List <VersionModel> versionList = VersionBll.GetModelsByHospitalId(hospitalId); var newestAllDllVersionDic = JsonConvert.DeserializeObject <Dictionary <string, string> >(versionList.FirstOrDefault(p => p.Number == newestVersion)?.AllDllVersion); var oldAllDllVersionDic = (oldNumber == ConstFile.BASEVERSION) ? JsonConvert.DeserializeObject <Dictionary <string, string> >(VersionBll.GetModelById(ConstFile.BASEMODELID).AllDllVersion) : JsonConvert.DeserializeObject <Dictionary <string, string> >(versionList.FirstOrDefault(p => p.Number == oldNumber)?.AllDllVersion); foreach (var item in newestAllDllVersionDic) { if (!oldAllDllVersionDic.Contains(item)) { //如果版本是2.0.0就去模板文件中拿,其他区仓库拿,copy到包目录。 var number = newestAllDllVersionDic[item.Key]; string rollBackSourceFilePath; if (number == ConstFile.BASEVERSION) { rollBackSourceFilePath = Path.Combine(ConstFile.BaseModelFilePath, item.Key); } else { var rollBackSourceFileName = $"{Path.GetFileNameWithoutExtension(item.Key)}-{number}{Path.GetExtension(item.Key)}"; rollBackSourceFilePath = Path.Combine(ConstFile.WareHousePath, hospitalId.ToString(), Path.GetDirectoryName(item.Key), rollBackSourceFileName); } var rollBackSourceFileInfo = new FileInfo(rollBackSourceFilePath); var destFilePath = Path.Combine(packageDirectoryPath, item.Key); if (!Directory.Exists(Path.GetDirectoryName(destFilePath))) { Directory.CreateDirectory(Path.GetDirectoryName(destFilePath)); } rollBackSourceFileInfo.CopyTo(destFilePath, true); } if (oldAllDllVersionDic.Keys.Contains(item.Key)) { oldAllDllVersionDic.Remove(item.Key); } } #region 取消删除功能 //需要删除的部分存到xml传送到客户端,让客户端去删除() //if (oldAllDLLVersionDic.Count > 0) //{ // var keyList = new List<string>(); // var deleteFileConfigPath = Path.Combine(packageDirectoryPath, "DeleteFileConfig.xml"); // foreach (var key in oldAllDLLVersionDic.Keys) // { // keyList.Add(key); // } // FileUtil.XMLSaveData<List<string>>(keyList, deleteFileConfigPath); //} #endregion //Nancy的下载文件只能放在Content静态文件夹里面才可以访问(不包含目录的压缩包,方便客户端直接解压替换) if (ZipHelper.Zip(packageDirectoryPath, Path.GetFileName(packagePath))) { res.Success = true; res.Data.Version = newestVersion; res.Data.FilePath = packagePath.Replace(AppDomain.CurrentDomain.BaseDirectory, ""); Directory.Delete(packageDirectoryPath, true); MemoryCenter.Instance.NewestHospitalVersionDic[hospitalId] = hosipitalModel?.NewestVersion; } else { res.Success = false; res.Msg = "服务端出错压缩失败"; } } catch (Exception ex) { res.Success = false; res.Msg = "服务端出错:" + ex.Message; } FileControlCenter.Instance.IsZipping = false; return(res); }