コード例 #1
0
        /// <summary>
        /// Builds an <see cref="NotOp"/>.
        /// </summary>
        /// <param name="statement">The statement.</param>
        /// <returns>
        /// The operation.
        /// </returns>
        public static NotOp Not(
            IReturningOperation <bool> statement)
        {
            var result = new NotOp(statement);

            return(result);
        }
        public override LocatedCellOpBase <Availability> DeepCloneWithCellLocator(IReturningOperation <CellLocatorBase> cellLocator)
        {
            var result = new GetAvailabilityOp(
                cellLocator);

            return(result);
        }
コード例 #3
0
        public override SingleStatementOpBase <bool, bool> DeepCloneWithStatement(IReturningOperation <bool> statement)
        {
            var result = new NotOp(
                statement);

            return(result);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="OperationOutputCellBase{TValue}"/> class.
        /// </summary>
        /// <param name="id">The cell's unique identifier.</param>
        /// <param name="columnsSpanned">The number of columns spanned or null if none (cell occupies a single column).</param>
        /// <param name="details">Details about the cell.</param>
        /// <param name="validation">The validation to perform.</param>
        /// <param name="validationEvents">The events that record the validation of this cell.</param>
        /// <param name="defaultAvailability">The default availability of the cell (before <paramref name="availabilityCheck"/> is run).</param>
        /// <param name="availabilityCheck">The availability check to perform.</param>
        /// <param name="availabilityCheckEvents">The events that record the availability checks on this cell.</param>
        /// <param name="operation">The operation.</param>
        /// <param name="operationExecutionEvents">The events that record the execution of <paramref name="operation"/>.</param>
        protected OperationOutputCellBase(
            string id,
            int?columnsSpanned,
            string details,
            Validation validation,
            IReadOnlyList <CellValidationEventBase> validationEvents,
            Availability defaultAvailability,
            AvailabilityCheck availabilityCheck,
            IReadOnlyList <CellAvailabilityCheckEventBase> availabilityCheckEvents,
            IReturningOperation <TValue> operation,
            IReadOnlyList <CellOpExecutionEventBase> operationExecutionEvents)
            : base(id, columnsSpanned, details, validation, validationEvents, defaultAvailability, availabilityCheck, availabilityCheckEvents)
        {
            if (operation == null)
            {
                throw new ArgumentNullException(nameof(operation));
            }

            if ((operationExecutionEvents != null) && operationExecutionEvents.Any(_ => _ == null))
            {
                throw new ArgumentException(Invariant($"{nameof(operationExecutionEvents)} contains a null element."));
            }

            this.Operation = operation;
            this.OperationExecutionEvents = operationExecutionEvents;
        }
コード例 #5
0
        public override SingleStatementOpBase <decimal, int> DeepCloneWithStatement(IReturningOperation <decimal> statement)
        {
            var result = new GetNumberOfSignificantDigitsOp(
                statement);

            return(result);
        }
コード例 #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AvailabilityCheckStep"/> class.
        /// </summary>
        /// <param name="operation">The operation to execute whose result determines what to do as specified by <paramref name="trueAction"/> and <paramref name="falseAction"/>.</param>
        /// <param name="stopMessageOp">OPTIONAL operation to execute to get the message that should be emitted when this availability check step stops the availability check (prevents the next step in the chain from executing).  DEFAULT is to omit this message.</param>
        /// <param name="trueAction">OPTIONAL action to perform when executing <paramref name="operation"/> returns true.  DEFAULT is to move on and execute the next step in the chain.</param>
        /// <param name="falseAction">OPTIONAL action to perform when executing <paramref name="operation"/> returns false.  DEFAULT is to stop the availability check (do not execute the next step in the chain) and determine that the subject is disabled.</param>
        /// <param name="details">OPTIONAL details about this availability check step.  DEFAULT is to omit any details.</param>
        public AvailabilityCheckStep(
            IReturningOperation <bool> operation,
            IReturningOperation <string> stopMessageOp = null,
            AvailabilityCheckStepAction trueAction     = AvailabilityCheckStepAction.NextStep,
            AvailabilityCheckStepAction falseAction    = AvailabilityCheckStepAction.StopAsDisabled,
            string details = null)
        {
            if (operation == null)
            {
                throw new ArgumentNullException(nameof(operation));
            }

            if (trueAction == AvailabilityCheckStepAction.Unknown)
            {
                throw new ArgumentOutOfRangeException(Invariant($"{nameof(trueAction)} is {nameof(AvailabilityCheckStepAction.Unknown)}."));
            }

            if (falseAction == AvailabilityCheckStepAction.Unknown)
            {
                throw new ArgumentOutOfRangeException(Invariant($"{nameof(falseAction)} is {nameof(AvailabilityCheckStepAction.Unknown)}."));
            }

            this.Operation     = operation;
            this.StopMessageOp = stopMessageOp;
            this.TrueAction    = trueAction;
            this.FalseAction   = falseAction;
            this.Details       = details;
        }
        public override LocatedCellOpBase <bool> DeepCloneWithCellLocator(IReturningOperation <CellLocatorBase> cellLocator)
        {
            var result = new HasCellValueOp(
                cellLocator);

            return(result);
        }
コード例 #8
0
        private async Task <LocatedCellHavingValue> GetCellAndExecuteOperationIfNecessaryAsync(
            IReturningOperation <CellLocatorBase> cellLocatorOp)
        {
            // NOTE: THIS CODE IS A NEAR DUPLICATE OF THE SYNC METHOD ABOVE; NO GOOD WAY TO D.R.Y. IT OUT
            var cellLocator = await this.protocolFactory.GetProtocolAndExecuteViaReflectionAsync <CellLocatorBase>(cellLocatorOp);

            var cell = this.GetCell(cellLocator);

            if (!(cell is IGetCellValue cellWithValue))
            {
                throw new CellNotFoundException(Invariant($"The operation addresses a cell whose type is not an {typeof(IGetCellValue).ToStringReadable()}: {cell.GetType().ToStringReadable()}."), cellLocator);
            }

            // This is necessary because we can't simply use new ExecuteOperationCellIfNecessaryOp<TValue>()
            // TValue is the TValue of THIS protocol factory.
            // HasCellValueOp does not have TValue in it's generic arguments; ALL instances of
            // DataStructureCellProtocols can execute that operation and the chain-of-responsibility
            // protocol factory will simply use the first instance of DataStructureCellProtocols that is registered.
            // So TValue of this factory might be int whereas the cell's TValue is a decimal.
            var executeOperationCellIfNecessaryOp = DataStructureCellProtocols.GetExecuteOperationCellIfNecessaryOpOrNull(cell);

            if (executeOperationCellIfNecessaryOp != null)
            {
                await this.protocolFactory.GetProtocolAndExecuteViaReflectionAsync(executeOperationCellIfNecessaryOp);
            }

            var result = new LocatedCellHavingValue
            {
                Cell        = cellWithValue,
                CellLocator = cellLocator,
            };

            return(result);
        }
コード例 #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GetCellValueOp{TResult}"/> class.
 /// </summary>
 /// <param name="cellLocator">A cell locator.</param>
 /// <param name="defaultValue">OPTIONAL value to use if the cell does not have a value.  DEFAULT is to throw if cell does not have a value.</param>
 public GetCellValueOp(
     IReturningOperation <CellLocatorBase> cellLocator,
     IReturningOperation <TResult> defaultValue = null)
     : base(cellLocator)
 {
     this.DefaultValue = defaultValue;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="AvailabilityCheckChain"/> class.
        /// </summary>
        /// <param name="steps">The individual availability check steps.</param>
        /// <param name="endMessageOp">OPTIONAL operation to execute to get the message that should be emitted when all <paramref name="steps"/> have been evaluated and none have stopped the availability check (we've reached the end of the chain).  DEFAULT is to omit this message.</param>
        /// <param name="endAvailability">OPTIONAL value that specifies the availability of the subject when all <paramref name="steps"/> have been evaluated and none have stopped the availability check (we've reached the end of the chain).  DEFAULT is to determine that the subject is enabled.</param>
        public AvailabilityCheckChain(
            IReadOnlyList <AvailabilityCheckStep> steps,
            IReturningOperation <string> endMessageOp = null,
            Availability endAvailability = Availability.Enabled)
        {
            if (steps == null)
            {
                throw new ArgumentNullException(nameof(steps));
            }

            if (!steps.Any())
            {
                throw new ArgumentException(Invariant($"{nameof(steps)} is an empty enumerable."));
            }

            if (steps.Any(_ => _ == null))
            {
                throw new ArgumentException(Invariant($"{nameof(steps)} contains at least one null element."));
            }

            if (endAvailability == Availability.Unknown)
            {
                throw new ArgumentOutOfRangeException(Invariant($"{nameof(endAvailability)} is {nameof(Availability.Unknown)}."));
            }

            this.Steps           = steps;
            this.EndMessageOp    = endMessageOp;
            this.EndAvailability = endAvailability;
        }
コード例 #11
0
        /// <summary>
        /// Builds an <see cref="GetNumberOfSignificantDigitsOp"/>.
        /// </summary>
        /// <param name="statement">The statement.</param>
        /// <returns>
        /// The operation.
        /// </returns>
        public static GetNumberOfSignificantDigitsOp GetNumberOfSignificantDigits(
            IReturningOperation <decimal> statement)
        {
            var result = new GetNumberOfSignificantDigitsOp(statement);

            return(result);
        }
コード例 #12
0
        /// <summary>
        /// Builds an <see cref="CompareOp"/>.
        /// </summary>
        /// <param name="left">The value to the left of the less-than-or-equal-to operator.</param>
        /// <param name="right">The value to the right of the less-than-or-equal-to operator.</param>
        /// <returns>
        /// The operation.
        /// </returns>
        public static CompareOp IsLessThanOrEqualTo(
            IReturningOperation <decimal> left,
            IReturningOperation <decimal> right)
        {
            var result = new CompareOp(left, Op.Const(CompareOperator.LessThanOrEqualTo), right);

            return(result);
        }
コード例 #13
0
        /// <summary>
        /// Builds an <see cref="IsEqualToOp{TResult}"/>.
        /// </summary>
        /// <typeparam name="TStatement">The type of the statements to compare.</typeparam>
        /// <param name="statement1">The first statement.</param>
        /// <param name="statement2">The second statement.</param>
        /// <returns>
        /// The operation.
        /// </returns>
        public static IsEqualToOp <TStatement> IsEqualTo <TStatement>(
            IReturningOperation <TStatement> statement1,
            IReturningOperation <TStatement> statement2)
        {
            var result = new IsEqualToOp <TStatement>(statement1, statement2);

            return(result);
        }
コード例 #14
0
        public DivideOp DeepCloneWithNumerator(IReturningOperation <decimal> numerator)
        {
            var result = new DivideOp(
                numerator,
                this.Denominator?.DeepClone());

            return(result);
        }
コード例 #15
0
        /// <summary>
        /// Builds an <see cref="DivideOp"/>.
        /// </summary>
        /// <param name="numerator">The numerator.</param>
        /// <param name="denominator">The denominator.</param>
        /// <returns>
        /// The operation.
        /// </returns>
        public static DivideOp Divide(
            IReturningOperation <decimal> numerator,
            IReturningOperation <decimal> denominator)
        {
            var result = new DivideOp(numerator, denominator);

            return(result);
        }
        public AvailabilityCheckResult DeepCloneWithMessageOp(IReturningOperation <string> messageOp)
        {
            var result = new AvailabilityCheckResult(
                this.AvailabilityOp?.DeepClone(),
                messageOp);

            return(result);
        }
        public AvailabilityCheckResult DeepCloneWithAvailabilityOp(IReturningOperation <Availability> availabilityOp)
        {
            var result = new AvailabilityCheckResult(
                availabilityOp,
                this.MessageOp?.DeepClone());

            return(result);
        }
コード例 #18
0
        public DivideOp DeepCloneWithDenominator(IReturningOperation <decimal> denominator)
        {
            var result = new DivideOp(
                this.Numerator?.DeepClone(),
                denominator);

            return(result);
        }
コード例 #19
0
        /// <summary>
        /// Builds an <see cref="CompareOp"/>.
        /// </summary>
        /// <param name="left">The value to the left of the greater-than operator.</param>
        /// <param name="right">The value to the right of the greater-than operator.</param>
        /// <returns>
        /// The operation.
        /// </returns>
        public static CompareOp IsGreaterThan(
            IReturningOperation <decimal> left,
            IReturningOperation <decimal> right)
        {
            var result = new CompareOp(left, Op.Const(CompareOperator.GreaterThan), right);

            return(result);
        }
        public GetCellValueOp <TResult> DeepCloneWithDefaultValue(IReturningOperation <TResult> defaultValue)
        {
            var result = new GetCellValueOp <TResult>(
                this.CellLocator?.DeepClone(),
                defaultValue);

            return(result);
        }
        public ValidationResult DeepCloneWithValidityOp(IReturningOperation <Validity> validityOp)
        {
            var result = new ValidationResult(
                validityOp,
                this.MessageOp?.DeepClone());

            return(result);
        }
        public override LocatedCellOpBase <TResult> DeepCloneWithCellLocator(IReturningOperation <CellLocatorBase> cellLocator)
        {
            var result = new GetCellValueOp <TResult>(
                cellLocator,
                this.DefaultValue?.DeepClone());

            return(result);
        }
        public ValidationResult DeepCloneWithMessageOp(IReturningOperation <string> messageOp)
        {
            var result = new ValidationResult(
                this.ValidityOp?.DeepClone(),
                messageOp);

            return(result);
        }
コード例 #24
0
        public ValidationChain DeepCloneWithEndMessageOp(IReturningOperation <string> endMessageOp)
        {
            var result = new ValidationChain(
                this.Steps?.DeepClone(),
                endMessageOp,
                this.EndValidity.DeepClone());

            return(result);
        }
コード例 #25
0
        public Validation DeepCloneWithOperation(IReturningOperation <ValidationResult> operation)
        {
            var result = new Validation(
                operation,
                this.MessageFormatKind?.DeepClone(),
                this.Details?.DeepClone());

            return(result);
        }
コード例 #26
0
        public AvailabilityCheckChain DeepCloneWithEndMessageOp(IReturningOperation <string> endMessageOp)
        {
            var result = new AvailabilityCheckChain(
                this.Steps?.DeepClone(),
                endMessageOp,
                this.EndAvailability.DeepClone());

            return(result);
        }
コード例 #27
0
        public AvailabilityCheck DeepCloneWithOperation(IReturningOperation <AvailabilityCheckResult> operation)
        {
            var result = new AvailabilityCheck(
                operation,
                this.MessageFormatKind?.DeepClone(),
                this.Details?.DeepClone());

            return(result);
        }
コード例 #28
0
        public CompareOp DeepCloneWithLeft(IReturningOperation <decimal> left)
        {
            var result = new CompareOp(
                left,
                this.Operator?.DeepClone(),
                this.Right?.DeepClone());

            return(result);
        }
コード例 #29
0
        public CompareOp DeepCloneWithOperator(IReturningOperation <CompareOperator> @operator)
        {
            var result = new CompareOp(
                this.Left?.DeepClone(),
                @operator,
                this.Right?.DeepClone());

            return(result);
        }
コード例 #30
0
        public CompareOp DeepCloneWithRight(IReturningOperation <decimal> right)
        {
            var result = new CompareOp(
                this.Left?.DeepClone(),
                this.Operator?.DeepClone(),
                right);

            return(result);
        }