-
Notifications
You must be signed in to change notification settings - Fork 1
/
GardenGateway.cs
103 lines (82 loc) · 3.27 KB
/
GardenGateway.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#define DEBUG // remove on build
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SEGarden.Files;
using SEGarden.Chat;
using SEGarden.Messaging;
using SEGarden.Logging;
using SEGarden.Logic;
using SEGarden.Testing;
using SEGarden.Tests.Definitions;
namespace SEGarden {
///<summary>
/// Public MyAPIGateway helpers
/// </summary>
/// <remarks>
/// TODO: Should we further hide these in their own static classes
/// so we can stop from exposing their Initialize and Terminate methods?
///
/// We could make them their own session components, problem solved
///
/// On the other hand, it's nice to have them all centralized for access
/// And the fact that they depend on initialization is nicely apparent
/// But ComponentManager needs to be accessed the other way.
/// Logic might be clearer to just have them all work like that
/// Or we could provide a layer over component manager to hide its dangerous
/// public methods
///
/// NVM, no matter what initialize and terminate for the components will have
/// to be public. There's really no way around this.
///
/// TODO: Provide thread-safety for anything accessed through here
///
/// IMPORTANT: Files needs to be constructed first, initialized first, and
/// terminated last, because all logging depends on it.
/// </remarks>
class GardenGateway : SessionComponent {
public override string ComponentName { get { return "GardenGateway"; } }
private static Logger Log = new Logger("SEGarden.GardenGateway");
public static FileManager Files { get; private set; }
public static ChatManager Commands { get; private set; }
public static MessageManager Messages { get; private set; }
public static RunLocation RunningOn { get; private set; }
/// <summary>
/// This only needs to be called from ComponentManager
/// </summary>
public override void Initialize() {
SetDebugConditional();
RunningOn = CurrentLocation;
Files = new FileManager();
Files.Initialize(); // logging depends on this
Log.Info("Starting SE Garden v" + ModInfo.Version, "");
Commands = new ChatManager();
Commands.Initialize();
Messages = new MessageManager();
Messages.Initialize();
if (ModInfo.DebugMode) {
Specification.RunSpecTests(
"SEGarden",
new List<Specification>() {
new ItemCountAggregateDefinitionSpec(),
new ItemCountDefinitionSpec()
}
);
}
base.Initialize();
}
/// <summary>
/// This only needs to be called from ComponentManager
/// </summary>
public override void Terminate() {
Log.Info("Stopping SE Garden.", "");
Commands.Terminate();
Messages.Terminate();
Files.Terminate(); // logging depends on this
base.Terminate();
}
[System.Diagnostics.Conditional("DEBUG")]
private static void SetDebugConditional() { ModInfo.DebugMode = true; }
}
}