wake machine from API by machineId
parent
509285766b
commit
24ef29449e
|
@ -5,5 +5,5 @@ dotnet pack /*--include-symbols*/
|
||||||
|
|
||||||
# Server:
|
# Server:
|
||||||
dotnet nuget push NetworkResurrector.Server.PublishedLanguage.1.0.3.nupkg -k ***REMOVED*** -s https://toodle.ddns.net/public-nuget-server/nuget
|
dotnet nuget push NetworkResurrector.Server.PublishedLanguage.1.0.3.nupkg -k ***REMOVED*** -s https://toodle.ddns.net/public-nuget-server/nuget
|
||||||
dotnet nuget push NetworkResurrector.Server.Wrapper.1.0.3.nupkg -k ***REMOVED*** -s https://toodle.ddns.net/public-nuget-server/nuget
|
dotnet nuget push NetworkResurrector.Server.Wrapper.1.0.3.1.nupkg -k ***REMOVED*** -s https://toodle.ddns.net/public-nuget-server/nuget
|
||||||
#######################################################################################################################################################
|
#######################################################################################################################################################
|
|
@ -0,0 +1,35 @@
|
||||||
|
using MediatR;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using NetworkResurrector.Api.Domain.Repositories;
|
||||||
|
using NetworkResurrector.Api.PublishedLanguage.Commands;
|
||||||
|
using NetworkResurrector.Api.PublishedLanguage.Events;
|
||||||
|
using NetworkResurrector.Server.Wrapper.Services;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace NetworkResurrector.Api.Application.CommandHandlers
|
||||||
|
{
|
||||||
|
public class WakeMachineHandler : IRequestHandler<WakeMachine, MachineWaked>
|
||||||
|
{
|
||||||
|
private readonly ILogger<WakeMachineHandler> _logger;
|
||||||
|
private readonly IResurrectorService _resurrectorService;
|
||||||
|
private readonly INetworkRepository _repository;
|
||||||
|
|
||||||
|
public WakeMachineHandler(ILogger<WakeMachineHandler> logger, IResurrectorService resurrectorService, INetworkRepository repository)
|
||||||
|
{
|
||||||
|
_logger=logger;
|
||||||
|
_resurrectorService=resurrectorService;
|
||||||
|
_repository=repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<MachineWaked> Handle(WakeMachine command, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var machine = await _repository.GetMachine(command.MachineId);
|
||||||
|
|
||||||
|
//log activity
|
||||||
|
var wakeResult = await _resurrectorService.Wake(machine.MACAddress);
|
||||||
|
var result = new MachineWaked(wakeResult.Success, wakeResult.Status);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -11,7 +11,7 @@
|
||||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="$(MicrosoftExtensionsPackageVersion)" />
|
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="$(MicrosoftExtensionsPackageVersion)" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="$(MicrosoftExtensionsPackageVersion)" />
|
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="$(MicrosoftExtensionsPackageVersion)" />
|
||||||
<PackageReference Include="NDB.Application.DataContracts" Version="$(NDBApplicationPackageVersion)" />
|
<PackageReference Include="NDB.Application.DataContracts" Version="$(NDBApplicationPackageVersion)" />
|
||||||
<PackageReference Include="NetworkResurrector.Server.Wrapper" Version="1.0.3" />
|
<PackageReference Include="NetworkResurrector.Server.Wrapper" Version="1.0.3.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
using NetworkResurrector.Api.Domain.Data.DbContexts;
|
using NetworkResurrector.Api.Domain.Data.DbContexts;
|
||||||
using NetworkResurrector.Api.Domain.Entities;
|
using NetworkResurrector.Api.Domain.Entities;
|
||||||
using NetworkResurrector.Api.Domain.Repositories;
|
using NetworkResurrector.Api.Domain.Repositories;
|
||||||
|
using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace NetworkResurrector.Api.Domain.Data.Repositories
|
namespace NetworkResurrector.Api.Domain.Data.Repositories
|
||||||
|
@ -19,5 +20,14 @@ namespace NetworkResurrector.Api.Domain.Data.Repositories
|
||||||
{
|
{
|
||||||
return _dbContext.Machines.ToArrayAsync();
|
return _dbContext.Machines.ToArrayAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<Machine> GetMachine(int machineId)
|
||||||
|
{
|
||||||
|
var machine = await _dbContext.Machines.FirstOrDefaultAsync(z => z.MachineId == machineId);
|
||||||
|
if (machine == null)
|
||||||
|
throw new Exception($"Machine with id {machineId} not found");
|
||||||
|
|
||||||
|
return machine;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,5 +6,6 @@ namespace NetworkResurrector.Api.Domain.Repositories
|
||||||
public interface INetworkRepository
|
public interface INetworkRepository
|
||||||
{
|
{
|
||||||
Task<Machine[]> GetMachines();
|
Task<Machine[]> GetMachines();
|
||||||
|
Task<Machine> GetMachine(int machineId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,5 +5,6 @@ namespace NetworkResurrector.Api.PublishedLanguage.Commands
|
||||||
{
|
{
|
||||||
public class PingMachine : Command<MachinePinged>
|
public class PingMachine : Command<MachinePinged>
|
||||||
{
|
{
|
||||||
|
public int MachineId { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,5 +5,6 @@ namespace NetworkResurrector.Api.PublishedLanguage.Commands
|
||||||
{
|
{
|
||||||
public class ShutdownMachine : Command<MachineShutdown>
|
public class ShutdownMachine : Command<MachineShutdown>
|
||||||
{
|
{
|
||||||
|
public int MachineId { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,5 +5,6 @@ namespace NetworkResurrector.Api.PublishedLanguage.Commands
|
||||||
{
|
{
|
||||||
public class WakeMachine : Command<MachineWaked>
|
public class WakeMachine : Command<MachineWaked>
|
||||||
{
|
{
|
||||||
|
public int MachineId { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,4 @@
|
||||||
namespace NetworkResurrector.Api.PublishedLanguage.Events
|
namespace NetworkResurrector.Api.PublishedLanguage.Events
|
||||||
{
|
{
|
||||||
public class MachineWaked
|
public record MachineWaked(bool Success, string Status);
|
||||||
{
|
|
||||||
public bool Success { get; set; }
|
|
||||||
public string Status { get; set; }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ using NDB.Extensions.Swagger.Constants;
|
||||||
using NDB.Security.Authentication.Identity;
|
using NDB.Security.Authentication.Identity;
|
||||||
using NetworkResurrector.Api.Application;
|
using NetworkResurrector.Api.Application;
|
||||||
using NetworkResurrector.Api.Domain.Data;
|
using NetworkResurrector.Api.Domain.Data;
|
||||||
|
using NetworkResurrector.Server.Wrapper;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
|
||||||
|
@ -40,12 +41,14 @@ namespace NetworkResurrector.Api
|
||||||
services.AddScoped(typeof(IPipelineBehavior<,>), typeof(RequestPostProcessorBehavior<,>));
|
services.AddScoped(typeof(IPipelineBehavior<,>), typeof(RequestPostProcessorBehavior<,>));
|
||||||
|
|
||||||
// AutoMapper
|
// AutoMapper
|
||||||
services.AddAutoMapper(
|
services.AddAutoMapper(typeof(Application.Mappings.MappingProfile).Assembly);
|
||||||
typeof(Application.Mappings.MappingProfile).Assembly);
|
|
||||||
|
|
||||||
// Swagger
|
// Swagger
|
||||||
services.AddSwagger("NetworkResurrector API", AuthorizationType.InhouseIdentity);
|
services.AddSwagger("NetworkResurrector API", AuthorizationType.InhouseIdentity);
|
||||||
|
|
||||||
|
// Add network resurrector server services
|
||||||
|
services.UseResurrectorServices(_configuration.GetSection("NetworkResurrectorServer")["BaseAddress"]);
|
||||||
|
|
||||||
// Data access
|
// Data access
|
||||||
services.AddDataAccess();
|
services.AddDataAccess();
|
||||||
|
|
||||||
|
|
|
@ -15,5 +15,8 @@
|
||||||
"IdentityServer": {
|
"IdentityServer": {
|
||||||
//"BaseAddress": "http://localhost:5063/"
|
//"BaseAddress": "http://localhost:5063/"
|
||||||
"BaseAddress": "https://toodle.ddns.net/identity-server-api/"
|
"BaseAddress": "https://toodle.ddns.net/identity-server-api/"
|
||||||
|
},
|
||||||
|
"NetworkResurrectorServer": {
|
||||||
|
"BaseAddress": "http://localhost:5062"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
<PackageProjectUrl>https://dev.azure.com/tstanciu94/NetworkResurrector</PackageProjectUrl>
|
<PackageProjectUrl>https://dev.azure.com/tstanciu94/NetworkResurrector</PackageProjectUrl>
|
||||||
<RepositoryUrl>https://dev.azure.com/tstanciu94/NetworkResurrector</RepositoryUrl>
|
<RepositoryUrl>https://dev.azure.com/tstanciu94/NetworkResurrector</RepositoryUrl>
|
||||||
<RepositoryType>Git</RepositoryType>
|
<RepositoryType>Git</RepositoryType>
|
||||||
|
<Version>1.0.3.1</Version>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
@ -1,7 +1,11 @@
|
||||||
namespace NetworkResurrector.Server.Wrapper.Services
|
using NetworkResurrector.Server.PublishedLanguage.Events;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace NetworkResurrector.Server.Wrapper.Services
|
||||||
{
|
{
|
||||||
public interface IResurrectorService
|
public interface IResurrectorService
|
||||||
{
|
{
|
||||||
|
Task<MachineWaked> Wake(string macAddress);
|
||||||
|
Task<MachinePinged> Ping(string ipAddressOrMachineName);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue