Ver código fonte

mxg:添加try catch

mengxiangge 5 anos atrás
pai
commit
be8cea3f25

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

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

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

@@ -43,6 +43,7 @@ namespace RevitToJBim
                  * 增加一些和JBIM无关,又和当前业务逻辑相关的属性
                  * 增加一些和JBIM无关,又和当前业务逻辑相关的属性
                  */
                  */
                 var json = BimJsonUtil.Serializer(mbiDocument);
                 var json = BimJsonUtil.Serializer(mbiDocument);
+                //var json = File.ReadAllText(@"C:\Users\SAGACLOUD\Desktop\新建文件夹\88.rvt_20191220105510.json");
 #if DEBUG
 #if DEBUG
                 //保存到本地
                 //保存到本地
                 string fileName = DateTime.Now.ToString("yyyyMMddHHmmss");
                 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)
         public static BResult UploadExportFile(string result)
         {
         {
-            return DelayRetryPolicy(result);
+            var tt= DelayRetryPolicy(result);
+            return tt;
         }
         }
         /// <summary>
         /// <summary>
         /// 上传导出文件
         /// 上传导出文件
@@ -37,8 +38,8 @@ namespace MBIRevitBase.Services
         {
         {
             var stream = ZipUtils.ZipString(result, "export.json");
             var stream = ZipUtils.ZipString(result, "export.json");
             var url = ApiConfig.AlgorithmUrl();
             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)
         static BResult DelayRetryPolicy(string result)

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

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

+ 2 - 2
Starter/Starter/Program.cs

@@ -41,8 +41,8 @@ namespace ExportStart
                 //command = "DataCheck";
                 //command = "DataCheck";
                 path = @"E:\导出测试\testSpace.rvt";
                 path = @"E:\导出测试\testSpace.rvt";
                 path = @"E:\导出测试\系统图修改编码版\给排水系统图模型第一版V1129.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 jObject = new JObject();
                 jObject.Add("ResultFileName", @"C:\Users\SAGACLOUD\AppData\Local\RevitService\Result_e26be2fd-2097-462b-bdd0-a2a86b616928.txt");
                 jObject.Add("ResultFileName", @"C:\Users\SAGACLOUD\AppData\Local\RevitService\Result_e26be2fd-2097-462b-bdd0-a2a86b616928.txt");
                 param = jObject.ToString();
                 param = jObject.ToString();