Exemple #1
0
        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();
            }
        }
Exemple #2
0
        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);
            }
        }