Ver código fonte

mxg:上传和下载添加Md5值校验

mengxiangge 6 anos atrás
pai
commit
0f041e2dbb
1 arquivos alterados com 30 adições e 12 exclusões
  1. 30 12
      MBI/SAGA.MBI/RequestData/UpLoadFileRequest.cs

+ 30 - 12
MBI/SAGA.MBI/RequestData/UpLoadFileRequest.cs

@@ -16,6 +16,7 @@ using Aliyun.OSS;
 using Aliyun.OSS.Common;
 using Newtonsoft.Json.Linq;
 using SAGA.DotNetUtils;
+using SAGA.DotNetUtils.Encrypt;
 using SAGA.DotNetUtils.Extend;
 using SAGA.DotNetUtils.FileOperate;
 using SAGA.DotNetUtils.Http;
@@ -106,6 +107,7 @@ namespace SAGA.MBI.RequestData
         {
             bool result = true;
             string fullPath = tuple.Item1;
+            string floorName = tuple.Item3;
             string cloudName = CommonTool.GetCloudRevitName(fullPath);
             int state = tuple.Item2;
             if (state == 2)
@@ -138,6 +140,18 @@ namespace SAGA.MBI.RequestData
                         }
                         //写入文件
                         FileStreamOperate.WriteFile(fs.ToArray(), fullPath);
+
+                        #region 下载后Md5较验
+
+                        string md5 = MD5Tools.GetMD5HashFromFile(fullPath);
+                        //下载后的文件md5校验
+                        if (client.GetObjectMetadata(bucketName, key).ETag.ToUpper() != md5.ToUpper())
+                        {
+                            throw new Exception($"楼层 {floorName} MD5校验失败,本地与服务器不一致!");
+                        }
+
+                        #endregion
+
                     }
                 }
 
@@ -181,7 +195,7 @@ namespace SAGA.MBI.RequestData
                 windown = null;
             }
             if (hasTip)
-                MessageShowBase.Infomation(issucess ? "模型文件下载完毕!" : "模型文件下载失败!");
+                MessageShowBase.Infomation(issucess ? "Revit模型文件下载成功!" : "Revit模型文件下载失败!");
         }
 
         #endregion
@@ -337,7 +351,7 @@ namespace SAGA.MBI.RequestData
                 win = null;
             }
             if (hasTip)
-                MessageBox.Show(issucess ? "数据上传完毕!" : "数据上传失败!");
+                MessageBox.Show(issucess ? "Revit模型文件上传成功!" : "Revit文件上传失败!");
 
         }
         /// <summary>
@@ -364,22 +378,26 @@ namespace SAGA.MBI.RequestData
                     putObjectRequest.StreamTransferProgress += StreamProgressCallback;
 
                     client.PutObject(putObjectRequest);
+
+                    #region 上传后MD5较验
+
+                    string md5 = MD5Tools.GetMD5HashFromFile(filePath);
+                    //上传后的文件md5校验
+                    if (client.GetObjectMetadata(bucketName, key).ETag.ToUpper() != md5.ToUpper())
+                    {
+                        throw new Exception($"楼层 {floorName} MD5校验失败,本地与服务器不一致!");
+                    }
+
+                    #endregion
+
                 }
                 Console.WriteLine("Put object:{0} succeeded", key);
             }
-            catch (OssException ex)
-            {
-                Console.WriteLine(@"Failed with error code: {0}; Error info: {1}. \nRequestID:{2}\tHostID:{3}",
-                    ex.ErrorCode, ex.Message, ex.RequestId, ex.HostId);
-                result = false;
-                CloseUploadWindow(result);
-                return false;
-            }
             catch (Exception ex)
             {
-                Console.WriteLine($@"Failed with error info: { ex.Message}");
+                MessageShowBase.Infomation("Revit文件上传载失败!\r\n" + ex.StackTrace);
                 result = false;
-                CloseUploadWindow(result);
+                CloseUploadWindow(result,false);
             }
             return result;
         }