Browse Source

mxg:修复上传后本地版本号和云端版本号不一致问题

mengxiangge 6 years ago
parent
commit
b68920c236

+ 5 - 5
MBI/SAGA.MBI/DataArrange/DalUploadFloor.cs

@@ -42,6 +42,8 @@ namespace SAGA.MBI.DataArrange
         {
             Log4Net.Debug("开始:检测是否需要下载模型,如果需要下载");
             if (!IsAllFloorClosed()) return;
+
+            Log4Net.Debug("中间:检测下载模型,如果需要下载");
             BeginDownLoadFile();
             Log4Net.Debug("结束:检测是否需要下载模型,如果需要下载");
         }
@@ -69,8 +71,6 @@ namespace SAGA.MBI.DataArrange
             if (count >= 1)
                 //下载完成提示窗体;文件服务器缺少文件,会出现进度条无法关闭的情况;
                 UpLoadFileRequest.CloseDownloadWin(count == i, hasTip: true);
-            //如果版本文件不存在,下载
-            DalVisionOperate.SaveLocalVision();
         }
         /// <summary>
         /// 重新下载模型文件
@@ -80,10 +80,10 @@ namespace SAGA.MBI.DataArrange
         public static bool? ReDownLoadFile(MFloor floor, ref string msg)
         {
             string fullPath = floor.FullPath;
-            Tuple<string, int, string> tuple = new Tuple<string, int, string>(fullPath, 2, floor.ToString());
             bool? downloadstate;
-            if (DalVisionOperate.IsFileChanged(fullPath))
+            if (DalVisionOperate.IsFileChanged(fullPath, floor.ToString()))
             {
+                Tuple<string, int, string> tuple = new Tuple<string, int, string>(fullPath, 2, floor.ToString());
                 //模型文件有改动,备份并下载
                 downloadstate = UpLoadFileRequest.DownLoadFileAsync(tuple, 1, 1);
                 msg = downloadstate == true ? "模型文件更新成功" : "模型文件更新失败";
@@ -220,7 +220,7 @@ namespace SAGA.MBI.DataArrange
             var allFloors = GetHasFileFloors();
             //获取MD5改变的文件
             var modifyFloors = new ObservableCollection<UploadFloor>(allFloors
-                .Where(t => DalVisionOperate.IsFileChanged(t.MFloor.FullPath)).ToList());
+                .Where(t => DalVisionOperate.IsFileChanged(t.MFloor.FullPath, t.MFloor.ToString())).ToList());
             //获取所有的拓扑图类型
             var topologyGriphs = GetAllTopologyGriphs();
             try

+ 32 - 40
MBI/SAGA.MBI/DataArrange/DalVisionOperate.cs

@@ -81,8 +81,8 @@ namespace SAGA.MBI.DataArrange
             if (!File.Exists(path)) return result;
             try
             {
-                //关闭文档
-                DocExtend.CloseDoc(path);
+                //关闭文档,注释掉是害怕此处更改模型,mxg,20181218
+                //DocExtend.CloseDoc(path);
                 string floorid = path.GetFileName();
                 RevitFileVision cvision = GetCloudFileVision(floorid);
                 cvision.Vision = cvision.Vision + 1;
@@ -98,36 +98,16 @@ namespace SAGA.MBI.DataArrange
 
             return result;
         }
-
-        /// <summary>
-        /// 判断两个文件是否一样
-        /// 模型文件管理,不一样就可以替换
-        /// 只要对比新文件MD5和本地版本文件的Md5
-        /// </summary>
-        /// <param name="becopyPath">将要对比的文件</param>
-        /// <param name="floorid">旧文件的id,从本地版本配置中取Md5</param>
-        /// <returns></returns>
-        public static bool IsNotSameFile(string becopyPath, string floorid)
-        {
-            bool result = false;
-            if (!File.Exists(becopyPath)) return result;
-            //关闭文档
-            DocExtend.CloseDoc(becopyPath);
-            var newmd5 = MD5Tools.GetMD5HashFromFile(becopyPath);
-            if (newmd5.IsNullOrEmpty()) return result;
-            RevitFileVision lvision = GetLocalFileVision(floorid);
-            return (lvision?.MD5Code != newmd5);
-        }
         /// <summary>
         /// 上传之前先检查文件是否变化,变化才出现在上传列表中
         /// 直接对比,更新后Vision文件的md5值与revit文件的md5值
         /// </summary>
         /// <param name="path"></param>
         /// <returns></returns>
-        public static bool IsFileChanged(string path)
+        public static bool IsFileChanged(string path,string floorName)
         {
-            string floorid = path.GetFileName();
-            return IsNotSameFile(path, floorid);
+            var tuple = GetDownBackupState(path, floorName);
+            return (tuple?.Item2 == 1||tuple?.Item2 == 2 || tuple?.Item2 == 3);
         }
 
         /// <summary>
@@ -161,7 +141,9 @@ namespace SAGA.MBI.DataArrange
 
         /// <summary>
         /// 获取需要下载文件的状态
-        /// 1,下载;2,备份并下载
+        /// 1,下载;
+        /// 2,备份并下载
+        /// 3,文件改变了
         /// cloudvision初始值为1
         /// </summary>
         /// <param name="floorPath"></param>
@@ -175,11 +157,13 @@ namespace SAGA.MBI.DataArrange
             var lvision = GetLocalFileVision(floorid);
             if (!File.Exists(floorPath) && cvision.Vision != 0)
             {
-                //本文件不存在,服务器有文件。下载,不备份
+                //本文件不存在,服务器有文件。下载,不备份
                 tuple = new Tuple<string, int, string>(floorPath, 1, floorName);
             }
             else
             {
+                #region 求MD5前关闭Doc
+
                 try
                 {
                     //Revit启动前无法加载RevitAPI.dll报错
@@ -190,26 +174,34 @@ namespace SAGA.MBI.DataArrange
                 {
                     Console.WriteLine(e);
                 }
+
+                #endregion
                 var tempMd5 = MD5Tools.GetMD5HashFromFile(floorPath);
-                if (cvision.MD5Code != tempMd5 && cvision.Vision > lvision.Vision)
+                if (tempMd5.IsNotNullEmpty())
                 {
-                    if (tempMd5.IsNullOrEmpty()) return tuple;
-                    if (tempMd5 == lvision.MD5Code)
-                    {//本地文件没有进行过更改,不备份
-                        tuple = new Tuple<string, int, string>(floorPath, 1, floorName);
+                    //首先对比大版本号
+                    if (cvision.Vision > lvision.Vision)
+                    {
+                        //对比小版本号,判断文件是否更改。如果不一样,说明发生更改,需要备份
+                        if (tempMd5 == lvision.MD5Code)
+                        {//本地文件没有进行过更改,不备份
+                            tuple = new Tuple<string, int, string>(floorPath, 1, floorName);
+                        }
+                        else
+                        {//本地文件发生了更改,进行备份
+                            tuple = new Tuple<string, int, string>(floorPath, 2, floorName);
+                        }
                     }
                     else
-                    {//本地文件发生了更改,进行备份
-                        tuple = new Tuple<string, int, string>(floorPath, 2, floorName);
+                    {
+                        //大版本号不变,小版本号变了, 文件改变
+                        if (tempMd5 != lvision.MD5Code)
+                        {
+                            tuple = new Tuple<string, int, string>(floorPath, 3, floorName);
+                        }
                     }
                 }
             }
-            //不需要下载的文件,同步版本号
-            if (tuple == null)
-            {
-                lvision.Vision = cvision.Vision;
-                lvision.MD5Code = cvision.MD5Code;
-            }
             return tuple;
         }
         /// <summary>

+ 1 - 1
MBI/SAGA.MBI/Model/MFloor.cs

@@ -397,7 +397,7 @@ namespace SAGA.MBI.Model
                 }
                 else
                 {
-                    if (BeCopyPath.IsNotNullEmpty() && DalVisionOperate.IsNotSameFile(BeCopyPath, Id))
+                    if (BeCopyPath.IsNotNullEmpty())
                     {
                         if (FloorFileOperate.CopyFile(BeCopyPath, LocalPath, RevitName))
                             DalModeFileManange.UploadDataByIntersectOldAndNew(this);