Browse Source

Merge branch 'master' of https://git.dev.tencent.com/xuhuo1234/saga

mengxiangge 6 years ago
parent
commit
9011ae82d6

+ 32 - 16
MBI/FirmLib/Com.FirmLib/BllHttpSetting.cs

@@ -8,6 +8,7 @@ using System.Text;
 using System.Threading.Tasks;
 using Com.FirmLib;
 using FWindSoft.Data;
+using SAGA.DotNetUtils.Utilities;
 
 namespace FirmHttpDao
 {
@@ -41,7 +42,7 @@ namespace FirmHttpDao
         public string EndUri
         {
             //get { return "http://101.201.234.108:28888/venders"; }
-            get { return InnerSetting.Current.BaseAddress; }
+            get { return InnerSetting.Current.VenderAddress; }
         }
         public string DpUri
         {
@@ -58,10 +59,10 @@ namespace FirmHttpDao
         {   //get { return "http://101.201.234.108:28888/data-platform-3/"; }
             get { return InnerSetting.Current.FileAddress; }
         }
-        public string SaasUri
-        {   //get { return "http://101.201.234.108:28888/data-platform-3/"; }
-            get { return InnerSetting.Current.SaasAddress; }
-        }
+        //public string SaasUri
+        //{   //get { return "http://101.201.234.108:28888/data-platform-3/"; }
+        //    get { return InnerSetting.Current.SaasAddress; }
+        //}
         public string H5Url
         {
             get { return InnerSetting.Current.H5Address; }
@@ -71,20 +72,38 @@ namespace FirmHttpDao
 
     public class InnerSetting
     {
+        #region 静态操作
+        public static void SaveConfigureInfo(string key, string value)
+        {
+            IniOperator.Instance(ConfigPath).SetData("Configure", key, value);
+        }
+        public static string GetConfigureInfo(string key)
+        {
+            return IniOperator.Instance(ConfigPath).GetData("Configure", key);
+        }
+        #endregion
+        private static string ConfigPath { get; set; }
         static InnerSetting()
         {                        
-            string path =Path.Combine(Directory.GetParent(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)).FullName, @"MBIResource\Config\HttpSetting.xml");
-            XmlFileConfig<InnerSetting> config = new XmlFileConfig<InnerSetting>(path, "");
-            config.Load(); 
-            Current = config.RefObject;
+            string path =Path.Combine(Directory.GetParent(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)).FullName, @"MBIResource\Config\HttpSetting.ini");
+            ConfigPath = path;
+            //XmlFileConfig<InnerSetting> config = new XmlFileConfig<InnerSetting>(path, "");
+            //config.Load(); 
+            //Current = config.RefObject;
+            Current = new InnerSetting();
+            Current.VenderAddress = GetConfigureInfo(nameof(Current.VenderAddress));
+            Current.DependencyAddress = GetConfigureInfo(nameof(Current.DependencyAddress));
+            Current.EquipmentFamilyAddress = GetConfigureInfo(nameof(Current.EquipmentFamilyAddress));
+            Current.FileAddress = GetConfigureInfo(nameof(Current.FileAddress));
+            Current.H5Address = GetConfigureInfo(nameof(Current.H5Address));
         }
         public InnerSetting()
         {
-            BaseAddress = @"http://127.0.0.1";
+            VenderAddress = @"http://127.0.0.1";
             DependencyAddress = @"http://127.0.0.1";
             EquipmentFamilyAddress = @"http://127.0.0.1";
             FileAddress= @"http://127.0.0.1";
-            SaasAddress = @"http://127.0.0.1";
+            //SaasAddress = @"http://127.0.0.1";
         }
 
        
@@ -92,7 +111,7 @@ namespace FirmHttpDao
         /// <summary>
         ///  基地址
         /// </summary>
-        public string BaseAddress { get; set; }
+        public string VenderAddress { get; set; }
         /// <summary>
         /// 辅助地址
         /// </summary>
@@ -105,10 +124,7 @@ namespace FirmHttpDao
         /// 文件服务器地址
         /// </summary>
         public string FileAddress { get; set; }
-        /// <summary>
-        /// 软件服务
-        /// </summary>
-        public string SaasAddress { get; set; }
+      
 
         /// <summary>
         /// H5网页展示

+ 6 - 0
MBI/MBIResource/Config/HttpSetting - 亚投行.ini

@@ -10,3 +10,9 @@ GoodHandLocalHost = http://39.96.187.128:28888/godhand/
 GplotViewHost = http://39.96.187.128:8888/#/
 ImageServiceLocalHost = http://39.96.187.128:28888/
 
+VenderAddress=http://39.96.187.128:28888/venders
+DependencyAddress=http://39.96.187.128:28888/venders-dp
+EquipmentFamilyAddress=http://39.96.187.128:28888/data-platform-3
+FileAddress=http://39.96.187.128:28888
+H5Address=http://39.96.187.128:8889/#
+

+ 5 - 0
MBI/MBIResource/Config/HttpSetting - 测试.ini

@@ -10,3 +10,8 @@ GoodHandLocalHost = http://192.168.20.225:8080/godhand/
 GplotViewHost = http://mbi.sagacloud.cn:8888/#/
 ImageServiceLocalHost = http://192.168.20.225:8080/
 
+VenderAddress=http://192.168.20.225:8080/venders
+DependencyAddress=http://192.168.20.225:8080/venders-dp
+EquipmentFamilyAddress=http://192.168.20.225:8080/data-platform-3
+FileAddress=http://192.168.30.96:8080
+H5Address=http://172.16.0.181:8889/#

+ 6 - 0
MBI/MBIResource/Config/HttpSetting.ini

@@ -6,3 +6,9 @@ OssClientFileKey = files/revit/
 GplotViewHost = http://mbi.sagacloud.cn:8888/#/
 ImageServiceLocalHost = http://service.sagacloud.cn:28888/
 Html5ScanLocalHost = http://mbi.sagacloud.cn:8888/#/
+
+VenderAddress=http://service.sagacloud.cn:28888/venders
+DependencyAddress=http://service.sagacloud.cn:28888/venders-dp
+EquipmentFamilyAddress=http://service.sagacloud.cn:28888/data-platform-3
+FileAddress=http://service.sagacloud.cn:28888
+H5Address=http://mbi.sagacloud.cn:8889/#

+ 156 - 0
MBI/SAGA.DotNetUtils/Data/MessageMapItem.cs

@@ -0,0 +1,156 @@
+/*-------------------------------------------------------------------------
+ * 功能描述:MessageMap
+ * 作者:xulisong
+ * 创建时间: 2019/4/8 17:53:21
+ * 版本号:v1.0
+ *  -------------------------------------------------------------------------*/
+
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Xml.Serialization;
+using SAGA.DotNetUtils.Serializer;
+using SAGA.DotNetUtils.Service;
+using SAGA.DotNetUtils.Utilities;
+
+namespace SAGA.DotNetUtils.Data
+{
+    public enum CodeMatchType
+    {
+        Exactness=1,
+        Mistiness=2
+    }
+    [XmlType("MessageItem")]
+    public class MessageMapItem
+    {
+        public MessageMapItem()
+        {
+            MatchType = CodeMatchType.Exactness;
+        }
+        /// <summary>
+        /// 消息码
+        /// </summary>
+        public string MessageCode { get; set; }
+
+        public CodeMatchType MatchType { get; set; }
+        /// <summary>
+        /// 消息描述
+        /// </summary>
+        public string MessageDescription { get; set; }
+
+        public bool IsMatch(string messageCode)
+        {
+            bool flag = false;
+            if (string.IsNullOrWhiteSpace(messageCode))
+            {
+                return flag;
+            }         
+            switch (MatchType)
+            {
+                case CodeMatchType.Exactness:
+                {
+                        flag = MessageCode == messageCode;
+                        break;
+                }
+                case CodeMatchType.Mistiness:
+                {
+                    flag = messageCode.Contains(MessageCode);
+                    break;
+                }
+            }
+
+            return flag;
+        }
+    }
+
+    /// <summary>
+    /// 映射信息
+    /// </summary>
+   [XmlType("Messages")]
+    public class MessageMap:List<MessageMapItem>, IMessageMap
+    {  
+        public string Path { get; private set; }
+        public MessageMap()
+        {
+            Path = CommonUtil.GetPath(this.GetType(), ".xml");
+        }
+        public MessageMap(string path)
+        {
+            Path = path;
+        }
+        /*
+         *要排序,精确的排在前面
+         */
+        private readonly Dictionary<string, string> m_CacheInfos = new Dictionary<string, string>();
+        public bool TryGetCustomDescription(string messageCode, out string description)
+        {
+            description = null;
+            if (m_CacheInfos.TryGetValue(messageCode, out description))
+            {
+                return true;
+            }
+            var item = this.FirstOrDefault(m => m.IsMatch(messageCode));
+            description = item?.MessageDescription;
+            m_CacheInfos[messageCode] = description ?? string.Empty;
+            return !description.IsNullOrEmpty();
+        }
+        /// <summary>
+        /// 获取自定义描述信息
+        /// </summary>
+        /// <param name="messageCode"></param>
+        /// <returns></returns>
+        public string GetCustomDescription(string messageCode)
+        {
+            if (!TryGetCustomDescription(messageCode, out string description))
+            {
+                return null;
+            }
+            return description;
+        }
+        #region 保存加载
+        /// <summary>
+        /// 保存消息映射
+        /// </summary>
+        /// <param name="path"></param>
+        public void Save(string path)
+        {
+            string result = SerializerByXml.Serialize(this);
+            var directory = Directory.GetParent(path);
+            if (!directory.Exists)
+            {
+                directory.Create();
+            }
+            File.WriteAllText(path, result);
+        }
+        /// <summary>
+        /// 加载消息映射
+        /// </summary>
+        /// <param name="path"></param>
+        public void Load(string path)
+        {
+            var obj = SerializerByXml.Desrialize<MessageMap>(path);
+            if (obj is MessageMap)
+            {
+                this.AddRange(obj);
+            }
+        }
+
+        public void Save()
+        {
+            this.Save(Path);
+        }
+        public void Load()
+        {
+            this.Load(Path);
+        }
+        #endregion
+
+        public string Map(string messageCode)
+        {
+            return this?.GetCustomDescription(messageCode);
+        }
+    }
+}

+ 8 - 0
MBI/SAGA.DotNetUtils/Http/HttpUtils.cs

@@ -6,6 +6,7 @@ using System.IO;
 using System.Net;
 using System.Text;
 using SAGA.DotNetUtils.Others;
+using SAGA.DotNetUtils.Service;
 
 namespace SAGA.DotNetUtils.Http
 {
@@ -122,6 +123,13 @@ namespace SAGA.DotNetUtils.Http
                 catch (Exception e)
                 {
                     List<string> list = new List<string>();
+                    #region 描述信息
+                    var description = ServiceManager.MessageMap.Default?.Map(EndPoint);
+                    if (!string.IsNullOrWhiteSpace(description))
+                    {
+                        list.Add(description);
+                    } 
+                    #endregion
                     list.Add(EndPoint);
                     //list.Add("\r\n");
                     list.Add(Method.ToString());

+ 19 - 35
MBI/SAGA.DotNetUtils/Http/RequestClient.cs

@@ -42,9 +42,8 @@ namespace SAGA.DotNetUtils.Http
                 request.Method = "POST";
 
                 #region 请求数据
-                //每次上传4k 
-                int bufferLength = 40960;
-                byte[] buffer = new byte[bufferLength];
+                //每次上传40k 
+                byte[] buffer = new byte[40960];
                 BinaryReader r = new BinaryReader(stream);     
                 Stream postStream = request.GetRequestStream();
                 if (postStream == null)
@@ -56,21 +55,10 @@ namespace SAGA.DotNetUtils.Http
                     int size = 0; 
                     do
                     {
-                       size = r.Read(buffer, 0, bufferLength);
+                       size = r.Read(buffer, 0, buffer.Length);
                        postStream.Write(buffer, 0, size);
                     }
                     while (size > 0);
-                    //while (size > 0)
-                    //{
-                    //    postStream = request.GetRequestStream();
-                    //    postStream.Write(buffer, 0, bufferLength);
-                    //    size = r.Read(buffer, 0, bufferLength);
-                    //}
-                }
-                catch (Exception e)
-                {
-                    //Console.WriteLine(e);
-                    throw;
                 }
                 finally
                 {
@@ -126,34 +114,30 @@ namespace SAGA.DotNetUtils.Http
                         var message = String.Format("Request failed. Received HTTP {0}", response.StatusCode);
                         throw new ApplicationException(message);
                     }
-                    using (var responseStream = response.GetResponseStream())
+
+                    using (MemoryStream memoryStream = new MemoryStream())
                     {
-                        if (responseStream != null)
+                        using (var responseStream = response.GetResponseStream())
                         {
-                            long totalLength = response.ContentLength;
-                            //这里面到时可以获取编码形式
-                            if (totalLength <= 0)//当没有连接是可能返回长度为0
-                                return null;//如果长度为零返回空
-                            int preLength = 40960;
-                            //results = new byte[totalLength+preLength];//适当加点         
-                            results = new byte[totalLength];
-                            var count = 0;
-                            int start = 0;
-                            do
+                            if (responseStream != null)
                             {
-                                start = start + count;
-                                long length = Math.Min(totalLength - start, preLength);
-                                count = responseStream.Read(results, start, (int)length);
-                            } while (count > 0);
-
+                                long totalLength = response.ContentLength;
+                                if (totalLength <= 0)//当没有连接是可能返回长度为0
+                                    return null;//如果长度为零返回空
+                                var buffer = new byte[40960];//缓存对象
+                                var bytesRead = 0;
+                                while ((bytesRead = responseStream.Read(buffer, 0, buffer.Length)) > 0)
+                                {
+                                    memoryStream.Write(buffer, 0, bytesRead);
+                                }
+                                results = memoryStream.ToArray();
+                            }
                         }
-
-                    }
+                    }              
                 }
             }
             finally
             {
-
             }
             return results;
         }

+ 5 - 0
MBI/SAGA.DotNetUtils/SAGA.DotNetUtils.csproj

@@ -293,6 +293,7 @@
     <Compile Include="Data\FlagDecorator.cs" />
     <Compile Include="Data\InitAttribute.cs" />
     <Compile Include="Data\InitObejct.cs" />
+    <Compile Include="Data\MessageMapItem.cs" />
     <Compile Include="Data\NumberGenerater.cs" />
     <Compile Include="Data\SingleFactory.cs" />
     <Compile Include="Data\SingleInstance.cs" />
@@ -375,9 +376,13 @@
     <Compile Include="PropertyGrid\XProp.cs" />
     <Compile Include="PropertyGrid\XPropDescriptor.cs" />
     <Compile Include="PropertyGrid\XProps.cs" />
+    <Compile Include="Service\IMessageMap.cs" />
     <Compile Include="Service\IServiceLocator.cs" />
     <Compile Include="Service\ServiceConfigItem.cs" />
     <Compile Include="Service\ServiceLocator.cs" />
+    <Compile Include="Service\ServiceManager.cs" />
+    <Compile Include="Service\ServiceWrapper.cs" />
+    <Compile Include="Utilities\CommonUtil.cs" />
     <Compile Include="Utilities\GuidUtil.cs" />
     <Compile Include="Utilities\CompressUtil.cs" />
     <Compile Include="Utilities\FileUp.cs" />

+ 31 - 0
MBI/SAGA.DotNetUtils/Service/IMessageMap.cs

@@ -0,0 +1,31 @@
+/*-------------------------------------------------------------------------
+ * 功能描述:IMessageMap
+ * 作者:xulisong
+ * 创建时间: 2019/4/9 10:34:11
+ * 版本号:v1.0
+ *  -------------------------------------------------------------------------*/
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using SAGA.DotNetUtils.Data;
+
+namespace SAGA.DotNetUtils.Service
+{
+    /// <summary>
+    /// 消息映射服务
+    /// </summary>
+    public interface IMessageMap
+    {
+        /// <summary>
+        /// 获取映射信息
+        /// </summary>
+        /// <param name="messageCode">传入信息</param>
+        /// <returns></returns>
+        string Map(string messageCode);
+    }
+
+   
+}

+ 51 - 0
MBI/SAGA.DotNetUtils/Service/ServiceManager.cs

@@ -0,0 +1,51 @@
+/*-------------------------------------------------------------------------
+ * 功能描述:ServiceManager
+ * 作者:xulisong
+ * 创建时间: 2019/4/9 11:33:57
+ * 版本号:v1.0
+ *  -------------------------------------------------------------------------*/
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using SAGA.DotNetUtils.Data;
+
+namespace SAGA.DotNetUtils.Service
+{
+    public static class ServiceManager
+    {
+        #region 缓存公共信息
+        private readonly static Dictionary<string, object> m_CacheItems = new Dictionary<string, object>();
+        private static ServiceWrapper<T> GetCurrentWrapper<T>(Func<T> defaultT) where T : class
+        {
+             var key = typeof(T).FullName;
+            ServiceWrapper<T> result = null;
+            if (m_CacheItems.TryGetValue(key, out object wrapper))
+            {
+                result = wrapper as ServiceWrapper<T>;
+            }
+            if (result == null)
+            {
+                result = new ServiceWrapper<T>(defaultT);
+                m_CacheItems[key] = result;
+            }
+            return result;
+        } 
+        #endregion
+        public static ServiceWrapper<IMessageMap> MessageMap
+        {
+            get
+            {              
+                return GetCurrentWrapper<IMessageMap>(() =>
+                {
+                    MessageMap map = new MessageMap();
+                    map.Load();
+                    return map;
+                });
+            }
+        }
+
+    }
+}

+ 40 - 0
MBI/SAGA.DotNetUtils/Service/ServiceWrapper.cs

@@ -0,0 +1,40 @@
+/*-------------------------------------------------------------------------
+ * 功能描述:ServiceWrapper
+ * 作者:xulisong
+ * 创建时间: 2019/4/9 11:36:36
+ * 版本号:v1.0
+ *  -------------------------------------------------------------------------*/
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SAGA.DotNetUtils.Service
+{
+    public class ServiceWrapper<T> where T : class
+    {
+        private readonly Func<T> m_CreateDefault;
+        public ServiceWrapper(Func<T> createDefault)
+        {
+            m_CreateDefault = createDefault;
+        }
+        public void Init(T map)
+        {
+            m_Default = map;
+        }
+        private T m_Default;
+        public T Default
+        {
+            get
+            {
+                if (m_Default == null)
+                {
+                    m_Default = m_CreateDefault?.Invoke();
+                }
+                return m_Default;
+            }
+        }
+    }
+}

+ 35 - 0
MBI/SAGA.DotNetUtils/Utilities/CommonUtil.cs

@@ -0,0 +1,35 @@
+/*-------------------------------------------------------------------------
+ * 功能描述:CommonUtil
+ * 作者:xulisong
+ * 创建时间: 2019/4/9 11:11:35
+ * 版本号:v1.0
+ *  -------------------------------------------------------------------------*/
+
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SAGA.DotNetUtils.Utilities
+{
+    public class CommonUtil
+    {
+        /// <summary>
+        /// 获取临时目录位置
+        /// </summary>
+        /// <param name="type"></param>
+        /// <param name="extensionName">带.的扩展名</param>
+        /// <returns></returns>
+        public static string GetPath(Type type, string extensionName)
+        {
+            //以临时目录为目录,以类所在dll路径生成MD5值为一级,以类名为文件名
+            var basePath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
+            var path = type.Assembly.Location;
+            var md5 = path.ToMD5();
+            string fileName = type.Name + extensionName;
+            return Path.Combine(basePath, md5, fileName);
+        }
+    }
+}

+ 1 - 0
MBI/SAGA.MBI/App.xaml.cs

@@ -30,6 +30,7 @@ namespace SAGA.MBI
         [STAThread]
         static void Main(string[] args)
         {
+            MessageManager.InitMessageMap();
 #if DEBUG
             WinLogin win = new WinLogin();
             Application myAp = new Application();

+ 36 - 0
MBI/SAGA.MBI/Common/MessageManager.cs

@@ -0,0 +1,36 @@
+/*-------------------------------------------------------------------------
+ * 功能描述:MessageManager
+ * 作者:xulisong
+ * 创建时间: 2019/4/9 12:03:54
+ * 版本号:v1.0
+ *  -------------------------------------------------------------------------*/
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using SAGA.DotNetUtils.Data;
+
+namespace SAGA.MBI.Common
+{
+    public class MessageManager
+    {
+        public static void InitMessageMap()
+        {
+            /*
+             * 本来想根据地址,映射变量动态生成。现在简化写成固定的
+             */
+            MessageMap map = new MessageMap();
+            map.Add(new MessageMapItem() {MessageCode = "godhand", MessageDescription = "上帝之后后台"});
+            map.Add(new MessageMapItem() { MessageCode = "ScanBuilding", MessageDescription = "扫楼后台" });
+            map.Add(new MessageMapItem() { MessageCode = "data-platform-3", MessageDescription = "数据平台" });
+            map.Add(new MessageMapItem() { MessageCode = "venders", MessageDescription = "厂商库" });
+            map.Add(new MessageMapItem() { MessageCode = "venders-dp", MessageDescription = "厂商库辅助" });
+            map.Add(new MessageMapItem() { MessageCode = "image-service", MessageDescription = "文件服务器" });
+            map.Add(new MessageMapItem() { MessageCode = ":8888/#/", MessageDescription = "前端页面" });
+            map.Add(new MessageMapItem() { MessageCode = ":8889/#/", MessageDescription = "前端页面" });
+            map.Save();
+        }
+    }
+}

+ 79 - 37
MBI/SAGA.MBI/RequestData/UpLoadFileRequest.cs

@@ -115,53 +115,87 @@ namespace SAGA.MBI.RequestData
                 FloorFileOperate.BakFile(fullPath);
             string key = $"{MBIConst.OssClientFileKey}{cloudName}";
             OssClient client = new OssClient(MBIConst.Endpoint, MBIConst.AccessKeyId, MBIConst.AccessKeySecret);
+            int timeoutNum = 20;
+            long totalLength = 0;
             try
             {
                 string bucketName = MBIConst.BucketName;
 
                 ShowDownloadWindow(tuple.Item3, fullPath, count, cur);
-
                 var getObjectRequest = new GetObjectRequest(bucketName, key);
-                getObjectRequest.StreamTransferProgress += DownStreamProgressCallback;
-                OssObject ossObject = client.GetObject(getObjectRequest);
-                //设置下载超时时间
-                ossObject.ResponseStream.ReadTimeout = 20*60*1000;
-                using (var stream = ossObject.Content)
+                //getObjectRequest.StreamTransferProgress += DownStreamProgressCallback;
+                var buffer = new byte[1024 * 1024];
+                long stargIndex = 0;
+                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);
+                    if (currentData >= 100d && windown.Count == windown.Cur)
+                    {
+                        //MessageBox.Show("数据上传完毕!");
+                        CloseDownloadWin(true, false);
+                    }
+                };
+                using (var fs = new MemoryStream())
                 {
-                    var buffer = new byte[1024 * 1024];
-                    using (var fs = new System.IO.MemoryStream())
+                    ReDownload:
+                    getObjectRequest.SetRange(stargIndex, -1);
+                    OssObject ossObject = client.GetObject(getObjectRequest);
+                    //设置下载超时时间
+                    ossObject.ResponseStream.ReadTimeout = 60 * 1000;//*20;
+                    if (totalLength == 0)
+                    {
+                        totalLength = ossObject.ContentLength;
+                    }
+                    using (var stream = ossObject.Content)
                     {
                         var bytesRead = 0;
-                        while (( bytesRead = stream.Read(buffer, 0, buffer.Length)) > 0)
+                        try
                         {
-                            // Process read data
-                            // TODO
-                            fs.Write(buffer, 0, bytesRead);
+                            while ((bytesRead = stream.Read(buffer, 0, buffer.Length)) > 0)
+                            {
+                                fs.Write(buffer, 0, bytesRead);
+                            }                    
                         }
-                        //写入文件
-                        FileStreamOperate.WriteFile(fs.ToArray(), fullPath);
-
-                        #region 下载后Md5较验
-
-                        string md5 = MD5Tools.GetMD5HashFromFileByBase64(fullPath);
-                        //下载后的文件md5校验
-                        if (client.GetObjectMetadata(bucketName, key).ContentMd5 != md5)
+                        catch (WebException e)
                         {
-                            string per = (fs.Length/(double)ossObject.Content.Length)*100+"%";
-                           string errorMessage=($"楼层 {floorName} MD5校验失败,本地与服务器不一致!下载进度{per}");
-                            MailLog.Log("下载MD5异常", errorMessage);
-                            MessageShowBase.Infomation(errorMessage);
-                            result = false;
-                            //f1层一致提示失败
-                            //throw new Exception(errorMessage);
+                            #region 超时重试
+                            timeoutNum--;
+                            if (0 < timeoutNum && e.Message.Contains("超时"))
+                            {
+                                stargIndex = fs.Length;
+                                goto ReDownload;
+                            }
+                            throw; 
+                            #endregion
+                        }
+                        if (fs.Length < totalLength)
+                        {
+                            stargIndex = fs.Length;
+                            goto ReDownload;
                         }
 
-                        #endregion
+                    }
 
+                    FileStreamOperate.WriteFile(fs.ToArray(), fullPath);
+                    #region 下载后Md5较验
+                    string md5 = MD5Tools.GetMD5HashFromFileByBase64(fullPath);
+                    //下载后的文件md5校验
+                    if (client.GetObjectMetadata(bucketName, key).ContentMd5 != md5)
+                    {
+                        string per =Math.Round((fs.Length / (double)totalLength) * 100,3) + "%";
+                        string errorMessage = ($"楼层 {floorName} MD5校验失败,本地与服务器不一致!下载进度{per}");
+                        MailLog.Log("下载MD5异常", errorMessage);
+                        MessageShowBase.Infomation(errorMessage);
+                        result = false;
                     }
+                    #endregion
                 }
-
-
                 Log4Net.Debug($"Get object:{key} succeeded");
             }
             catch (Exception ex)
@@ -180,14 +214,22 @@ namespace SAGA.MBI.RequestData
         /// <param name="args"></param>
         private static void DownStreamProgressCallback(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);
-            windown?.Update(currentData);
-            if (currentData >= 100d && windown.Count == windown.Cur)
+            try
             {
-                //MessageBox.Show("数据上传完毕!");
-                CloseDownloadWin(true, false);
+                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>

+ 1 - 0
MBI/SAGA.MBI/SAGA.MBI.csproj

@@ -293,6 +293,7 @@
     <Compile Include="Common\CacheAspect.cs" />
     <Compile Include="Common\EquipmentCodeMap.cs" />
     <Compile Include="Common\MailLog.cs" />
+    <Compile Include="Common\MessageManager.cs" />
     <Compile Include="Common\PhaseUtil.cs" />
     <Compile Include="Common\RevitBuiltInParameter.cs" />
     <Compile Include="Common\WaitingView.cs" />