|
10 | 10 | using FWO.Middleware.Client; |
11 | 11 | using System.Data; |
12 | 12 | using Microsoft.AspNetCore.Components; |
13 | | -using static FWO.Data.Modelling.ModellingTypes; |
14 | | -using System.Collections.Generic; |
15 | 13 |
|
16 | 14 |
|
17 | 15 | namespace FWO.Services |
@@ -278,6 +276,87 @@ public void AddExtraConfig() |
278 | 276 | AddExtraConfigMode = true; |
279 | 277 | } |
280 | 278 |
|
| 279 | + /// <summary> |
| 280 | + /// Checks the opposite direction if it already contains a network area. |
| 281 | + /// </summary> |
| 282 | + private bool IsAreaForbiddenInDirection(Direction direction) |
| 283 | + { |
| 284 | + return direction switch |
| 285 | + { |
| 286 | + Direction.Source => ActConn.DestinationAreas.Count > 0 || DstAreasToAdd.Count > 0, |
| 287 | + Direction.Destination => ActConn.SourceAreas.Count > 0 || SrcAreasToAdd.Count > 0, |
| 288 | + _ => false, |
| 289 | + }; |
| 290 | + } |
| 291 | + |
| 292 | + /// <summary> |
| 293 | + /// Checks if the given network areas are allowed in the current connection/interface/service. |
| 294 | + /// </summary> |
| 295 | + /// <param name="networkAreas">The list of network areas to check.</param> |
| 296 | + /// <param name="reason">Out parameter to give context as a reason why it's not allowed, otherwise is's empty.</param> |
| 297 | + public bool NetworkAreaUseAllowed(List<ModellingNetworkArea> networkAreas, Direction direction, out (string Title, string Text) reason) |
| 298 | + { |
| 299 | + reason.Text = ""; |
| 300 | + |
| 301 | + |
| 302 | + if (ActConn.IsCommonService) |
| 303 | + { |
| 304 | + reason.Title = userConfig.GetText("edit_service"); |
| 305 | + } |
| 306 | + else if (ActConn.IsInterface) |
| 307 | + { |
| 308 | + reason.Title = userConfig.GetText("edit_interface"); |
| 309 | + } |
| 310 | + else |
| 311 | + { |
| 312 | + reason.Title = userConfig.GetText("edit_connection"); |
| 313 | + } |
| 314 | + |
| 315 | + if (IsAreaForbiddenInDirection(direction)) |
| 316 | + { |
| 317 | + reason.Text = userConfig.GetText("direction_contain_nwarea"); |
| 318 | + return false; |
| 319 | + } |
| 320 | + |
| 321 | + if (ActConn.IsInterface) |
| 322 | + { |
| 323 | + reason.Text = userConfig.GetText("interface_contain_nwarea"); |
| 324 | + return false; |
| 325 | + } |
| 326 | + |
| 327 | + bool hasCommonNetworkAreas = HasCommonNetworkAreas(networkAreas); |
| 328 | + |
| 329 | + if (!hasCommonNetworkAreas && ActConn.IsCommonService) |
| 330 | + { |
| 331 | + return true; |
| 332 | + } |
| 333 | + else if (hasCommonNetworkAreas && ( ActConn.IsCommonService || ( !ActConn.IsInterface && !ActConn.IsCommonService ) )) |
| 334 | + { |
| 335 | + return true; |
| 336 | + } |
| 337 | + |
| 338 | + reason.Text = userConfig.GetText("only_common_service"); |
| 339 | + return false; |
| 340 | + } |
| 341 | + |
| 342 | + /// <summary> |
| 343 | + /// Checks the given list of network areas against common network area settings. |
| 344 | + /// </summary> |
| 345 | + /// <param name="networkAreas"></param> |
| 346 | + /// <returns></returns> |
| 347 | + private bool HasCommonNetworkAreas(List<ModellingNetworkArea> networkAreas) |
| 348 | + { |
| 349 | + foreach (ModellingNetworkArea area in networkAreas) |
| 350 | + { |
| 351 | + if (CommonAreaConfigItems.Any(_ => _.AreaId == area.Id)) |
| 352 | + { |
| 353 | + return true; |
| 354 | + } |
| 355 | + } |
| 356 | + |
| 357 | + return false; |
| 358 | + } |
| 359 | + |
281 | 360 | public bool SaveExtraConfig(ModellingExtraConfig extraConfig) |
282 | 361 | { |
283 | 362 | extraConfig.Id = ActConn.ExtraConfigs.Count > 0 ? ActConn.ExtraConfigs.OrderByDescending(x => x.Id).First().Id + 1 : 1; |
@@ -1021,87 +1100,6 @@ public bool CalcVisibility() |
1021 | 1100 | return true; |
1022 | 1101 | } |
1023 | 1102 |
|
1024 | | - /// <summary> |
1025 | | - /// Checks the opposite direction if it already contains a network area. |
1026 | | - /// </summary> |
1027 | | - private bool IsAreaForbiddenInDirection(Direction direction) |
1028 | | - { |
1029 | | - return direction switch |
1030 | | - { |
1031 | | - Direction.Source => ActConn.DestinationAreas.Count > 0 || DstAreasToAdd.Count > 0, |
1032 | | - Direction.Destination => ActConn.SourceAreas.Count > 0 || SrcAreasToAdd.Count > 0, |
1033 | | - _ => false, |
1034 | | - }; |
1035 | | - } |
1036 | | - |
1037 | | - /// <summary> |
1038 | | - /// Checks if the given network areas are allowed in the current connection/interface/service. |
1039 | | - /// </summary> |
1040 | | - /// <param name="networkAreas">The list of network areas to check.</param> |
1041 | | - /// <param name="reason">Out parameter to give context as a reason why it's not allowed, otherwise is's empty.</param> |
1042 | | - public bool NetworkAreaUseAllowed(List<ModellingNetworkArea> networkAreas, Direction direction, out (string Title, string Text) reason) |
1043 | | - { |
1044 | | - reason.Text = ""; |
1045 | | - |
1046 | | - |
1047 | | - if (ActConn.IsCommonService) |
1048 | | - { |
1049 | | - reason.Title = userConfig.GetText("edit_service"); |
1050 | | - } |
1051 | | - else if (ActConn.IsInterface) |
1052 | | - { |
1053 | | - reason.Title = userConfig.GetText("edit_interface"); |
1054 | | - } |
1055 | | - else |
1056 | | - { |
1057 | | - reason.Title = userConfig.GetText("edit_connection"); |
1058 | | - } |
1059 | | - |
1060 | | - if (IsAreaForbiddenInDirection(direction)) |
1061 | | - { |
1062 | | - reason.Text = userConfig.GetText("direction_contain_nwarea"); |
1063 | | - return false; |
1064 | | - } |
1065 | | - |
1066 | | - if (ActConn.IsInterface) |
1067 | | - { |
1068 | | - reason.Text = userConfig.GetText("interface_contain_nwarea"); |
1069 | | - return false; |
1070 | | - } |
1071 | | - |
1072 | | - bool hasCommonNetworkAreas = HasCommonNetworkAreas(networkAreas); |
1073 | | - |
1074 | | - if (!hasCommonNetworkAreas && ActConn.IsCommonService) |
1075 | | - { |
1076 | | - return true; |
1077 | | - } |
1078 | | - else if (hasCommonNetworkAreas && ( ActConn.IsCommonService || ( !ActConn.IsInterface && !ActConn.IsCommonService ) )) |
1079 | | - { |
1080 | | - return true; |
1081 | | - } |
1082 | | - |
1083 | | - reason.Text = userConfig.GetText("only_common_service"); |
1084 | | - return false; |
1085 | | - } |
1086 | | - |
1087 | | - /// <summary> |
1088 | | - /// Checks the given list of network areas against common network area settings. |
1089 | | - /// </summary> |
1090 | | - /// <param name="networkAreas"></param> |
1091 | | - /// <returns></returns> |
1092 | | - private bool HasCommonNetworkAreas(List<ModellingNetworkArea> networkAreas) |
1093 | | - { |
1094 | | - foreach (ModellingNetworkArea area in networkAreas) |
1095 | | - { |
1096 | | - if (CommonAreaConfigItems.Any(_ => _.AreaId == area.Id)) |
1097 | | - { |
1098 | | - return true; |
1099 | | - } |
1100 | | - } |
1101 | | - |
1102 | | - return false; |
1103 | | - } |
1104 | | - |
1105 | 1103 | public bool SrcDropForbidden() |
1106 | 1104 | { |
1107 | 1105 | return SrcReadOnly || ( ActConn.IsInterface && DstFilledInWork() ); |
|
0 commit comments