Refactor version retrieval to use Assembly.GetName().Version and add version formatting in GetSystemVersion and GetServiceVersion queries
parent
5ab5d0777f
commit
5fe5fb9f4f
|
@ -3,6 +3,7 @@ using Microsoft.Extensions.Logging;
|
|||
using NetworkResurrector.Server.Wrapper.Services;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
@ -35,12 +36,12 @@ namespace NetworkResurrector.Api.Application.Queries
|
|||
public async Task<Model> Handle(Query request, CancellationToken cancellationToken)
|
||||
{
|
||||
var apiVersion = GetApiVersion();
|
||||
var serverVersion = await GetServerVersion();
|
||||
var (version, lastUpdateDate) = await GetServerVersion();
|
||||
|
||||
var result = new Model
|
||||
{
|
||||
Api = apiVersion,
|
||||
Server = serverVersion
|
||||
Server = new ServiceVersion(FormatVersion(version), lastUpdateDate)
|
||||
};
|
||||
|
||||
return result;
|
||||
|
@ -52,7 +53,7 @@ namespace NetworkResurrector.Api.Application.Queries
|
|||
var appDate = Environment.GetEnvironmentVariable("APP_DATE");
|
||||
|
||||
if (string.IsNullOrEmpty(version))
|
||||
version = Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion;
|
||||
version = Assembly.GetEntryAssembly().GetName().Version.ToString();
|
||||
|
||||
if (!DateTime.TryParse(appDate, out var lastReleaseDate))
|
||||
{
|
||||
|
@ -60,7 +61,7 @@ namespace NetworkResurrector.Api.Application.Queries
|
|||
lastReleaseDate = File.GetLastWriteTime(location);
|
||||
}
|
||||
|
||||
var result = new ServiceVersion(version, lastReleaseDate);
|
||||
var result = new ServiceVersion(FormatVersion(version), lastReleaseDate);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -77,6 +78,17 @@ namespace NetworkResurrector.Api.Application.Queries
|
|||
}
|
||||
return new ServiceVersion("0.0.0", DateTime.MinValue);
|
||||
}
|
||||
|
||||
private string FormatVersion(string version)
|
||||
{
|
||||
if (string.IsNullOrEmpty(version))
|
||||
return string.Empty;
|
||||
var parts = version.Split('.');
|
||||
if (parts.Length < 3)
|
||||
return version;
|
||||
var shortVersion = string.Join('.', parts.Take(3));
|
||||
return shortVersion;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ namespace NetworkResurrector.Server.Application.Queries
|
|||
var appDate = Environment.GetEnvironmentVariable("APP_DATE");
|
||||
|
||||
if (string.IsNullOrEmpty(version))
|
||||
version = Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion;
|
||||
version = Assembly.GetEntryAssembly().GetName().Version.ToString();
|
||||
|
||||
if (!DateTime.TryParse(appDate, out var lastReleaseDate))
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue