添加项目文件。
This commit is contained in:
@@ -0,0 +1,125 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Windows.Forms;
|
||||
using KGdev.BI3D.Revit.Common;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace KGdev.BI3D.Revit.Addin.MainWindow.External.BrowserConnector
|
||||
{
|
||||
public class ExternalMainWindow : IMainWindow
|
||||
{
|
||||
public bool IsVisible
|
||||
{
|
||||
get
|
||||
{
|
||||
bool flag = this.browserProcess == null;
|
||||
bool flag2;
|
||||
if (flag)
|
||||
{
|
||||
flag2 = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
bool hasExited = this.browserProcess.HasExited;
|
||||
if (hasExited)
|
||||
{
|
||||
flag2 = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
bool flag3 = this.messageHandler.BrowserHandle == IntPtr.Zero;
|
||||
flag2 = !flag3;
|
||||
}
|
||||
}
|
||||
return flag2;
|
||||
}
|
||||
}
|
||||
|
||||
public ExternalMainWindow(IReduxReducer reducer)
|
||||
{
|
||||
this.reducer = reducer;
|
||||
reducer.OnStateChanged += this.Reducer_OnStateChanged;
|
||||
this.messageHandler.MessageReceivedEvent += this.MessageHandler_MessageReceivedEvent;
|
||||
}
|
||||
|
||||
private void Reducer_OnStateChanged(object sender, Dictionary<string, object> e)
|
||||
{
|
||||
string text = JsonConvert.SerializeObject(e);
|
||||
this.messageHandler.Send(text);
|
||||
}
|
||||
|
||||
private void MessageHandler_MessageReceivedEvent(object sender, MessageReceivedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
string message = e.Message;
|
||||
Dictionary<string, object> dictionary = JsonConvert.DeserializeObject<
|
||||
Dictionary<string, object>
|
||||
>(message);
|
||||
this.reducer.Reduce(dictionary);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(
|
||||
"Something went wrong when processing the request. Please contact info@kg-dev.be."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
bool flag = this.browserProcess == null;
|
||||
if (!flag)
|
||||
{
|
||||
bool hasExited = this.browserProcess.HasExited;
|
||||
if (!hasExited)
|
||||
{
|
||||
this.browserProcess.Kill();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Show()
|
||||
{
|
||||
bool flag = !this.IsVisible;
|
||||
if (flag)
|
||||
{
|
||||
this.CreateNew();
|
||||
}
|
||||
IntPtr browserHandle = this.messageHandler.BrowserHandle;
|
||||
User32.SetForegroundWindow(browserHandle);
|
||||
}
|
||||
|
||||
private void CreateNew()
|
||||
{
|
||||
Process process = new Process();
|
||||
process.StartInfo.FileName = Path.Combine(
|
||||
this.assemblyDirectory,
|
||||
"KGdev.BI3D.Revit.Addin.MainWindow.External.Browser.exe"
|
||||
);
|
||||
process.StartInfo.Arguments = string.Format(
|
||||
"{0} {1}",
|
||||
this.messageHandler.Handle,
|
||||
Process.GetCurrentProcess().Id
|
||||
);
|
||||
process.Start();
|
||||
this.browserProcess = process;
|
||||
}
|
||||
|
||||
private const string BROWSER_EXECUTABLE_RELATIVE_PATH =
|
||||
"KGdev.BI3D.Revit.Addin.MainWindow.External.Browser.exe";
|
||||
|
||||
private readonly MessageHandler messageHandler = new MessageHandler();
|
||||
|
||||
private readonly string assemblyDirectory = Path.GetDirectoryName(
|
||||
new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath
|
||||
);
|
||||
|
||||
private Process browserProcess;
|
||||
|
||||
private IReduxReducer reducer;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user