Skip to content

Commit 2ec3892

Browse files
committed
working with the spooler
1 parent 0a1701e commit 2ec3892

File tree

8 files changed

+273
-319
lines changed

8 files changed

+273
-319
lines changed

Application/Configuration/Extensions/KeyExtensions.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ public static String ServiceStartup(this Key junk) {
5050
return "ServiceStartup";
5151
}
5252

53+
public static String ServiceCustom(this Key junk) {
54+
return "ServiceCustom";
55+
}
56+
5357
public static String ServiceShutdown(this Key junk) {
5458
return "ServiceShutdown";
5559
}

Application/Configuration/Messages/Messages.cs

Lines changed: 25 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -28,105 +28,53 @@ public void Load(IConfiguration config) {
2828
var key = config.Key;
2929
var section = config.Section;
3030

31-
config.AddKey(
32-
section.Messages(),
33-
key.InvalidOperation(),
34-
"Invalid operation"
35-
);
36-
37-
config.AddKey(
38-
section.Messages(),
39-
key.InvalidOption(),
40-
"Invalid option: {0}"
41-
);
42-
43-
config.AddKey(
44-
section.Messages(),
45-
key.InvalidOptionsNoValue(),
46-
"Expecting a value after option \"{0}\", found \"{1}\""
47-
);
48-
49-
config.AddKey(
50-
section.Messages(),
51-
key.InvalidOptionsUnknowOption(),
52-
"Unsupported using bundled options \"{0}\" that requires a value"
53-
);
54-
55-
config.AddKey(
56-
section.Messages(),
57-
key.ServiceStartup(),
58-
"Service has been started"
59-
);
31+
config.AddKey(section.Messages(), key.InvalidOperation(), "Invalid operation.");
32+
config.AddKey(section.Messages(), key.InvalidOption(), "Invalid option: {0}.");
6033

61-
config.AddKey(
62-
section.Messages(),
63-
key.ServicePaused(),
64-
"Service has been paused"
34+
config.AddKey(section.Messages(), key.InvalidOptionsNoValue(),
35+
"Expecting a value after option \"{0}\", found \"{1}\"."
6536
);
6637

67-
config.AddKey(
68-
section.Messages(),
69-
key.ServiceResumed(),
70-
"Service has been resumed"
38+
config.AddKey(section.Messages(), key.InvalidOptionsUnknowOption(),
39+
"Unsupported using bundled options \"{0}\" that requires a value."
7140
);
7241

73-
config.AddKey(
74-
section.Messages(),
75-
key.ServiceStopped(),
76-
"Service has been stopped"
77-
);
78-
79-
config.AddKey(
80-
section.Messages(),
81-
key.ServiceShutdown(),
82-
"Service has been shutdown"
83-
);
42+
config.AddKey(section.Messages(), key.ServiceStartup(), "Service has been started.");
43+
config.AddKey(section.Messages(), key.ServicePaused(), "Service has been paused.");
44+
config.AddKey(section.Messages(), key.ServiceResumed(), "Service has been resumed.");
45+
config.AddKey(section.Messages(), key.ServiceStopped(), "Service has been stopped.");
46+
config.AddKey(section.Messages(), key.ServiceShutdown(), "Service has been shutdown.");
47+
config.AddKey(section.Messages(), key.ServiceCustom(), "Service received a custom command: {0}.");
8448

85-
config.AddKey(
86-
section.Messages(),
87-
key.ServiceImplementation(),
88-
"IWindowsService cannot be null in call to GenericWindowsService"
49+
config.AddKey(section.Messages(), key.ServiceImplementation(),
50+
"IWindowsService cannot be null in call to GenericWindowsService."
8951
);
9052

91-
config.AddKey(
92-
section.Messages(),
93-
key.IWindowsServiceImplementation(),
94-
"IWindowsService implementer {0} must have a WindowsServiceAttribute"
53+
config.AddKey(section.Messages(), key.IWindowsServiceImplementation(),
54+
"IWindowsService implementer {0} must have a WindowsServiceAttribute."
9555
);
9656

97-
config.AddKey(
98-
section.Messages(),
99-
key.IWindowsServiceType(),
100-
"Type to install must implement IWindowsService: \"{0}\""
57+
config.AddKey(section.Messages(), key.IWindowsServiceType(),
58+
"Type to install must implement IWindowsService: \"{0}\"."
10159
);
10260

103-
config.AddKey(
104-
section.Messages(),
105-
key.WindowsServiceAttribute(),
106-
"Type to install must be marked with a WindowsServiceAttribute: \"{0}\""
61+
config.AddKey(section.Messages(), key.WindowsServiceAttribute(),
62+
"Type to install must be marked with a WindowsServiceAttribute: \"{0}\"."
10763
);
10864

109-
config.AddKey(
110-
section.Messages(),
111-
key.ProcessInterrupt(),
112-
"Process interrupted by signal {0}"
65+
config.AddKey(section.Messages(), key.ProcessInterrupt(),
66+
"Process interrupted by signal {0}."
11367
);
11468

115-
config.AddKey(
116-
section.Messages(),
117-
key.NoLogConf(),
69+
config.AddKey(section.Messages(), key.NoLogConf(),
11870
"The configuration file: \"{0}\", doesn't exist."
11971
);
12072

121-
config.AddKey(
122-
section.Messages(),
123-
key.InvLogType(),
73+
config.AddKey(section.Messages(), key.InvLogType(),
12474
"Invalid log type: {0}, should be \"console\", \"file\", \"json\" or \"event\"."
12575
);
12676

127-
config.AddKey(
128-
section.Messages(),
129-
key.UnknownCommand(),
77+
config.AddKey(section.Messages(), key.UnknownCommand(),
13078
"I didn't understand that command."
13179
);
13280

Network/STOMP/Client.cs

Lines changed: 40 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using XAS.Core.Exceptions;
88
using XAS.Core.Configuration;
99
using XAS.Core.Configuration.Extensions;
10+
using XAS.Network.Configuration.Extensions;
1011

1112
namespace XAS.Network.STOMP {
1213

@@ -128,17 +129,17 @@ public void Send(Frame frame) {
128129

129130
log.Debug(frame.ToString());
130131

131-
this.Send(frame.ToArray());
132+
Send(frame.ToArray());
132133

133134
}
134135

135136
#region Delegate Methods
136137

137-
private new void OnException(Exception ex) {
138+
public new void OnException(Exception ex) {
138139

139140
log.Trace("Entering OnException()");
140141

141-
//this.Cancellation.Cancel();
142+
handler.Exceptions(ex);
142143

143144
log.Trace("Leaving OnException()");
144145

@@ -155,15 +156,18 @@ public void Send(Frame frame) {
155156

156157
log.Trace("Entering OnConnect()");
157158

158-
this.StartDispatch();
159-
this.Receive();
160-
this.Send(
159+
var key = config.Key;
160+
161+
log.InfoMsg(key.ServerConnect(), Server, Port);
162+
163+
StartDispatch();
164+
Send(
161165
stomp.Connect(
162-
login: this.Username,
163-
passcode: this.Password,
164-
virtualhost: this.VirtualHost,
165-
acceptable: this.Level.ToString(),
166-
level: this.Level.ToString()
166+
login: Username,
167+
passcode: Password,
168+
virtualhost: VirtualHost,
169+
acceptable: Level.ToString(),
170+
level: Level.ToString()
167171
)
168172
);
169173

@@ -209,7 +213,17 @@ public void Send(Frame frame) {
209213

210214
log.Trace("Entering OnDisconnect()");
211215

212-
this.StopDispatch();
216+
var key = config.Key;
217+
218+
log.WarnMsg(key.ServerDisconnect(), Server);
219+
220+
StopDispatch();
221+
222+
if (! Cancellation.IsCancellationRequested) {
223+
224+
Reconnect();
225+
226+
}
213227

214228
log.Trace("Leaving OnDisconnect()");
215229

@@ -222,14 +236,8 @@ private void StartDispatch() {
222236

223237
log.Trace("Entering StartDispatch()");
224238

225-
if (this.Cancellation.IsCancellationRequested) {
226-
227-
this.Cancellation = new CancellationTokenSource();
228-
229-
}
230-
231-
this.dispatchTask = new Task(this.Dispatch, this.Cancellation.Token, TaskCreationOptions.LongRunning);
232-
this.dispatchTask.Start();
239+
dispatchTask = new Task(Dispatch, Cancellation.Token, TaskCreationOptions.LongRunning);
240+
dispatchTask.Start();
233241

234242
log.Trace("Leaving StartDispatch()");
235243

@@ -239,12 +247,13 @@ private void StopDispatch() {
239247

240248
log.Trace("Entering StopDispatch()");
241249

242-
if (this.dispatchTask != null) {
250+
if (dispatchTask != null) {
251+
252+
Task[] tasks = { dispatchTask };
243253

244-
Task[] tasks = { this.dispatchTask };
254+
Cancellation.Cancel(true);
255+
dispatchEvent.Set();
245256

246-
this.Cancellation.Cancel(true);
247-
this.dispatchEvent.Set();
248257
Task.WaitAll(tasks);
249258

250259
}
@@ -263,7 +272,7 @@ private void Dispatch() {
263272

264273
Frame frame;
265274

266-
if (this.Cancellation.Token.IsCancellationRequested) {
275+
if (Cancellation.Token.IsCancellationRequested) {
267276

268277
log.Debug("Dispatch() - cancellation requested");
269278
break;
@@ -272,7 +281,7 @@ private void Dispatch() {
272281

273282
while (frames.TryDequeue(out frame)) {
274283

275-
if (this.Cancellation.Token.IsCancellationRequested) {
284+
if (Cancellation.Token.IsCancellationRequested) {
276285

277286
log.Debug("Dispatch() - cancellation requested");
278287
break;
@@ -282,27 +291,27 @@ private void Dispatch() {
282291
switch (frame.Command) {
283292
case "CONNECTED":
284293
log.Debug("Dispatch() - received a \"CONNECTED\" message");
285-
this.OnStompConnected(frame);
294+
OnStompConnected(frame);
286295
break;
287296

288297
case "MESSAGE":
289298
log.Debug("Dispatch() - received a \"MESSAGE\" message");
290-
this.OnStompMessage(frame);
299+
OnStompMessage(frame);
291300
break;
292301

293302
case "RECEIPT":
294303
log.Debug("Dispatch() - received a \"RECEIPT\" message");
295-
this.OnStompReceipt(frame);
304+
OnStompReceipt(frame);
296305
break;
297306

298307
case "ERROR":
299308
log.Debug("Dispatch() - received a \"ERROR\" message");
300-
this.OnStompError(frame);
309+
OnStompError(frame);
301310
break;
302311

303312
default:
304313
log.Debug("Dispatch() - received a \"NOOP\" message");
305-
this.OnStompNoop(frame);
314+
OnStompNoop(frame);
306315
break;
307316

308317
}

ServiceSpooler/Configuration/Messages/Messages.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@ public void Load(IConfiguration config) {
2929
var key = config.Key;
3030
var section = config.Section;
3131

32-
config.AddKey(section.Messages(), key.UnlinkFile(), "Removed file \"{0}\"");
33-
config.AddKey(section.Messages(), key.Disconnected(), "Disconnected from {0}");
34-
config.AddKey(section.Messages(), key.CorruptFile(), "Corrupted file \"{0}\"");
35-
config.AddKey(section.Messages(), key.Connected(), "Connected to {0} on port {1}");
36-
config.AddKey(section.Messages(), key.ProtocolError(), "Protocol error: {0} - {1}");
37-
config.AddKey(section.Messages(), key.NoData(), "Empty file \"{0}\", for queue {1}");
38-
config.AddKey(section.Messages(), key.WatchDirectory(), "Watching directory \"{0}\"");
39-
config.AddKey(section.Messages(), key.NoDirectory(), "Directory \"{0}\" was not found");
40-
config.AddKey(section.Messages(), key.FileFound(), "Found file \"{0}\", queuing to {1}");
41-
config.AddKey(section.Messages(), key.UnknownFile(), "\"{0}\" is from an unwatched directory");
32+
config.AddKey(section.Messages(), key.UnlinkFile(), "Removed file \"{0}\".");
33+
config.AddKey(section.Messages(), key.Disconnected(), "Disconnected from {0}.");
34+
config.AddKey(section.Messages(), key.CorruptFile(), "Corrupted file \"{0}\".");
35+
config.AddKey(section.Messages(), key.Connected(), "Connected to {0} on port {1}.");
36+
config.AddKey(section.Messages(), key.ProtocolError(), "Protocol error: {0} - {1}.");
37+
config.AddKey(section.Messages(), key.NoData(), "Empty file \"{0}\", for queue {1}.");
38+
config.AddKey(section.Messages(), key.WatchDirectory(), "Watching directory \"{0}\".");
39+
config.AddKey(section.Messages(), key.NoDirectory(), "Directory \"{0}\" was not found.");
40+
config.AddKey(section.Messages(), key.FileFound(), "Found file \"{0}\", queuing to {1}.");
41+
config.AddKey(section.Messages(), key.UnknownFile(), "\"{0}\" is from an unwatched directory.");
4242

4343
}
4444

0 commit comments

Comments
 (0)