-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
76 lines (68 loc) · 2.61 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using System;
using System.Reflection;
namespace HSPI_WebSocket2
{
class Program
{
// our homeseer connection details - we can get these from the console arguments too
private const string serverAddress = "127.0.0.1";
private const int serverPort = 10400;
static void Main(string[] args)
{
if (AppDomain.CurrentDomain.IsDefaultAppDomain())
{
AppDomainSetup appSetup = new AppDomainSetup()
{
ApplicationName = "WebSocketDomain",
ApplicationBase = AppDomain.CurrentDomain.BaseDirectory,
PrivateBinPath = @"bin/WebSocket",
ConfigurationFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile
};
var currentAssembly = Assembly.GetExecutingAssembly();
var otherDomain = AppDomain.CreateDomain("WebSocketDomain", null, appSetup);
var ret = otherDomain.ExecuteAssemblyByName(
currentAssembly.FullName,
//currentAssembly.Evidence,
args);
Environment.ExitCode = ret;
return;
}
// create an instance of our plugin.
HSPI myPlugin = new HSPI();
try
{
myPlugin.Connect(serverAddress, serverPort);
}
catch (Exception ex)
{
Console.WriteLine(" connection to homeseer failed: " + ex.Message);
return;
}
// let the plugin do it's thing, wait until it shuts down or the connection to homeseer fails.
try
{
while (true)
{
// do nothing for a bit
System.Threading.Thread.Sleep(200);
// test the connection to homeseer
if (!myPlugin.Connected)
{
Console.WriteLine("Connection to homeseer lost, exiting");
break;
}
// test for a shutdown signal
else if (myPlugin.Shutdown)
{
Console.WriteLine("Plugin has been shut down, exiting");
break;
}
}
}
catch (Exception ex)
{
Console.WriteLine("Unhandled exception from Plugin: " + ex.Message);
}
}
}
}