From 81f50b7bdea621e1effb77b392c0ee81f32224e4 Mon Sep 17 00:00:00 2001 From: Tudor Stanciu Date: Sat, 25 Mar 2023 12:54:38 +0200 Subject: [PATCH] New methods have been added to the API for reading the system version and release notes. --- Directory.Build.props | 2 +- ReleaseNotes.xml | 45 ++++++++++++ .../NetworkResurrector.Api.Application.csproj | 2 +- .../Queries/GetReleaseNotes.cs | 71 +++++++++++++++++++ .../Queries/GetSystemVersion.cs | 36 ++++++++-- .../Controllers/SystemController.cs | 7 ++ .../NetworkResurrector.Api.csproj | 4 ++ 7 files changed, 159 insertions(+), 8 deletions(-) create mode 100644 src/api/NetworkResurrector.Api.Application/Queries/GetReleaseNotes.cs diff --git a/Directory.Build.props b/Directory.Build.props index 3f1e700..ebde317 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,7 +1,7 @@ - 1.1.3 + 1.2.3 Tudor Stanciu STA NetworkResurrector diff --git a/ReleaseNotes.xml b/ReleaseNotes.xml index 06d5a8f..84ff027 100644 --- a/ReleaseNotes.xml +++ b/ReleaseNotes.xml @@ -99,6 +99,10 @@ Tuitio latest updates • Tuitio nuget packages upgrade • Tuitio configuration changes + • Many frontend developments + • Tuitio client NPM package integration: @flare/tuitio-react-client + • Added license file + • Login with enter key @@ -110,4 +114,45 @@ • Netmash.Security.Authentication.Tuitio nuget package upgrade + + 1.2.0 + 2023-03-19 14:56 + + Massive frontend developments + • Complete UI refactoring + • A complete menu has been added to the application. + • The theme and the switch between dark and light mode have been implemented. + • Axios upgrade. + • The ugly and useless stepper has been removed from the machines page. + + + + 1.2.1 + 2023-03-19 20:11 + + Frontend developments + • Added sensitive info toggle. + • Apply mask on sensitive information. + • Mask machine logs. + + + + 1.2.2 + 2023-03-19 23:14 + + Added user profile page + • The data on the page is extracted from the Tuitio token. + + + + 1.2.3 + 2023-03-25 02:26 + + Important developments in frontend + • Machines view modes + • New menu entries: About, Administration and System + • About page. It contains information about the system and the release notes. + • New methods have been added to the API for reading the system version and release notes. + + \ No newline at end of file diff --git a/src/api/NetworkResurrector.Api.Application/NetworkResurrector.Api.Application.csproj b/src/api/NetworkResurrector.Api.Application/NetworkResurrector.Api.Application.csproj index 3791b17..b687deb 100644 --- a/src/api/NetworkResurrector.Api.Application/NetworkResurrector.Api.Application.csproj +++ b/src/api/NetworkResurrector.Api.Application/NetworkResurrector.Api.Application.csproj @@ -13,7 +13,7 @@ - + diff --git a/src/api/NetworkResurrector.Api.Application/Queries/GetReleaseNotes.cs b/src/api/NetworkResurrector.Api.Application/Queries/GetReleaseNotes.cs new file mode 100644 index 0000000..befe8de --- /dev/null +++ b/src/api/NetworkResurrector.Api.Application/Queries/GetReleaseNotes.cs @@ -0,0 +1,71 @@ +using MediatR; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using System.Xml; + +namespace NetworkResurrector.Api.Application.Queries +{ + public class GetReleaseNotes + { + public class Query : IRequest + { + public Query() { } + } + + public record Model(string Version, DateTime Date, string[] Notes); + + public class QueryHandler : IRequestHandler + { + public QueryHandler() { } + + public async Task Handle(Query request, CancellationToken cancellationToken) + { + var x = Directory.GetCurrentDirectory(); + Console.WriteLine(x); + + var releaseNotes = new XmlDocument(); + releaseNotes.Load("ReleaseNotes.xml"); + + var rows = releaseNotes.DocumentElement.SelectNodes("Note"); + var result = new List(); + + foreach (XmlNode node in rows) + { + var version = node.SelectSingleNode("Version").InnerText; + var date = GetReleaseDateUtc(node.SelectSingleNode("Date").InnerText); + var notes = ParseContent(node.SelectSingleNode("Content").InnerText); + + result.Add(new Model(version, date, notes)); + } + + return await Task.FromResult(result.ToArray()); + } + + private string[] ParseContent(string text) + { + var lines = text + .Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None) + .Where(z => !string.IsNullOrWhiteSpace(z)) + .ToArray(); + + for (int i = 0; i < lines.Count(); i++) + { + lines[i] = lines[i].TrimStart().TrimEnd(); + } + + return lines; + } + + private DateTime GetReleaseDateUtc(string date) + { + var datetime = Convert.ToDateTime(date); + var utcDatetime = TimeZoneInfo.ConvertTimeToUtc(datetime, TimeZoneInfo.Local); + return utcDatetime; + } + } + } +} diff --git a/src/api/NetworkResurrector.Api.Application/Queries/GetSystemVersion.cs b/src/api/NetworkResurrector.Api.Application/Queries/GetSystemVersion.cs index 19d6bfc..f60fe0c 100644 --- a/src/api/NetworkResurrector.Api.Application/Queries/GetSystemVersion.cs +++ b/src/api/NetworkResurrector.Api.Application/Queries/GetSystemVersion.cs @@ -1,4 +1,5 @@ using MediatR; +using NetworkResurrector.Server.Wrapper.Services; using System; using System.IO; using System.Reflection; @@ -11,15 +12,38 @@ namespace NetworkResurrector.Api.Application.Queries { public class Query : IRequest { } - public record Model(string Version, DateTime LastUpdateDate); + public class Model + { + public ServiceVersion Api { get; set; } + public ServiceVersion Server { get; set; } + } + + public record ServiceVersion(string Version, DateTime LastReleaseDate); public class QueryHandler : IRequestHandler { - public QueryHandler() + private readonly IResurrectorService _resurrectorService; + + public QueryHandler(IResurrectorService resurrectorService) { + _resurrectorService=resurrectorService; } public async Task Handle(Query request, CancellationToken cancellationToken) + { + var serverVersion = await _resurrectorService.GetServiceVersion(); + var apiVersion = GetApiVersion(); + + var result = new Model + { + Api = apiVersion, + Server = new ServiceVersion(serverVersion.Version, serverVersion.LastReleaseDate) + }; + + return result; + } + + private ServiceVersion GetApiVersion() { var version = Environment.GetEnvironmentVariable("APP_VERSION"); var appDate = Environment.GetEnvironmentVariable("APP_DATE"); @@ -27,14 +51,14 @@ namespace NetworkResurrector.Api.Application.Queries if (string.IsNullOrEmpty(version)) version = Assembly.GetEntryAssembly().GetCustomAttribute().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); - return await Task.FromResult(result); + var result = new ServiceVersion(version, lastReleaseDate); + return result; } } } diff --git a/src/api/NetworkResurrector.Api/Controllers/SystemController.cs b/src/api/NetworkResurrector.Api/Controllers/SystemController.cs index f5a0113..32734ee 100644 --- a/src/api/NetworkResurrector.Api/Controllers/SystemController.cs +++ b/src/api/NetworkResurrector.Api/Controllers/SystemController.cs @@ -32,5 +32,12 @@ namespace NetworkResurrector.Api.Controllers var result = await _mediator.Send(query); return Ok(result); } + + [HttpGet("release-notes")] + public async Task GetReleaseNotes([FromRoute] GetReleaseNotes.Query query) + { + var result = await _mediator.Send(query); + return Ok(result); + } } } diff --git a/src/api/NetworkResurrector.Api/NetworkResurrector.Api.csproj b/src/api/NetworkResurrector.Api/NetworkResurrector.Api.csproj index 19f03af..6096ae9 100644 --- a/src/api/NetworkResurrector.Api/NetworkResurrector.Api.csproj +++ b/src/api/NetworkResurrector.Api/NetworkResurrector.Api.csproj @@ -5,6 +5,10 @@ Linux + + + +