/// <summary> /// Gets the validity of a specified cell. /// </summary> /// <param name="cell">The cell.</param> /// <returns> /// The validity of the specified cell. /// </returns> public static Validity GetValidity( this IValidationCell cell) { if (cell == null) { throw new ArgumentNullException(nameof(cell)); } var validationStatus = cell.GetValidationStatus(); switch (validationStatus) { case ValidationStatus.ValidationMissing: case ValidationStatus.DeterminedSubjectIsValid: return(Validity.Valid); case ValidationStatus.DeemedNotApplicable: return(Validity.NotApplicable); case ValidationStatus.DeterminedSubjectIsInvalid: return(Validity.Invalid); case ValidationStatus.Aborted: return(Validity.Aborted); default: return(Validity.Unknown); } }
private async Task ValidateCellIfNecessaryAsync( IValidationCell cell) { // NOTE: THIS CODE IS A NEAR DUPLICATE OF THE SYNC METHOD ABOVE; NO GOOD WAY TO D.R.Y. IT OUT var validationStatus = cell.GetValidationStatus(); if (validationStatus == ValidationStatus.ValidationMissing) { // no-op } else if (validationStatus == ValidationStatus.Unvalidated) { CellValidationEventBase validationEvent; try { var validation = cell.Validation; var validationResult = await this.protocolFactory.GetProtocolAndExecuteViaReflectionAsync <ValidationResult>(validation.Operation); string message = null; if (validationResult.MessageOp != null) { message = await this.protocolFactory.GetProtocolAndExecuteViaReflectionAsync <string>(validationResult.MessageOp); } var validity = await this.protocolFactory.GetProtocolAndExecuteViaReflectionAsync <Validity>(validationResult.ValidityOp); if (validity == Validity.Invalid) { validationEvent = new CellValidationDeterminedCellInvalidEvent(this.timestampUtc, null, message); } else if (validity == Validity.Valid) { validationEvent = new CellValidationDeterminedCellValidEvent(this.timestampUtc, null, message); } else if (validity == Validity.NotApplicable) { validationEvent = new CellValidationDeemedNotApplicableEvent(this.timestampUtc, null, message); } else if (validity == Validity.Aborted) { validationEvent = new CellValidationAbortedEvent(this.timestampUtc, null, message); } else { throw new NotSupportedException(Invariant($"This {nameof(Validity)} is not supported: {validity}.")); } } catch (OpExecutionAbortedExceptionBase ex) { // Here are are purposefully setting message to null because we have no idea who the thrower is // nor whether the report author wants to emit this message to the user. validationEvent = new CellValidationAbortedEvent(this.timestampUtc, ex.ToString(), null); } catch (OpExecutionDeemedNotApplicableExceptionBase ex) { // Here are are purposefully setting message to null because we have no idea who the thrower is // nor whether the report author wants to emit this message to the user. validationEvent = new CellValidationDeemedNotApplicableEvent(this.timestampUtc, ex.ToString(), null); } catch (Exception ex) { // The "proper" exception for a protocol to throw is an OpExecutionFailedExceptionBase. // Protocol authors might not comply. validationEvent = new CellValidationFailedEvent(this.timestampUtc, ex.ToString()); } cell.Record(validationEvent); } else if (cell.ValidationEvents.Last().TimestampUtc != this.timestampUtc) { throw new InvalidOperationException("Something went wrong. The cell was validated, but the recorded timestamp doesn't match this timestamp."); } }