Explorar el Código

xls:mbi底层服务类提交

xulisong hace 5 años
padre
commit
4747e7c764

+ 2 - 0
.gitignore

@@ -17,3 +17,5 @@
 /JBIM/RevitExport/obj/
 /JBIM/ServiceDataCheck/obj
 /JBIM/RevitToJBim/bin/x64/Debug
+/JBIM/MBIRevitBase/bin/Debug
+/JBIM/MBIRevitBase/obj/Debug

+ 1 - 1
JBIM/ExportStart/Program.cs

@@ -32,7 +32,7 @@ namespace ExportStart
             var app = RevitCoreContext.Instance.Application;
             var doc = app.OpenDocumentFile(path);
             Export(doc);
-            Check(doc);
+           // Check(doc);
             //Console.WriteLine("RevitVision:"+RevitVisionUtil.GetRevitVision(path));
             Console.ReadKey();
         }

+ 6 - 0
JBIM/JBIM.sln

@@ -13,6 +13,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExportStart", "ExportStart\
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServiceDataCheck", "ServiceDataCheck\ServiceDataCheck.csproj", "{7B748B09-DC20-4406-85A3-101E7833F8CE}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MBIRevitBase", "MBIRevitBase\MBIRevitBase.csproj", "{1A2935EA-3450-4DF3-B7AE-9D67475747E6}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -39,6 +41,10 @@ Global
 		{7B748B09-DC20-4406-85A3-101E7833F8CE}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{7B748B09-DC20-4406-85A3-101E7833F8CE}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{7B748B09-DC20-4406-85A3-101E7833F8CE}.Release|Any CPU.Build.0 = Release|Any CPU
+		{1A2935EA-3450-4DF3-B7AE-9D67475747E6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{1A2935EA-3450-4DF3-B7AE-9D67475747E6}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{1A2935EA-3450-4DF3-B7AE-9D67475747E6}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{1A2935EA-3450-4DF3-B7AE-9D67475747E6}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE

+ 56 - 0
JBIM/MBIRevitBase/BResult.cs

@@ -0,0 +1,56 @@
+/*-------------------------------------------------------------------------
+ * 功能描述:BResult
+ * 作者:xulisong
+ * 创建时间: 2019/7/29 17:54:09
+ * 版本号:v1.0
+ *  -------------------------------------------------------------------------*/
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace MBIRevitBase
+{
+    /// <summary>
+    /// bool类型结果
+    /// </summary>
+    public class BResult
+    {
+        public BResult(bool isSuccessed)
+        {
+            IsSuccessed = isSuccessed;
+        }
+        public BResult(bool isSuccessed, string message) : this(isSuccessed)
+        {
+            Message = message;
+        }
+        public bool IsSuccessed { get; private set; }
+        public string Id { get; set; }
+        public string Message { get; set; }
+
+        /// <summary>
+        /// tag
+        /// </summary>
+        public object Tag { get; set; }
+
+        public static implicit operator bool(BResult result)
+        {
+            return result.IsSuccessed;
+        }
+        public static implicit operator BResult(bool d)
+        {
+            return new BResult(d);
+        }
+        public static implicit operator BResult(string errorMessage)
+        {
+            //有消息,则隐式转换成错误结果
+            return new BResult(false, errorMessage);
+        }
+        public override string ToString()
+        {
+            return Message ?? string.Empty;
+        }
+    }
+}

+ 52 - 0
JBIM/MBIRevitBase/MBIRevitBase.csproj

@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProjectGuid>{1A2935EA-3450-4DF3-B7AE-9D67475747E6}</ProjectGuid>
+    <OutputType>Library</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>MBIRevitBase</RootNamespace>
+    <AssemblyName>MBIRevitBase</AssemblyName>
+    <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+    <Deterministic>true</Deterministic>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="System" />
+    <Reference Include="System.Core" />
+    <Reference Include="System.IO.Compression" />
+    <Reference Include="System.IO.Compression.FileSystem" />
+    <Reference Include="System.Xml.Linq" />
+    <Reference Include="System.Data.DataSetExtensions" />
+    <Reference Include="Microsoft.CSharp" />
+    <Reference Include="System.Data" />
+    <Reference Include="System.Net.Http" />
+    <Reference Include="System.Xml" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="BResult.cs" />
+    <Compile Include="Tools\HttpUtils.cs" />
+    <Compile Include="Tools\ZipUtils.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+</Project>

+ 36 - 0
JBIM/MBIRevitBase/Properties/AssemblyInfo.cs

@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// 有关程序集的一般信息由以下
+// 控制。更改这些特性值可修改
+// 与程序集关联的信息。
+[assembly: AssemblyTitle("MBIRevitBase")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("MBIRevitBase")]
+[assembly: AssemblyCopyright("Copyright ©  2019")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// 将 ComVisible 设置为 false 会使此程序集中的类型
+//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
+//请将此类型的 ComVisible 特性设置为 true。
+[assembly: ComVisible(false)]
+
+// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
+[assembly: Guid("1a2935ea-3450-4df3-b7ae-9d67475747e6")]
+
+// 程序集的版本信息由下列四个值组成: 
+//
+//      主版本
+//      次版本
+//      生成号
+//      修订号
+//
+// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
+//通过使用 "*",如下所示:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]

+ 61 - 0
JBIM/MBIRevitBase/Tools/HttpUtils.cs

@@ -0,0 +1,61 @@
+/*-------------------------------------------------------------------------
+ * 功能描述:HttpUtils
+ * 作者:xulisong
+ * 创建时间: 2019/7/29 10:16:56
+ * 版本号:v1.0
+ *  -------------------------------------------------------------------------*/
+
+using System;
+using System.Diagnostics;
+using System.IO;
+using System.Net.Http;
+
+namespace MBIRevitBase.Tools
+{
+    /// <summary>
+    /// HttpUtils信息处理
+    /// </summary>
+    public class HttpUtils
+    {
+        private static HttpClient m_Client;
+        /// <summary>
+        /// 创建HttpClient,单例对象生成
+        /// </summary>
+        /// <returns></returns>
+        public static HttpClient CreateClient()
+        {
+            if (m_Client == null)
+            {
+                m_Client = new HttpClient();
+            }
+            return m_Client;
+        }
+        public const string WebKitFormBoundary = "----WebKitFormBoundary";
+        public static BResult PostFormDataFile(string url,Stream stream)
+        {
+            using (HttpClient client = CreateClient())
+            {
+                string boundary = string.Format("{0}{1}", WebKitFormBoundary, DateTime.Now.Ticks.ToString("x"));
+                MultipartFormDataContent content = new MultipartFormDataContent(boundary);
+                #region Stream请求
+                var streamContent = new StreamContent(stream);
+                content.Add(streamContent, "file");
+                #endregion
+                var result = client.PostAsync(url, content).Result;
+                try
+                {
+                    if (result.IsSuccessStatusCode)
+                    {
+                        string rslt = result.Content.ReadAsStringAsync().Result;
+                        return new BResult(true,rslt);
+                    }
+                }
+                finally
+                {
+                    client.Dispose();
+                }
+            }
+            return string.Empty;        
+        }
+    }
+}

+ 35 - 0
JBIM/MBIRevitBase/Tools/ZipUtils.cs

@@ -0,0 +1,35 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.IO.Compression;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace MBIRevitBase.Tools
+{
+    public static class ZipUtils
+    {
+        /// <summary>
+        /// 压缩zip字符串流
+        /// </summary>
+        /// <param name="data"></param>
+        /// <param name="fileName"></param>
+        /// <returns></returns>
+        public static Stream ZipString(string data,string fileName)
+        {
+            MemoryStream zipStream = new MemoryStream();
+            using (ZipArchive zipArchive = new ZipArchive(zipStream, ZipArchiveMode.Create, true))
+            {
+                ZipArchiveEntry entry = zipArchive.CreateEntry(fileName);
+                using (StreamWriter writer = new StreamWriter(entry.Open()))
+                {
+                    writer.Write(data);
+                }
+                //zipArchive释放才会写入相关流
+            }
+            zipStream.Seek(0, SeekOrigin.Begin);
+            return zipStream;
+        }
+    }
+}

+ 5 - 1
JBIM/RevitToJBim/MbiExport.cs

@@ -16,6 +16,7 @@ using Autodesk.Revit.DB;
 using Autodesk.Revit.DB.Mechanical;
 using Autodesk.Revit.DB.Plumbing;
 using Autodesk.Revit.UI;
+using MBIRevitBase.Tools;
 using RevitExport;
 using RevitExport.Export;
 using RevitToJBim.ComponentParse;
@@ -47,9 +48,12 @@ namespace RevitToJBim
                  * 增加一些和JBIM无关,又和当前业务逻辑相关的属性
                  */
                 var result = BimJsonUtil.Serializer(mbiDocument);
+                var stream = ZipUtils.ZipString(result,"export.json");
+               
+                var resultResponse=HttpUtils.PostFormDataFile("http://192.168.20.225:8080/revit-algorithm/upload-json-zip/upload", stream);
                 string fileName = DateTime.Now.ToString("yyyyMMddHHmmss");
                 string path = Path.Combine(@"D:\", $"{fileName}.json");
-                File.WriteAllText(path, result);
+                File.WriteAllText(path, resultResponse);
                 System.Diagnostics.Process.Start("notepad.exe", path);
             }
             catch (Exception ex)

+ 4 - 0
JBIM/RevitToJBim/RevitToJBim.csproj

@@ -114,6 +114,10 @@
       <Project>{a6a90bfe-126d-4499-860a-f0e2c40ebb23}</Project>
       <Name>JBIM</Name>
     </ProjectReference>
+    <ProjectReference Include="..\MBIRevitBase\MBIRevitBase.csproj">
+      <Project>{1a2935ea-3450-4df3-b7ae-9d67475747e6}</Project>
+      <Name>MBIRevitBase</Name>
+    </ProjectReference>
     <ProjectReference Include="..\RevitExport\RevitExport.csproj">
       <Project>{825b43f4-1f7b-44ac-9bd4-501de9422d32}</Project>
       <Name>RevitExport</Name>