Server version query update

master
Tudor Stanciu 2023-03-25 02:58:55 +02:00
parent 099fa90e24
commit e9b4201a22
6 changed files with 27 additions and 11 deletions

View File

@ -1,4 +1,5 @@
using MediatR;
using NetworkResurrector.Server.PublishedLanguage.Dto;
using System;
using System.IO;
using System.Reflection;
@ -9,17 +10,15 @@ namespace NetworkResurrector.Server.Application.Queries
{
public class GetSystemVersion
{
public class Query : IRequest<Model> { }
public class Query : IRequest<ServiceVersion> { }
public record Model(string Version, DateTime LastUpdateDate);
public class QueryHandler : IRequestHandler<Query, Model>
public class QueryHandler : IRequestHandler<Query, ServiceVersion>
{
public QueryHandler()
{
}
public async Task<Model> Handle(Query request, CancellationToken cancellationToken)
public async Task<ServiceVersion> Handle(Query request, CancellationToken cancellationToken)
{
var version = Environment.GetEnvironmentVariable("APP_VERSION");
var appDate = Environment.GetEnvironmentVariable("APP_DATE");
@ -27,13 +26,13 @@ namespace NetworkResurrector.Server.Application.Queries
if (string.IsNullOrEmpty(version))
version = Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion;
if (!DateTime.TryParse(appDate, out var lastUpdateDate))
if (!DateTime.TryParse(appDate, out var lastReleaseDate))
{
var location = Assembly.GetExecutingAssembly().Location;
lastUpdateDate = File.GetLastWriteTime(location);
lastReleaseDate = File.GetLastWriteTime(location);
}
var result = new Model(version, lastUpdateDate);
var result = new ServiceVersion(version, lastReleaseDate);
return await Task.FromResult(result);
}
}

View File

@ -0,0 +1,6 @@
using System;
namespace NetworkResurrector.Server.PublishedLanguage.Dto
{
public record ServiceVersion(string Version, DateTime LastReleaseDate);
}

View File

@ -6,7 +6,7 @@
<RepositoryUrl>https://lab.code-rove.com/gitea/tudor.stanciu/network-resurrector</RepositoryUrl>
<RepositoryType>Git</RepositoryType>
<PackageProjectUrl>https://lab.code-rove.com/gitea/tudor.stanciu/network-resurrector</PackageProjectUrl>
<Version>1.1.0</Version>
<Version>1.1.1</Version>
</PropertyGroup>
<ItemGroup>

View File

@ -3,6 +3,7 @@
internal struct ApiRoutes
{
public const string
SystemVersion = "system/version",
Wake = "resurrector/wake",
Ping = "resurrector/ping",
Shutdown = "resurrector/shutdown";

View File

@ -6,7 +6,7 @@
<PackageProjectUrl>https://lab.code-rove.com/gitea/tudor.stanciu/network-resurrector</PackageProjectUrl>
<RepositoryUrl>https://lab.code-rove.com/gitea/tudor.stanciu/network-resurrector</RepositoryUrl>
<RepositoryType>Git</RepositoryType>
<Version>1.1.0</Version>
<Version>1.1.1</Version>
</PropertyGroup>
<ItemGroup>
@ -15,7 +15,10 @@
<PackageReference Include="Microsoft.Extensions.Http" Version="$(MicrosoftExtensionsPackageVersion)" />
<PackageReference Include="Microsoft.Net.Http.Headers" Version="2.2.8" />
<PackageReference Include="Netmash.Extensions.Http" Version="1.0.0" />
<PackageReference Include="NetworkResurrector.Server.PublishedLanguage" Version="1.1.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\NetworkResurrector.Server.PublishedLanguage\NetworkResurrector.Server.PublishedLanguage.csproj" />
</ItemGroup>
</Project>

View File

@ -1,5 +1,6 @@
using Netmash.Extensions.Http;
using NetworkResurrector.Server.PublishedLanguage.Commands;
using NetworkResurrector.Server.PublishedLanguage.Dto;
using NetworkResurrector.Server.PublishedLanguage.Events;
using NetworkResurrector.Server.Wrapper.Constants;
using NetworkResurrector.Server.Wrapper.Models;
@ -29,6 +30,12 @@ namespace NetworkResurrector.Server.Wrapper.Services
_httpClient = httpClient;
}
public async Task<ServiceVersion> GetServiceVersion()
{
var result = await _httpClient.ExecuteGetRequest<ServiceVersion>(ApiRoutes.SystemVersion);
return result;
}
public async Task<MachineWaked> Wake(string macAddress)
{
var body = new WakeMachine() { MacAddress = macAddress };