From 49315aaf94980990b50f0627a9d3b028b046e9c9 Mon Sep 17 00:00:00 2001 From: pfh59 <109206285+pfh59@users.noreply.github.com> Date: Thu, 11 Jul 2024 23:06:28 +0200 Subject: [PATCH 1/7] Update EveMapperCacheService.cs fix --- src/WHMapper/Services/EveMapper/EveMapperCacheService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WHMapper/Services/EveMapper/EveMapperCacheService.cs b/src/WHMapper/Services/EveMapper/EveMapperCacheService.cs index e53bf287..f068b090 100644 --- a/src/WHMapper/Services/EveMapper/EveMapperCacheService.cs +++ b/src/WHMapper/Services/EveMapper/EveMapperCacheService.cs @@ -36,7 +36,7 @@ public async Task GetAsync(int key) { string cacheKey = GetEntityCacheKey(); var result = await _cacheService.Get>(cacheKey); - return result?.Single(x => x.Id == key)!; + return result?.FirstOrDefault(x => x.Id == key)!; } catch(InvalidOperationException e) { From 85bfe6cdb97af35f7205be8a1e7108606d87bd43 Mon Sep 17 00:00:00 2001 From: pfh59 <109206285+pfh59@users.noreply.github.com> Date: Tue, 23 Jul 2024 17:54:30 +0200 Subject: [PATCH 2/7] Import signatures improvements (#294) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - #288 :✅ - #291 : ✅ - #290 : ✅ - #289 : ✅ - FIX : route unit test , CCP fix api GetRoute - Update MudBlazor to 7.3.0 --- .../EveOnlineAPI/PublicEveOnlineAPITest.cs | 8 +- .../WHHelper/WHColorHelperTest.cs | 14 +++ .../WHHelper/WHSignatureHelperTest.cs | 57 +++++++++ .../Enums/WHAnalizedSignatureEnums.cs | 10 ++ .../DTO/EveMapper/WHAnalizedSignature.cs | 23 ++++ src/WHMapper/Pages/Mapper/Overview.cs | 2 +- .../Pages/Mapper/RoutePlanner/Overview.cs | 2 +- .../Pages/Mapper/RoutePlanner/Overview.razor | 4 +- .../Pages/Mapper/Signatures/Import.cs | 114 ++++++++++++++--- .../Pages/Mapper/Signatures/Import.razor | 34 +++++- .../Pages/Mapper/Signatures/Overview.cs | 2 +- .../Services/WHColor/IWHColorHelper.cs | 1 + .../Services/WHColor/WHColorHelper.cs | 19 +++ .../WHSignatures/IWHSignatureHelper.cs | 6 +- .../WHSignatures/WHSignatureHelper.cs | 115 +++++++++++------- src/WHMapper/Shared/AccessControl.razor | 6 +- src/WHMapper/Shared/MainLayout.razor | 7 +- src/WHMapper/WHMapper.csproj | 4 +- 18 files changed, 348 insertions(+), 80 deletions(-) create mode 100644 src/WHMapper/Models/DTO/EveMapper/Enums/WHAnalizedSignatureEnums.cs create mode 100644 src/WHMapper/Models/DTO/EveMapper/WHAnalizedSignature.cs diff --git a/src/WHMapper.Tests/Services/EveOnlineAPI/PublicEveOnlineAPITest.cs b/src/WHMapper.Tests/Services/EveOnlineAPI/PublicEveOnlineAPITest.cs index acdd9f74..aa81c89e 100644 --- a/src/WHMapper.Tests/Services/EveOnlineAPI/PublicEveOnlineAPITest.cs +++ b/src/WHMapper.Tests/Services/EveOnlineAPI/PublicEveOnlineAPITest.cs @@ -278,9 +278,9 @@ public async Task Get_Route() var route = await _routeServices.GetRoute(SOLAR_SYSTEM_JITA_ID, SOLAR_SYSTEM_AMARR_ID); Assert.NotNull(route); Assert.NotEmpty(route); - Assert.Equal(24, route.Length); + Assert.Equal(12, route.Length); Assert.Equal(SOLAR_SYSTEM_JITA_ID, route[0]); - Assert.Equal(SOLAR_SYSTEM_AMARR_ID, route[23]); + Assert.Equal(SOLAR_SYSTEM_AMARR_ID, route[11]); //WH route to Jita without connections route = await _routeServices.GetRoute(SOLAR_SYSTEM_WH_ID, SOLAR_SYSTEM_JITA_ID); @@ -292,10 +292,10 @@ public async Task Get_Route() route = await _routeServices.GetRoute(SOLAR_SYSTEM_WH_ID, SOLAR_SYSTEM_JITA_ID, connections); Assert.NotNull(route); Assert.NotEmpty(route); - Assert.Equal(25, route.Length); + Assert.Equal(13, route.Length); Assert.Equal(SOLAR_SYSTEM_WH_ID, route[0]); Assert.Equal(SOLAR_SYSTEM_AMARR_ID, route[1]); - Assert.Equal(SOLAR_SYSTEM_JITA_ID, route[24]); + Assert.Equal(SOLAR_SYSTEM_JITA_ID, route[12]); //wh route from jita to amarr with avoid Ahbazon var avoid = new int[] { SOLAR_SYSTEM_AHBAZON_ID }; diff --git a/src/WHMapper.Tests/WHHelper/WHColorHelperTest.cs b/src/WHMapper.Tests/WHHelper/WHColorHelperTest.cs index cd098937..7cd84ab4 100644 --- a/src/WHMapper.Tests/WHHelper/WHColorHelperTest.cs +++ b/src/WHMapper.Tests/WHHelper/WHColorHelperTest.cs @@ -84,6 +84,11 @@ public class WHColorHelperTest private const string NODE_STATUS_HOSTILE_COLOR = "#be0000"; private const string NODE_STATUS_UNKNOWN_COLOR = IWHColorHelper.DEFAULT_COLOR; + + private const string WH_SIGNATURE_ADD_COLOR = "#5cb85c"; + private const string WH_SIGNATURE_UPDATE_COLOR = IWHColorHelper.DEFAULT_COLOR; + private const string WH_SIGNATURE_DELETE_COLOR = "#a52521"; + private IWHColorHelper _whHelper; public WHColorHelperTest() @@ -174,6 +179,15 @@ public void Get_Node_Status_Color() Assert.Equal(NODE_STATUS_UNKNOWN_COLOR, _whHelper.GetNodeStatusColor(WHSystemStatus.Unknown)); Assert.Equal(IWHColorHelper.DEFAULT_COLOR, _whHelper.GetNodeStatusColor((WHSystemStatus)28)); } + + [Fact] + public void Get_Analyzed_Signature_Color() + { + Assert.Equal(WH_SIGNATURE_ADD_COLOR, _whHelper.GetWHAnalyzedSignatureColor(WHAnalizedSignatureEnums.toAdd)); + Assert.Equal(WH_SIGNATURE_DELETE_COLOR, _whHelper.GetWHAnalyzedSignatureColor(WHAnalizedSignatureEnums.toDelete)); + Assert.Equal(WH_SIGNATURE_UPDATE_COLOR, _whHelper.GetWHAnalyzedSignatureColor(WHAnalizedSignatureEnums.toUpdate)); + Assert.Equal(IWHColorHelper.DEFAULT_COLOR, _whHelper.GetWHAnalyzedSignatureColor((WHAnalizedSignatureEnums)28)); + } } diff --git a/src/WHMapper.Tests/WHHelper/WHSignatureHelperTest.cs b/src/WHMapper.Tests/WHHelper/WHSignatureHelperTest.cs index ab99ff60..115b7278 100644 --- a/src/WHMapper.Tests/WHHelper/WHSignatureHelperTest.cs +++ b/src/WHMapper.Tests/WHHelper/WHSignatureHelperTest.cs @@ -1,6 +1,8 @@ using System; using System.Collections.ObjectModel; +using WHMapper.Models.Db; using WHMapper.Models.Db.Enums; +using WHMapper.Models.DTO.EveMapper.Enums; using WHMapper.Services.WHColor; using WHMapper.Services.WHSignature; using WHMapper.Services.WHSignatures; @@ -66,6 +68,61 @@ public async Task Parse_Scan_Result_Test() Assert.Equal(UNSTABLE_WORMHOLE, lastSig.Type); } + [Fact] + public async Task Import_Scan_Result_Test() + { + var ex = await Assert.ThrowsAsync(() => _whHelper.ImportScanResult(SCAN_USER, WH_ID, string.Empty, false)); + Assert.Equal("Bad signatures format", ex.Message); + + /* + bool valideScan = await _whHelper.ImportScanResult(SCAN_USER, WH_ID, DSCAN, false); + Assert.True(valideScan); + + bool invalidateScan = await _whHelper.ImportScanResult(SCAN_USER, WH_ID, SCAN_USER, false); + Assert.False(invalidateScan); + + bool valideScan2 = await _whHelper.ImportScanResult(SCAN_USER, WH_ID, DSCAN, true); + Assert.True(valideScan2);*/ + } + + [Fact] + public async Task Analyzed_Signature_Test() + { + var currentSystemSigs = new Collection + { + new WHSignature(0, FIRST_SIG_NAME,WHSignatureGroup.Unknow,string.Empty,SCAN_USER), + new WHSignature(0, LAST_SIG_NAME,WHSignatureGroup.Wormhole,UNSTABLE_WORMHOLE,SCAN_USER) + }; + + var parsedSigs = new Collection + { + new WHSignature(0, FIRST_SIG_NAME, WHSignatureGroup.Unknow,string.Empty,SCAN_USER), + new WHMapper.Models.Db.WHSignature(0, LAST_SIG_NAME, WHSignatureGroup.Wormhole,UNSTABLE_WORMHOLE,SCAN_USER) + }; + + var analyzedSigs = await _whHelper.AnalyzedSignatures(parsedSigs, currentSystemSigs, false); + Assert.NotNull(analyzedSigs); + Assert.NotEmpty(analyzedSigs); + Assert.Equal(2, analyzedSigs.Count()); + + var firstSig = analyzedSigs.First(); + Assert.Equal(FIRST_SIG_NAME, firstSig.Name); + Assert.Equal(WHAnalizedSignatureEnums.toUpdate, firstSig.Status); + Assert.Equal(WHSignatureGroup.Unknow.ToString(), firstSig.Group); + Assert.Equal(string.Empty, firstSig.Type); + + parsedSigs.RemoveAt(0); + parsedSigs.Add(new WHSignature(0, "NEW_SIG", WHSignatureGroup.Unknow, string.Empty, SCAN_USER)); + + analyzedSigs = await _whHelper.AnalyzedSignatures(parsedSigs, currentSystemSigs, true); + Assert.NotNull(analyzedSigs); + Assert.NotEmpty(analyzedSigs); + Assert.Equal(3, analyzedSigs.Count()); + Assert.Equal(WHAnalizedSignatureEnums.toAdd, analyzedSigs.First().Status); + Assert.Equal(WHAnalizedSignatureEnums.toUpdate, analyzedSigs.ElementAt(1).Status); + Assert.Equal(WHAnalizedSignatureEnums.toDelete, analyzedSigs.Last().Status); + } + } diff --git a/src/WHMapper/Models/DTO/EveMapper/Enums/WHAnalizedSignatureEnums.cs b/src/WHMapper/Models/DTO/EveMapper/Enums/WHAnalizedSignatureEnums.cs new file mode 100644 index 00000000..2ad2c4f5 --- /dev/null +++ b/src/WHMapper/Models/DTO/EveMapper/Enums/WHAnalizedSignatureEnums.cs @@ -0,0 +1,10 @@ +namespace WHMapper.Models.DTO.EveMapper.Enums +{ + + public enum WHAnalizedSignatureEnums + { + toAdd, + toUpdate, + toDelete + } +} \ No newline at end of file diff --git a/src/WHMapper/Models/DTO/EveMapper/WHAnalizedSignature.cs b/src/WHMapper/Models/DTO/EveMapper/WHAnalizedSignature.cs new file mode 100644 index 00000000..6a58af17 --- /dev/null +++ b/src/WHMapper/Models/DTO/EveMapper/WHAnalizedSignature.cs @@ -0,0 +1,23 @@ +using WHMapper.Models.DTO.EveMapper.Enums; + +namespace WHMapper.Models.DTO.EveMapper +{ + + + public class WHAnalizedSignature + { + private readonly WHMapper.Models.Db.WHSignature _signature; + public WHAnalizedSignatureEnums Status { get; private set;} + + public string Name { get { return _signature.Name; } } + public string Group { get { return _signature.Group.ToString(); } } + public string? Type { get { return _signature.Type; } } + + public WHAnalizedSignature(WHMapper.Models.Db.WHSignature whsig,WHAnalizedSignatureEnums status) + { + _signature= whsig; + Status = status; + } + } +} + diff --git a/src/WHMapper/Pages/Mapper/Overview.cs b/src/WHMapper/Pages/Mapper/Overview.cs index 5aaee350..6feb3849 100644 --- a/src/WHMapper/Pages/Mapper/Overview.cs +++ b/src/WHMapper/Pages/Mapper/Overview.cs @@ -1741,7 +1741,7 @@ private async Task OpenSearchAndAddDialog(ItemClickEventArgs e) { DialogOptions disableBackdropClick = new DialogOptions() { - DisableBackdropClick = true, + BackdropClick=false, Position = DialogPosition.Center, MaxWidth = MaxWidth.Medium, FullWidth = true diff --git a/src/WHMapper/Pages/Mapper/RoutePlanner/Overview.cs b/src/WHMapper/Pages/Mapper/RoutePlanner/Overview.cs index cc7c1637..f781707f 100644 --- a/src/WHMapper/Pages/Mapper/RoutePlanner/Overview.cs +++ b/src/WHMapper/Pages/Mapper/RoutePlanner/Overview.cs @@ -148,7 +148,7 @@ private async Task AddRoute() { DialogOptions disableBackdropClick = new DialogOptions() { - DisableBackdropClick = true, + BackdropClick=false, Position = DialogPosition.Center, MaxWidth = MaxWidth.Medium, FullWidth = true diff --git a/src/WHMapper/Pages/Mapper/RoutePlanner/Overview.razor b/src/WHMapper/Pages/Mapper/RoutePlanner/Overview.razor index 7b2a43b0..9427ce54 100644 --- a/src/WHMapper/Pages/Mapper/RoutePlanner/Overview.razor +++ b/src/WHMapper/Pages/Mapper/RoutePlanner/Overview.razor @@ -34,7 +34,7 @@ @route.DestinationName - @route.RouteLength + @route.RouteLength @@ -54,7 +54,7 @@ @route.DestinationName - @route.RouteLength + @route.RouteLength @if(_isEditable) diff --git a/src/WHMapper/Pages/Mapper/Signatures/Import.cs b/src/WHMapper/Pages/Mapper/Signatures/Import.cs index fab53fe5..19470643 100644 --- a/src/WHMapper/Pages/Mapper/Signatures/Import.cs +++ b/src/WHMapper/Pages/Mapper/Signatures/Import.cs @@ -18,6 +18,11 @@ using System.Diagnostics.Tracing; using System.Reflection.Emit; using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Components.Rendering; +using WHMapper.Models.DTO.EveMapper.Enums; +using WHMapper.Models.DTO.EveMapper; +using WHMapper.Services.WHColor; +using Blazor.Diagrams.Core.Events; namespace WHMapper.Pages.Mapper.Signatures { @@ -34,24 +39,93 @@ public partial class Import : Microsoft.AspNetCore.Components.ComponentBase [Inject] private IWHSignatureHelper SignatureHelper { get; set; } = null!; + [Inject] + private IWHColorHelper ColorHelper { get; set; } = null!; + [CascadingParameter] MudDialogInstance MudDialog { get; set; } = null!; [Parameter] public int CurrentSystemNodeId { get; set; } + private IEnumerable? _currentSystemSigs = null!; + private string scanUser = String.Empty; private MudForm _form = null!; private bool _success = false; - private FluentValueValidator _ccValidator = new FluentValueValidator(x => x - .NotEmpty() - .NotNull() - .Matches(IWHSignatureHelper.SCAN_VALIDATION_REGEX)); + private bool Success + { + get => _success; + set + { + _success = value; + if(_success) + { + Task.Run(()=>Analyze()); + } + else + { + AnalyzesSignatures = Enumerable.Empty(); + } + } + } - private string _scanResult = String.Empty; - private bool _lazyDeleted = false; + private IEnumerable? AnalyzesSignatures { get; set; } = null!; + + + private FluentSignatureValueValidator _ccValidator; + + + private string _scanResult = string.Empty; + private string ScanResult + { + get + { + return _scanResult; + } + set + { + Success = false; + _scanResult = value; + } + } + private bool _lazyDeleted = false; + private bool LazyDeleted + { + get => _lazyDeleted; + set + { + _lazyDeleted = value; + Task.Run(()=>Analyze()); + } + } + + protected override void OnInitialized() + { + _ccValidator = new FluentSignatureValueValidator(x => x + .NotEmpty() + .NotNull() + .MustAsync(async (context, value, cancellationToken) => await SignatureHelper.ValidateScanResult(value)) + ); + } + + protected override Task OnParametersSetAsync() + { + Task.Run(() => Restore()); + return base.OnParametersSetAsync(); + } + + private async Task Restore() + { + + ScanResult = String.Empty; + _lazyDeleted = false; + Success = false; + _currentSystemSigs = await SignatureHelper.GetCurrentSystemSignatures(CurrentSystemNodeId); + scanUser = await UserService.GetUserName(); + } private async Task Submit() { @@ -61,9 +135,7 @@ private async Task Submit() { try { - String scanUser = await UserService.GetUserName(); - - if (await SignatureHelper.ImportScanResult(scanUser, CurrentSystemNodeId, _scanResult, _lazyDeleted)) + if (await SignatureHelper.ImportScanResult(scanUser, CurrentSystemNodeId, ScanResult, _lazyDeleted)) { Snackbar.Add("Signatures successfully added/updated", Severity.Success); MudDialog.Close(DialogResult.Ok(true)); @@ -93,6 +165,20 @@ private Task Cancel() return Task.CompletedTask; } + private async Task Analyze() + { + var sigs = await SignatureHelper.ParseScanResult(scanUser, CurrentSystemNodeId, ScanResult); + var res = await SignatureHelper.AnalyzedSignatures(sigs, _currentSystemSigs, _lazyDeleted); + AnalyzesSignatures = res?.OrderBy(x=>x.Name); + await InvokeAsync(() => { + StateHasChanged(); + }); + } + + private string RowStyleFunc(WHAnalizedSignature item, int index) + { + return "background-color:"+ColorHelper.GetWHAnalyzedSignatureColor(item.Status); + } } /// @@ -100,22 +186,22 @@ private Task Cancel() /// You can reuse this class for all your fields, like for the credit card rules above. /// /// - internal class FluentValueValidator : AbstractValidator + internal class FluentSignatureValueValidator : AbstractValidator { - public FluentValueValidator(Action> rule) + public FluentSignatureValueValidator(Action> rule) { rule(RuleFor(x => x)); } - private IEnumerable ValidateValue(T arg) + private async Task> ValidateValue(T arg) { - var result = Validate(arg); + var result = await ValidateAsync(arg); if (result.IsValid) return new string[0]; return result.Errors.Select(e => e.ErrorMessage); } - public Func> Validation => ValidateValue; + public Func>> Validation => async item => await ValidateValue(item); } } diff --git a/src/WHMapper/Pages/Mapper/Signatures/Import.razor b/src/WHMapper/Pages/Mapper/Signatures/Import.razor index 697050b7..d1f2e67d 100644 --- a/src/WHMapper/Pages/Mapper/Signatures/Import.razor +++ b/src/WHMapper/Pages/Mapper/Signatures/Import.razor @@ -1,10 +1,34 @@  - - - + + + + + + + + + + + + + + Name + Group + Type + + + @context.Name + @context.Group + @context.Type + + + + + diff --git a/src/WHMapper/Pages/Mapper/Signatures/Overview.cs b/src/WHMapper/Pages/Mapper/Signatures/Overview.cs index aa29216d..3e5529ff 100644 --- a/src/WHMapper/Pages/Mapper/Signatures/Overview.cs +++ b/src/WHMapper/Pages/Mapper/Signatures/Overview.cs @@ -161,7 +161,7 @@ protected async Task OpenImportDialog() { DialogOptions disableBackdropClick = new DialogOptions() { - DisableBackdropClick = true, + BackdropClick=false, Position = DialogPosition.Center, MaxWidth = MaxWidth.Medium, FullWidth = true diff --git a/src/WHMapper/Services/WHColor/IWHColorHelper.cs b/src/WHMapper/Services/WHColor/IWHColorHelper.cs index 6b61f0a6..2f45b90c 100644 --- a/src/WHMapper/Services/WHColor/IWHColorHelper.cs +++ b/src/WHMapper/Services/WHColor/IWHColorHelper.cs @@ -14,5 +14,6 @@ public interface IWHColorHelper string GetLinkStatusColor(SystemLinkMassStatus status); string GetLinkSelectedColor(); string GetNodeStatusColor(WHSystemStatus status); + string GetWHAnalyzedSignatureColor(WHAnalizedSignatureEnums status); } } diff --git a/src/WHMapper/Services/WHColor/WHColorHelper.cs b/src/WHMapper/Services/WHColor/WHColorHelper.cs index 3164fc81..85fd4de0 100644 --- a/src/WHMapper/Services/WHColor/WHColorHelper.cs +++ b/src/WHMapper/Services/WHColor/WHColorHelper.cs @@ -72,6 +72,11 @@ public class WHColorHelper : IWHColorHelper private const string NODE_STATUS_UNKNOWN_COLOR = IWHColorHelper.DEFAULT_COLOR; + private const string WH_ANALYZED_SIGNATURE_ADD = "#5cb85c"; + private const string WH_ANALYZED_SIGNATURE_UPDATE = IWHColorHelper.DEFAULT_COLOR; + private const string WH_ANALYZED_SIGNATURE_DELETE = "#a52521"; + + private bool FloatEquals(float a, float b) { return Math.Abs(a - b) < EPSILON; @@ -222,6 +227,20 @@ public string GetLinkSelectedColor() } #endregion + public string GetWHAnalyzedSignatureColor(WHAnalizedSignatureEnums status) + { + switch (status) + { + case WHAnalizedSignatureEnums.toAdd: + return WH_ANALYZED_SIGNATURE_ADD; + case WHAnalizedSignatureEnums.toUpdate: + return WH_ANALYZED_SIGNATURE_UPDATE; + case WHAnalizedSignatureEnums.toDelete: + return WH_ANALYZED_SIGNATURE_DELETE; + default: + return IWHColorHelper.DEFAULT_COLOR; + } + } } } diff --git a/src/WHMapper/Services/WHSignatures/IWHSignatureHelper.cs b/src/WHMapper/Services/WHSignatures/IWHSignatureHelper.cs index 40093237..f60e0e29 100644 --- a/src/WHMapper/Services/WHSignatures/IWHSignatureHelper.cs +++ b/src/WHMapper/Services/WHSignatures/IWHSignatureHelper.cs @@ -1,4 +1,6 @@ -namespace WHMapper.Services.WHSignature +using WHMapper.Models.DTO.EveMapper; + +namespace WHMapper.Services.WHSignature { public interface IWHSignatureHelper { @@ -6,5 +8,7 @@ public interface IWHSignatureHelper Task ValidateScanResult(string? scanResult); Task?> ParseScanResult(string scanUser, int currentSystemScannedId, string? scanResult); Task ImportScanResult(string scanUser, int currentSystemScannedId, string? scanResult, bool lazyDeleted); + Task?> GetCurrentSystemSignatures(int whId); + Task?> AnalyzedSignatures(IEnumerable? parsedSigs,IEnumerable? currentSystemSigs , bool lazyDeleted); } } diff --git a/src/WHMapper/Services/WHSignatures/WHSignatureHelper.cs b/src/WHMapper/Services/WHSignatures/WHSignatureHelper.cs index 77107177..2566c304 100644 --- a/src/WHMapper/Services/WHSignatures/WHSignatureHelper.cs +++ b/src/WHMapper/Services/WHSignatures/WHSignatureHelper.cs @@ -1,5 +1,7 @@ using System.Text.RegularExpressions; using WHMapper.Models.Db.Enums; +using WHMapper.Models.DTO.EveMapper; +using WHMapper.Models.DTO.EveMapper.Enums; using WHMapper.Repositories.WHSignatures; using WHMapper.Services.WHSignature; @@ -8,7 +10,7 @@ namespace WHMapper.Services.WHSignatures { public class WHSignatureHelper : IWHSignatureHelper { - private IWHSignatureRepository _dbWHSignatures; + private readonly IWHSignatureRepository _dbWHSignatures; public WHSignatureHelper(IWHSignatureRepository sigRepo) { @@ -21,8 +23,11 @@ public Task ValidateScanResult(string? scanResult) { if (!string.IsNullOrEmpty(scanResult)) { - Match match = Regex.Match(scanResult, IWHSignatureHelper.SCAN_VALIDATION_REGEX, RegexOptions.IgnoreCase, TimeSpan.FromSeconds(2)); - return Task.FromResult(match.Success); + var matches = Regex.Matches(scanResult, IWHSignatureHelper.SCAN_VALIDATION_REGEX, RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.ExplicitCapture, TimeSpan.FromSeconds(2)); + // Compter le nombre de lignes non vides dans scanResult + int nonEmptyLinesCount = scanResult.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries).Length; + + return Task.FromResult(matches.Count == nonEmptyLinesCount); } return Task.FromResult(false); } @@ -33,63 +38,85 @@ public Task ValidateScanResult(string? scanResult) } - public Task?> ParseScanResult(string scanUser, int currentSystemScannedId, string? scanResult) + public Task?> ParseScanResult(string scanUser, int currentSystemScannedId, string? scanResult) + { + + IList sigResult = new List(); + + if (string.IsNullOrEmpty(scanResult)) { - string sigName = string.Empty; - WHSignatureGroup sigGroup = WHSignatureGroup.Unknow; - string sigType = string.Empty; - string[]? sigvalues = null; - string[]? splittedSig = null; + return Task.FromResult?>(sigResult); + } - IList sigResult = new List(); + try + { + string[] sigValues = scanResult.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); - if (!string.IsNullOrEmpty(scanResult)) + foreach (string sigValue in sigValues) { - Regex lineRegex = new Regex("\n", RegexOptions.None, TimeSpan.FromSeconds(2)); - Regex tabRegex = new Regex("\t", RegexOptions.None, TimeSpan.FromSeconds(2)); - try - { - sigvalues = lineRegex.Split(scanResult); - } - catch (RegexMatchTimeoutException) + string[] splittedSig = sigValue.Split('\t'); + if (splittedSig.Length < 4) continue; // Assurez-vous qu'il y a suffisamment d'éléments pour éviter les erreurs d'index + + string sigName = splittedSig[0]; + WHSignatureGroup sigGroup = WHSignatureGroup.Unknow; + string sigType = string.Empty; + + if (!string.IsNullOrWhiteSpace(splittedSig[2])) { - return Task.FromResult?>(null); + string textGroup = splittedSig[2].Contains(' ') ? splittedSig[2].Split(' ').First() : splittedSig[2]; + Enum.TryParse(textGroup, out sigGroup); + sigType = splittedSig[3]; } - foreach (string sigValue in sigvalues) - { - sigGroup = WHSignatureGroup.Unknow; - sigType = string.Empty; + sigResult.Add(new WHMapper.Models.Db.WHSignature(currentSystemScannedId, sigName, sigGroup, sigType, scanUser)); + } + } + catch (Exception ex) when (ex is RegexMatchTimeoutException || ex is ArgumentException) + { + // Log l'exception si nécessaire + return Task.FromResult?>(null); + } - try - { - splittedSig = tabRegex.Split(sigValue); - } - catch (RegexMatchTimeoutException) - { - return Task.FromResult?>(null); - } + return Task.FromResult?>(sigResult); + } - sigName = splittedSig[0]; + public Task?> AnalyzedSignatures(IEnumerable? parsedSigs,IEnumerable? currentSystemSigs , bool lazyDeleted) + { + IEnumerable? toAdd = new List(); + IEnumerable? toUpdate = new List(); + IEnumerable? toDelete = new List(); + if (parsedSigs == null || !parsedSigs.Any()) return Task.FromResult?>(null); - if (!String.IsNullOrWhiteSpace(splittedSig[2])) - { - var textGroup = splittedSig[2]; - if (splittedSig[2].Contains(' ')) - textGroup = splittedSig[2].Split(' ').First(); + if (currentSystemSigs == null || !currentSystemSigs.Any()) + { + toAdd = parsedSigs.Select(x => new WHAnalizedSignature(x, WHAnalizedSignatureEnums.toAdd)).ToList(); + return Task.FromResult?>(toAdd); + } - Enum.TryParse(textGroup, out sigGroup); + var sigsToAdd = parsedSigs.ExceptBy(currentSystemSigs.Select(x => x.Name), y => y.Name); + if (sigsToAdd.Any()) + toAdd=sigsToAdd.Select(x=>new WHAnalizedSignature(x,WHAnalizedSignatureEnums.toAdd)).ToList(); - sigType = splittedSig[3]; - } + var sigsToUpdate = currentSystemSigs.IntersectBy(parsedSigs.Select(x => x.Name), y => y.Name); + if (sigsToUpdate.Any()) + toUpdate = sigsToUpdate.Select(x=>new WHAnalizedSignature(x,WHAnalizedSignatureEnums.toUpdate)).ToList(); - sigResult.Add(new WHMapper.Models.Db.WHSignature(currentSystemScannedId, sigName, sigGroup, sigType, scanUser)); - } + if (lazyDeleted) + { + var sigsToDeleted = currentSystemSigs.ExceptBy(parsedSigs.Select(x => x.Name), y => y.Name); + if (sigsToDeleted.Any()) + toDelete = sigsToDeleted.Select(x=>new WHAnalizedSignature(x,WHAnalizedSignatureEnums.toDelete)).ToList(); } + - return Task.FromResult?>(sigResult); + return Task.FromResult?>(toAdd.Concat(toUpdate).Concat(toDelete)); + } + public async Task?> GetCurrentSystemSignatures(int whId) + { + var signatures = await _dbWHSignatures.GetByWHId(whId); + return signatures; } public async Task ImportScanResult(string scanUser, int currentSystemScannedId, string? scanResult, bool lazyDeleted) @@ -164,5 +191,7 @@ private async Task DeleteSignatures(IEnumerable currentSy await _dbWHSignatures.DeleteById(sig.Id); } } + + } } diff --git a/src/WHMapper/Shared/AccessControl.razor b/src/WHMapper/Shared/AccessControl.razor index fd27dc04..cf20bdca 100644 --- a/src/WHMapper/Shared/AccessControl.razor +++ b/src/WHMapper/Shared/AccessControl.razor @@ -7,7 +7,7 @@ - @_username + @_username
@@ -34,7 +34,7 @@ - @_username + @_username @@ -58,7 +58,7 @@ - Account + Account diff --git a/src/WHMapper/Shared/MainLayout.razor b/src/WHMapper/Shared/MainLayout.razor index a1cfb7dd..129d3067 100644 --- a/src/WHMapper/Shared/MainLayout.razor +++ b/src/WHMapper/Shared/MainLayout.razor @@ -1,6 +1,7 @@ @inherits LayoutComponentBase - + + @@ -59,11 +60,11 @@ { _currentTheme = new MudTheme() { - Palette = new PaletteDark() + PaletteDark = new PaletteDark() { Black = "#27272f", Background = "#32333d", - BackgroundGrey = "#27272f", + BackgroundGray = "#27272f", Surface = "#373740", DrawerBackground = "#27272f", DrawerText = "rgba(255,255,255, 0.50)", diff --git a/src/WHMapper/WHMapper.csproj b/src/WHMapper/WHMapper.csproj index 75b6b54f..02970b3b 100644 --- a/src/WHMapper/WHMapper.csproj +++ b/src/WHMapper/WHMapper.csproj @@ -1,4 +1,4 @@ - + net8.0 @@ -96,7 +96,7 @@ - + From aebf9151d172d7f532f04abd67422f203e60c76c Mon Sep 17 00:00:00 2001 From: pfhuillet Date: Sun, 28 Jul 2024 22:35:21 +0200 Subject: [PATCH 3/7] Fix test checksum SDE file Fix MudAutocomplete search method --- src/WHMapper/Pages/Mapper/Add.cs | 1 - src/WHMapper/Pages/Mapper/Add.razor | 2 +- src/WHMapper/Pages/Mapper/Administration/Overview.razor | 4 ++-- src/WHMapper/Services/SDE/SDEServiceManager.cs | 5 +++++ 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/WHMapper/Pages/Mapper/Add.cs b/src/WHMapper/Pages/Mapper/Add.cs index 36c4b718..83e88b10 100644 --- a/src/WHMapper/Pages/Mapper/Add.cs +++ b/src/WHMapper/Pages/Mapper/Add.cs @@ -163,7 +163,6 @@ private async Task Submit() } } - private void Cancel() { MudDialog.Cancel(); diff --git a/src/WHMapper/Pages/Mapper/Add.razor b/src/WHMapper/Pages/Mapper/Add.razor index 32af71f8..2958159c 100644 --- a/src/WHMapper/Pages/Mapper/Add.razor +++ b/src/WHMapper/Pages/Mapper/Add.razor @@ -3,7 +3,7 @@ - Date: Sun, 28 Jul 2024 23:03:51 +0200 Subject: [PATCH 4/7] fix checksum exist --- src/WHMapper/Services/SDE/SDEServiceManager.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/WHMapper/Services/SDE/SDEServiceManager.cs b/src/WHMapper/Services/SDE/SDEServiceManager.cs index b2c895f8..fa579ae4 100644 --- a/src/WHMapper/Services/SDE/SDEServiceManager.cs +++ b/src/WHMapper/Services/SDE/SDEServiceManager.cs @@ -70,14 +70,13 @@ private string GetCurrentChecksum() { try { - if(!_fileSystem.File.Exists(SDE_CHECKSUM_FILE)) - { - return string.Empty; - } - var fileContent = _fileSystem.File.ReadLines(SDE_CHECKSUM_FILE); return string.Join(";", fileContent); } + catch (FileNotFoundException) + { + _logger.LogInformation("No checksum file found"); + } catch (Exception ex) { _logger.LogWarning(ex.ToString()); From 8848e98d40887b44aed06c8483c6d77518872b4a Mon Sep 17 00:00:00 2001 From: pfh59 <109206285+pfh59@users.noreply.github.com> Date: Thu, 1 Aug 2024 12:30:56 +0200 Subject: [PATCH 5/7] fix : (#295) - signature update time and updater - import sigs ui - preview sigs import preview value --- .../Pages/Mapper/Signatures/Import.razor | 4 ++-- .../WHSignatures/WHSignatureHelper.cs | 19 ++++++++++++------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/WHMapper/Pages/Mapper/Signatures/Import.razor b/src/WHMapper/Pages/Mapper/Signatures/Import.razor index d1f2e67d..1a6621ff 100644 --- a/src/WHMapper/Pages/Mapper/Signatures/Import.razor +++ b/src/WHMapper/Pages/Mapper/Signatures/Import.razor @@ -7,9 +7,9 @@ RequiredError="Required Scan Result!" Validation="@_ccValidator.Validation" Immediate="true"/> + Virtualize="true" Loading="@(AnalyzesSignatures==null)" LoadingProgressColor="Color.Info" Editable="false" Height="230px" HorizontalScrollbar="false" RowStyleFunc="RowStyleFunc"> - + diff --git a/src/WHMapper/Services/WHSignatures/WHSignatureHelper.cs b/src/WHMapper/Services/WHSignatures/WHSignatureHelper.cs index 2566c304..16e64954 100644 --- a/src/WHMapper/Services/WHSignatures/WHSignatureHelper.cs +++ b/src/WHMapper/Services/WHSignatures/WHSignatureHelper.cs @@ -98,7 +98,11 @@ public Task ValidateScanResult(string? scanResult) if (sigsToAdd.Any()) toAdd=sigsToAdd.Select(x=>new WHAnalizedSignature(x,WHAnalizedSignatureEnums.toAdd)).ToList(); - var sigsToUpdate = currentSystemSigs.IntersectBy(parsedSigs.Select(x => x.Name), y => y.Name); + var sigsToUpdate = currentSystemSigs.IntersectBy(parsedSigs.Where(x=> x.Group==WHSignatureGroup.Unknow).Select(x => x.Name), y => y.Name); + var sigsToUpdate2 = parsedSigs.Where(x=> x.Group!=WHSignatureGroup.Unknow).IntersectBy(currentSystemSigs.Select(x => x.Name), y => y.Name); + + sigsToUpdate = sigsToUpdate.Concat(sigsToUpdate2); + if (sigsToUpdate.Any()) toUpdate = sigsToUpdate.Select(x=>new WHAnalizedSignature(x,WHAnalizedSignatureEnums.toUpdate)).ToList(); @@ -148,8 +152,6 @@ public async Task ImportScanResult(string scanUser, int currentSystemScann sigUpdated = await UpdateSignatures(currentSystemSigs, sigs); sigAdded = await AddNewSignatures(currentSystemSigs, sigs, currentSystemScannedId); - - await Task.Delay(500); // Consider removing or justifying this delay. return sigUpdated || sigAdded; } @@ -161,17 +163,20 @@ private async Task UpdateSignatures(IEnumerable cur foreach (var sig in sigsToUpdate) { var sigParse = sigs.FirstOrDefault(x => x.Name == sig.Name); - if (sigParse != null && sigParse.Group != WHSignatureGroup.Unknow) + if (sigParse != null) { - sig.Group = sigParse.Group; - sig.Type = String.IsNullOrEmpty(sig.Type) ? sigParse.Type : sig.Type; sig.Updated = sigParse.Updated; sig.UpdatedBy = sigParse.UpdatedBy; + if(sigParse.Group != WHSignatureGroup.Unknow) + { + sig.Group = sigParse.Group; + sig.Type = String.IsNullOrEmpty(sig.Type) ? sigParse.Type : sig.Type; + } } } var resUpdate = await _dbWHSignatures.Update(sigsToUpdate); - return resUpdate != null && resUpdate.Count() == sigsToUpdate.Count(); + return resUpdate != null && resUpdate.Count() == sigsToUpdate.Count(); } private async Task AddNewSignatures(IEnumerable currentSystemSigs, IEnumerable sigs, int currentSystemScannedId) From f7c8a6e67d2f62f08c22f0bcf01d78b6ff7d9571 Mon Sep 17 00:00:00 2001 From: pfh59 <109206285+pfh59@users.noreply.github.com> Date: Thu, 1 Aug 2024 18:23:56 +0200 Subject: [PATCH 6/7] Multi fixes Fix : admin UI FIx : menu UI Fix : antiforegy error Fix : route planner search system Intercept SDE checksum error when directory not present --- src/WHMapper/App.razor | 1 - .../Models/DTO/InitialApplicationState.cs | 1 - src/WHMapper/Models/DTO/TokenProvider.cs | 1 - .../Mapper/Administration/Overview.razor | 99 ++++++++++--------- .../Pages/Mapper/RoutePlanner/Add.razor | 2 +- src/WHMapper/Pages/_Host.cshtml | 1 - src/WHMapper/Program.cs | 9 +- .../Services/SDE/SDEServiceManager.cs | 4 + src/WHMapper/Shared/AccessControl.razor | 52 ++-------- 9 files changed, 69 insertions(+), 101 deletions(-) diff --git a/src/WHMapper/App.razor b/src/WHMapper/App.razor index 032f5016..3dc1943c 100644 --- a/src/WHMapper/App.razor +++ b/src/WHMapper/App.razor @@ -30,7 +30,6 @@ { TokenProvider.AccessToken = InitialState?.AccessToken; TokenProvider.RefreshToken = InitialState?.RefreshToken; - TokenProvider.XsrfToken = InitialState?.XsrfToken; return base.OnInitializedAsync(); } diff --git a/src/WHMapper/Models/DTO/InitialApplicationState.cs b/src/WHMapper/Models/DTO/InitialApplicationState.cs index d7814356..aacb7169 100644 --- a/src/WHMapper/Models/DTO/InitialApplicationState.cs +++ b/src/WHMapper/Models/DTO/InitialApplicationState.cs @@ -5,7 +5,6 @@ public class InitialApplicationState { public string? AccessToken { get; set; } public string? RefreshToken { get; set; } - public string? XsrfToken { get; set; } } } diff --git a/src/WHMapper/Models/DTO/TokenProvider.cs b/src/WHMapper/Models/DTO/TokenProvider.cs index e5a27bf8..79da1919 100644 --- a/src/WHMapper/Models/DTO/TokenProvider.cs +++ b/src/WHMapper/Models/DTO/TokenProvider.cs @@ -7,7 +7,6 @@ public class TokenProvider { public string? AccessToken { get; set; } public string? RefreshToken { get; set; } - public string? XsrfToken { get; set; } } } diff --git a/src/WHMapper/Pages/Mapper/Administration/Overview.razor b/src/WHMapper/Pages/Mapper/Administration/Overview.razor index c3b5871c..844cc01a 100644 --- a/src/WHMapper/Pages/Mapper/Administration/Overview.razor +++ b/src/WHMapper/Pages/Mapper/Administration/Overview.razor @@ -36,38 +36,39 @@ - - - - - @if (item.EntityType == EveEntityEnums.Alliance) - { - - } - else if (item.EntityType == EveEntityEnums.Corporation) - { - - } - else - { - - } - @item.Name - - - - + +
+ + + + @if (item.EntityType == EveEntityEnums.Alliance) + { + + } + else if (item.EntityType == EveEntityEnums.Corporation) + { + + } + else + { + + } + @item.Name + + + + +
- @@ -98,23 +99,25 @@ - - - - - - @item?.Name - - - - + +
+ + + + + @item?.Name + + + + +
diff --git a/src/WHMapper/Pages/Mapper/RoutePlanner/Add.razor b/src/WHMapper/Pages/Mapper/RoutePlanner/Add.razor index 21f1c3d7..b659d92b 100644 --- a/src/WHMapper/Pages/Mapper/RoutePlanner/Add.razor +++ b/src/WHMapper/Pages/Mapper/RoutePlanner/Add.razor @@ -3,7 +3,7 @@ - { option.Configuration = builder.Configuration.GetConnectionString("RedisConnection"); option.InstanceName = "WHMapper"; }); + builder.Services.AddDataProtection() + .SetApplicationName("WHMapper") + .PersistKeysToStackExchangeRedis(redis,"DataProtection-Keys"); + builder.Services.AddSignalR(); builder.Services.AddRazorPages(); diff --git a/src/WHMapper/Services/SDE/SDEServiceManager.cs b/src/WHMapper/Services/SDE/SDEServiceManager.cs index fa579ae4..bde2274c 100644 --- a/src/WHMapper/Services/SDE/SDEServiceManager.cs +++ b/src/WHMapper/Services/SDE/SDEServiceManager.cs @@ -77,6 +77,10 @@ private string GetCurrentChecksum() { _logger.LogInformation("No checksum file found"); } + catch(DirectoryNotFoundException) + { + _logger.LogInformation("No checksum file found"); + } catch (Exception ex) { _logger.LogWarning(ex.ToString()); diff --git a/src/WHMapper/Shared/AccessControl.razor b/src/WHMapper/Shared/AccessControl.razor index cf20bdca..511f2bb7 100644 --- a/src/WHMapper/Shared/AccessControl.razor +++ b/src/WHMapper/Shared/AccessControl.razor @@ -5,50 +5,25 @@ - + @_username - - - - Add Account - - -
- - - Access List - -
-
- - - Logout - -
+ Add Account + Access List + Logout
- + @_username -
- - - Add Account - -
-
- - - Logout - -
+ Add Account + Logout
@@ -56,17 +31,12 @@
- + Account -
- - - Login - -
+ Login
@@ -81,13 +51,9 @@ [Inject] private IEveUserInfosServices UserService { get; set; } = null!; - [Inject] - private Models.DTO.TokenProvider TokenProvider {get;set;} = null!; - protected override async Task OnInitializedAsync() { _username = await UserService.GetUserName(); StateHasChanged(); - } } From 3c8b7936723aab85d52ecc8bcc0a202b0582ec2a Mon Sep 17 00:00:00 2001 From: pfh59 <109206285+pfh59@users.noreply.github.com> Date: Thu, 8 Aug 2024 21:20:36 +0200 Subject: [PATCH 7/7] WH propeties infos and bugs fixes (#299) - #297 - #298 - remove WHStatic and use WormholeType - fix #300 - add WH properties tooltip on signatures tabs - refactor some codes - Fix reliability : - Use a comparison to 'default(TEveApiEntity)' instead or add a constraint to 'TEveApiEntity' so that it can't be a value type. - Fix ui --- .../Models/Graph/GraphModelsTest.cs | 2 +- .../WHHelper/EveWHMapperEntityTest.cs | 4 +- .../Models/Custom/Node/EveSystemNodeModel.cs | 4 +- .../DTO/EveMapper/EveEntity/WHEntity.cs | 30 ++- src/WHMapper/Models/DTO/EveMapper/WHStatic.cs | 20 -- .../Models/DTO/EveMapper/WormholeType.cs | 25 ++- .../Pages/Mapper/Administration/Delete.razor | 4 +- .../Pages/Mapper/Administration/Overview.cs | 4 +- .../Mapper/CustomNode/EveSystemNode.razor | 2 +- .../Pages/Mapper/LinkInfos/Overview.razor | 35 +-- src/WHMapper/Pages/Mapper/Overview.cs | 212 +++++++++++------- src/WHMapper/Pages/Mapper/Overview.razor | 27 ++- .../Pages/Mapper/RoutePlanner/Delete.razor | 2 +- .../Pages/Mapper/RoutePlanner/Overview.cs | 8 +- .../Pages/Mapper/RoutePlanner/Overview.razor | 8 +- .../Pages/Mapper/Signatures/Delete.razor | 4 +- .../Pages/Mapper/Signatures/Import.cs | 2 +- .../Pages/Mapper/Signatures/Import.razor | 2 +- .../Pages/Mapper/Signatures/Overview.cs | 14 +- .../Pages/Mapper/Signatures/Overview.razor | 25 ++- .../Pages/Mapper/SystemInfos/Overview.razor | 51 +++-- .../Services/EveMapper/EveMapperHelper.cs | 26 +-- .../Services/EveMapper/EveMapperService.cs | 20 +- src/WHMapper/Shared/AccessControl.razor | 6 +- 24 files changed, 323 insertions(+), 214 deletions(-) delete mode 100644 src/WHMapper/Models/DTO/EveMapper/WHStatic.cs diff --git a/src/WHMapper.Tests/Models/Graph/GraphModelsTest.cs b/src/WHMapper.Tests/Models/Graph/GraphModelsTest.cs index 83ba2541..e1df2e1e 100644 --- a/src/WHMapper.Tests/Models/Graph/GraphModelsTest.cs +++ b/src/WHMapper.Tests/Models/Graph/GraphModelsTest.cs @@ -109,7 +109,7 @@ public void Eve_System_Link_Model() { var node = new EveSystemNodeModel(new WHSystem(DEFAULT_MAP_ID,SOLAR_SYSTEM_JITA_ID, SOLAR_SYSTEM_JITA_NAME, SOLAR_SYSTEM_JITA_SECURITY), null, REGION_JITA_NAME, CONSTELLATION_JITA_NAME); Assert.Equal(WHSystemStatus.Unknown,node.SystemStatus); - var node2 = new EveSystemNodeModel(new WHSystem(DEFAULT_MAP_ID, SOLAR_SYSTEM_WH_ID, SOLAR_SYSTEM_WH_NAME, -1.0F), null, REGION_WH_NAME, CONSTELLATION_WH_NAME,SOLAR_SYSTEM_WH_CLASS, SOLAR_SYSTEM_WH_EFFECT,null, new List() { new WHStatic(SOLAR_SYSTEM_WH_STATICS,EveSystemType.C3) }) ; + var node2 = new EveSystemNodeModel(new WHSystem(DEFAULT_MAP_ID, SOLAR_SYSTEM_WH_ID, SOLAR_SYSTEM_WH_NAME, -1.0F), null, REGION_WH_NAME, CONSTELLATION_WH_NAME,SOLAR_SYSTEM_WH_CLASS, SOLAR_SYSTEM_WH_EFFECT,null, new List() { new WormholeType(SOLAR_SYSTEM_WH_STATICS,EveSystemType.C3) }) ; var link = new EveSystemLinkModel(new WHSystemLink(1, 2), node, node2); diff --git a/src/WHMapper.Tests/WHHelper/EveWHMapperEntityTest.cs b/src/WHMapper.Tests/WHHelper/EveWHMapperEntityTest.cs index 11a97ba5..be54bc41 100644 --- a/src/WHMapper.Tests/WHHelper/EveWHMapperEntityTest.cs +++ b/src/WHMapper.Tests/WHHelper/EveWHMapperEntityTest.cs @@ -53,8 +53,8 @@ public class EveWHMapperEntityTest private const int WH_TYPE_ID1 = 30583; private const int WH_TYPE_ID2 = 30584; - private readonly IEveMapperService _eveMapperService; - private readonly IEveMapperCacheService _eveMapperCacheService; + private readonly IEveMapperService _eveMapperService = null!; + private readonly IEveMapperCacheService _eveMapperCacheService = null!; public EveWHMapperEntityTest() { diff --git a/src/WHMapper/Models/Custom/Node/EveSystemNodeModel.cs b/src/WHMapper/Models/Custom/Node/EveSystemNodeModel.cs index 4a14c4e4..1e6f0c1e 100644 --- a/src/WHMapper/Models/Custom/Node/EveSystemNodeModel.cs +++ b/src/WHMapper/Models/Custom/Node/EveSystemNodeModel.cs @@ -115,13 +115,13 @@ public WHSystemStatus SystemStatus public EveSystemType SystemType { get; private set; } public WHEffect Effect { get; private set; } = WHEffect.None; public IList? EffectDetails { get; private set; } = null!; - public IList? Statics { get; private set; } = null!; + public IList? Statics { get; private set; } = null!; public BlockingCollection ConnectedUsers { get; private set; } = new BlockingCollection(); public bool IsRouteWaypoint{get;set;} = false; - public EveSystemNodeModel(WHSystem wh, WHNote? note, string regionName, string constellationName, EveSystemType systemType, WHEffect whEffect, IList? effectDetails, IList? whStatics) + public EveSystemNodeModel(WHSystem wh, WHNote? note, string regionName, string constellationName, EveSystemType systemType, WHEffect whEffect, IList? effectDetails, IList? whStatics) { this._wh = wh; if(note != null) diff --git a/src/WHMapper/Models/DTO/EveMapper/EveEntity/WHEntity.cs b/src/WHMapper/Models/DTO/EveMapper/EveEntity/WHEntity.cs index 60043f1a..4ace4681 100644 --- a/src/WHMapper/Models/DTO/EveMapper/EveEntity/WHEntity.cs +++ b/src/WHMapper/Models/DTO/EveMapper/EveEntity/WHEntity.cs @@ -6,23 +6,47 @@ namespace WHMapper.Models.DTO.EveMapper.EveEntity; public class WHEntity : AEveEntity { private const int DOGMA_ATTR_TARGET_SYSTEM_CLASS_FOR_WORMHOLES_ID = 1381; - //private const int DOGMA_ATTR_DISTRIBUTION_ID_OF_TARGET_WORMHOLE_DISTRIBUTION_ID = 1457; - + private const int DOGMA_ATTR_WORMHOLE_MAX_STABLE_MASS = 1383; + private const int DOGMA_ATTR_WORMHOLE_MAX_JUMP_MASS = 1385; + private const int DOGMA_ATTR_WORMHOLE_MAX_STABLE_TIME = 1382; //unit8id 3 value 1440 = 24h??? + + public float SystemTypeValue { get; private set; } + public float MassMax {get; private set;} + public float JumpMassMax {get; private set;} + + /// + /// Time in minutes + /// 24h = 1440 + /// 18h = 1080 + /// + public float StableTime {get;private set;} public WHEntity(int id, WHMapper.Models.DTO.EveAPI.Universe.Type type) : base(id, type.Name[9..].Trim(), EveEntityEnums.Wormhole) { SystemTypeValue = 0; + MassMax = 0; + JumpMassMax = 0; + StableTime = 0; if (type.DogmaAttributes != null) + { SystemTypeValue = type.DogmaAttributes.Where(x => x.AttributeId == DOGMA_ATTR_TARGET_SYSTEM_CLASS_FOR_WORMHOLES_ID).Select(x => x.Value).FirstOrDefault(0); + MassMax = type.DogmaAttributes.Where(x => x.AttributeId == DOGMA_ATTR_WORMHOLE_MAX_STABLE_MASS).Select(x => x.Value).FirstOrDefault(0); + JumpMassMax = type.DogmaAttributes.Where(x => x.AttributeId == DOGMA_ATTR_WORMHOLE_MAX_JUMP_MASS).Select(x => x.Value).FirstOrDefault(0); + StableTime = type.DogmaAttributes.Where(x => x.AttributeId == DOGMA_ATTR_WORMHOLE_MAX_STABLE_TIME).Select(x => x.Value).FirstOrDefault(0); + } } [JsonConstructor] - public WHEntity(int id, string name,float systemTypeValue) + public WHEntity(int id, string name,float systemTypeValue, float massMax, float jumpMassMax, float stableTime) : base(id, name, EveEntityEnums.Wormhole) { SystemTypeValue = systemTypeValue; + MassMax = massMax; + JumpMassMax = jumpMassMax; + StableTime = stableTime; } + } diff --git a/src/WHMapper/Models/DTO/EveMapper/WHStatic.cs b/src/WHMapper/Models/DTO/EveMapper/WHStatic.cs deleted file mode 100644 index 91111938..00000000 --- a/src/WHMapper/Models/DTO/EveMapper/WHStatic.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.ComponentModel; -using WHMapper.Models.DTO.EveMapper.Enums; - -namespace WHMapper.Models.DTO.EveMapper -{ - public class WHStatic - { - public string WHName { get; private set; } - public EveSystemType EveSystemDestinationType { get; private set; } - - public WHStatic(string whName, EveSystemType destType) - { - WHName = whName; - EveSystemDestinationType = destType; - } - } -} - - diff --git a/src/WHMapper/Models/DTO/EveMapper/WormholeType.cs b/src/WHMapper/Models/DTO/EveMapper/WormholeType.cs index 3546c7e2..137982b3 100644 --- a/src/WHMapper/Models/DTO/EveMapper/WormholeType.cs +++ b/src/WHMapper/Models/DTO/EveMapper/WormholeType.cs @@ -1,5 +1,6 @@ using System; using WHMapper.Models.DTO.EveMapper.Enums; +using WHMapper.Models.DTO.EveMapper.EveEntity; namespace WHMapper.Models.DTO.EveMapper { @@ -7,15 +8,33 @@ public class WormholeType { public string Name { private set; get; } public EveSystemType Destination { private set; get; } - public EveSystemType[]? Sources { private set; get; } - public WormholeType(string name, EveSystemType dest, EveSystemType[]? srcs) + public float MassMax {get; private set;} + public float JumpMassMax {get; private set;} + + /// + /// Time in minutes + /// 24h = 1440 + /// 18h = 1080 + /// + public float StableTime {get;private set;} + + public WormholeType(string name, EveSystemType dest) { Name = name; Destination = dest; - Sources = srcs; } + public WormholeType(WHEntity entity) + { + Name = entity.Name; + Destination = (EveSystemType)entity.SystemTypeValue; + MassMax = entity.MassMax; + JumpMassMax = entity.JumpMassMax; + StableTime = entity.StableTime; + } + + public override string ToString() { if (string.IsNullOrEmpty(Destination.ToString())) diff --git a/src/WHMapper/Pages/Mapper/Administration/Delete.razor b/src/WHMapper/Pages/Mapper/Administration/Delete.razor index 5b00aa1f..03e217bf 100644 --- a/src/WHMapper/Pages/Mapper/Administration/Delete.razor +++ b/src/WHMapper/Pages/Mapper/Administration/Delete.razor @@ -2,12 +2,12 @@ @if (AccessId > 0) { - @MSG_ACCESS_DELETE + @MSG_ACCESS_DELETE } @if (AdminId > 0) { - @MSG_ADMIN_DELETE + @MSG_ADMIN_DELETE } diff --git a/src/WHMapper/Pages/Mapper/Administration/Overview.cs b/src/WHMapper/Pages/Mapper/Administration/Overview.cs index 3a00ef52..602c02a8 100644 --- a/src/WHMapper/Pages/Mapper/Administration/Overview.cs +++ b/src/WHMapper/Pages/Mapper/Administration/Overview.cs @@ -182,7 +182,7 @@ private async Task DeleteAccess(int id) var options = new DialogOptions() { CloseButton = true, MaxWidth = MaxWidth.ExtraSmall }; var dialog = await DialogService.ShowAsync("Delete WHMapper Access", parameters, options); - DialogResult result = await dialog.Result; + DialogResult? result = await dialog.Result; if (result!=null && !result.Canceled) await Restore(); @@ -197,7 +197,7 @@ private async Task DeleteAdmin(int id) var options = new DialogOptions() { CloseButton = true, MaxWidth = MaxWidth.ExtraSmall }; var dialog = await DialogService.ShowAsync("Delete WHMapper Admin", parameters, options); - DialogResult result = await dialog.Result; + DialogResult? result = await dialog.Result; if (result != null && !result.Canceled) await Restore(); diff --git a/src/WHMapper/Pages/Mapper/CustomNode/EveSystemNode.razor b/src/WHMapper/Pages/Mapper/CustomNode/EveSystemNode.razor index d60c63b1..2f24bbdf 100644 --- a/src/WHMapper/Pages/Mapper/CustomNode/EveSystemNode.razor +++ b/src/WHMapper/Pages/Mapper/CustomNode/EveSystemNode.razor @@ -69,7 +69,7 @@ { @foreach (var item in Node.Statics) { - @item.EveSystemDestinationType.ToString() + @item.Destination.ToString() } } diff --git a/src/WHMapper/Pages/Mapper/LinkInfos/Overview.razor b/src/WHMapper/Pages/Mapper/LinkInfos/Overview.razor index a4319bb6..c7070cc3 100644 --- a/src/WHMapper/Pages/Mapper/LinkInfos/Overview.razor +++ b/src/WHMapper/Pages/Mapper/LinkInfos/Overview.razor @@ -1,50 +1,51 @@ @using WHMapper.Models.Db.Enums @using WHMapper.Services.WHColor -