Esempio n. 1
0
        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;
        }
Esempio n. 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);
            }
        }
Esempio n. 3
0
        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);
        }