From f0794a54fda9b7a7bf17fb9c5106f236e2e3672c Mon Sep 17 00:00:00 2001 From: abarz722 Date: Tue, 28 May 2024 15:59:54 +0200 Subject: [PATCH 01/13] formal changes --- roles/lib/files/FWO.Config.Api/Config.cs | 4 +- .../lib/files/FWO.Config.Api/GlobalConfig.cs | 31 ++++++------ roles/lib/files/FWO.Config.Api/UserConfig.cs | 47 ++++++++++--------- .../FWO.GlobalConstants/GlobalConstants.cs | 1 + .../files/FWO.Report/Data/ManagementReport.cs | 29 ++++++------ .../Pages/Settings/SettingsCustomTexts.razor | 4 +- .../Pages/Settings/SettingsDefaults.razor | 4 +- .../Pages/Settings/SettingsImport.razor | 2 +- .../Pages/Settings/SettingsLanguage.razor | 4 +- .../Pages/Settings/SettingsModelling.razor | 22 ++++----- roles/ui/files/FWO.UI/Pages/Start.razor | 4 +- .../files/FWO.UI/Services/RequestHandler.cs | 2 +- .../files/FWO.UI/Shared/NavigationMenu.razor | 2 +- 13 files changed, 79 insertions(+), 77 deletions(-) diff --git a/roles/lib/files/FWO.Config.Api/Config.cs b/roles/lib/files/FWO.Config.Api/Config.cs index 2154ca607..a88d4d013 100644 --- a/roles/lib/files/FWO.Config.Api/Config.cs +++ b/roles/lib/files/FWO.Config.Api/Config.cs @@ -20,9 +20,9 @@ public abstract class Config : ConfigData public event Action? OnChange; - protected SemaphoreSlim semaphoreSlim = new SemaphoreSlim(1, 1); + protected SemaphoreSlim semaphoreSlim = new(1, 1); - public ConfigItem[] RawConfigItems { get; set; } + public ConfigItem[] RawConfigItems { get; set; } = []; protected Config() { } diff --git a/roles/lib/files/FWO.Config.Api/GlobalConfig.cs b/roles/lib/files/FWO.Config.Api/GlobalConfig.cs index fc350798a..dbc60576c 100644 --- a/roles/lib/files/FWO.Config.Api/GlobalConfig.cs +++ b/roles/lib/files/FWO.Config.Api/GlobalConfig.cs @@ -1,5 +1,6 @@ using FWO.Logging; using FWO.Config.File; +using FWO.GlobalConstants; using FWO.Api.Client; using FWO.Config.Api.Data; using FWO.Api.Client.Queries; @@ -14,10 +15,10 @@ public class GlobalConfig : Config /// /// Global config constants /// - public string productVersion { get; set; } - public Language[] uiLanguages { get; set; } - public Dictionary> langDict { get; set; } - public Dictionary> overDict { get; set; } + public string ProductVersion { get; set; } + public Language[] UiLanguages { get; set; } + public Dictionary> LangDict { get; set; } + public Dictionary> OverDict { get; set; } /// @@ -33,9 +34,9 @@ public static async Task ConstructAsync(ApiConnection apiConnectio { string productVersion = ConfigFile.ProductVersion; - Language[] uiLanguages = Array.Empty(); - Dictionary> tmpLangDicts = new(); - Dictionary> tmpLangOverDicts = new(); + Language[] uiLanguages = []; + Dictionary> tmpLangDicts = []; + Dictionary> tmpLangOverDicts = []; if (loadLanguageData) { @@ -72,25 +73,25 @@ private GlobalConfig(ApiConnection apiConnection, string productVersion, Languag Dictionary> langDict, Dictionary> overDict) : base(apiConnection, 0) { - this.productVersion = productVersion; - this.uiLanguages = uiLanguages; - this.langDict = langDict; - this.overDict = overDict; + ProductVersion = productVersion; + UiLanguages = uiLanguages; + LangDict = langDict; + OverDict = overDict; } public override string GetText(string key) { - if(langDict.ContainsKey(DefaultLanguage) && langDict[DefaultLanguage].ContainsKey(key)) + if(LangDict.TryGetValue(DefaultLanguage, out Dictionary? langDict) && langDict.TryGetValue(key, out string? value)) { - return System.Web.HttpUtility.HtmlDecode(langDict[DefaultLanguage][key]); + return System.Web.HttpUtility.HtmlDecode(value); } - return "(undefined text)"; + return GlobalConst.kUndefinedText; } private static async Task> LoadLangDict(Language lang, ApiConnection apiConnection, bool over = false) { var languageVariable = new { language = lang.Name }; - Dictionary dict = new(); + Dictionary dict = []; List uiTexts = await apiConnection.SendQueryAsync>(over ? ConfigQueries.getCustomTextsPerLanguage : ConfigQueries.getTextsPerLanguage, languageVariable); foreach (UiText text in uiTexts) { diff --git a/roles/lib/files/FWO.Config.Api/UserConfig.cs b/roles/lib/files/FWO.Config.Api/UserConfig.cs index 68ed1973b..9d1e4ffcf 100644 --- a/roles/lib/files/FWO.Config.Api/UserConfig.cs +++ b/roles/lib/files/FWO.Config.Api/UserConfig.cs @@ -3,7 +3,6 @@ using FWO.Logging; using FWO.Config.Api.Data; using FWO.Api.Client; -using FWO.GlobalConstants; using FWO.Api.Data; using FWO.Api.Client.Queries; using System.Reflection; @@ -19,7 +18,7 @@ public class UserConfig : Config private readonly GlobalConfig globalConfig; public Dictionary Translate { get; set; } - public Dictionary Overwrite { get; set; } = new(); + public Dictionary Overwrite { get; set; } = []; public UiUser User { private set; get; } @@ -38,8 +37,8 @@ public static async Task ConstructAsync(GlobalConfig globalConfig, A public UserConfig(GlobalConfig globalConfig, ApiConnection apiConnection, UiUser user) : base(apiConnection, user.DbId) { User = user; - Translate = globalConfig.langDict[user.Language!]; - Overwrite = apiConnection != null ? Task.Run(async () => await GetCustomDict(user.Language!)).Result : globalConfig.overDict[user.Language!]; + Translate = globalConfig.LangDict[user.Language!]; + Overwrite = apiConnection != null ? Task.Run(async () => await GetCustomDict(user.Language!)).Result : globalConfig.OverDict[user.Language!]; this.globalConfig = globalConfig; globalConfig.OnChange += GlobalConfigOnChange; } @@ -47,7 +46,7 @@ public UserConfig(GlobalConfig globalConfig, ApiConnection apiConnection, UiUser public UserConfig(GlobalConfig globalConfig) : base() { User = new UiUser(); - Translate = globalConfig.langDict[globalConfig.DefaultLanguage]; + Translate = globalConfig.LangDict[globalConfig.DefaultLanguage]; this.globalConfig = globalConfig; globalConfig.OnChange += GlobalConfigOnChange; } @@ -76,7 +75,9 @@ public async Task SetUserInformation(string userDn, ApiConnection apiConnection) Log.WriteDebug("Get User Data", $"Get user data from user with DN: \"{userDn}\""); UiUser[]? users = await apiConnection.SendQueryAsync(AuthQueries.getUserByDn, new { dn = userDn }); if (users.Length > 0) + { User = users[0]; + } await SetUserId(apiConnection, User.DbId); if (User.Language == null) @@ -89,8 +90,8 @@ public async Task SetUserInformation(string userDn, ApiConnection apiConnection) public async Task ChangeLanguage(string languageName, ApiConnection apiConnection) { await apiConnection.SendQueryAsync(AuthQueries.updateUserLanguage, new { id = User.DbId, language = languageName }); - Translate = globalConfig.langDict[languageName]; - Overwrite = apiConnection != null ? await GetCustomDict(languageName): globalConfig.overDict[languageName]; + Translate = globalConfig.LangDict[languageName]; + Overwrite = apiConnection != null ? await GetCustomDict(languageName): globalConfig.OverDict[languageName]; User.Language = languageName; InvokeOnChange(this, null); } @@ -107,22 +108,22 @@ public void SetLanguage(string languageName) { User.Language = languageName; } - if (globalConfig.langDict.ContainsKey(User.Language)) + if (globalConfig.LangDict.TryGetValue(User.Language, out Dictionary? langDict)) { - Translate = globalConfig.langDict[User.Language]; - Overwrite = globalConfig.overDict[User.Language]; + Translate = langDict; + Overwrite = globalConfig.OverDict[User.Language]; } } public override string GetText(string key) { - if (Overwrite != null && Overwrite.ContainsKey(key)) + if (Overwrite != null && Overwrite.TryGetValue(key, out string? overwriteValue)) { - return Convert(Overwrite[key]); + return Convert(overwriteValue); } - if (Translate != null && Translate.ContainsKey(key)) + if (Translate != null && Translate.TryGetValue(key, out string? translateValue)) { - return Convert(Translate[key]); + return Convert(translateValue); } else { @@ -131,17 +132,17 @@ public override string GetText(string key) { defaultLanguage = GlobalConst.kEnglish; } - if (globalConfig.langDict[defaultLanguage].ContainsKey(key)) + if (globalConfig.LangDict[defaultLanguage].TryGetValue(key, out string? defaultLangValue)) { - return Convert(globalConfig.langDict[defaultLanguage][key]); + return Convert(defaultLangValue); } - else if (defaultLanguage != GlobalConst.kEnglish && globalConfig.langDict[GlobalConst.kEnglish].ContainsKey(key)) + else if (defaultLanguage != GlobalConst.kEnglish && globalConfig.LangDict[GlobalConst.kEnglish].TryGetValue(key, out string? englValue)) { - return Convert(globalConfig.langDict[GlobalConst.kEnglish][key]); + return Convert(englValue); } else { - return "(undefined text)"; + return GlobalConst.kUndefinedText; } } } @@ -171,7 +172,7 @@ public string GetApiText(string key) if (m.Success) { string msg = GetText(key.Substring(0, 5)); - if (msg != "(undefined text)") + if (msg != GlobalConst.kUndefinedText) { text = msg; } @@ -181,7 +182,7 @@ public string GetApiText(string key) public async Task> GetCustomDict(string languageName) { - Dictionary dict = new(); + Dictionary dict = []; try { List uiTexts = await apiConnection.SendQueryAsync>(ConfigQueries.getCustomTextsPerLanguage, new { language = languageName }); @@ -212,7 +213,7 @@ private static string RemoveLinks(string txtString) begin = txtString.IndexOf(startLink, index); if (begin >= 0) { - end = txtString.IndexOf(">", begin + startLink.Length); + end = txtString.IndexOf('>', begin + startLink.Length); if (end > 0) { txtString = txtString.Remove(begin, end - begin + 1); @@ -262,7 +263,7 @@ private string Convert(string rawText) begin = plainText.IndexOf(startLink, index); if (begin >= 0) { - end = plainText.IndexOf("\"", begin + startLink.Length); + end = plainText.IndexOf('"', begin + startLink.Length); if (end > 0) { plainText = plainText.Insert(end, insertString); diff --git a/roles/lib/files/FWO.GlobalConstants/GlobalConstants.cs b/roles/lib/files/FWO.GlobalConstants/GlobalConstants.cs index abf0a1598..40cf8e17c 100644 --- a/roles/lib/files/FWO.GlobalConstants/GlobalConstants.cs +++ b/roles/lib/files/FWO.GlobalConstants/GlobalConstants.cs @@ -34,6 +34,7 @@ public struct GlobalConst public const string kLdapInternalPostfix = "dc=" + kFwoProdName + ",dc=internal"; public const string kDummyAppRole = "DummyAppRole"; + public const string kUndefinedText = "(undefined text)"; } public struct ObjectType diff --git a/roles/lib/files/FWO.Report/Data/ManagementReport.cs b/roles/lib/files/FWO.Report/Data/ManagementReport.cs index 1e9dc376e..4a2f6f468 100644 --- a/roles/lib/files/FWO.Report/Data/ManagementReport.cs +++ b/roles/lib/files/FWO.Report/Data/ManagementReport.cs @@ -1,6 +1,5 @@ using Newtonsoft.Json; using System.Text.Json.Serialization; -using FWO.GlobalConstants; using FWO.Api.Data; namespace FWO.Report @@ -14,47 +13,47 @@ public class ManagementReport public string Name { get; set; } = ""; [JsonProperty("devices"), JsonPropertyName("devices")] - public DeviceReport[] Devices { get; set; } = Array.Empty(); + public DeviceReport[] Devices { get; set; } = []; [JsonProperty("import"), JsonPropertyName("import")] - public Import Import { get; set; } = new Import(); + public Import Import { get; set; } = new (); public long? RelevantImportId { get; set; } [JsonProperty("networkObjects"), JsonPropertyName("networkObjects")] - public NetworkObject[] Objects { get; set; } = Array.Empty(); + public NetworkObject[] Objects { get; set; } = []; [JsonProperty("serviceObjects"), JsonPropertyName("serviceObjects")] - public NetworkService[] Services { get; set; } = Array.Empty(); + public NetworkService[] Services { get; set; } = []; [JsonProperty("userObjects"), JsonPropertyName("userObjects")] - public NetworkUser[] Users { get; set; } = Array.Empty(); + public NetworkUser[] Users { get; set; } = []; [JsonProperty("reportNetworkObjects"), JsonPropertyName("reportNetworkObjects")] - public NetworkObject[] ReportObjects { get; set; } = Array.Empty(); + public NetworkObject[] ReportObjects { get; set; } = []; [JsonProperty("reportServiceObjects"), JsonPropertyName("reportServiceObjects")] - public NetworkService[] ReportServices { get; set; } = Array.Empty(); + public NetworkService[] ReportServices { get; set; } = []; [JsonProperty("reportUserObjects"), JsonPropertyName("reportUserObjects")] - public NetworkUser[] ReportUsers { get; set; } = Array.Empty(); + public NetworkUser[] ReportUsers { get; set; } = []; //[JsonProperty("rule_id"), JsonPropertyName("rule_id")] - public List ReportedRuleIds { get; set; } = new List(); - public List ReportedNetworkServiceIds { get; set; } = new List(); + public List ReportedRuleIds { get; set; } = []; + public List ReportedNetworkServiceIds { get; set; } = []; [JsonProperty("objects_aggregate"), JsonPropertyName("objects_aggregate")] - public ObjectStatistics NetworkObjectStatistics { get; set; } = new ObjectStatistics(); + public ObjectStatistics NetworkObjectStatistics { get; set; } = new (); [JsonProperty("services_aggregate"), JsonPropertyName("services_aggregate")] - public ObjectStatistics ServiceObjectStatistics { get; set; } = new ObjectStatistics(); + public ObjectStatistics ServiceObjectStatistics { get; set; } = new (); [JsonProperty("usrs_aggregate"), JsonPropertyName("usrs_aggregate")] - public ObjectStatistics UserObjectStatistics { get; set; } = new ObjectStatistics(); + public ObjectStatistics UserObjectStatistics { get; set; } = new (); [JsonProperty("rules_aggregate"), JsonPropertyName("rules_aggregate")] - public ObjectStatistics RuleStatistics { get; set; } = new ObjectStatistics(); + public ObjectStatistics RuleStatistics { get; set; } = new (); public bool Ignore { get; set; } diff --git a/roles/ui/files/FWO.UI/Pages/Settings/SettingsCustomTexts.razor b/roles/ui/files/FWO.UI/Pages/Settings/SettingsCustomTexts.razor index 588271904..4c1cb9c09 100644 --- a/roles/ui/files/FWO.UI/Pages/Settings/SettingsCustomTexts.razor +++ b/roles/ui/files/FWO.UI/Pages/Settings/SettingsCustomTexts.razor @@ -19,7 +19,7 @@
- + @(userConfig.GetText(language.Name)) @@ -106,7 +106,7 @@ protected override void OnInitialized() { - selectedLanguage = globalConfig.uiLanguages.FirstOrDefault() ?? new Language(); + selectedLanguage = globalConfig.UiLanguages.FirstOrDefault() ?? new Language(); } private async Task LoadDicts(Language lang) diff --git a/roles/ui/files/FWO.UI/Pages/Settings/SettingsDefaults.razor b/roles/ui/files/FWO.UI/Pages/Settings/SettingsDefaults.razor index 4807c0687..779e8a463 100644 --- a/roles/ui/files/FWO.UI/Pages/Settings/SettingsDefaults.razor +++ b/roles/ui/files/FWO.UI/Pages/Settings/SettingsDefaults.razor @@ -22,7 +22,7 @@
- + @(userConfig.GetText(language.Name)) @@ -200,7 +200,7 @@ else try { configData = await globalConfig.GetEditableConfig(); - selectedLanguage = globalConfig.uiLanguages.FirstOrDefault(l => l.Name == configData.DefaultLanguage) ?? new Language(); + selectedLanguage = globalConfig.UiLanguages.FirstOrDefault(l => l.Name == configData.DefaultLanguage) ?? new Language(); startDate = startTime = configData.AutoDiscoverStartAt; } catch (Exception exception) diff --git a/roles/ui/files/FWO.UI/Pages/Settings/SettingsImport.razor b/roles/ui/files/FWO.UI/Pages/Settings/SettingsImport.razor index c3e37b857..3336360ca 100644 --- a/roles/ui/files/FWO.UI/Pages/Settings/SettingsImport.razor +++ b/roles/ui/files/FWO.UI/Pages/Settings/SettingsImport.razor @@ -130,7 +130,7 @@ else try { configData = await globalConfig.GetEditableConfig(); - selectedLanguage = globalConfig.uiLanguages.FirstOrDefault(l => l.Name == configData.DefaultLanguage) ?? new Language(); + selectedLanguage = globalConfig.UiLanguages.FirstOrDefault(l => l.Name == configData.DefaultLanguage) ?? new Language(); selectedImpChgNotType = (ImpChangeNotificationType)configData.ImpChangeNotifyType; startDate = startTime = configData.ImpChangeNotifyStartAt; } diff --git a/roles/ui/files/FWO.UI/Pages/Settings/SettingsLanguage.razor b/roles/ui/files/FWO.UI/Pages/Settings/SettingsLanguage.razor index 464ccfb1b..699b7d69f 100644 --- a/roles/ui/files/FWO.UI/Pages/Settings/SettingsLanguage.razor +++ b/roles/ui/files/FWO.UI/Pages/Settings/SettingsLanguage.razor @@ -19,7 +19,7 @@
- + @(userConfig.GetText(language.Name)) @@ -37,7 +37,7 @@ protected override void OnInitialized() { - selectedLanguage = globalConfig.uiLanguages.FirstOrDefault(l => l.Name == userConfig.User.Language) ?? new Language(); + selectedLanguage = globalConfig.UiLanguages.FirstOrDefault(l => l.Name == userConfig.User.Language) ?? new Language(); StateHasChanged(); } diff --git a/roles/ui/files/FWO.UI/Pages/Settings/SettingsModelling.razor b/roles/ui/files/FWO.UI/Pages/Settings/SettingsModelling.razor index 84032e8f7..494d1ddb7 100644 --- a/roles/ui/files/FWO.UI/Pages/Settings/SettingsModelling.razor +++ b/roles/ui/files/FWO.UI/Pages/Settings/SettingsModelling.razor @@ -234,22 +234,22 @@ else Action DisplayMessageInUi { get; set; } = DefaultInit.DoNothing; private ConfigData? configData; - private List appDataPaths = new(); - private List PathsToAdd = new(); - private List PathsToDelete = new(); + private List appDataPaths = []; + private List PathsToAdd = []; + private List PathsToDelete = []; private string actPath = ""; - private List appServerTypes = new(); - private List appServerTypesToAdd = new(); - private List appServerTypesToDelete = new(); + private List appServerTypes = []; + private List appServerTypesToAdd = []; + private List appServerTypesToDelete = []; private AppServerType actAppServerType = new(); private string appServerDefaultTypeName = ""; - private List allAreas = new(); - private List pureAreaList = new(); - private List commAreaConfigItems = new(); - private List commonAreas = new(); - private List AreasToDelete = new(); + private List allAreas = []; + private List pureAreaList = []; + private List commAreaConfigItems = []; + private List commonAreas = []; + private List AreasToDelete = []; private bool predefServices = false; private bool searchArea = false; private ModellingNamingConvention namingConvention = new(); diff --git a/roles/ui/files/FWO.UI/Pages/Start.razor b/roles/ui/files/FWO.UI/Pages/Start.razor index da16f57ec..f60d88fef 100644 --- a/roles/ui/files/FWO.UI/Pages/Start.razor +++ b/roles/ui/files/FWO.UI/Pages/Start.razor @@ -8,10 +8,10 @@
-

@((MarkupString)userConfig.GetText("welcome_to")) @(globalConfig.productVersion)

+

@((MarkupString)userConfig.GetText("welcome_to")) @(globalConfig.ProductVersion)


    -
  • @((MarkupString)userConfig.GetText("whats_new_in_version")) @(globalConfig.productVersion)
  • +
  • @((MarkupString)userConfig.GetText("whats_new_in_version")) @(globalConfig.ProductVersion)
  • @((MarkupString) userConfig.GetText("whats_new_facts"))
  • @((MarkupString)userConfig.GetText("getting_started"))
  • diff --git a/roles/ui/files/FWO.UI/Services/RequestHandler.cs b/roles/ui/files/FWO.UI/Services/RequestHandler.cs index 337e3f5aa..beaecede7 100644 --- a/roles/ui/files/FWO.UI/Services/RequestHandler.cs +++ b/roles/ui/files/FWO.UI/Services/RequestHandler.cs @@ -362,7 +362,7 @@ public async Task SaveTicket(RequestStatefulObject ticket) { if(reqtask.StateId <= ActTicket.StateId) { - List ticketStateList = new () { ActTicket.StateId }; + List ticketStateList = [ActTicket.StateId]; reqtask.StateId = stateMatrixDict.Matrices[reqtask.TaskType].getDerivedStateFromSubStates(ticketStateList); await dbAcc.UpdateReqTaskStateInDb(reqtask); } diff --git a/roles/ui/files/FWO.UI/Shared/NavigationMenu.razor b/roles/ui/files/FWO.UI/Shared/NavigationMenu.razor index a7782a66f..d321df7d6 100644 --- a/roles/ui/files/FWO.UI/Shared/NavigationMenu.razor +++ b/roles/ui/files/FWO.UI/Shared/NavigationMenu.razor @@ -14,7 +14,7 @@ {