From c3b839635ba3a52ee103c64db95b7155c9423c9c Mon Sep 17 00:00:00 2001 From: Daniel Schick Date: Thu, 9 Nov 2023 07:19:47 +0100 Subject: [PATCH] small error fixes and additions --- .../OverViewDetailControl.xaml | 7 ++ bsmd.database/CREW.cs | 2 + bsmd.database/PAS.cs | 2 + bsmd.database/RuleEngine.cs | 112 +++++++++--------- 4 files changed, 67 insertions(+), 56 deletions(-) diff --git a/ENI2/DetailViewControls/OverViewDetailControl.xaml b/ENI2/DetailViewControls/OverViewDetailControl.xaml index 7218b25c..931a9414 100644 --- a/ENI2/DetailViewControls/OverViewDetailControl.xaml +++ b/ENI2/DetailViewControls/OverViewDetailControl.xaml @@ -155,6 +155,13 @@ + + + + + + + diff --git a/bsmd.database/CREW.cs b/bsmd.database/CREW.cs index 8f890eb8..7e4ba5ad 100644 --- a/bsmd.database/CREW.cs +++ b/bsmd.database/CREW.cs @@ -273,6 +273,8 @@ namespace bsmd.database return result; } + public override string Title => "CREWA"; + #endregion #region Validation diff --git a/bsmd.database/PAS.cs b/bsmd.database/PAS.cs index 044b926e..8337dec0 100644 --- a/bsmd.database/PAS.cs +++ b/bsmd.database/PAS.cs @@ -312,6 +312,8 @@ namespace bsmd.database return result; } + public override string Title => "PASA"; + #endregion #region Validation diff --git a/bsmd.database/RuleEngine.cs b/bsmd.database/RuleEngine.cs index 3d10764b..df7114d9 100644 --- a/bsmd.database/RuleEngine.cs +++ b/bsmd.database/RuleEngine.cs @@ -137,7 +137,7 @@ namespace bsmd.database public static void RegisterNationalityChecker(NationalityValidHandler handler) { _nationalityChecker = handler; } /// - /// Test function checks decorated properties on an entity for errors (only errors, violations cannot + /// Test function checks decorated properties on an entity for errors (only errors, violations cannot /// happen here) /// /// @@ -208,7 +208,7 @@ namespace bsmd.database if(((value.Length >= 90) && isStandardML) || ((mla.MaxLength == value.Length) && (value.Length > 20) && !isStandardML)) { // put out a warning this might be truncated - violations.Add(RuleEngine.CreateViolation(ValidationCode.TRUNCATE, property.Name, value, entity.Title, identifier, entity.Tablename)); + violations.Add(RuleEngine.CreateViolation(ValidationCode.TRUNCATE, property.Name, value, entity.Title, identifier, entity.Title)); } } @@ -216,11 +216,11 @@ namespace bsmd.database if (Attribute.IsDefined(property, typeof(MaxWordLengthAttribute))) { MaxWordLengthAttribute mwla = Attribute.GetCustomAttribute(property, typeof(MaxWordLengthAttribute)) as MaxWordLengthAttribute; - + if (value.MaxLenNoWS() > mwla.MaxWordLength) { // put out a warning this might be overflowing in the report - violations.Add(RuleEngine.CreateViolation(ValidationCode.WORDOVERFLOW, property.Name, value, entity.Title, identifier, entity.Tablename)); + violations.Add(RuleEngine.CreateViolation(ValidationCode.WORDOVERFLOW, property.Name, value, entity.Title, identifier, entity.Title)); } } @@ -229,68 +229,68 @@ namespace bsmd.database switch (validationCode) { case ValidationCode.NOT_NULL: - if (value.Length == 0) errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Tablename)); + if (value.Length == 0) errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Title)); break; case ValidationCode.LOCODE: { Regex rgx = new Regex("^[A-Z]{2}[A-Z0-9]{3}$"); if (!rgx.IsMatch(value)) { - errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Tablename)); + errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Title)); } else if (_locodeChecker != null) { if (!_locodeChecker(value, LocodeMode.STANDARD)) - errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Tablename)); + errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Title)); } } break; case ValidationCode.LOCODE_NOPORT: { Regex rgx = new Regex("^[A-Z]{2}[A-Z0-9]{3}$"); - if (!rgx.IsMatch(value)) errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Tablename)); + if (!rgx.IsMatch(value)) errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Title)); if (_locodeChecker != null) if (!_locodeChecker(value, LocodeMode.NO_PORT_FLAG)) - errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Tablename)); + errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Title)); } break; case ValidationCode.LOCODE_SSN: { Regex rgx = new Regex("^[A-Z]{2}[A-Z0-9]{3}$"); - if (!rgx.IsMatch(value)) errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Tablename)); + if (!rgx.IsMatch(value)) errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Title)); if (_locodeChecker != null) if (!_locodeChecker(value, LocodeMode.SSN)) - errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Tablename)); + errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Title)); } break; case ValidationCode.LOCODE_GER: { - if(!RuleEngine.gerLocodeList.Contains(value)) - errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Tablename)); + if(!RuleEngine.gerLocodeList.Contains(value)) + errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Title)); } break; case ValidationCode.INT_GT_ZERO: { if (!Int32.TryParse(value, out int intVal) || intVal <= 0) - errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Tablename)); + errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Title)); } break; case ValidationCode.DOUBLE_GT_ZERO: { if (!Double.TryParse(value, out double dVal) || dVal <= 0) - errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Tablename)); + errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Title)); } break; case ValidationCode.GISIS: { Regex rgx = new Regex("[0-9]{4}"); - if (!rgx.IsMatch(value)) errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Tablename)); + if (!rgx.IsMatch(value)) errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Title)); } break; case ValidationCode.FLAG_CODE: - { + { if(!RuleEngine.NationalityChecker(value)) - errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Tablename)); + errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Title)); } break; case ValidationCode.OPTIONAL_FLAG_CODE: @@ -298,14 +298,14 @@ namespace bsmd.database if(!value.IsNullOrEmpty()) { if (!RuleEngine.NationalityChecker(value)) - errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Tablename)); + errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Title)); } } break; case ValidationCode.TWO_DIGIT: { Regex rgx = new Regex("[0-9]{2}"); - if (!rgx.IsMatch(value)) errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Tablename)); + if (!rgx.IsMatch(value)) errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Title)); } break; case ValidationCode.STRING_EXACT_LEN: @@ -313,54 +313,54 @@ namespace bsmd.database if (!value.IsNullOrEmpty()) { if (value.Length != maxlen) - errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Tablename)); + errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Title)); } } break; case ValidationCode.STRING_MAXLEN: { if (value.Length > maxlen) - errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Tablename)); + errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Title)); } break; case ValidationCode.STRING_IMOCLASS: { Regex rgx = new Regex(@"[1-9]{1}(\.[1-9]{1})?"); - if (!rgx.IsMatch(value)) errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Tablename)); + if (!rgx.IsMatch(value)) errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Title)); } break; case ValidationCode.STRING_UNNUMBER: { Regex rgx = new Regex("[0-9]{4}"); - if (!rgx.IsMatch(value)) errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Tablename)); + if (!rgx.IsMatch(value)) errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Title)); } break; case ValidationCode.DRAUGHT_IMPLAUSIBLE: { if (!Double.TryParse(value, out double dVal) || dVal <= 0) - errors.Add(RuleEngine.CreateError(ValidationCode.DOUBLE_GT_ZERO, property.Name, value, entity.Title, identifier, entity.Tablename)); + errors.Add(RuleEngine.CreateError(ValidationCode.DOUBLE_GT_ZERO, property.Name, value, entity.Title, identifier, entity.Title)); else if ((dVal < 20) || (dVal > 150)) - errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Tablename)); + errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Title)); } break; case ValidationCode.TIME_IMPLAUSIBLE: { - if (value.Length == 0) errors.Add(RuleEngine.CreateError(ValidationCode.NOT_NULL, property.Name, value, entity.Title, identifier, entity.Tablename)); + if (value.Length == 0) errors.Add(RuleEngine.CreateError(ValidationCode.NOT_NULL, property.Name, value, entity.Title, identifier, entity.Title)); if (DateTime.TryParse(value, out DateTime aTime)) { if ((aTime - DateTime.UtcNow).Minutes > 15) - errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Tablename)); + errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Title)); } } break; case ValidationCode.PAST_DATE: { - if (value.Length == 0) violations.Add(RuleEngine.CreateViolation(ValidationCode.NOT_NULL, property.Name, value, entity.Title, identifier, entity.Tablename)); + if (value.Length == 0) violations.Add(RuleEngine.CreateViolation(ValidationCode.NOT_NULL, property.Name, value, entity.Title, identifier, entity.Title)); if (DateTime.TryParse(value, out DateTime aTime)) { if (aTime < DateTime.UtcNow) - violations.Add(RuleEngine.CreateViolation(validationCode, property.Name, value, entity.Title, identifier, entity.Tablename)); + violations.Add(RuleEngine.CreateViolation(validationCode, property.Name, value, entity.Title, identifier, entity.Title)); } } break; @@ -368,11 +368,11 @@ namespace bsmd.database { if(!value.IsNullOrEmpty() && (value.Contains(","))) { - errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Tablename)); + errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Title)); } if(!value.IsNullOrEmpty() && !value.Trim().Any(char.IsDigit)) // falls "-" oder keine Zahl enthalten, Fehler! { - errors.Add(RuleEngine.CreateError(ValidationCode.IMPLAUSIBLE, property.Name, value, entity.Title, identifier, entity.Tablename)); + errors.Add(RuleEngine.CreateError(ValidationCode.IMPLAUSIBLE, property.Name, value, entity.Title, identifier, entity.Title)); } break; } @@ -380,25 +380,25 @@ namespace bsmd.database { if((value.Length == 0) || (STAT.VesselTypeDict?.ContainsKey(value) == false)) { - errors.Add(RuleEngine.CreateError(ValidationCode.NOT_NULL, property.Name, value, entity.Title, identifier, entity.Tablename)); + errors.Add(RuleEngine.CreateError(ValidationCode.NOT_NULL, property.Name, value, entity.Title, identifier, entity.Title)); } break; } case ValidationCode.NOT_NULL_MAX_LEN: if ((value.Length > maxlen) || (value.Length == 0)) - errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Tablename)); - break; + errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Title)); + break; case ValidationCode.FRZ: - { + { Regex rgx = new Regex("^[A-Z,a-z,0-9]{4,7}$"); - if (!rgx.IsMatch(value)) errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Tablename)); + if (!rgx.IsMatch(value)) errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Title)); break; } case ValidationCode.MMSI: { Regex rgx = new Regex("^[0-9]{9}$"); - if (!rgx.IsMatch(value)) errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Tablename)); + if (!rgx.IsMatch(value)) errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Title)); break; } case ValidationCode.INVALID_NUMBER_CHARS: @@ -409,7 +409,7 @@ namespace bsmd.database { if((elems[i].Length > 50) || (elems[i].IndexOfAny(invalidChars) >= 0)) { - errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Tablename)); + errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Title)); break; } } @@ -437,7 +437,7 @@ namespace bsmd.database // individuelle Fehler nach Nachrichtenklasse prüfen derivedEntity.MessageCore = aMessage.MessageCore; // some instance we need info from core (NOA / Transit) if ((derivedEntity is LADG) && aMessage.MessageCore.IsTransit) continue; // kein error reporting für LADG bei Transit (CH, 1.2.16) - // if ((derivedEntity is SEC) && aMessage.MessageCore.IsSmallShip) continue; // keine SEC Validierung für kleine Schiffe (CH, 1.11.18) // Ausnahme wieder entfernt 18.5.22 + // if ((derivedEntity is SEC) && aMessage.MessageCore.IsSmallShip) continue; // keine SEC Validierung für kleine Schiffe (CH, 1.11.18) // Ausnahme wieder entfernt 18.5.22 RuleEngine.ValidateProperties(derivedEntity, errors, violations); derivedEntity.Validate(errors, violations); } @@ -448,7 +448,7 @@ namespace bsmd.database /// /// Diese Funktion wird für Nachrichtenklassen (MDH, SEC,.. usw.) aufgerufen. Error in eingebetteten /// Klassen werden dann der Nachrichtenklasse zugeordnet (können dann logischerweise mehrfach auftreten) - /// + /// public void Validate(DatabaseEntity entity) { if (!(entity is Message)) return; @@ -463,7 +463,7 @@ namespace bsmd.database // individuelle Fehler nach Nachrichtenklasse prüfen derivedEntity.MessageCore = entity.MessageCore; // some instance we need info from core (NOA / Transit) if ((derivedEntity is LADG) && entity.MessageCore.IsTransit) continue; // kein error reporting für LADG bei Transit (CH, 1.2.16) - // if ((derivedEntity is SEC) && entity.MessageCore.IsSmallShip) continue; // keine STAT Validierung für kleine Schiffe (CH, 1.11.18) // Ausnahme wieder entfernt 18.5.22 + // if ((derivedEntity is SEC) && entity.MessageCore.IsSmallShip) continue; // keine STAT Validierung für kleine Schiffe (CH, 1.11.18) // Ausnahme wieder entfernt 18.5.22 ValidateProperties(derivedEntity, errors, violations); derivedEntity.Validate(errors, violations); } @@ -505,21 +505,21 @@ namespace bsmd.database #region private helper - public static MessageError CreateError(ValidationCode validationCode, string p, string value, string entityName, + public static MessageError CreateError(ValidationCode validationCode, string property, string value, string entityName, string identifier = "", string notificationClass = "") { - + MessageError error = new MessageError(); if (identifier.IsNullOrEmpty()) - error.FullName = string.Format("{0}.{1}", entityName, p); + error.FullName = string.Format("{0}.{1}", entityName, property); else - error.FullName = string.Format("{0}.{1}_{2}", entityName, p, identifier); + error.FullName = string.Format("{0}.{1}_{2}", entityName, property, identifier); error.ErrorCode = (int)validationCode; - error.Identifier = identifier; - error.PropertyName = p; - + error.Identifier = identifier; + error.PropertyName = property; + var match = Regex.Match(notificationClass, @"\[*\]\.\[(.*)\]"); if (match.Success) error.NotificationClass = match.Groups[1].Value; @@ -527,22 +527,22 @@ namespace bsmd.database error.NotificationClass = notificationClass; if (errorTextList.ContainsKey((int)validationCode)) - { - error.ErrorText = string.Format(errorTextList[(int)validationCode], p, value); + { + error.ErrorText = string.Format(errorTextList[(int)validationCode], property, value); } else { - error.ErrorText = p; + error.ErrorText = property; if (value != null) - error.ErrorText += " - " + value; + error.ErrorText += " - " + value; } return error; } - public static MessageViolation CreateViolation(ValidationCode validationCode, string p, + public static MessageViolation CreateViolation(ValidationCode validationCode, string p, string value, string entityName, string identifier = "", string notificationClass = "") { - + MessageViolation violation = new MessageViolation(); if (identifier.IsNullOrEmpty()) @@ -551,7 +551,7 @@ namespace bsmd.database violation.FullName = string.Format("{0}.{1}_{2}", entityName, p, identifier); violation.ViolationCode = (int)validationCode; - violation.Identifier = identifier; + violation.Identifier = identifier; violation.PropertyName = p; var match = Regex.Match(notificationClass, @"\[*\]\.\[(.*)\]");