-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
74 lines (67 loc) · 2.55 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
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TimerAndClock
{
class Program
{
// StreamDeck launches the plugin with these details
// -port [number] -pluginUUID [GUID] -registerEvent [string?] -info [json]
static void Main(string[] args)
{
Task mainTask = MainAsync(args);
mainTask.Wait();
}
static async Task MainAsync(string[] args)
{
// This makes debugging the plug-in much easer.
// Uncomment this line, launch stream deck, add a button, attach debugger
// while (!System.Diagnostics.Debugger.IsAttached) { System.Threading.Thread.Sleep(100); }
ParseArgs(args, out int? port, out string uuid, out string registerEvent, out JObject info);
if (!port.HasValue || string.IsNullOrEmpty(uuid) || string.IsNullOrEmpty(registerEvent) || (info == null))
{
// Failed to get expected arguments
Console.WriteLine("Missing arguments. Expected: -port [number] -pluginUUID [GUID] -registerEvent [string?] -info [json]");
return;
}
TimerAndClockPlugin plugin = new TimerAndClockPlugin();
await plugin.RunAsync(port.Value, uuid, registerEvent);
}
private static void ParseArgs(string[] args, out int? port, out string uuid, out string registerEvent, out JObject info)
{
port = null;
uuid = null;
registerEvent = null;
info = null;
if ((args.Length % 2) != 0)
{
// Expect an even # of args
}
for (int count = 0; count < args.Length; count += 2)
{
switch (args[count].ToLower())
{
case "-port":
int portValue;
if (int.TryParse(args[count + 1], out portValue))
{
port = portValue;
}
break;
case "-pluginuuid":
uuid = args[count + 1];
break;
case "-registerevent":
registerEvent = args[count + 1];
break;
case "-info":
info = JObject.Parse(args[count + 1]);
break;
}
}
}
}
}