2using System.Collections.Generic;
4using System.Xml.Serialization;
5using LotSizingDataModel.Core.Common;
23[XmlType(TypeName =
"knownProblemRuleDefinition")]
45 "GREATER_THAN_OR_EQUAL";
92 private static readonly HashSet<string>
93 SupportedOperatorCodes =
110 StringComparer.OrdinalIgnoreCase);
112 private string _ruleCode =
115 private string _featureCode =
118 private string _operatorCode =
121 private string _expectedValue =
124 private string _description =
127 private double _weight = 1.0;
128 private bool _isEnabled =
true;
167 string expectedValue =
"",
168 string description =
"")
170 if (
string.IsNullOrWhiteSpace(ruleCode))
172 throw new ArgumentException(
173 "A classification-rule code is required.",
177 if (
string.IsNullOrWhiteSpace(featureCode))
179 throw new ArgumentException(
180 "A feature code is required.",
181 nameof(featureCode));
184 if (
string.IsNullOrWhiteSpace(operatorCode))
186 throw new ArgumentException(
187 "A comparison-operator code is required.",
188 nameof(operatorCode));
207 [XmlAttribute(
"ruleCode")]
215 NormalizeRuleCode(value)))
217 NotifyDefinitionProperties();
236 [XmlAttribute(
"featureCode")]
244 value?.Trim() ??
string.Empty))
246 NotifyDefinitionProperties();
272 [XmlAttribute(
"operatorCode")]
275 get => _operatorCode;
280 NormalizeOperatorCode(value)))
282 NotifyDefinitionProperties();
301 [XmlElement(
"expectedValue")]
304 get => _expectedValue;
309 value?.Trim() ??
string.Empty))
311 NotifyDefinitionProperties();
320 [XmlElement(
"description")]
326 value?.Trim() ??
string.Empty);
346 [XmlAttribute(
"weight")]
352 if (!
double.IsFinite(value) ||
355 throw new ArgumentOutOfRangeException(
358 "The rule weight must be finite and " +
372 [XmlAttribute(
"enabled")]
394 !
string.IsNullOrWhiteSpace(
403 !
string.IsNullOrWhiteSpace(
424 StringComparison.OrdinalIgnoreCase) &&
428 StringComparison.OrdinalIgnoreCase);
436 !
string.IsNullOrWhiteSpace(
476 string normalizedOperatorCode =
477 NormalizeOperatorCode(
480 return SupportedOperatorCodes.Contains(
481 normalizedOperatorCode);
490 public static IReadOnlyList<string>
493 return SupportedOperatorCodes
497 StringComparer.Ordinal)
504 string expectedDescription =
506 ? $
" {ExpectedValue}"
510 $
"{RuleCode}: {FeatureCode} " +
512 $
"{expectedDescription}";
515 private static string NormalizeRuleCode(
520 .ToUpperInvariant() ??
524 private static string NormalizeOperatorCode(
527 if (
string.IsNullOrWhiteSpace(value))
537 char.IsLetterOrDigit(
541 char.ToUpperInvariant(
545 return compactCode
switch
547 "EQUALS" or
"EQUAL" =>
550 "NOTEQUALS" or
"NOTEQUAL" =>
556 "GREATERTHANOREQUAL" or
557 "GREATERTHANOREQUALTO" =>
564 "LESSTHANOREQUALTO" =>
567 "CONTAINS" or
"CONTAIN" =>
570 "NOTCONTAINS" or
"NOTCONTAIN" =>
579 "ISTRUE" or
"TRUE" =>
582 "ISFALSE" or
"FALSE" =>
586 value.Trim().ToUpperInvariant()
590 private void NotifyDefinitionProperties()
const string GreaterThanOperator
Identifies a strict greater-than comparison.
string ExpectedValue
Gets or sets the value expected by the comparison.
string FeatureCode
Gets or sets the stable code of the feature evaluated by this rule.
const string NotContainsOperator
Identifies a negative collection or text containment test.
bool HasRuleCode
Gets a value indicating whether a stable rule code has been recorded.
bool HasFeatureCode
Gets a value indicating whether a feature code has been recorded.
const string ContainsOperator
Identifies a collection or text containment test.
const string GreaterThanOrEqualOperator
Identifies a greater-than-or-equal comparison.
const string IsFalseOperator
Identifies a Boolean condition requiring the observed value to be false.
string RuleCode
Gets or sets the stable code identifying this classification rule.
const string LessThanOperator
Identifies a strict less-than comparison.
const string InOperator
Identifies a membership test against a collection of accepted values.
const string NotEqualsOperator
Identifies an inequality comparison.
KnownProblemRuleDefinition(string ruleCode, string featureCode, string operatorCode, string expectedValue="", string description="")
Initializes a known-problem rule definition.
const string IsTrueOperator
Identifies a Boolean condition requiring the observed value to be true.
bool CanBeEvaluated
Gets a value indicating whether this rule can currently be evaluated.
static bool IsSupportedOperatorCode(string operatorCode)
Determines whether an operator code is supported by the standard rule evaluator.
string Description
Gets or sets a human-readable description of the classification rule.
bool RequiresExpectedValue
Gets a value indicating whether this operator requires an explicit expected value.
const string LessThanOrEqualOperator
Identifies a less-than-or-equal comparison.
static IReadOnlyList< string > GetSupportedOperatorCodes()
Returns all standard comparison-operator codes.
double Weight
Gets or sets the relative importance of this rule during weighted matching.
bool HasSupportedOperator
Gets a value indicating whether the operator code is supported by the standard rule evaluator.
bool HasExpectedValue
Gets a value indicating whether an expected value has been recorded.
bool IsEnabled
Gets or sets a value indicating whether this rule is enabled for automatic evaluation.
string OperatorCode
Gets or sets the code of the comparison operator used by this rule.
const string NotInOperator
Identifies a negative membership test.
override string ToString()
KnownProblemRuleDefinition()
Initializes an empty known-problem rule definition.
const string EqualsOperator
Identifies an equality comparison.
bool IsValidDefinition
Gets a value indicating whether this rule contains the metadata required for evaluation.