コード例 #1
0
        /// <summary>
        /// Builds a <see cref="CheckAvailabilityOp"/>.
        /// </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>
        /// <returns>
        /// The operation.
        /// </returns>
        public static CheckAvailabilityOp CheckAvailability(
            this IReadOnlyList <AvailabilityCheckStep> steps,
            IReturningOperation <string> endMessageOp = null,
            Availability endAvailability = Availability.Enabled)
        {
            var availabilityCheckChain = new AvailabilityCheckChain(steps, endMessageOp, endAvailability);

            var result = new CheckAvailabilityOp(availabilityCheckChain);

            return(result);
        }
コード例 #2
0
        /// <inheritdoc />
        public async Task <AvailabilityCheckResult> ExecuteAsync(
            CheckAvailabilityOp operation)
        {
            // NOTE: THIS CODE IS A NEAR DUPLICATE OF THE SYNC METHOD ABOVE; NO GOOD WAY TO D.R.Y. IT OUT
            if (operation == null)
            {
                throw new ArgumentNullException(nameof(operation));
            }

            AvailabilityCheckResult result = null;

            var availabilityCheckChain = operation.AvailabilityCheckChain;

            foreach (var availabilityCheckStep in availabilityCheckChain.Steps)
            {
                var operationResult = await this.protocolFactory.GetProtocolAndExecuteViaReflectionAsync <bool>(availabilityCheckStep.Operation);

                var availabilityCheckStepAction = operationResult
                    ? availabilityCheckStep.TrueAction
                    : availabilityCheckStep.FalseAction;

                if (availabilityCheckStepAction == AvailabilityCheckStepAction.NextStep)
                {
                    continue;
                }

                var availability = GetAvailability(availabilityCheckStepAction);

                result = new AvailabilityCheckResult(Op.Const(availability), availabilityCheckStep.StopMessageOp);

                break;
            }

            if (result == null)
            {
                result = new AvailabilityCheckResult(Op.Const(availabilityCheckChain.EndAvailability), availabilityCheckChain.EndMessageOp);
            }

            return(result);
        }