protected virtual void PerformAtomicOperation(IAtomicOperation operation, CancellationToken cancellationToken)
 {
     if (operation != null)
     {
         try {
             IOperation successor = operation.Operator.Execute((IExecutionContext)operation, cancellationToken);
             if (successor != null)
             {
                 OperatorTrace.RegisterParenthood(operation, successor);
                 ExecutionStack.Add(successor);
             }
             CurrentOperation = null;
         }
         catch (Exception ex) {
             if (ex is OperationCanceledException)
             {
                 throw ex;
             }
             else
             {
                 throw new OperatorExecutionException(operation.Operator, ex);
             }
         }
     }
 }
Beispiel #2
0
 public DebugEngine()
     : base()
 {
     Log            = new Log();
     ExecutionStack = new ExecutionStack();
     OperatorTrace  = new OperatorTrace();
     InitializeTimer();
 }
Beispiel #3
0
 public sealed override void Prepare()
 {
     base.Prepare();
     ExecutionStack.Clear();
     CurrentOperation = null;
     OperatorTrace.Reset();
     OnPrepared();
 }
Beispiel #4
0
 public void Prepare(IOperation initialOperation)
 {
     base.Prepare();
     ExecutionStack.Clear();
     if (initialOperation != null)
     {
         ExecutionStack.Add(initialOperation);
     }
     CurrentOperation = null;
     OperatorTrace.Reset();
     OnPrepared();
 }
Beispiel #5
0
        /// <summary>
        /// Deals with the next operation, if it is an <see cref="AtomicOperation"/> it is executed,
        /// if it is a <see cref="CompositeOperation"/> its single operations are pushed on the execution stack.
        /// </summary>
        /// <remarks>If an error occurs during the execution the operation is aborted and the operation
        /// is pushed on the stack again.<br/>
        /// If the execution was successful <see cref="EngineBase.OnOperationExecuted"/> is called.</remarks>
        protected virtual void ProcessNextOperation(bool logOperations, CancellationToken cancellationToken)
        {
            IAtomicOperation    atomicOperation = CurrentOperation as IAtomicOperation;
            OperationCollection operations      = CurrentOperation as OperationCollection;

            if (atomicOperation != null && operations != null)
            {
                throw new InvalidOperationException("Current operation is both atomic and an operation collection");
            }

            if (atomicOperation != null)
            {
                if (logOperations)
                {
                    Log.LogMessage(string.Format("Performing atomic operation {0}", Utils.Name(atomicOperation)));
                }
                PerformAtomicOperation(atomicOperation, cancellationToken);
            }
            else if (operations != null)
            {
                if (logOperations)
                {
                    Log.LogMessage("Expanding operation collection");
                }
                ExecutionStack.AddRange(operations.Reverse());
                CurrentOperation = null;
            }
            else if (ExecutionStack.Count > 0)
            {
                if (logOperations)
                {
                    Log.LogMessage("Popping execution stack");
                }
                CurrentOperation = ExecutionStack.Last();
                ExecutionStack.RemoveAt(ExecutionStack.Count - 1);
            }
            else
            {
                if (logOperations)
                {
                    Log.LogMessage("Nothing to do");
                }
            }
            OperatorTrace.Regenerate(CurrentAtomicOperation);
        }
Beispiel #6
0
 protected OperatorTrace(OperatorTrace original, Cloner cloner)
 {
     cloner.RegisterClonedObject(original, this);
     AddRange(original.Select(op => cloner.Clone(op)));
     parents = original.parents.ToDictionary(kvp => cloner.Clone(kvp.Key), kvp => cloner.Clone(kvp.Value));
 }