Exemplo n.º 1
0
        /// <summary>
        /// Checks if input is compatible and address accordingly (Exception, Empty or Fail)
        /// </summary>
        /// <returns>False if stack in fail state and needs to end, true otherwise</returns>
        public bool AssertCurrentBlockInput()
        {
            if (CurrentBlockSpec.InputType != null)
            {
                try
                {
                    NextInput = NextInput.ConvertTo(CurrentBlockSpec.InputType);
                }
                catch (Exception e)
                {
                    if (options.IncompatibleInputTypeBehaviour == IncompatibleInputTypeBehaviour.Exception)
                    {
                        throw new OperationStackExecutionException("Invalid input coming from " + PreviousBlockSpec?.Tag ?? "unknwon" + " block and going into " + CurrentBlockSpec.Tag + " block. Exception was " + e.Message);
                    }
                    else if (options.IncompatibleInputTypeBehaviour == IncompatibleInputTypeBehaviour.AssumeEmpty)
                    {
                        NextInput = Emptyable.Empty;
                    }
                    else if (options.IncompatibleInputTypeBehaviour == IncompatibleInputTypeBehaviour.Fail)
                    {
                        IsFail = true;
                        var error = ExceptionErrorBuilder <TOperationEvent> .Build(new OperationStackExecutionException("Invalid input coming from " + PreviousBlockSpec?.Tag ?? "unknwon" + " block and going into " + CurrentBlockSpec.Tag + " block. Exception was " + e.Message));

                        StackTrace.Add(new BlockTraceResult <TOperationEvent>(CurrentBlockSpec.Tag, error, NextInput));
                        return(false);
                    }
                }
            }
            return(true);
        }