瀏覽代碼

mxg:添加命令异常重试,

mengxiangge 6 年之前
父節點
當前提交
bfe7afcc5d

+ 68 - 59
MBI/SAGA.DotNetUtils/Http/HttpUtils.cs

@@ -63,74 +63,83 @@ namespace SAGA.DotNetUtils.Http
         {
             System.GC.Collect();
             var responseValue = string.Empty;
-            var request = (HttpWebRequest)WebRequest.Create(EndPoint + parameters);
-            try
+            bool retry = false;
+            do
             {
-                request.ServicePoint.Expect100Continue = false;
-                request.ServicePoint.UseNagleAlgorithm = false;
-                request.ServicePoint.ConnectionLimit = int.MaxValue;
-                request.AllowWriteStreamBuffering = false;
-                request.Proxy = null;
-
-                request.Method = Method.ToString();
-                request.ContentLength = 0;
-                request.ContentType = ContentType;
-                Stopwatch st=new Stopwatch();
-                st.Start();
-                if (PostData != null && Method == HttpVerb.POST)
+                retry = false;
+                var request = (HttpWebRequest)WebRequest.Create(EndPoint + parameters);
+                try
                 {
-                    //解决上传汉字乱码问题
-                    var encoding = new UTF8Encoding();
-                    //var bytes = Encoding.GetEncoding("iso-8859-1").GetBytes(PostData);
-                    var bytes = encoding.GetBytes(PostData);
-                    //var bytes = PostData;
-                    request.ContentLength = bytes.Length;
-
-                    using (var writeStream = request.GetRequestStream())
+                    request.ServicePoint.Expect100Continue = false;
+                    request.ServicePoint.UseNagleAlgorithm = false;
+                    request.ServicePoint.ConnectionLimit = int.MaxValue;
+                    request.AllowWriteStreamBuffering = false;
+                    request.Proxy = null;
+
+                    request.Method = Method.ToString();
+                    request.ContentLength = 0;
+                    request.ContentType = ContentType;
+                    Stopwatch st = new Stopwatch();
+                    st.Start();
+                    if (PostData != null && Method == HttpVerb.POST)
                     {
-
-                        writeStream.Write(bytes, 0, bytes.Length);
+                        //解决上传汉字乱码问题
+                        var encoding = new UTF8Encoding();
+                        //var bytes = Encoding.GetEncoding("iso-8859-1").GetBytes(PostData);
+                        var bytes = encoding.GetBytes(PostData);
+                        //var bytes = PostData;
+                        request.ContentLength = bytes.Length;
+
+                        using (var writeStream = request.GetRequestStream())
+                        {
+
+                            writeStream.Write(bytes, 0, bytes.Length);
+                        }
                     }
-                }
-                using (var response = (HttpWebResponse)request.GetResponse())
-                {
-
-                    if (response.StatusCode != HttpStatusCode.OK)
+                    using (var response = (HttpWebResponse)request.GetResponse())
                     {
-                        var message = String.Format("Request failed. Received HTTP {0}", response.StatusCode);
-                        throw new ApplicationException(message);
-                    }
 
-                    // grab the response
-                    using (var responseStream = response.GetResponseStream())
-                    {
-                        if (responseStream != null)
-                            using (var reader = new StreamReader(responseStream))
-                            {
-                                responseValue = reader.ReadToEnd();
+                        if (response.StatusCode != HttpStatusCode.OK)
+                        {
+                            var message = String.Format("Request failed. Received HTTP {0}", response.StatusCode);
+                            throw new ApplicationException(message);
+                        }
 
-                            }
-                    }
+                        // grab the response
+                        using (var responseStream = response.GetResponseStream())
+                        {
+                            if (responseStream != null)
+                                using (var reader = new StreamReader(responseStream))
+                                {
+                                    responseValue = reader.ReadToEnd();
+
+                                }
+                        }
 
+                    }
+                    Debug.WriteLine("Response:" + st.Elapsed + ":" + EndPoint + ":" + PostData);
                 }
-                Debug.WriteLine("Response:"+st.Elapsed+":"+ EndPoint + ":" + PostData);
-            }
-            catch (Exception e)
-            {
-                List<string> list = new List<string>();
-                list.Add(EndPoint);
-                list.Add("\r\n");
-                list.Add(Method.ToString());
-                list.Add("\r\n");
-                list.Add(PostData ?? "");
-                list.Add("\r\n");
-                list.Add(e.Message);
-                MessageShowBase.Infomation(list);
-            }
-            finally
-            {
-                request.Abort();
-            }
+                catch (Exception e)
+                {
+                    List<string> list = new List<string>();
+                    list.Add(EndPoint);
+                    //list.Add("\r\n");
+                    list.Add(Method.ToString());
+                    //list.Add("\r\n");
+                    list.Add(PostData ?? "");
+                    //list.Add("\r\n");
+                    list.Add(e.Message);
+                    //命令异常,重试
+                    retry = (MessageShowBase.Retry(string.Join("\r\n", list)));
+                    if (!retry)
+                        throw ;
+                }
+                finally
+                {
+                    request.Abort();
+                }
+            } while (retry);
+
 
             return responseValue;
         }

+ 19 - 10
MBI/SAGA.MBI/Command.cs

@@ -126,7 +126,7 @@ namespace SAGA.MBI
                 var doc = ExternalDataWrapper.Current.Doc;
                 if (doc == null) return Result.Cancelled;
                 string floorId = doc.PathName.GetFileName();
-                DalLock.LockFloor(floorId,true);
+                DalLock.LockFloor(floorId, true);
             }
             catch (Exception e)
             {
@@ -200,8 +200,8 @@ namespace SAGA.MBI
                 Log4Net.Debug("开始命令:待建模型清单");
                 var doc = ExternalDataWrapper.Current.Doc;
                 if (doc == null) return Result.Cancelled;
-                VMBeModeDutyList vm=new VMBeModeDutyList();
-                WinBeModeDutyList win=new WinBeModeDutyList();
+                VMBeModeDutyList vm = new VMBeModeDutyList();
+                WinBeModeDutyList win = new WinBeModeDutyList();
                 win.DataContext = vm;
                 win.Show();
                 Log4Net.Debug("结束命令:待建模型清单");
@@ -377,7 +377,7 @@ namespace SAGA.MBI
         }
     }
 
-   
+
     /// <summary>
     /// 空间管理
     /// </summary>
@@ -387,19 +387,28 @@ namespace SAGA.MBI
     {
         public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
         {
-   
-            var win = new WinCreateSpaces();
-            win.Show();
+
+            try
+            {
+                var win = new WinCreateSpaces();
+                win.Show();
+            }
+            catch (Exception e)
+            {
+                MessageShow.Show(e);
+                return Result.Cancelled;
+            }
+
             return Result.Succeeded;
         }
 
-          
+
         public override bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
         {
             return true;
         }
 
-     
+
     }
     /// <summary>
     /// 同步模型本地名称
@@ -424,7 +433,7 @@ namespace SAGA.MBI
                     }
                     contexts.Add(new CalcContext(floor.MFloor));
                 }
-                 MBIModelInfoManager.SyncPlatformToRevit(contexts);
+                MBIModelInfoManager.SyncPlatformToRevit(contexts);
                 wait.Close();
             }
             catch (Exception e)

+ 1 - 1
MBI/SAGA.MBI/Common/MBIConst.cs

@@ -107,7 +107,7 @@ namespace SAGA.MBI.Common
                 string url = ProjectDirOperate.GetConfigureInfo(key);
                 if (url.IsNullOrEmpty())
                 {
-                    // url = "http://172.16.3.12:8080/ScanBuilding/";
+                    // url = "http://172.16.0.141:8080/ScanBuilding/";
                     url = "http://mbi.sagacloud.cn:8080/ScanBuilding/";
                     ProjectDirOperate.SaveConfigureInfo(key, url);
                 }

+ 22 - 16
MBI/SAGA.MBI/DataArrange/DalUploadFloor.cs

@@ -260,7 +260,7 @@ namespace SAGA.MBI.DataArrange
                             (DocumentChangedOperator)Enum.Parse(typeof(DocumentChangedOperator), log.Operator);
                         var mode = context.FindItem(bimId);
                         //模型和物理世界都找不到这条数据,Next
-                        if(mode==null&&elem==null)continue;
+                        if (mode == null && elem == null) continue;
                         switch (operate)
                         {
                             case DocumentChangedOperator.Add:
@@ -296,7 +296,7 @@ namespace SAGA.MBI.DataArrange
             catch (Exception e)
             {
                 //MessageShowBase.Show(e);
-                MessageShow.Show(e,strMessage: currentFloor??string.Empty);
+                MessageShow.Show(e, strMessage: $"楼层 { currentFloor ?? string.Empty} 打开异常,请检查!");
             }
             finally
             {
@@ -305,7 +305,7 @@ namespace SAGA.MBI.DataArrange
 
             return vm;
         }
-    
+
         /// <summary>
         /// 对 删除并保留岗位日志 进行的操作
         /// </summary>
@@ -347,7 +347,7 @@ namespace SAGA.MBI.DataArrange
                     else
                     {
                         var cloudmode = CommonConvert.QueryObjectById(dutyId);
-                        if (cloudmode==null)
+                        if (cloudmode == null)
                         {
                             revitmode.Operator = DocumentChangedOperator.Add;
                             context.Add(revitmode);
@@ -363,19 +363,25 @@ namespace SAGA.MBI.DataArrange
                 }
             }
         }
-         /// <summary>
-         /// 判断设备类编码是否更改
-         /// 如果发生更改,把之前的删除。
-         /// 重建岗位。
-         /// </summary>
-         /// <param name="mode"></param>
-         /// <param name="tempmode"></param>
-         /// <param name="context"></param>
-         /// <returns></returns>
+        /// <summary>
+        /// 判断设备类编码是否更改
+        /// 如果发生更改,把之前的删除。
+        /// 重建岗位。
+        /// </summary>
+        /// <param name="mode"></param>
+        /// <param name="tempmode"></param>
+        /// <param name="context"></param>
+        /// <returns></returns>
         private static bool IsEquipClassCodeChanged(MRevitEquipBase mode, MRevitEquipBase tempmode, CalcContext context)
         {
             bool result = false;
-            if (mode != null&& !tempmode.IsNullOrDefaultEquip())
+
+            if (tempmode.IsNullOrDefaultEquip())
+            {
+                //本地编码不可识别,删除服务器数据
+                mode.Operator = DocumentChangedOperator.Delete;
+            }
+            else
             {
                 //如果设备族四位或六位改了,需要将岗位删除,重建岗位
                 if (mode.EquipClassCode != tempmode.EquipClassCode)
@@ -393,7 +399,7 @@ namespace SAGA.MBI.DataArrange
 
             return result;
         }
-       
+
         /// <summary>
         /// 1,处理是无用的空间,周长为零
         /// 2,对象被删除
@@ -420,7 +426,7 @@ namespace SAGA.MBI.DataArrange
                     }
                 }
             }
-           
+
 
             return result;
         }

+ 2 - 1
MBI/SAGA.MBI/Extend/ElementExtend.cs

@@ -170,7 +170,8 @@ namespace SAGA.MBI.Tools
         public static string GetFamilyCode(this Element fi)
         {
             string code = "";
-            string familyName = fi.GetFamily().Name;
+            string familyName = fi.GetFamily()?.Name;
+            if (familyName == null) return code;
             //族名称的命名规则:ATFC-风机盘管
             int index = familyName.IndexOf('-');
             if (index != -1 && index + 1 != familyName.Length)

+ 20 - 3
MBI/SAGA.MBI/ToolCommand.cs

@@ -261,9 +261,18 @@ namespace SAGA.MBI
         {
             try
             {
-                var tip = MessageShow.Question("确定要执行本层岗位的设备类与Revit设备族编码一致性检查?\r\n设备类与Revit设备族编码不一致,将删除岗位然后重建。");
-                if (tip)
-                    CheckEquipCategory.OperateCurFloor();
+                var tip = MessageShow.Question2("确定要执行本层岗位的设备类与Revit设备族编码一致性检查?\r\n设备类与Revit设备族编码不一致,将删除岗位然后重建。");
+                switch (tip)
+                {
+                    case DialogResult.Yes:
+                        CheckEquipCategory.OperateAll();
+                        break;
+                    case DialogResult.No:
+                        CheckEquipCategory.OperateCurFloor();
+                        break;
+                    default:
+                        break;
+                }
             }
             catch (Exception e)
             {
@@ -272,6 +281,14 @@ namespace SAGA.MBI
             }
             return Result.Succeeded;
         }
+        /// <summary>
+        /// Onlys show the dialog when a document is open, as Dockable dialogs are only available
+        /// when a document is open.
+        /// </summary>
+        public override bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
+        {
+            return true;
+        }
     }
 
     /// <summary>

+ 5 - 0
MBI/SAGA.MBI/ToolsData/CheckEquipCategory.cs

@@ -109,6 +109,7 @@ namespace SAGA.MBI.ToolsData
                 Element elem = doc.GetElement(bimid);
                 if (elem == null) continue;
                 FamilyInstance fi = elem as FamilyInstance;
+                if (fi == null) continue;
                 var code = fi.GetFamilyCode();
                 var cCode = mode.EquipClassCode;
                 if (code != cCode)
@@ -117,6 +118,9 @@ namespace SAGA.MBI.ToolsData
 
                     MEquipment equip = DalEquip.GetEquipment(fi);
                     if (equip == null) continue;
+                    //暂时保留本地名称和本地编码
+                    equip.LocalId = mode.LocalId;
+                    equip.LocalName = mode.LocalName;
                     equip.Operator = DocumentChangedOperator.Add;
                     addContext.MEquipments.Add(equip);
 
@@ -143,6 +147,7 @@ namespace SAGA.MBI.ToolsData
                 Element elem = doc.GetElement(bimid);
                 if (elem == null) continue;
                 FamilyInstance fi = elem as FamilyInstance;
+                if (fi == null) continue;
                 var code = fi.GetFamilyCode();
                 var cCode = mode.EquipClassCode;
                 if (code != cCode)