WakeMachineHandler fix

master
Tudor Stanciu 2022-01-17 19:22:31 +02:00
parent 9af7aea208
commit 7be1fd6a69
2 changed files with 32 additions and 6 deletions

View File

@ -1,9 +1,11 @@
using MediatR;
using Microsoft.Extensions.Logging;
using NetworkResurrector.Api.Domain.Constants;
using NetworkResurrector.Api.Domain.Repositories;
using NetworkResurrector.Api.PublishedLanguage.Commands;
using NetworkResurrector.Api.PublishedLanguage.Events;
using NetworkResurrector.Server.Wrapper.Services;
using System;
using System.Threading;
using System.Threading.Tasks;
@ -26,11 +28,22 @@ namespace NetworkResurrector.Api.Application.CommandHandlers
{
_logger.LogDebug($"Start pinging machine {command.MachineId}");
var machine = await _repository.GetMachine(command.MachineId);
var powerConfiguration = await _repository.GetPowerActionConfiguration(command.MachineId, PowerActions.PING);
//log activity
var pingResult = await _resurrectorService.Ping(machine.IPv4Address ?? machine.MachineName);
var result = new MachinePinged(pingResult.Success, pingResult.Status);
_logger.LogDebug($"Machine {command.MachineId} pinging finished. Success: {result.Success}; Status: {result.Status}");
MachinePinged result;
switch (powerConfiguration.Performer.PerformerCode)
{
case PowerActionPerformers.NETWORK_RESURRECTOR_SERVER:
var pingResult = await _resurrectorService.Ping(machine.IPv4Address ?? machine.MachineName);
result = new MachinePinged(pingResult.Success, pingResult.Status);
_logger.LogDebug($"Machine {command.MachineId} pinging finished. Success: {result.Success}; Status: {result.Status}");
break;
default:
throw new Exception($"Power action performer {powerConfiguration.Performer.PerformerCode} is not implemented.");
}
return result;
}

View File

@ -1,9 +1,11 @@
using MediatR;
using Microsoft.Extensions.Logging;
using NetworkResurrector.Api.Domain.Constants;
using NetworkResurrector.Api.Domain.Repositories;
using NetworkResurrector.Api.PublishedLanguage.Commands;
using NetworkResurrector.Api.PublishedLanguage.Events;
using NetworkResurrector.Server.Wrapper.Services;
using System;
using System.Threading;
using System.Threading.Tasks;
@ -26,11 +28,22 @@ namespace NetworkResurrector.Api.Application.CommandHandlers
{
_logger.LogDebug($"Start waking up machine {command.MachineId}");
var machine = await _repository.GetMachine(command.MachineId);
var powerConfiguration = await _repository.GetPowerActionConfiguration(command.MachineId, PowerActions.WAKE);
//log activity
var wakeResult = await _resurrectorService.Wake(machine.MACAddress);
var result = new MachineWaked(wakeResult.Success, wakeResult.Status);
_logger.LogDebug($"Machine {command.MachineId} wake up finished. Success: {result.Success}; Status: {result.Status}");
MachineWaked result;
switch (powerConfiguration.Performer.PerformerCode)
{
case PowerActionPerformers.NETWORK_RESURRECTOR_SERVER:
var wakeResult = await _resurrectorService.Wake(machine.MACAddress);
result = new MachineWaked(wakeResult.Success, wakeResult.Status);
_logger.LogDebug($"Machine {command.MachineId} wake up finished. Success: {result.Success}; Status: {result.Status}");
break;
default:
throw new Exception($"Power action performer {powerConfiguration.Performer.PerformerCode} is not implemented.");
}
return result;
}