2using System.Globalization;
3using System.Xml.Serialization;
4using LotSizingDataModel.Core.Common;
49[XmlType(TypeName =
"methodCompatibilityEvidence")]
52 private string _criterionCode =
55 private string _featureCode =
58 private string _description =
61 private string _expectedValue =
64 private string _observedValue =
67 private string _affectedEntityKey =
70 private bool _isSatisfied;
72 private bool _isRequired =
75 private bool _isBlocking;
77 private double _weight =
80 private string _comment =
126 string criterionCode,
129 bool isRequired =
true,
130 bool isBlocking =
false,
133 if (
string.IsNullOrWhiteSpace(criterionCode))
135 throw new ArgumentException(
136 "A compatibility criterion code is required.",
137 nameof(criterionCode));
140 if (
string.IsNullOrWhiteSpace(description))
142 throw new ArgumentException(
143 "A compatibility criterion description is " +
145 nameof(description));
188 [XmlAttribute(
"criterionCode")]
191 get => _criterionCode;
196 value?.Trim() ??
string.Empty))
217 [XmlAttribute(
"featureCode")]
225 value?.Trim() ??
string.Empty))
242 [XmlElement(
"description")]
250 value?.Trim() ??
string.Empty))
269 [XmlAttribute(
"expectedValue")]
272 get => _expectedValue;
277 value?.Trim() ??
string.Empty))
289 [XmlAttribute(
"observedValue")]
292 get => _observedValue;
297 value?.Trim() ??
string.Empty))
314 [XmlAttribute(
"affectedEntityKey")]
317 get => _affectedEntityKey;
321 ref _affectedEntityKey,
322 value?.Trim() ??
string.Empty))
334 [XmlAttribute(
"isSatisfied")]
344 NotifyEvaluationProperties();
361 [XmlAttribute(
"isRequired")]
371 NotifyEvaluationProperties();
386 [XmlAttribute(
"isBlocking")]
396 NotifyEvaluationProperties();
416 [XmlAttribute(
"weight")]
422 if (!
double.IsFinite(value) ||
425 throw new ArgumentOutOfRangeException(
428 "The compatibility-evidence weight must " +
429 "be finite and non-negative.");
452 [XmlElement(
"comment")]
460 value?.Trim() ??
string.Empty))
474 !
string.IsNullOrWhiteSpace(
483 !
string.IsNullOrWhiteSpace(
492 !
string.IsNullOrWhiteSpace(
501 !
string.IsNullOrWhiteSpace(
510 !
string.IsNullOrWhiteSpace(
519 !
string.IsNullOrWhiteSpace(
528 !
string.IsNullOrWhiteSpace(
601 double.IsFinite(
Weight) &&
615 object? expectedValue,
616 object? observedValue)
619 ConvertToInvariantString(
623 ConvertToInvariantString(
634 object? observedValue =
null)
636 if (observedValue is not
null)
639 ConvertToInvariantString(
657 object? observedValue =
null,
660 if (observedValue is not
null)
663 ConvertToInvariantString(
681 ?
"blocking mismatch"
683 ?
"required mismatch"
684 :
"optional mismatch";
687 $
"{CriterionCode}: {state}; " +
691 private static string ConvertToInvariantString(
699 if (value is
bool booleanValue)
706 if (value is DateTime dateTimeValue)
708 return dateTimeValue.ToString(
710 CultureInfo.InvariantCulture);
713 if (value is DateTimeOffset dateTimeOffsetValue)
715 return dateTimeOffsetValue.ToString(
717 CultureInfo.InvariantCulture);
720 if (value is IFormattable formattableValue)
722 return formattableValue.ToString(
724 CultureInfo.InvariantCulture) ??
728 return value.ToString() ??
732 private void NotifyEvaluationProperties()
bool IsBlocking
Gets or sets a value indicating whether failure of the criterion makes the method incompatible with t...
string Description
Gets or sets the human-readable explanation of the compatibility criterion.
bool IsSatisfied
Gets or sets a value indicating whether the compatibility criterion is satisfied.
bool HasComment
Gets a value indicating whether an explanatory comment has been recorded.
double Weight
Gets or sets the non-negative importance assigned to the criterion.
bool HasDescription
Gets a value indicating whether a human-readable description has been recorded.
MethodCompatibilityEvidence(string criterionCode, string description, bool isSatisfied, bool isRequired=true, bool isBlocking=false, double weight=1.0)
Initializes compatibility evidence for one evaluated criterion.
string FeatureCode
Gets or sets the code of the problem feature evaluated by this evidence.
string ObservedValue
Gets or sets the value observed in the analyzed instance.
bool IsRequired
Gets or sets a value indicating whether the criterion represents a required condition.
void MarkAsUnsatisfied(object? observedValue=null, string comment="")
Marks the criterion as unsatisfied.
bool IsBlockingMismatch
Gets a value indicating whether the evidence represents a blocking incompatibility.
bool IsMismatch
Gets a value indicating whether the evaluated criterion is not satisfied.
string ExpectedValue
Gets or sets the value expected by the method or compatibility criterion.
bool HasExpectedValue
Gets a value indicating whether an expected value has been recorded.
bool HasFeatureCode
Gets a value indicating whether a problem-feature code has been recorded.
bool SupportsCompatibility
Gets a value indicating whether this evidence supports the compatibility of the method.
void MarkAsSatisfied(object? observedValue=null)
Marks the criterion as satisfied.
override string ToString()
string AffectedEntityKey
Gets or sets an optional key identifying the entity to which the evidence applies.
bool IsValidEvidence
Gets a value indicating whether this evidence contains the minimum information required for use by th...
bool HasCriterionCode
Gets a value indicating whether a criterion code has been recorded.
bool HasObservedValue
Gets a value indicating whether an observed value has been recorded.
MethodCompatibilityEvidence()
Initializes an empty compatibility-evidence record.
double ScoreContribution
Gets the signed numerical contribution of this evidence to a compatibility score.
bool IsRequiredMismatch
Gets a value indicating whether a required criterion is not satisfied.
bool IsOptionalMismatch
Gets a value indicating whether a non-required and non-blocking criterion is not satisfied.
void SetComparedValues(object? expectedValue, object? observedValue)
Sets the textual expected and observed values of the evaluated criterion.
bool HasAffectedEntityKey
Gets a value indicating whether an affected entity key has been recorded.
string Comment
Gets or sets an optional explanatory comment.
string CriterionCode
Gets or sets the stable code identifying the evaluated compatibility criterion.