WakeMachineHandler fix
parent
9af7aea208
commit
7be1fd6a69
|
@ -1,9 +1,11 @@
|
||||||
using MediatR;
|
using MediatR;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using NetworkResurrector.Api.Domain.Constants;
|
||||||
using NetworkResurrector.Api.Domain.Repositories;
|
using NetworkResurrector.Api.Domain.Repositories;
|
||||||
using NetworkResurrector.Api.PublishedLanguage.Commands;
|
using NetworkResurrector.Api.PublishedLanguage.Commands;
|
||||||
using NetworkResurrector.Api.PublishedLanguage.Events;
|
using NetworkResurrector.Api.PublishedLanguage.Events;
|
||||||
using NetworkResurrector.Server.Wrapper.Services;
|
using NetworkResurrector.Server.Wrapper.Services;
|
||||||
|
using System;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
@ -26,11 +28,22 @@ namespace NetworkResurrector.Api.Application.CommandHandlers
|
||||||
{
|
{
|
||||||
_logger.LogDebug($"Start pinging machine {command.MachineId}");
|
_logger.LogDebug($"Start pinging machine {command.MachineId}");
|
||||||
var machine = await _repository.GetMachine(command.MachineId);
|
var machine = await _repository.GetMachine(command.MachineId);
|
||||||
|
var powerConfiguration = await _repository.GetPowerActionConfiguration(command.MachineId, PowerActions.PING);
|
||||||
|
|
||||||
//log activity
|
//log activity
|
||||||
|
|
||||||
|
MachinePinged result;
|
||||||
|
switch (powerConfiguration.Performer.PerformerCode)
|
||||||
|
{
|
||||||
|
case PowerActionPerformers.NETWORK_RESURRECTOR_SERVER:
|
||||||
var pingResult = await _resurrectorService.Ping(machine.IPv4Address ?? machine.MachineName);
|
var pingResult = await _resurrectorService.Ping(machine.IPv4Address ?? machine.MachineName);
|
||||||
var result = new MachinePinged(pingResult.Success, pingResult.Status);
|
result = new MachinePinged(pingResult.Success, pingResult.Status);
|
||||||
_logger.LogDebug($"Machine {command.MachineId} pinging finished. Success: {result.Success}; Status: {result.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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
using MediatR;
|
using MediatR;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using NetworkResurrector.Api.Domain.Constants;
|
||||||
using NetworkResurrector.Api.Domain.Repositories;
|
using NetworkResurrector.Api.Domain.Repositories;
|
||||||
using NetworkResurrector.Api.PublishedLanguage.Commands;
|
using NetworkResurrector.Api.PublishedLanguage.Commands;
|
||||||
using NetworkResurrector.Api.PublishedLanguage.Events;
|
using NetworkResurrector.Api.PublishedLanguage.Events;
|
||||||
using NetworkResurrector.Server.Wrapper.Services;
|
using NetworkResurrector.Server.Wrapper.Services;
|
||||||
|
using System;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
@ -26,11 +28,22 @@ namespace NetworkResurrector.Api.Application.CommandHandlers
|
||||||
{
|
{
|
||||||
_logger.LogDebug($"Start waking up machine {command.MachineId}");
|
_logger.LogDebug($"Start waking up machine {command.MachineId}");
|
||||||
var machine = await _repository.GetMachine(command.MachineId);
|
var machine = await _repository.GetMachine(command.MachineId);
|
||||||
|
var powerConfiguration = await _repository.GetPowerActionConfiguration(command.MachineId, PowerActions.WAKE);
|
||||||
|
|
||||||
//log activity
|
//log activity
|
||||||
|
|
||||||
|
MachineWaked result;
|
||||||
|
switch (powerConfiguration.Performer.PerformerCode)
|
||||||
|
{
|
||||||
|
case PowerActionPerformers.NETWORK_RESURRECTOR_SERVER:
|
||||||
var wakeResult = await _resurrectorService.Wake(machine.MACAddress);
|
var wakeResult = await _resurrectorService.Wake(machine.MACAddress);
|
||||||
var result = new MachineWaked(wakeResult.Success, wakeResult.Status);
|
result = new MachineWaked(wakeResult.Success, wakeResult.Status);
|
||||||
_logger.LogDebug($"Machine {command.MachineId} wake up finished. Success: {result.Success}; Status: {result.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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue