2024-08-21 22:42:52 +02:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Threading;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using Serilog;
|
|
|
|
|
|
using Wino.Core.Domain.Models.Server;
|
|
|
|
|
|
using Wino.Messaging.Server;
|
|
|
|
|
|
using Wino.Server.Core;
|
|
|
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
|
namespace Wino.Server.MessageHandlers;
|
|
|
|
|
|
|
|
|
|
|
|
public class TerminateServerRequestHandler : ServerMessageHandler<TerminateServerRequested, bool>
|
2024-08-21 22:42:52 +02:00
|
|
|
|
{
|
2025-02-16 11:54:23 +01:00
|
|
|
|
public override WinoServerResponse<bool> FailureDefaultResponse(Exception ex) => WinoServerResponse<bool>.CreateErrorResponse(ex.Message);
|
2025-02-16 11:43:30 +01:00
|
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
|
protected override Task<WinoServerResponse<bool>> HandleAsync(TerminateServerRequested message, CancellationToken cancellationToken = default)
|
|
|
|
|
|
{
|
|
|
|
|
|
// This handler is only doing the logging right now.
|
|
|
|
|
|
// Client will always expect success response.
|
|
|
|
|
|
// Server will be terminated in the server context once the client gets the response.
|
2024-08-21 22:42:52 +02:00
|
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
|
Log.Information("Terminate server is requested by client. Killing server.");
|
2024-08-21 22:42:52 +02:00
|
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
|
return Task.FromResult(WinoServerResponse<bool>.CreateSuccessResponse(true));
|
2024-08-21 22:42:52 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|