Skip to content

Commit 8c29a89

Browse files
authored
Merge branch 'develop' into issue_2973
2 parents a3a88c7 + 01ecc64 commit 8c29a89

File tree

10 files changed

+171
-63
lines changed

10 files changed

+171
-63
lines changed

roles/database/files/sql/idempotent/fworch-texts.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2932,7 +2932,7 @@ INSERT INTO txt VALUES ('U9021', 'German', 'Schnittstellen dürfen keine Ne
29322932
INSERT INTO txt VALUES ('U9021', 'English', 'Interfaces must not contain network areas.');
29332933
INSERT INTO txt VALUES ('U9022', 'German', 'Quelle und Ziel dürfen nicht gleichzeitig einen Netzbereich enthalten.');
29342934
INSERT INTO txt VALUES ('U9022', 'English', 'Source and destination must not contain a network area at the same time.');
2935-
INSERT INTO txt VALUES ('U9023', 'German', 'Dieser Netzbereich kann nur in der Registerkarte Gemeinsame Dienste verwendet werden.');
2935+
INSERT INTO txt VALUES ('U9023', 'German', 'Dieser Netzbereich kann nur in der Registerkarte Common Services verwendet werden.');
29362936
INSERT INTO txt VALUES ('U9023', 'English', 'This network area can only be used in common services tab.');
29372937
INSERT INTO txt VALUES ('U9024', 'German', 'Netzbereiche können nicht zusammen mit Schnittstellen anderer Apps genutzt werden.');
29382938
INSERT INTO txt VALUES ('U9024', 'English', 'Network areas cannot be used together with interfaces from foreign apps.');

roles/lib/files/FWO.Data/Sanitizer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public static string SanitizeJsonMand(string input, ref bool shortened)
165165
return output;
166166
}
167167

168-
// not allowed: +*(){}[]?!#<>=,;'\"'/\\\t@$%^|&~
168+
// not allowed: +*(){}[]?!#<>=,;'\"'/\\\t@$%^|&~ -> replaced by "_"
169169
public static string SanitizeJsonFieldMand(string input, ref bool changed)
170170
{
171171
string output = Regex.Replace(input.Trim(), @"[\+\*\(\)\{\}\[\]\?\!#<>\=\,\;\/\\\t@\$\%\^\|\&\~ ]", "_");

roles/lib/files/FWO.Services/AppServerComparer.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using FWO.Data;
2-
using FWO.Data.Modelling;
1+
using FWO.Data.Modelling;
32
using System.Diagnostics.CodeAnalysis;
43

54
namespace FWO.Services
@@ -25,8 +24,9 @@ public bool Equals(ModellingAppServer? appServer1, ModellingAppServer? appServer
2524
return false;
2625
}
2726

28-
string appServer2Name = AppServerHelper.ConstructAppServerName(appServer2, NamingConvention);
29-
return appServer1.Name.Trim() == appServer2Name.Trim(); // || appServer1.Name.Trim() == sanitizedAS2Name.Trim();
27+
string appServer1Name = AppServerHelper.ConstructSanitizedAppServerName(appServer1, NamingConvention);
28+
string appServer2Name = AppServerHelper.ConstructSanitizedAppServerName(appServer2, NamingConvention);
29+
return appServer1Name == appServer2Name;
3030
}
3131

3232
public int GetHashCode(ModellingAppServerWrapper appServerWrapper)
@@ -36,7 +36,7 @@ public int GetHashCode(ModellingAppServerWrapper appServerWrapper)
3636

3737
public int GetHashCode(ModellingAppServer appServer)
3838
{
39-
string appServerName = AppServerHelper.ConstructAppServerName(appServer, NamingConvention).Trim();
39+
string appServerName = AppServerHelper.ConstructSanitizedAppServerName(appServer, NamingConvention).Trim();
4040
return HashCode.Combine(appServerName);
4141
}
4242
}

roles/lib/files/FWO.Services/AppServerHelper.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ public static async Task<string> ConstructAppServerNameFromDns(ModellingAppServe
3838
return appServer.Name;
3939
}
4040

41+
public static string ConstructSanitizedAppServerName(ModellingAppServer appServer, ModellingNamingConvention namingConvention, bool overwriteExistingNames=false)
42+
{
43+
bool shortened = false;
44+
return Sanitizer.SanitizeJsonFieldMand(ConstructAppServerName(appServer, namingConvention, overwriteExistingNames), ref shortened);
45+
}
46+
4147
public static string ConstructAppServerName(ModellingAppServer appServer, ModellingNamingConvention namingConvention, bool overwriteExistingNames=false)
4248
{
4349
return string.IsNullOrEmpty(appServer.Name) || overwriteExistingNames ? GetPrefix(appServer, namingConvention) + DisplayBase.DisplayIp(appServer.Ip, appServer.IpEnd) :

roles/lib/files/FWO.Services/ModellingVarianceAnalysis.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ private void CollectModelledAppRoles(List<ModellingConnection> connections)
9090
allModelledAppRoles.Add(modelledAppRole);
9191
}
9292
}
93-
allModelledAppRoles = allModelledAppRoles.Distinct(appRoleComparer).ToList();
93+
allModelledAppRoles = [.. allModelledAppRoles.Distinct(appRoleComparer)];
9494
}
9595

9696
private void AnalyseAppRole(ModellingAppRole modelledAppRole, Management mgt)

roles/lib/files/FWO.Services/ModellingVarianceAnalysisRules.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ private bool IsImplementation(Rule rule, ModellingConnection conn)
6868
isImpl &= IsNwImplementation(rule.Froms, conn.SourceAppServers, conn.SourceAppRoles, conn.SourceAreas, conn.SourceOtherGroups, disregardedFroms);
6969
isImpl &= IsNwImplementation(rule.Tos, conn.DestinationAppServers, conn.DestinationAppRoles, conn.DestinationAreas, conn.DestinationOtherGroups, disregardedTos);
7070
isImpl &= IsSvcImplementation(rule.Services, conn.Services, conn.ServiceGroups, disregardedServices);
71-
rule.DisregardedFroms = disregardedFroms.ToArray();
72-
rule.DisregardedTos = disregardedTos.ToArray();
73-
rule.DisregardedServices = disregardedServices.ToArray();
71+
rule.DisregardedFroms = [.. disregardedFroms];
72+
rule.DisregardedTos = [.. disregardedTos];
73+
rule.DisregardedServices = [.. disregardedServices];
7474
}
7575
else if (isImpl)
7676
{
@@ -101,7 +101,7 @@ private bool IsNwImplementation(NetworkLocation[] networkLocations, List<Modelli
101101
}
102102
isImpl = false;
103103
}
104-
return (ruleRecognitionOption.NwResolveGroup ? true : CompareRemainingNwGroups(networkLocations, appRoles, otherGroups, disregardedLocations)) && isImpl;
104+
return (ruleRecognitionOption.NwResolveGroup || CompareRemainingNwGroups(networkLocations, appRoles, otherGroups, disregardedLocations)) && isImpl;
105105
}
106106

107107
private bool CompareNwAreas(NetworkLocation[] networkLocations, List<ModellingNetworkAreaWrapper> areas, List<NetworkLocation> disregardedLocations)
@@ -149,8 +149,8 @@ private bool CompareNwObjects(List<NetworkObject> allModGroups, List<NetworkObje
149149
{
150150
if(FullAnalysis)
151151
{
152-
List<NetworkObject> disregardedGroups = allModGroups.Except(allProdGroups, comparer).ToList();
153-
List<NetworkObject> surplusGroups = allProdGroups.Except(allModGroups, comparer).ToList();
152+
List<NetworkObject> disregardedGroups = [.. allModGroups.Except(allProdGroups, comparer)];
153+
List<NetworkObject> surplusGroups = [.. allProdGroups.Except(allModGroups, comparer)];
154154
foreach (var obj in surplusGroups)
155155
{
156156
NetworkLocation? extLoc = networkLocations.FirstOrDefault(n => n.Object.Id == obj.Id);
@@ -179,18 +179,18 @@ private bool IsSvcImplementation(ServiceWrapper[] networkServices, List<Modellin
179179
}
180180
isImpl = false;
181181
}
182-
return (ruleRecognitionOption.SvcResolveGroup ? true : CompareSvcGroups(networkServices, serviceGroups, disregardedServices)) && isImpl;
182+
return (ruleRecognitionOption.SvcResolveGroup || CompareSvcGroups(networkServices, serviceGroups, disregardedServices)) && isImpl;
183183
}
184184

185185
private bool CompareServices(ServiceWrapper[] networkServices, List<ModellingServiceWrapper> services, List<ModellingServiceGroupWrapper> serviceGroups, List<NetworkService> disregardedServices)
186186
{
187-
List<NetworkService> allProdServices = networkServices.Where(s => s.Content.Type.Name != ServiceType.Group).ToList().ConvertAll(s => s.Content).ToList();
187+
List<NetworkService> allProdServices = [.. networkServices.Where(s => s.Content.Type.Name != ServiceType.Group).ToList().ConvertAll(s => s.Content)];
188188
List<NetworkService> allModServices = ModellingServiceWrapper.Resolve(services).ToList().ConvertAll(s => ModellingService.ToNetworkService(s));
189189
if(ruleRecognitionOption.SvcResolveGroup)
190190
{
191191
foreach(var svc in networkServices.Where(n => n.Content.Type.Name == ServiceType.Group).ToList().ConvertAll(s => s.Content).ToList())
192192
{
193-
allProdServices.AddRange([.. svc.ServiceGroupFlats.ToList().ConvertAll(g => g.Object)]);
193+
allProdServices.AddRange([.. svc.ServiceGroupFlats.ToList().ConvertAll(g => g.Object ?? new())]);
194194
}
195195
foreach(var svcGrp in ModellingServiceGroupWrapper.Resolve(serviceGroups))
196196
{
@@ -202,7 +202,7 @@ private bool CompareServices(ServiceWrapper[] networkServices, List<ModellingSer
202202

203203
private bool CompareSvcGroups(ServiceWrapper[] networkServices, List<ModellingServiceGroupWrapper> serviceGroups, List<NetworkService> disregardedServices)
204204
{
205-
List<NetworkService> allProdSvcGroups = networkServices.Where(n => n.Content.Type.Name == ServiceType.Group).ToList().ConvertAll(s => s.Content).ToList();
205+
List<NetworkService> allProdSvcGroups = [.. networkServices.Where(n => n.Content.Type.Name == ServiceType.Group).ToList().ConvertAll(s => s.Content)];
206206
List<NetworkService> allModSvcGroups = ModellingServiceGroupWrapper.Resolve(serviceGroups).ToList().ConvertAll(a => a.ToNetworkServiceGroup());
207207
return CompareSvcObjects(allModSvcGroups, allProdSvcGroups, networkServices, disregardedServices, networkServiceGroupComparer);
208208
}
@@ -212,8 +212,8 @@ private bool CompareSvcObjects(List<NetworkService> allModGroups, List<NetworkSe
212212
{
213213
if(FullAnalysis)
214214
{
215-
List<NetworkService> disregardedGroups = allModGroups.Except(allProdGroups, comparer).ToList();
216-
List<NetworkService> surplusGroups = allProdGroups.Except(allModGroups, comparer).ToList();
215+
List<NetworkService> disregardedGroups = [.. allModGroups.Except(allProdGroups, comparer)];
216+
List<NetworkService> surplusGroups = [.. allProdGroups.Except(allModGroups, comparer)];
217217
foreach (var svc in surplusGroups)
218218
{
219219
ServiceWrapper? exSvc = networkServices.FirstOrDefault(n => n.Content.Id == svc.Id);

roles/lib/files/FWO.Services/NetworkServiceComparer.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,26 @@ public bool Equals(NetworkService? service1, NetworkService? service2)
1818
return false;
1919
}
2020

21-
return (option.SvcRegardPortAndProt ? service1.ProtoId == service2.ProtoId
21+
int destPortEnd1 = service1.DestinationPortEnd ?? service1.DestinationPort ?? 0;
22+
int destPortEnd2 = service2.DestinationPortEnd ?? service2.DestinationPort ?? 0;
23+
24+
return (!option.SvcRegardPortAndProt || service1.ProtoId == service2.ProtoId
2225
&& service1.DestinationPort == service2.DestinationPort
23-
&& service1.DestinationPortEnd == service2.DestinationPortEnd : true)
24-
&& (option.SvcRegardName ? service1.Name == service2.Name : true);
26+
&& destPortEnd1 == destPortEnd2)
27+
&& (!option.SvcRegardName || service1.Name == service2.Name);
2528
}
2629

2730
public int GetHashCode(NetworkService service)
2831
{
29-
return (option.SvcRegardPortAndProt ? HashCode.Combine(service.ProtoId, service.DestinationPort, service.DestinationPortEnd) : 0)
32+
int destPortEnd = service.DestinationPortEnd ?? service.DestinationPort ?? 0;
33+
return (option.SvcRegardPortAndProt ? HashCode.Combine(service.ProtoId, service.DestinationPort, destPortEnd) : 0)
3034
^ (option.SvcRegardName ? HashCode.Combine(service.Name) : 0);
3135
}
3236
}
3337

3438
public class NetworkServiceGroupComparer(RuleRecognitionOption option) : IEqualityComparer<NetworkService?>
3539
{
36-
NetworkServiceComparer networkServiceComparer = new(option);
40+
readonly NetworkServiceComparer networkServiceComparer = new(option);
3741

3842
public bool Equals(NetworkService? service1, NetworkService? service2)
3943
{

0 commit comments

Comments
 (0)