HandleEvent() public method

public HandleEvent ( object sender, MyEventArgs, args ) : void
sender object
args MyEventArgs,
return void
Beispiel #1
0
        /// <inheritdoc />
        protected override async Task <MonitorAction> HandleMonitorWakeup(MonitorActivationReason reason, CancellationToken cancellationToken)
        {
            switch (reason)
            {
            case MonitorActivationReason.ActiveServerCrashed:
                var eventType = Server.TerminationWasRequested
                                                ? EventType.WorldEndProcess
                                                : EventType.WatchdogCrash;
                await EventConsumer.HandleEvent(eventType, Enumerable.Empty <string>(), cancellationToken).ConfigureAwait(false);

                var exitWord = Server.TerminationWasRequested ? "exited" : "crashed";
                if (Server.RebootState == Session.RebootState.Shutdown)
                {
                    // the time for graceful shutdown is now
                    await Chat.QueueWatchdogMessage(
                        String.Format(
                            CultureInfo.InvariantCulture,
                            "Server {0}! Shutting down due to graceful termination request...",
                            exitWord),
                        cancellationToken)
                    .ConfigureAwait(false);

                    return(MonitorAction.Exit);
                }

                await Chat.QueueWatchdogMessage(
                    String.Format(
                        CultureInfo.InvariantCulture,
                        "Server {0}! Rebooting...",
                        exitWord),
                    cancellationToken)
                .ConfigureAwait(false);

                return(MonitorAction.Restart);

            case MonitorActivationReason.ActiveServerRebooted:
                var rebootState = Server.RebootState;
                if (gracefulRebootRequired && rebootState == Session.RebootState.Normal)
                {
                    Logger.LogError("Watchdog reached normal reboot state with gracefulRebootRequired set!");
                    rebootState = Session.RebootState.Restart;
                }

                gracefulRebootRequired = false;
                Server.ResetRebootState();

                await EventConsumer.HandleEvent(EventType.WorldReboot, Enumerable.Empty <string>(), cancellationToken).ConfigureAwait(false);

                switch (rebootState)
                {
                case Session.RebootState.Normal:
                    return(await HandleNormalReboot(cancellationToken).ConfigureAwait(false));

                case Session.RebootState.Restart:
                    return(MonitorAction.Restart);

                case Session.RebootState.Shutdown:
                    // graceful shutdown time
                    await Chat.QueueWatchdogMessage(
                        "Active server rebooted! Shutting down due to graceful termination request...",
                        cancellationToken)
                    .ConfigureAwait(false);

                    return(MonitorAction.Exit);

                default:
                    throw new InvalidOperationException($"Invalid reboot state: {rebootState}");
                }

            case MonitorActivationReason.ActiveLaunchParametersUpdated:
                await Server.SetRebootState(Session.RebootState.Restart, cancellationToken).ConfigureAwait(false);

                gracefulRebootRequired = true;
                break;

            case MonitorActivationReason.NewDmbAvailable:
                await HandleNewDmbAvailable(cancellationToken).ConfigureAwait(false);

                break;

            case MonitorActivationReason.ActiveServerPrimed:
                await EventConsumer.HandleEvent(EventType.WorldPrime, Enumerable.Empty <string>(), cancellationToken).ConfigureAwait(false);

                break;

            case MonitorActivationReason.Heartbeat:
            default:
                throw new InvalidOperationException($"Invalid activation reason: {reason}");
            }

            return(MonitorAction.Continue);
        }