Repository navigation
Expand file tree
/
Copy pathControlSystem.cs
More file actions
96 lines (87 loc) · 3.41 KB
/
Copy pathControlSystem.cs
File metadata and controls
96 lines (87 loc) · 3.41 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
using Crestron.SimplSharp;
using Crestron.SimplSharp.CrestronIO;
using Crestron.SimplSharpPro;
using Crestron.SimplSharpPro.CrestronThread;
using Serilog;
using WebLogger.Crestron;
using WebLogger.Utilities;
namespace WebLogger.CrestronApp
{
public class ControlSystem : CrestronControlSystem
{
public ControlSystem()
: base()
{
try
{
CrestronEnvironment.ProgramStatusEventHandler += new ProgramStatusEventHandler(ControllerProgramEventHandler);
}
catch (Exception e)
{
ErrorLog.Error("Error in the constructor: {0}", e.Message);
}
}
public override void InitializeSystem()
{
try
{
var commands = new List<IWebLoggerCommand>()
{
new WebLoggerCommand(
(cmd, args) => CommandResponse.Success("EXAMPLE", $"{cmd} Received"),
"EXAMPLE",
"Simple example of console command",
"Parameter: NA"),
new WebLoggerCommand(
(cmd, args) => CommandResponse.Success("TEST", $"{cmd} Received"),
"TEST",
"Simple example of console command",
"Parameter: NA")
};
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Verbose()
.WriteTo.WebloggerSink(
options =>
{
options.Commands = commands;
options.Secured = false;
options.DestinationWebpageDirectory = Crestron.SimplSharp.CrestronIO.Path.Combine(Directory.GetApplicationRootDirectory(), "html/logger");
options.WebSocketTcpPort = 54321;
},
logger =>
{
logger.ServeWebLoggerHtml(8081)
.DiscoverProvidedCommands()
.DiscoverCrestronCommands();
})
.CreateLogger();
}
catch (Exception e)
{
ErrorLog.Error("Error in InitializeSystem: {0}", e.Message);
}
}
/// <summary>
/// Event Handler for Programmatic events: Stop, Pause, Resume.
/// Use this event to clean up when a program is stopping, pausing, and resuming.
/// This event only applies to this SIMPL#Pro program, it doesn't receive events
/// for other programs stopping
/// </summary>
/// <param name="programStatusEventType"></param>
void ControllerProgramEventHandler(eProgramStatusEventType programStatusEventType)
{
switch (programStatusEventType)
{
case (eProgramStatusEventType.Paused):
break;
case (eProgramStatusEventType.Resumed):
break;
case (eProgramStatusEventType.Stopping):
Log.CloseAndFlush();
break;
default:
throw new ArgumentOutOfRangeException(nameof(programStatusEventType), programStatusEventType, null);
}
}
}
}