示例#1
0
        /// <summary>
        /// Gets the outcome of executing an <see cref="IOperationOutputCell{TValue}"/>'s <see cref="IOperationOutputCell{TValue}.Operation"/>.
        /// </summary>
        /// <param name="cell">The cell.</param>
        /// <returns>
        /// The outcome of executing an <see cref="IOperationOutputCell{TValue}"/>'s <see cref="IOperationOutputCell{TValue}.Operation"/>.
        /// </returns>
        public static CellOpExecutionOutcome GetCellOpExecutionOutcome(
            this IOperationOutputCell cell)
        {
            if (cell == null)
            {
                throw new ArgumentNullException(nameof(cell));
            }

            var executionStatus = cell.GetCellOpExecutionStatus();

            switch (executionStatus)
            {
            case CellOpExecutionStatus.DeemedNotApplicable:
                return(CellOpExecutionOutcome.NotApplicable);

            case CellOpExecutionStatus.Aborted:
                return(CellOpExecutionOutcome.Aborted);

            case CellOpExecutionStatus.Failed:
                return(CellOpExecutionOutcome.Failed);

            case CellOpExecutionStatus.Completed:
                return(CellOpExecutionOutcome.Completed);

            default:
                return(CellOpExecutionOutcome.Unknown);
            }
        }
示例#2
0
        private async Task ExecuteOperationCellIfNecessaryAsync(
            IOperationOutputCell <TValue> cell)
        {
            // NOTE: THIS CODE IS A NEAR DUPLICATE OF THE SYNC METHOD ABOVE; NO GOOD WAY TO D.R.Y. IT OUT
            if (cell.GetCellOpExecutionStatus() == CellOpExecutionStatus.NotExecuted)
            {
                CellOpExecutionEventBase operationExecutionEvent;

                try
                {
                    var operationResult = await this.protocolFactory.GetProtocolAndExecuteViaReflectionAsync <TValue>(cell.Operation);

                    operationExecutionEvent = new CellOpExecutionCompletedEvent <TValue>(this.timestampUtc, null, operationResult);
                }
                catch (OpExecutionAbortedExceptionBase ex)
                {
                    operationExecutionEvent = new CellOpExecutionAbortedEvent(this.timestampUtc, ex.ToString());
                }
                catch (OpExecutionDeemedNotApplicableExceptionBase ex)
                {
                    operationExecutionEvent = new CellOpExecutionDeemedNotApplicableEvent(this.timestampUtc, ex.ToString());
                }
                catch (Exception ex)
                {
                    // The "proper" exception for a protocol to throw is an OpExecutionFailedExceptionBase.
                    // Protocol authors might not comply.
                    operationExecutionEvent = new CellOpExecutionFailedEvent(this.timestampUtc, ex.ToString());
                }

                cell.Record(operationExecutionEvent);
            }
            else if (cell.OperationExecutionEvents.Last().TimestampUtc != this.timestampUtc)
            {
                throw new InvalidOperationException("Something went wrong.  The operation was executed, but the recorded timestamp doesn't match this timestamp.");
            }
        }