tgstation-server  4.4.0
The /tg/station 13 server suite
EventConsumer.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using System.Threading;
4 using System.Threading.Tasks;
7 
8 namespace Tgstation.Server.Host.Components.Events
9 {
12  {
17 
22 
27  public EventConsumer(IConfiguration configuration)
28  {
29  this.configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
30  }
31 
33  public async Task HandleEvent(EventType eventType, IEnumerable<string> parameters, CancellationToken cancellationToken)
34  {
35  if (watchdog == null)
36  throw new InvalidOperationException("EventConsumer used without watchdog set!");
37 
38  await configuration.HandleEvent(eventType, parameters, cancellationToken).ConfigureAwait(false);
39  await watchdog.HandleEvent(eventType, parameters, cancellationToken).ConfigureAwait(false);
40  }
41 
46  public void SetWatchdog(IWatchdog watchdog)
47  {
48 #pragma warning disable IDE0016 // Use 'throw' expression
49  if (watchdog == null)
50  throw new ArgumentNullException(nameof(watchdog));
51 #pragma warning restore IDE0016 // Use 'throw' expression
52  if (this.watchdog != null)
53  throw new InvalidOperationException("watchdog already set!");
54  this.watchdog = watchdog;
55  }
56  }
57 }
EventConsumer(IConfiguration configuration)
Construct an IEventConsumer
EventType
Types of events. Mirror in tgs.dm
Definition: EventType.cs:6
async Task HandleEvent(EventType eventType, IEnumerable< string > parameters, CancellationToken cancellationToken)
Handle a given eventType
void SetWatchdog(IWatchdog watchdog)
Set the watchdog for the EventConsumer
readonly IConfiguration configuration
The IConfiguration for the EventConsumer
IWatchdog watchdog
The IWatchdog for the EventConsumer
Consumes EventTypes and takes the appropriate actions
For managing the Configuration directory
Task HandleEvent(EventType eventType, IEnumerable< string > parameters, CancellationToken cancellationToken)
Handle a given eventType
Runs and monitors the twin server controllers
Definition: IWatchdog.cs:15