Browse Source

mxg:添加Client后台运行

mengxiangge 5 years ago
parent
commit
fef51e88a7

+ 1 - 0
.gitignore

@@ -28,3 +28,4 @@
 /Executer/OutputDll
 /Starter/Starter/obj/Release
 /Starter/StartVisionSelector/obj/Release
+/OutputDll - Test

+ 0 - 24
Dispatcher/Client/Class1.cs

@@ -1,24 +0,0 @@
-using System;
-using System.Windows.Forms;
-using Client.Start;
-
-namespace Client
-{
-    public class Class1
-    {
-        public static void Main()
-        {
-            try
-            {
-                ServiceMBIClientHandler.Start();
-            }
-            catch (Exception ex)
-            {
-
-                MessageBox.Show(ex.Message);
-            }
-
-            Console.ReadKey();
-        }
-    }
-}

+ 2 - 1
Dispatcher/Client/Client.csproj

@@ -83,6 +83,7 @@
     </Reference>
     <Reference Include="System.ComponentModel.Composition" />
     <Reference Include="System.ComponentModel.DataAnnotations" />
+    <Reference Include="System.Configuration" />
     <Reference Include="System.Core" />
     <Reference Include="System.Diagnostics.DiagnosticSource, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
       <HintPath>..\packages\System.Diagnostics.DiagnosticSource.4.3.0\lib\net46\System.Diagnostics.DiagnosticSource.dll</HintPath>
@@ -110,7 +111,7 @@
     <Reference Include="System.Xml" />
   </ItemGroup>
   <ItemGroup>
-    <Compile Include="Class1.cs" />
+    <Compile Include="MainClass.cs" />
     <Compile Include="ClientApp.cs" />
     <Compile Include="ClientInfo.cs" />
     <Compile Include="IRevitCommandExcutor.cs" />

+ 50 - 0
Dispatcher/Client/MainClass.cs

@@ -0,0 +1,50 @@
+using System;
+using System.Runtime.InteropServices;
+using System.Threading;
+using System.Windows.Forms;
+using Client.Start;
+
+namespace Client
+{
+    public class MainClass
+    {
+        public static void Main()
+        {
+            try
+            {
+                //Client后台运行
+                new MainClass();
+                ServiceMBIClientHandler.Start();
+            }
+            catch (Exception ex)
+            {
+                Console.WriteLine(ex.Message);
+            }
+
+            Console.ReadKey();
+        }
+        [DllImport("User32.dll", EntryPoint = "FindWindow")]
+        private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
+
+        [DllImport("user32.dll", EntryPoint = "FindWindowEx")]   //找子窗体   
+        private static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
+
+        [DllImport("User32.dll", EntryPoint = "SendMessage")]   //用于发送信息给窗体   
+        private static extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, string lParam);
+
+        [DllImport("User32.dll", EntryPoint = "ShowWindow")]   //
+        private static extern bool ShowWindow(IntPtr hWnd, int type);
+
+        public MainClass()
+        {
+            Console.Title = "MyConsoleApp";
+            IntPtr ParenthWnd = new IntPtr(0);
+            IntPtr et = new IntPtr(0);
+            ParenthWnd = FindWindow(null, "MyConsoleApp");
+
+            ShowWindow(ParenthWnd, 0);//隐藏本dos窗体, 0: 后台执行;1:正常启动;2:最小化到任务栏;3:最大化
+            
+
+        }
+    }
+}

+ 1 - 1
Dispatcher/Client/Start/RevitCmdExecutor.cs

@@ -53,7 +53,7 @@ namespace Client.Start
                 //执行完成后,删除文件
                 foreach (var f in filePathList)
                 {
-                    File.Delete(f);
+                    //File.Delete(f);
                 }
             }
             catch (Exception e)

+ 8 - 1
Dispatcher/Client/Start/ServiceMBIClientHandler.cs

@@ -8,6 +8,7 @@ using System;
 using System.Windows.Forms;
 using TaskDatabase;
 using TaskDatabase.Model;
+using System.Configuration;
 
 namespace Client.Start
 {
@@ -19,8 +20,14 @@ namespace Client.Start
         private static ClientApp m_Client;
         public static void Start()
         {
+            string ip = ConfigurationManager.AppSettings["IP"];
+            Console.WriteLine(ip);
+            int port = Convert.ToInt32(ConfigurationManager.AppSettings["Port"]);
+            string dir = ConfigurationManager.AppSettings["DownloadFileDir"];
+            int maxtask = Convert.ToInt32(ConfigurationManager.AppSettings["MaxTaskCount"]);
+            int maxDownloadTask = Convert.ToInt32(ConfigurationManager.AppSettings["MaxDownloadTaskCount"]);
             //192.168.20.225
-            m_Client = new ClientApp("192.168.20.225", 6666, "E:\\", 3, new RevitCmdExecutor(), 5);
+            m_Client = new ClientApp(ip, port, dir, maxtask, new RevitCmdExecutor(), maxDownloadTask);
             m_Client.Start();
             //Console.ReadKey();
         }

+ 11 - 1
Dispatcher/Client/app.config

@@ -1,5 +1,12 @@
 <?xml version="1.0" encoding="utf-8"?>
 <configuration>
+  <appSettings>
+    <add key="IP" value="47.94.18.1"/>
+    <add key="Port" value="6666"/>
+    <add key="DownloadFileDir" value="E:\\"/>
+    <add key="MaxTaskCount" value="3"/>
+    <add key="MaxDownloadTaskCount" value="6"/>
+  </appSettings>
   <runtime>
     <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
       <dependentAssembly>
@@ -68,4 +75,7 @@
       </dependentAssembly>
     </assemblyBinding>
   </runtime>
-<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" /></startup></configuration>
+  <startup>
+    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
+  </startup>
+</configuration>

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

@@ -48,7 +48,7 @@ namespace RevitToJBim
                 //保存到本地
                 string fileName = DateTime.Now.ToString("yyyyMMddHHmmss");
                 string path = Path.Combine($"{document.PathName}_{fileName}.json");
-                File.WriteAllText(path, json.ToString());
+                //File.WriteAllText(path, json.ToString());
             }
             catch (Exception ex)
             {

+ 1 - 1
Starter/Starter/Program.cs

@@ -39,7 +39,7 @@ namespace ExportStart
                 command = "DataExport";
                 path = @"E:\导出测试\testR17.rvt";
                 path = @"E:\导出测试\延庆园-B1.rvt";
-                path = @"E:\导出测试\spacezero.rvt";
+                path = @"E:\导出测试\abc.rvt";
                 JObject jObject=new JObject();
                 jObject.Add("ResultFileName", @"C:\Users\SAGACLOUD\AppData\Local\RevitService\Result_e26be2fd-2097-462b-bdd0-a2a86b616928.txt");
                 param = jObject.ToString();