diff --git a/roles/lib/files/FWO.Api.Client/Data/ModellingAppZone.cs b/roles/lib/files/FWO.Api.Client/Data/ModellingAppZone.cs index 822a40c3f..1bc13f578 100644 --- a/roles/lib/files/FWO.Api.Client/Data/ModellingAppZone.cs +++ b/roles/lib/files/FWO.Api.Client/Data/ModellingAppZone.cs @@ -17,5 +17,22 @@ public ModellingAppZone(ModellingAppZone appZone) : base(appZone) AppServers = appZone.AppServers; Area = appZone.Area; } + + public ModellingAppZone(NetworkObject nwObj, ModellingNamingConvention? namCon = null) : base(nwObj, namCon) + { + Comment = nwObj.Comment; + CreationDate = nwObj.CreateTime.Time; + AppServers = ConvertNwObjectsToAppServers(nwObj.ObjectGroupFlats); + } + + private static List ConvertNwObjectsToAppServers(GroupFlat[] groupFlats) + { + List appServers = []; + foreach (var obj in groupFlats.Where(x => x.Object?.IP != null && x.Object?.IP != "").ToList()) + { + appServers.Add(new ModellingAppServerWrapper() { Content = obj.Object != null ? new(obj.Object) : new() }); + } + return appServers; + } } } diff --git a/roles/lib/files/FWO.Services/AppZoneStateHelper.cs b/roles/lib/files/FWO.Services/AppZoneStateHelper.cs index 4821f0cf9..c7909c3be 100644 --- a/roles/lib/files/FWO.Services/AppZoneStateHelper.cs +++ b/roles/lib/files/FWO.Services/AppZoneStateHelper.cs @@ -7,6 +7,7 @@ namespace FWO.Services { + //Luca test internal static class AppZoneStateHelper { //int = mgtId = Management Id diff --git a/roles/lib/files/FWO.Services/ModellingAppZoneHandler.cs b/roles/lib/files/FWO.Services/ModellingAppZoneHandler.cs index ede33b42b..d7ee34174 100644 --- a/roles/lib/files/FWO.Services/ModellingAppZoneHandler.cs +++ b/roles/lib/files/FWO.Services/ModellingAppZoneHandler.cs @@ -3,6 +3,7 @@ using FWO.Api.Client.Queries; using FWO.Api.Data; using FWO.Config.Api; +using System.Linq; using System.Text.Json; namespace FWO.Services @@ -11,7 +12,7 @@ public class ModellingAppZoneHandler(ApiConnection apiConnection, UserConfig use { private ModellingNamingConvention NamingConvention = new(); - public async Task CreateAppZones(string extAppId) + public async Task CreateAppZone(string extAppId) { List owners = await apiConnection.SendQueryAsync>(OwnerQueries.getOwners); @@ -28,7 +29,7 @@ public async Task CreateAppZones(string extAppId) await CreateAppZone(owner); } - public async Task CreateAppZones(int appId) + public async Task CreateAppZone(int appId) { List owners = await apiConnection.SendQueryAsync>(OwnerQueries.getOwners); @@ -45,7 +46,7 @@ public async Task CreateAppZones(int appId) await CreateAppZone(owner); } - public async Task? CreateAppZone(FwoOwner owner) + public async Task CreateAppZone(FwoOwner owner) { //await DeleteExistingAppZones(owner.Id); @@ -67,11 +68,72 @@ public async Task CreateAppZones(int appId) appZone.Id = appZoneId; - await AddAppServersToAppZone(appZone); + await AddAppServersToAppZone(appZoneId, appZone.AppServers); return appZone; } + public async Task UpsertAppZone(FwoOwner owner) + { + ModellingAppZone? appZone; + + List tempAppServers = await apiConnection.SendQueryAsync>(ModellingQueries.getAppServers, new { appId = owner.Id }); + List allAppServers = []; + + foreach (ModellingAppServer appServer in tempAppServers) + { + allAppServers.Add(new ModellingAppServerWrapper() { Content = appServer }); + } + + appZone = await GetExistingAppZone(owner.Id); + + if (appZone is null) + { + appZone = new() + { + AppId = owner.Id + }; + + ApplyNamingConvention(owner.ExtAppId.ToUpper(), appZone); + + appZone.AppServers.AddRange(allAppServers); + + int newAppZoneId = await AddAppZoneToDb(appZone); + appZone.Id = newAppZoneId; + } + else + { + List? removedAppServers = FindRemovedAppServers(appZone, allAppServers); + + if (removedAppServers.Count > 0) + { + await RemoveAppServersFromAppZone(appZone.Id, removedAppServers); + + appZone.AppServers.RemoveAll(_ => removedAppServers.Contains(_)); + } + + List? newAppServers = FindNewAppServers(appZone, allAppServers); + + if (newAppServers.Count > 0) + { + await AddAppServersToAppZone(appZone.Id, newAppServers); + appZone.AppServers.AddRange(newAppServers); + } + } + + return appZone; + } + + private static List FindNewAppServers(ModellingAppZone existingAppZone, List allAppServers) + { + return allAppServers.Except(existingAppZone.AppServers, new AppServerComparer()).ToList(); + } + + private static List FindRemovedAppServers(ModellingAppZone existingAppZone, List allAppServers) + { + return existingAppZone.AppServers.Except(allAppServers, new AppServerComparer()).ToList(); + } + public async Task CreateAppZone(ModellingConnection conn, FwoOwner owner) { if (conn is null || ( conn.SourceAppServers.Count == 0 && conn.DestinationAppServers.Count == 0 )) @@ -84,8 +146,6 @@ public async Task CreateAppZones(int appId) ApplyNamingConvention(owner.ExtAppId.ToUpper(), appZone); - //await DeleteExistingAppZones(appZone.AppId); - foreach (ModellingAppServerWrapper srcAppServer in conn.SourceAppServers) { appZone.AppServers.Add(srcAppServer); @@ -100,48 +160,44 @@ public async Task CreateAppZones(int appId) appZone.Id = appZoneId; - await AddAppServersToAppZone(appZone); + await AddAppServersToAppZone(appZoneId, appZone.AppServers); return appZone; } - private async Task DeleteExistingAppZones(int? ownerId) + private async Task DeleteExistingAppZone(int ownerId) { - (bool success, List? existingAppZones) = await GetExistingAppZones(ownerId); + ModellingAppZone? existingAppZone = await GetExistingAppZone(ownerId); - if (success && existingAppZones is not null) + if (existingAppZone is not null) { - foreach (ModellingAppZone existingAppZone in existingAppZones) + try { - try - { - await apiConnection.SendQueryAsync(ModellingQueries.deleteNwGroup, new { id = existingAppZone.Id }); - - await LogChange(ModellingTypes.ChangeType.Delete, ModellingTypes.ModObjectType.AppZone, existingAppZone.Id, $"Delete App Zone: {existingAppZone.Display()}", ownerId); - } - catch (Exception ex) - { - DisplayMessageInUi(ex, userConfig.GetText("delete_app_zone"), userConfig.GetText("E9201"), true); - } + await apiConnection.SendQueryAsync(ModellingQueries.deleteNwGroup, new { id = existingAppZone.Id }); + + await LogChange(ModellingTypes.ChangeType.Delete, ModellingTypes.ModObjectType.AppZone, existingAppZone.Id, $"Delete App Zone: {existingAppZone.Display()}", ownerId); + } + catch (Exception ex) + { + DisplayMessageInUi(ex, userConfig.GetText("delete_app_zone"), userConfig.GetText("E9201"), true); } } } - public async Task<(bool, List?)> GetExistingAppZones(int? appId) + public async Task GetExistingAppZone(int appId) { try { - List existingAppZones = await apiConnection.SendQueryAsync>(ModellingQueries.getAppZonesByAppId, new { appId = appId }); + List? existingAppZones = await apiConnection.SendQueryAsync>(ModellingQueries.getAppZonesByAppId, new { appId = appId }); - if (existingAppZones is not null) - return (true, existingAppZones); + return existingAppZones.FirstOrDefault(); } catch (Exception ex) { DisplayMessageInUi(ex, userConfig.GetText("app_zone_creation"), userConfig.GetText("E9203"), true); } - return (false, default); + return default; } private void ApplyNamingConvention(string extAppId, ModellingAppZone appZone) @@ -179,14 +235,14 @@ private async Task AddAppZoneToDb(ModellingAppZone appZone) return -1; } - public async Task AddAppServersToAppZone(ModellingAppZone appZone) + public async Task AddAppServersToAppZone(long appZoneId, List appServers) { - foreach (ModellingAppServerWrapper appServer in appZone.AppServers) + foreach (ModellingAppServerWrapper appServer in appServers) { var nwobject_nwgroupVars = new { nwObjectId = appServer.Content.Id, - nwGroupId = appZone.Id + nwGroupId = appZoneId }; try @@ -199,5 +255,26 @@ public async Task AddAppServersToAppZone(ModellingAppZone appZone) } } } + + public async Task RemoveAppServersFromAppZone(long appZoneId, List appServers) + { + foreach (ModellingAppServer appServer in ModellingAppServerWrapper.Resolve(appServers)) + { + var nwobject_nwgroupVars = new + { + nwObjectId = appServer.Id, + nwGroupId = appZoneId + }; + + try + { + await apiConnection.SendQueryAsync(ModellingQueries.removeNwObjectFromNwGroup, nwobject_nwgroupVars); + } + catch (Exception ex) + { + DisplayMessageInUi(ex, userConfig.GetText("app_zone_creation"), userConfig.GetText("E9204"), true); + } + } + } } } diff --git a/roles/lib/files/FWO.Services/ModellingVarianceAnalysis.cs b/roles/lib/files/FWO.Services/ModellingVarianceAnalysis.cs index 20a8bd0b6..21edd5dcd 100644 --- a/roles/lib/files/FWO.Services/ModellingVarianceAnalysis.cs +++ b/roles/lib/files/FWO.Services/ModellingVarianceAnalysis.cs @@ -9,9 +9,9 @@ namespace FWO.Services { public class ModellingVarianceAnalysis(ApiConnection apiConnection, ExtStateHandler extStateHandler, UserConfig userConfig, Action displayMessageInUi = null) - { + { private ModellingNamingConvention namingConvention = System.Text.Json.JsonSerializer.Deserialize(userConfig.ModNamingConvention) ?? new(); - private ModellingAppZoneHandler AppZoneHandler = new(apiConnection, userConfig, displayMessageInUi); + private ModellingAppZoneHandler AppZoneHandler = new(apiConnection, userConfig, displayMessageInUi); private List managements = []; private List TaskList = []; @@ -23,11 +23,10 @@ public class ModellingVarianceAnalysis(ApiConnection apiConnection, ExtStateHand private Dictionary> allExistingAppRoles = []; private Dictionary> allExistingAppServers = []; private Dictionary> alreadyCreatedAppServers = []; - private Dictionary> allExistingAppZones = []; + private Dictionary> ExistingProdAppZones = []; private Dictionary> alreadyCreatedAppZones = []; private ModellingAppRole? existingAppRole; - private ModellingAppZone? existingAppZone; private List newAppServers = []; private List deletedAppServers = []; private List unchangedAppServers = []; @@ -51,6 +50,9 @@ public async Task> AnalyseModelledConnections(List> AnalyseModelledConnections(List 0) { - Dictionary? addInfo = new() { {AdditionalInfoKeys.ConnId, conn.Id.ToString()} }; + Dictionary? addInfo = new() { { AdditionalInfoKeys.ConnId, conn.Id.ToString() } }; AccessTaskList.Add(new() { Title = userConfig.GetText("new_connection") + ": " + conn.Name ?? "", @@ -79,7 +80,7 @@ public async Task> AnalyseModelledConnections(List? existingAppZones) = await AppZoneHandler.GetExistingAppZones(owner.Id); + ModellingAppZone? existingAppZone = await AppZoneHandler.GetExistingAppZone(owner.Id); - if (success && existingAppZones is not null) + if (existingAppZone is not null) { - foreach (ModellingAppZone appZone in existingAppZones) + WfReqTask? taskEntry = TaskList.FirstOrDefault(x => x.Title == userConfig.GetText("new_app_zone") + existingAppZone.IdString && x.OnManagement?.Id == mgt.Id); + + if (!ResolveProdAppZone(existingAppZone, mgt) && taskEntry is null) { - if (!ResolveExistingAppZone(appZone, mgt)) - { - if (TaskList.FirstOrDefault(x => x.Title == userConfig.GetText("new_app_zone") + appZone.IdString && x.OnManagement?.Id == mgt.Id) == null) - { - ModellingAppZone? newFWAppZone = await AppZoneHandler.CreateAppZone(owner); - RequestNewFWAppZone(newFWAppZone, mgt); - } - } - else if (AppZoneChanged(appZone)) - { - RequestUpdateAppZone(appZone, mgt); - } + RequestNewFWAppZone(existingAppZone, mgt); + } + else if (AppZoneChanged(existingAppZone, mgt)) + { + RequestUpdateAppZone(existingAppZone, mgt); + } + else if (taskEntry is null) + { + CreateAppZoneTaskListEntry(existingAppZone, mgt); } - - allExistingAppZones[mgt.Id] = existingAppZones; - } - - if (existingAppZones is null || existingAppZones.Count == 0) - { - ModellingAppZone? newFWAppZone = await AppZoneHandler.CreateAppZone(owner); - RequestNewFWAppZone(newFWAppZone, mgt); } - AppZoneStateHelper.SetManagementAppZones(allExistingAppZones); + AppZoneStateHelper.SetManagementAppZones(ExistingProdAppZones); } private bool ResolveExistingAppRole(ModellingAppRole appRole, Management mgt) @@ -280,7 +278,7 @@ private bool ResolveExistingAppRole(ModellingAppRole appRole, Management mgt) Log.WriteDebug("Search AppRole", $"Name: {appRole.Name}, IdString: {appRole.IdString}, Management: {mgt.Name}"); bool shortened = false; string sanitizedARName = Sanitizer.SanitizeJsonFieldMand(appRole.IdString, ref shortened); - if(allExistingAppRoles.ContainsKey(mgt.Id)) + if (allExistingAppRoles.ContainsKey(mgt.Id)) { existingAppRole = allExistingAppRoles[mgt.Id].FirstOrDefault(a => a.Name == appRole.IdString || a.Name == sanitizedARName); } @@ -312,17 +310,14 @@ private bool ResolveExistingAppRole(ModellingAppRole appRole, Management mgt) } } - private bool ResolveExistingAppZone(ModellingAppZone appZone, Management mgt) + private bool ResolveProdAppZone(ModellingAppZone existingAppZone, Management mgt) { - if (allExistingAppZones.TryGetValue(mgt.Id, out List? mgtAppZones)) + if (ExistingProdAppZones.TryGetValue(mgt.Id, out List? prodAppZones)) { - existingAppZone = mgtAppZones.FirstOrDefault(_ => new AppZoneComparer().Equals(_, appZone)); + return prodAppZones.Contains(existingAppZone, new AppZoneComparer()); } - if (existingAppZone != null) - { - Log.WriteDebug("Search AppZone", $"Found!!"); - } - return existingAppZone != null; + + return false; } private bool AppZoneAlreadyRequested(ModellingAppZone appZone, Management mgt) @@ -339,11 +334,10 @@ private bool AppServerAlreadyRequested(ModellingAppServer appServer, Management return ( alreadyCreatedAppServers.TryGetValue(mgt.Id, out List? alreadyRequestedAppServers) && alreadyRequestedAppServers.Contains(appServer, new AppServerComparer()) ); } - private static string ConstructAppServerName(ModellingAppServer appServer, ModellingNamingConvention namingConvention) { - return string.IsNullOrEmpty(appServer.Name) ? namingConvention.AppServerPrefix + appServer.Ip : - (char.IsLetter(appServer.Name[0]) ? appServer.Name : namingConvention?.AppServerPrefix + appServer.Name); + return string.IsNullOrEmpty(appServer.Name) ? namingConvention.AppServerPrefix + appServer.Ip : + ( char.IsLetter(appServer.Name[0]) ? appServer.Name : namingConvention?.AppServerPrefix + appServer.Name ); } private bool AreEqual(ModellingAppServer appServer1, ModellingAppServer appServer2) @@ -374,7 +368,7 @@ private bool AppRoleChanged(ModellingAppRole appRole) } foreach (ModellingAppServerWrapper exAppserver in existingAppRole.AppServers) { - if(appRole.AppServers.FirstOrDefault(a => AreEqual(exAppserver.Content, a.Content)) == null) + if (appRole.AppServers.FirstOrDefault(a => AreEqual(exAppserver.Content, a.Content)) == null) { deletedAppServers.Add(exAppserver); } @@ -382,27 +376,29 @@ private bool AppRoleChanged(ModellingAppRole appRole) return newAppServers.Count > 0 || deletedAppServers.Count > 0; } - private bool AppZoneChanged(ModellingAppZone appZone) + private bool AppZoneChanged(ModellingAppZone existingAppZone, Management mgt) { newAppServers = []; deletedAppServers = []; unchangedAppServers = []; - List diff1 = appZone.AppServers.Except(existingAppZone.AppServers, new AppServerComparer()) + ModellingAppZone? prodAppZone = ExistingProdAppZones[mgt.Id].FirstOrDefault(); + + List diff1 = prodAppZone.AppServers.Except(existingAppZone.AppServers, new AppServerComparer()) .ToList(); if (diff1.Count > 0) { newAppServers.AddRange(diff1); } - List diff2 = existingAppZone.AppServers.Except(appZone.AppServers, new AppServerComparer()) + List diff2 = existingAppZone.AppServers.Except(prodAppZone.AppServers, new AppServerComparer()) .ToList(); if (diff2.Count > 0) { deletedAppServers.AddRange(diff2); } - List unchanged = existingAppZone.AppServers.Intersect(appZone.AppServers, new AppServerComparer()) + List unchanged = existingAppZone.AppServers.Intersect(prodAppZone.AppServers, new AppServerComparer()) .ToList(); if (unchanged.Count > 0) { @@ -465,7 +461,7 @@ private void RequestNewAppRole(ModellingAppRole appRole, Management mgt) NetworkId = networkId }); } - Dictionary? addInfo = new() { {AdditionalInfoKeys.GrpName, appRole.IdString}, {AdditionalInfoKeys.AppRoleId, appRole.Id.ToString()} }; + Dictionary? addInfo = new() { { AdditionalInfoKeys.GrpName, appRole.IdString }, { AdditionalInfoKeys.AppRoleId, appRole.Id.ToString() } }; TaskList.Add(new() { Title = userConfig.GetText("new_app_role") + appRole.IdString, @@ -483,7 +479,7 @@ private void RequestNewFWAppZone(ModellingAppZone appZone, Management mgt) List groupMembers = []; foreach (ModellingAppServer appServer in ModellingAppServerWrapper.Resolve(appZone.AppServers)) { - bool alreadyRequested = AppZoneAlreadyRequested(appZone, mgt); + bool alreadyRequested = AppServerAlreadyRequested(appServer, mgt); groupMembers.Add(new() { RequestAction = alreadyRequested ? RequestAction.addAfterCreation.ToString() : RequestAction.create.ToString(), @@ -506,11 +502,11 @@ private void RequestNewFWAppZone(ModellingAppZone appZone, Management mgt) AdditionalInfo = System.Text.Json.JsonSerializer.Serialize(addInfo) }); - if (!allExistingAppZones.ContainsKey(mgt.Id)) + if (!ExistingProdAppZones.ContainsKey(mgt.Id)) { - allExistingAppZones.Add(mgt.Id, []); + ExistingProdAppZones.Add(mgt.Id, []); } - allExistingAppZones[mgt.Id].Add(appZone); + ExistingProdAppZones[mgt.Id].Add(appZone); if (!alreadyCreatedAppZones.ContainsKey(mgt.Id)) { @@ -519,11 +515,50 @@ private void RequestNewFWAppZone(ModellingAppZone appZone, Management mgt) alreadyCreatedAppZones[mgt.Id].Add(appZone); } + private void CreateAppZoneTaskListEntry(ModellingAppZone appZone, Management mgt) + { + List groupMembers = GetAppZoneGroupMembers(appZone, mgt); + + bool alreadyRequested = AppZoneAlreadyRequested(appZone, mgt); + + Dictionary? addInfo = new() { { AdditionalInfoKeys.GrpName, appZone.IdString } }; + TaskList.Add(new() + { + Title = userConfig.GetText("new_app_zone") + appZone.IdString, + TaskType = WfTaskType.group_create.ToString(), + RequestAction = alreadyRequested ? RequestAction.unchanged.ToString() : RequestAction.modify.ToString(), + ManagementId = mgt.Id, + OnManagement = mgt, + Elements = groupMembers, + AdditionalInfo = System.Text.Json.JsonSerializer.Serialize(addInfo) + }); + } + + private List GetAppZoneGroupMembers(ModellingAppZone appZone, Management mgt) + { + List groupMembers = []; + foreach (ModellingAppServer appServer in ModellingAppServerWrapper.Resolve(appZone.AppServers)) + { + bool alreadyRequested = AppServerAlreadyRequested(appServer, mgt); + groupMembers.Add(new() + { + RequestAction = alreadyRequested ? RequestAction.addAfterCreation.ToString() : RequestAction.create.ToString(), + Field = ElemFieldType.source.ToString(), + Name = appServer.Name, + IpString = appServer.Ip, + IpEnd = appServer.IpEnd, + GroupName = appZone.IdString + }); + } + + return groupMembers; + } + private void RequestUpdateAppRole(ModellingAppRole appRole, Management mgt) { FillGroupMembers(appRole, mgt); - Dictionary? addInfo = new() { {AdditionalInfoKeys.GrpName, appRole.IdString}, {AdditionalInfoKeys.AppRoleId, appRole.Id.ToString()} }; - if(newGroupMembers.Count > 0) + Dictionary? addInfo = new() { { AdditionalInfoKeys.GrpName, appRole.IdString }, { AdditionalInfoKeys.AppRoleId, appRole.Id.ToString() } }; + if (newGroupMembers.Count > 0) { newGroupMembers.AddRange(unchangedGroupMembers); newGroupMembers.AddRange(unchangedGroupMembersDuringCreate); // will be deleted later @@ -771,7 +806,7 @@ private void RequestNewServiceGroup(ModellingServiceGroup svcGrp, Management mgt GroupName = svcGrp.Name }); } - Dictionary? addInfo = new() { {AdditionalInfoKeys.GrpName, svcGrp.Name}, {AdditionalInfoKeys.SvcGrpId, svcGrp.Id.ToString()} }; + Dictionary? addInfo = new() { { AdditionalInfoKeys.GrpName, svcGrp.Name }, { AdditionalInfoKeys.SvcGrpId, svcGrp.Id.ToString() } }; TaskList.Add(new() { Title = userConfig.GetText("new_svc_grp") + svcGrp.Name, diff --git a/roles/ui/files/FWO.UI/Pages/NetworkModelling/RequestFwChangePopup.razor b/roles/ui/files/FWO.UI/Pages/NetworkModelling/RequestFwChangePopup.razor index d83ace937..ad573bd18 100644 --- a/roles/ui/files/FWO.UI/Pages/NetworkModelling/RequestFwChangePopup.razor +++ b/roles/ui/files/FWO.UI/Pages/NetworkModelling/RequestFwChangePopup.razor @@ -22,19 +22,19 @@
- + - + - + @@ -51,7 +51,7 @@
- @if(SelectedApp.Id > 0 && !WorkInProgress && !RequestInProcess) + @if (SelectedApp.Id > 0 && !WorkInProgress && !RequestInProcess) { } @@ -62,12 +62,12 @@ - +
- + @code @@ -126,9 +126,12 @@ { try { - if(!await GetActTicketStatus()) + ModellingAppZoneHandler appZoneHandler = new(apiConnection, userConfig, DisplayMessageInUi); + await appZoneHandler.UpsertAppZone(SelectedApp); + + if (!await GetActTicketStatus()) { - ModellingVarianceAnalysis varianceAnalysis = new(apiConnection, extStateHandler, userConfig, DisplayMessageInUi); + ModellingVarianceAnalysis varianceAnalysis = new(apiConnection, extStateHandler, userConfig, DisplayMessageInUi); TaskList = await varianceAnalysis.AnalyseModelledConnections(Connections, SelectedApp); } } @@ -140,11 +143,11 @@ private async Task GetActTicketStatus() { - List ticketIds = await apiConnection.SendQueryAsync>(ExtRequestQueries.getLatestTicketId, new{ownerId = SelectedApp.Id}); - if(ticketIds.Count > 0) + List ticketIds = await apiConnection.SendQueryAsync>(ExtRequestQueries.getLatestTicketId, new { ownerId = SelectedApp.Id }); + if (ticketIds.Count > 0) { WfTicket? intTicket = await apiConnection.SendQueryAsync(RequestQueries.getTicketById, new { ticketIds.First().Id }); - if(intTicket != null) + if (intTicket != null) { intTicket.UpdateCidrsInTaskElements(); TaskList = intTicket.Tasks.OrderBy(t => t.TaskNumber).ToList(); @@ -158,14 +161,14 @@ private string DisplayTaskDetails(WfReqTask task) { - if(task.TaskType == WfTaskType.access.ToString()) + if (task.TaskType == WfTaskType.access.ToString()) { return userConfig.GetText("source") + ": " + DisplayNwObjects(task, ElemFieldType.source.ToString()) + "
" + userConfig.GetText("service") + ": " + DisplayServices(task) + "
" + userConfig.GetText("destination") + ": " + DisplayNwObjects(task, ElemFieldType.destination.ToString()) + (task.Comments.Count > 0 ? "
" + userConfig.GetText("comment") + ": " + task.Comments.First().Comment.CommentText : ""); } - else if(task.TaskType == WfTaskType.group_create.ToString() || task.TaskType == WfTaskType.group_modify.ToString()) + else if (task.TaskType == WfTaskType.group_create.ToString() || task.TaskType == WfTaskType.group_modify.ToString()) { return DisplayMembers(task); } @@ -178,9 +181,9 @@ private string DisplayNwObjects(WfReqTask task, string fieldType) { List nwObjects = []; - foreach(var elem in task.Elements.Where(e => e.Field == fieldType)) + foreach (var elem in task.Elements.Where(e => e.Field == fieldType)) { - if(elem.GroupName != null) + if (elem.GroupName != null) { nwObjects.Add(elem.GroupName); } @@ -195,9 +198,9 @@ private string DisplayServices(WfReqTask task) { List services = []; - foreach(var elem in task.Elements.Where(e => e.Field == ElemFieldType.service.ToString())) + foreach (var elem in task.Elements.Where(e => e.Field == ElemFieldType.service.ToString())) { - if(elem.GroupName != null) + if (elem.GroupName != null) { services.Add(elem.GroupName); } @@ -211,17 +214,17 @@ private string DisplayMembers(WfReqTask task) { - List members =[]; - if(task.IsNetworkFlavor()) + List members = []; + if (task.IsNetworkFlavor()) { - foreach(var elem in task.Elements) + foreach (var elem in task.Elements) { members.Add($"{DisplayBase.DisplayIpWithName(WfElementBase.ToNetworkObject(elem))}"); } } else { - foreach(var elem in task.Elements) + foreach (var elem in task.Elements) { members.Add($"{elem.Port + "/" + ipProtos.Find(x => x.Id == elem.ProtoId)?.Name}"); } @@ -231,15 +234,15 @@ private string CssClass(WfReqElement elem) { - if(elem.RequestAction == RequestAction.create.ToString()) + if (elem.RequestAction == RequestAction.create.ToString()) { return "text-success"; } - else if(elem.RequestAction == RequestAction.addAfterCreation.ToString()) + else if (elem.RequestAction == RequestAction.addAfterCreation.ToString()) { return "text-info"; } - else if(elem.RequestAction == RequestAction.delete.ToString()) + else if (elem.RequestAction == RequestAction.delete.ToString()) { return "text-danger"; } @@ -251,10 +254,10 @@ WorkInProgress = true; try { - TicketCreator ticketCreator = new (apiConnection, userConfig, authenticationStateTask!.Result.User, middlewareClient); + TicketCreator ticketCreator = new(apiConnection, userConfig, authenticationStateTask!.Result.User, middlewareClient); WfTicket intTicket = await ticketCreator.CreateTicket(SelectedApp, TaskList, "Rollout modelled connections for: " + SelectedApp.Name, extStateHandler.GetInternalStateId(ExtStates.ExtReqInitialized), ""); - if(intTicket != null) + if (intTicket != null) { RequestInProcess = true; TaskList = intTicket.Tasks; @@ -275,7 +278,7 @@ { try { - await apiConnection.SendQueryAsync(ExtRequestQueries.addTicketId, new{ownerId = SelectedApp.Id, ticketId = ticketId}); + await apiConnection.SendQueryAsync(ExtRequestQueries.addTicketId, new { ownerId = SelectedApp.Id, ticketId = ticketId }); } catch (Exception exception) { @@ -287,7 +290,7 @@ { try { - RestResponse middlewareServerResponse = await middlewareClient.AddExternalRequest(new ExternalRequestAddParameters(){ TicketId = intTicket.Id }); + RestResponse middlewareServerResponse = await middlewareClient.AddExternalRequest(new ExternalRequestAddParameters() { TicketId = intTicket.Id }); if (middlewareServerResponse.StatusCode != HttpStatusCode.OK || middlewareServerResponse.Data == false) { DisplayMessageInUi(null, userConfig.GetText("request_fw_change"), userConfig.GetText("E9101"), true); @@ -299,8 +302,8 @@ } await ModellingHandlerBase.LogChange(ModellingTypes.ChangeType.InitRequests, ModellingTypes.ModObjectType.CommunicationProfile, - 0, $"Initialized Rollout Requests", apiConnection, userConfig, - intTicket.Tasks.First()?.Owners.First()?.Owner.Id, DefaultInit.DoNothing, intTicket.Requester?.Name); + 0, $"Initialized Rollout Requests", apiConnection, userConfig, + intTicket.Tasks.First()?.Owners.First()?.Owner.Id, DefaultInit.DoNothing, intTicket.Requester?.Name); } catch (Exception exception) {