Agent ShutdownService
parent
2e21ad3b60
commit
c0b07ed59e
|
@ -56,7 +56,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetworkResurrector.Agent",
|
|||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetworkResurrector.Agent.Application", "src\agent\NetworkResurrector.Agent.Application\NetworkResurrector.Agent.Application.csproj", "{3795AB02-7F2A-424B-BFD2-1B915E155829}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetworkResurrector.Agent.Wrapper", "src\agent\NetworkResurrector.Agent.Wrapper\NetworkResurrector.Agent.Wrapper.csproj", "{BA96E3C3-3E18-4882-8BDB-ED7B40836892}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetworkResurrector.Agent.Wrapper", "src\agent\NetworkResurrector.Agent.Wrapper\NetworkResurrector.Agent.Wrapper.csproj", "{BA96E3C3-3E18-4882-8BDB-ED7B40836892}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetworkResurrector.Agent.PublishedLanguage", "src\agent\NetworkResurrector.Agent.PublishedLanguage\NetworkResurrector.Agent.PublishedLanguage.csproj", "{2B084ADC-829E-4B72-8FF3-69780E06083D}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
|
@ -116,6 +118,10 @@ Global
|
|||
{BA96E3C3-3E18-4882-8BDB-ED7B40836892}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{BA96E3C3-3E18-4882-8BDB-ED7B40836892}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{BA96E3C3-3E18-4882-8BDB-ED7B40836892}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{2B084ADC-829E-4B72-8FF3-69780E06083D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{2B084ADC-829E-4B72-8FF3-69780E06083D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{2B084ADC-829E-4B72-8FF3-69780E06083D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{2B084ADC-829E-4B72-8FF3-69780E06083D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -139,6 +145,7 @@ Global
|
|||
{C8C4CA6F-39E2-46FE-89E2-0A81D2F4161E} = {C04663A1-E0CD-41D6-A8D7-FADDF9DA8302}
|
||||
{3795AB02-7F2A-424B-BFD2-1B915E155829} = {C04663A1-E0CD-41D6-A8D7-FADDF9DA8302}
|
||||
{BA96E3C3-3E18-4882-8BDB-ED7B40836892} = {C04663A1-E0CD-41D6-A8D7-FADDF9DA8302}
|
||||
{2B084ADC-829E-4B72-8FF3-69780E06083D} = {C04663A1-E0CD-41D6-A8D7-FADDF9DA8302}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {351D76E9-FE02-4C30-A464-7B29AFC64BC7}
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
using MediatR;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NetworkResurrector.Agent.Application.Services.Abstractions;
|
||||
using NetworkResurrector.Agent.PublishedLanguage.Commands;
|
||||
using NetworkResurrector.Agent.PublishedLanguage.Events;
|
||||
using System.Diagnostics;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NetworkResurrector.Agent.Application.CommandHandlers
|
||||
{
|
||||
public class ShutdownHandler : IRequestHandler<Shutdown, ShutdownResult>
|
||||
{
|
||||
private readonly ILogger<ShutdownHandler> _logger;
|
||||
private readonly IShutdownService _shutdownService;
|
||||
|
||||
public ShutdownHandler(ILogger<ShutdownHandler> logger, IShutdownService shutdownService)
|
||||
{
|
||||
_logger = logger;
|
||||
_shutdownService = shutdownService;
|
||||
}
|
||||
|
||||
public async Task<ShutdownResult> Handle(Shutdown command, CancellationToken cancellationToken)
|
||||
{
|
||||
return await Task.Run(() => Handle(command));
|
||||
}
|
||||
|
||||
private ShutdownResult Handle(Shutdown command)
|
||||
{
|
||||
_logger.LogDebug($"Start shutting down the system.");
|
||||
|
||||
var stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
|
||||
_shutdownService.Run();
|
||||
|
||||
stopWatch.Stop();
|
||||
_logger.LogDebug($"System shutdown finished - {stopWatch.ElapsedMilliseconds:N0} ms");
|
||||
|
||||
return new ShutdownResult() { Success = true };
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
using Microsoft.Extensions.DependencyInjection;
|
||||
using NetworkResurrector.Agent.Application.Services;
|
||||
using NetworkResurrector.Agent.Application.Services.Abstractions;
|
||||
|
||||
namespace NetworkResurrector.Agent.Application
|
||||
{
|
||||
public static class DependencyInjectionExtensions
|
||||
{
|
||||
public static void AddApplicationServices(this IServiceCollection services)
|
||||
{
|
||||
// services.AddSingleton<IParamProvider, ParamProvider>();
|
||||
services.AddSingleton<IShutdownService, ShutdownService>();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -13,4 +13,8 @@
|
|||
<PackageReference Include="NDB.Application.DataContracts" Version="$(NDBApplicationPackageVersion)" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\NetworkResurrector.Agent.PublishedLanguage\NetworkResurrector.Agent.PublishedLanguage.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
namespace NetworkResurrector.Agent.Application.Services.Abstractions
|
||||
{
|
||||
public interface IShutdownService
|
||||
{
|
||||
void Run();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
using Microsoft.Extensions.Logging;
|
||||
using NetworkResurrector.Agent.Application.Services.Abstractions;
|
||||
|
||||
namespace NetworkResurrector.Agent.Application.Services
|
||||
{
|
||||
internal class ShutdownService : IShutdownService
|
||||
{
|
||||
private readonly ILogger<ShutdownService> _logger;
|
||||
|
||||
public ShutdownService(ILogger<ShutdownService> logger)
|
||||
{
|
||||
_logger=logger;
|
||||
}
|
||||
|
||||
public void Run()
|
||||
{
|
||||
_logger.LogInformation("In development...");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
using NDB.Application.DataContracts;
|
||||
using NetworkResurrector.Agent.PublishedLanguage.Dto;
|
||||
using NetworkResurrector.Agent.PublishedLanguage.Events;
|
||||
|
||||
namespace NetworkResurrector.Agent.PublishedLanguage.Commands
|
||||
{
|
||||
public class Shutdown : Command<ShutdownResult>
|
||||
{
|
||||
public ActionOwner Owner { get; set; }
|
||||
public ActionOptions Options { get; set; }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
namespace NetworkResurrector.Agent.PublishedLanguage.Dto
|
||||
{
|
||||
public record ActionOwner(string OwnerCode);
|
||||
public record ActionOptions(int Delay);
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
namespace NetworkResurrector.Agent.PublishedLanguage.Dto
|
||||
{
|
||||
public record HostInfo(string[] Messages);
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
using NetworkResurrector.Agent.PublishedLanguage.Dto;
|
||||
|
||||
namespace NetworkResurrector.Agent.PublishedLanguage.Events
|
||||
{
|
||||
public class ShutdownResult
|
||||
{
|
||||
public bool Success { get; set; }
|
||||
public HostInfo Host { get; set; }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="NDB.Application.DataContracts" Version="$(NDBApplicationPackageVersion)" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
|
@ -1,6 +1,7 @@
|
|||
using MediatR;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NetworkResurrector.Agent.PublishedLanguage.Commands;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NetworkResurrector.Agent.Controllers
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\NetworkResurrector.Agent.Application\NetworkResurrector.Agent.Application.csproj" />
|
||||
<ProjectReference Include="..\NetworkResurrector.Agent.PublishedLanguage\NetworkResurrector.Agent.PublishedLanguage.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -8,6 +8,7 @@ using Microsoft.Extensions.Hosting;
|
|||
using NDB.Extensions.Swagger;
|
||||
using NDB.Extensions.Swagger.Constants;
|
||||
using NDB.Security.Authentication.Identity;
|
||||
using NetworkResurrector.Agent.Application;
|
||||
using Newtonsoft.Json;
|
||||
using System.Reflection;
|
||||
|
||||
|
@ -48,7 +49,7 @@ namespace NetworkResurrector.Agent
|
|||
// services.AddDataAccess();
|
||||
|
||||
// Application
|
||||
// services.AddApplicationServices();
|
||||
services.AddApplicationServices();
|
||||
}
|
||||
|
||||
private Assembly[] GetMediatRAssemblies()
|
||||
|
|
|
@ -17,5 +17,8 @@
|
|||
},
|
||||
"IdentityServer": {
|
||||
"BaseAddress": "https://toodle.ddns.net/identity-server-api/"
|
||||
},
|
||||
"Restrictions": {
|
||||
"EnforceActionOwner": true
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue