Forráskód Böngészése

mxg:修改上传模型文件通知次数过多,引起上传速度慢的问题。

mengxiangge 6 éve
szülő
commit
52589fa11a
2 módosított fájl, 42 hozzáadás és 60 törlés
  1. 40 58
      MBI/SAGA.MBI/RequestData/UpLoadFileRequest.cs
  2. 2 2
      MBI/SAGA.Revit.sln

+ 40 - 58
MBI/SAGA.MBI/RequestData/UpLoadFileRequest.cs

@@ -15,6 +15,7 @@ using SAGA.MBI.Common;
 using Utilities;
 using Aliyun.OSS;
 using Aliyun.OSS.Common;
+using FWindSoft.SystemExtensions;
 using Newtonsoft.Json.Linq;
 using SAGA.DotNetUtils;
 using SAGA.DotNetUtils.Encrypt;
@@ -44,7 +45,7 @@ namespace SAGA.MBI.RequestData
         public static bool UseOss()
         {
             var flag = ConfigurationUtil.Default.GetSettingValue("UpDownFlag");
-            return flag==null||flag.Trim() == "0";
+            return flag == null || flag.Trim() == "0";
         }
         #region Download
 
@@ -90,7 +91,7 @@ namespace SAGA.MBI.RequestData
         #endregion
 
         #region DownLoadAsync
-        
+
         private static WinMFMDownloadProcress windown = null;
 
         public static WinMFMDownloadProcress GetProcessWin()
@@ -110,7 +111,7 @@ namespace SAGA.MBI.RequestData
             windown.LabelFloorName = $"正在下载{floorName}层模型文件,请稍后。。。";
             windown.LabelPath = fullPath;
             windown.Count = count;
-            windown.Cur = cur; 
+            windown.Cur = cur;
         }
         /// <summary>
         /// 下载指定文件到指定
@@ -132,7 +133,7 @@ namespace SAGA.MBI.RequestData
             if (state == 2)
                 FloorFileOperate.BakFile(fullPath);
             string key = $"{MBIConst.OssClientFileKey}{cloudName}";
-            
+
             DownLoadNew:
             OssClient client;
             if (WebRequestProxy.IsOnline(out ClientConfiguration conf))
@@ -143,7 +144,7 @@ namespace SAGA.MBI.RequestData
             {
                 client = new OssClient(MBIConst.Endpoint, MBIConst.AccessKeyId, MBIConst.AccessKeySecret);
             }
-            
+
             int timeoutNum = 20;
             long totalLength = 0;
             try
@@ -155,22 +156,21 @@ namespace SAGA.MBI.RequestData
                 //getObjectRequest.StreamTransferProgress += DownStreamProgressCallback;
                 var buffer = new byte[1024 * 1024];
                 long stargIndex = 0;
+                #region ProgressCallback
                 getObjectRequest.StreamTransferProgress += (s, args) =>
-                {
-                  
-                    var tempTrans = stargIndex + args.TransferredBytes;
-                    var tempTotal = stargIndex + args.TotalBytes;
-                    var currentData = Math.Round(((double)tempTrans)/ tempTotal *100d, 3);
-                    Debug.WriteLine("ProgressCallback - TotalBytes:{0}M, TransferredBytes:{1}M,上传百分比:{2}%",
-                        Math.Round(tempTotal / 1024d / 1024,3), Math.Round(tempTrans / 1024d / 1024,3), currentData);
-                    windown?.Update(currentData);
-                    //currentData >= 100d
-                    if (tempTrans >= tempTotal && windown!=null&&windown.Count == windown.Cur)
-                    {
-                        //MessageBox.Show("数据上传完毕!");
-                        CloseDownloadWin(true, false);
-                    }
-                };
+                               {
+
+                                   var tempTrans = stargIndex + args.TransferredBytes;
+                                   var tempTotal = stargIndex + args.TotalBytes;
+                                   var currentData = Math.Round(((double)tempTrans) / tempTotal * 100d, 3);
+                                   windown?.Update(currentData);
+                                   if (tempTrans >= tempTotal && windown != null && windown.Count == windown.Cur)
+                                   {
+                                       CloseDownloadWin(true, false);
+                                   }
+                               };
+                #endregion
+
                 using (var fs = new MemoryStream())
                 {
                     ReDownload:
@@ -190,7 +190,7 @@ namespace SAGA.MBI.RequestData
                             while ((bytesRead = stream.Read(buffer, 0, buffer.Length)) > 0)
                             {
                                 fs.Write(buffer, 0, bytesRead);
-                            }                    
+                            }
                         }
                         catch (WebException e)
                         {
@@ -201,7 +201,7 @@ namespace SAGA.MBI.RequestData
                                 //timeoutNum--;
                                 goto ReDownload;
                             }
-                            throw; 
+                            throw;
                             #endregion
                         }
                         if (fs.Length < totalLength)
@@ -220,15 +220,15 @@ namespace SAGA.MBI.RequestData
                     {
                         string per = Math.Round((fs.Length / (double)totalLength) * 100, 3) + "%";
                         string errorMessage = ($"楼层 {floorName} MD5校验失败,本地与服务器不一致!下载进度{per}");
-                        if (fs.Length== totalLength)
+                        if (fs.Length == totalLength)
                         {
                             if (MessageShowBase.Question(errorMessage + "\r\n是否重新下载该层文件"))
                             {
                                 goto DownLoadNew;
-                            }                          
+                            }
                         }
                         else
-                        {                         
+                        {
                             MessageShowBase.Infomation(errorMessage);
                         }
                         MailLog.Log("下载MD5异常", errorMessage);
@@ -240,39 +240,14 @@ namespace SAGA.MBI.RequestData
             }
             catch (Exception ex)
             {
-                MessageShowBase.Infomation("Revit文件下载失败!\r\n"+ex.Message+"\r\n"+ex.StackTrace);
+                MessageShowBase.Infomation("Revit文件下载失败!\r\n" + ex.Message + "\r\n" + ex.StackTrace);
                 result = false;
-                CloseDownloadWin(result,false);
+                CloseDownloadWin(result, false);
             }
 
             return result;
         }
         /// <summary>
-        /// 下载进度条
-        /// </summary>
-        /// <param name="sender"></param>
-        /// <param name="args"></param>
-        private static void DownStreamProgressCallback(object sender, StreamTransferProgressArgs args)
-        {
-            try
-            {
-                var currentData = Math.Round(args.TransferredBytes * 100d / args.TotalBytes, 3);
-                Debug.WriteLine("ProgressCallback - TotalBytes:{0}M, TransferredBytes:{1}M,上传百分比:{2}%",
-                    args.TotalBytes / 1024 / 1024, args.TransferredBytes / 1024 / 1024, currentData);
-                windown?.Update(currentData);
-                if (currentData >= 100d && windown.Count == windown.Cur)
-                {
-                    //MessageBox.Show("数据上传完毕!");
-                    CloseDownloadWin(true, false);
-                }
-            }
-            catch (Exception ex)
-            {
-
-                throw;
-            }
-        }
-        /// <summary>
         /// 关闭下载窗口
         /// </summary>
         public static void CloseDownloadWin(bool issucess, bool hasTip = true)
@@ -456,7 +431,7 @@ namespace SAGA.MBI.RequestData
         {
             if (!UpLoadFileRequest.UseOss())
             {
-                return FileContentTransferUnit.UpLoadRevitAsync(floorName, filePath, fileName,count,cur);
+                return FileContentTransferUnit.UpLoadRevitAsync(floorName, filePath, fileName, count, cur);
             }
             bool result = true;
             string key = $"{MBIConst.OssClientFileKey}{fileName}";
@@ -485,7 +460,7 @@ namespace SAGA.MBI.RequestData
                         MailLog.Log("上传MD5异常", errorMessage);
                         MessageShowBase.Infomation(errorMessage);
                         //不关闭窗体
-                       // throw new Exception(errorMessage);
+                        // throw new Exception(errorMessage);
                     }
 
                     #endregion
@@ -497,10 +472,13 @@ namespace SAGA.MBI.RequestData
             {
                 MessageShowBase.Infomation("Revit文件上传载失败!\r\n" + ex.Message + "\r\n" + ex.StackTrace);
                 result = false;
-                CloseUploadWindow(result,false);
+                CloseUploadWindow(result, false);
             }
             return result;
         }
+
+        //减少刷新界面次数,一兆更新一次
+        private static int m_TransferredMB = 0;
         /// <summary>
         /// 上传进度条
         /// </summary>
@@ -509,9 +487,13 @@ namespace SAGA.MBI.RequestData
         private static void StreamProgressCallback(object sender, StreamTransferProgressArgs args)
         {
             var currentData = Math.Round(args.TransferredBytes * 100d / args.TotalBytes, 3);
-            Debug.WriteLine("ProgressCallback - TotalBytes:{0}M, TransferredBytes:{1}M,上传百分比:{2}%",
-        args.TotalBytes / 1024 / 1024, args.TransferredBytes / 1024 / 1024, currentData);
-            win?.Update(currentData);
+            var transferredMb = (args.TransferredBytes / 1024 / 1024).ToDouble().RoundDown();
+            if (transferredMb != m_TransferredMB)
+            {
+                win?.Update(currentData);
+                m_TransferredMB = transferredMb;
+            }
+
             if (currentData >= 100d)
             {
                 CloseUploadWindow(true, false);

+ 2 - 2
MBI/SAGA.Revit.sln

@@ -733,8 +733,8 @@ Global
 		{6449F956-11A3-4207-AE0F-9AB8563DFDCE}.R17|x64.Build.0 = Release|Any CPU
 		{6449F956-11A3-4207-AE0F-9AB8563DFDCE}.R17|x86.ActiveCfg = Release|Any CPU
 		{6449F956-11A3-4207-AE0F-9AB8563DFDCE}.R17|x86.Build.0 = Release|Any CPU
-		{6449F956-11A3-4207-AE0F-9AB8563DFDCE}.R18|Any CPU.ActiveCfg = Release|Any CPU
-		{6449F956-11A3-4207-AE0F-9AB8563DFDCE}.R18|Any CPU.Build.0 = Release|Any CPU
+		{6449F956-11A3-4207-AE0F-9AB8563DFDCE}.R18|Any CPU.ActiveCfg = Release|x64
+		{6449F956-11A3-4207-AE0F-9AB8563DFDCE}.R18|Any CPU.Build.0 = Release|x64
 		{6449F956-11A3-4207-AE0F-9AB8563DFDCE}.R18|x64.ActiveCfg = Release|Any CPU
 		{6449F956-11A3-4207-AE0F-9AB8563DFDCE}.R18|x64.Build.0 = Release|Any CPU
 		{6449F956-11A3-4207-AE0F-9AB8563DFDCE}.R18|x86.ActiveCfg = Release|Any CPU