Browse Source

mxg:添加try catch

mengxiangge 5 years ago
parent
commit
be8cea3f25

+ 8 - 2
Executer/DataExport/RevitToJBim/MBI/MBIDocument.cs

@@ -50,10 +50,16 @@ namespace RevitToJBim.MBI
             MBIDocument dto = new MBIDocument();
             JObject jObject = JObject.Parse(param);
 
+#if DEBUG
+            //dto.MBIName = "Pj1101010038";//待读取
+            //dto.ModelId = "47e62800220811ea962a7d2b043144ce";
+#else
             dto.MBIName = jObject.GetValueEx("MBIName");//待读取
             dto.ModelId = jObject.GetValueEx("ModelId");
-            //dto.MBIName = "Pj1101010015";//待读取
-            //dto.ModelId = "6d8642d9d92a11e98e2d2108fa0baa21";
+#endif
+
+
+
             dto.PlanName = document.GetUseView()?.Name;
             dto.BaseLevel = document.GetUseView()?.GenLevel.Elevation.FromApi().Round(2)??0;
             return dto;

+ 1 - 0
Executer/DataExport/RevitToJBim/MbiExport.cs

@@ -43,6 +43,7 @@ namespace RevitToJBim
                  * 增加一些和JBIM无关,又和当前业务逻辑相关的属性
                  */
                 var json = BimJsonUtil.Serializer(mbiDocument);
+                //var json = File.ReadAllText(@"C:\Users\SAGACLOUD\Desktop\新建文件夹\88.rvt_20191220105510.json");
 #if DEBUG
                 //保存到本地
                 string fileName = DateTime.Now.ToString("yyyyMMddHHmmss");

+ 4 - 3
Executer/MBIRevitBase/Services/UploadService.cs

@@ -26,7 +26,8 @@ namespace MBIRevitBase.Services
     {
         public static BResult UploadExportFile(string result)
         {
-            return DelayRetryPolicy(result);
+            var tt= DelayRetryPolicy(result);
+            return tt;
         }
         /// <summary>
         /// 上传导出文件
@@ -37,8 +38,8 @@ namespace MBIRevitBase.Services
         {
             var stream = ZipUtils.ZipString(result, "export.json");
             var url = ApiConfig.AlgorithmUrl();
-            
-            return HttpUtils.PostFormDataFileThrowException(url, stream) as T;
+            var tt= HttpUtils.PostFormDataFileThrowException(url, stream) as T;
+            return tt;
         }
 
         static BResult DelayRetryPolicy(string result)

+ 11 - 3
Executer/MBIRevitBase/Tools/HttpUtils.cs

@@ -72,6 +72,7 @@ namespace MBIRevitBase.Tools
         /// <returns></returns>
         public static BResult PostFormDataFileThrowException(string url, Stream stream)
         {
+            BResult rslt= (BResult)string.Empty;
             using (HttpClient client = CreateClient())
             {
                 try
@@ -80,10 +81,13 @@ namespace MBIRevitBase.Tools
                     client.Timeout = new TimeSpan(0, 30, 0);
                     string boundary = string.Format("{0}{1}", WebKitFormBoundary, DateTime.Now.Ticks.ToString("x"));
                     MultipartFormDataContent content = new MultipartFormDataContent(boundary);
+
                     #region Stream请求
+
                     var streamContent = new StreamContent(stream);
                     //"file.zip"必须有,它的格式可能影响到内部的一些配置
                     content.Add(streamContent, "file", "file.zip");
+
                     #endregion
 
                     var tt = client.PostAsync(url, content);
@@ -91,20 +95,24 @@ namespace MBIRevitBase.Tools
 
                     if (result.IsSuccessStatusCode)
                     {
-                        string rslt = result.Content.ReadAsStringAsync().Result;
-                        return ((HttpResult)rslt);
+                        rslt = (HttpResult) result.Content.ReadAsStringAsync().Result;
                     }
                     else
                     {
                         throw new Exception(result.ToString());
                     }
                 }
+                catch (Exception e)
+                {
+                    throw new Exception(e.ToString());
+                }
                 finally
                 {
                     client.Dispose();
                 }
             }
-            return string.Empty;
+
+            return rslt;
 
         }
     }

+ 2 - 2
Starter/Starter/Program.cs

@@ -41,8 +41,8 @@ namespace ExportStart
                 //command = "DataCheck";
                 path = @"E:\导出测试\testSpace.rvt";
                 path = @"E:\导出测试\系统图修改编码版\给排水系统图模型第一版V1129.rvt";
-                path = @"C:\Users\SAGACLOUD\Desktop\新建文件夹\b1-2172005.rvt";
-                path = @"C:\Users\SAGACLOUD\Desktop\a1.json";
+                path = @"C:\Users\SAGACLOUD\Desktop\新建文件夹\88.rvt";
+                //path = @"D:\安装包\CAD\测试模型\F4测试.rvt";
                 JObject jObject = new JObject();
                 jObject.Add("ResultFileName", @"C:\Users\SAGACLOUD\AppData\Local\RevitService\Result_e26be2fd-2097-462b-bdd0-a2a86b616928.txt");
                 param = jObject.ToString();