/// <inheritdoc />
        public T Walk <T>(Model model)
        {
            if (_compiledLambda != null)
            {
                return((_compiledLambda as Func <Model, T>).Invoke(model));
            }

            lock (_lockObj)
            {
                if (_compiledLambda != null)
                {
                    return((_compiledLambda as Func <Model, T>).Invoke(model));
                }

                var operation = _tree.Children[0] as CommonTree;

                VisitOperation(operation);

                var expression = _opStack.Pop();

                Expression <Func <Model, T> > lambda = Expression.Lambda <Func <Model, T> >(
                    expression, new[] { _param });

                var compiledLambda = lambda.Compile();

                // cache compiled lambda expression
                _compiledLambda = compiledLambda;
                // clear state
                _tree    = null;
                _param   = null;
                _opStack = null;
                return(compiledLambda.Invoke(model));
            }
        }
 public void Intercept(IInvocation invocation)
 {
     using (OperationStack.Push(GetMethodInformation(invocation)))
     {
         invocation.Proceed();
     }
 }
 /// <summary> Creates ExpressionEvalTreeWalker. </summary>
 /// <param name="tree">Parse tree.</param>
 public ExpressionEvalTreeWalker(CommonTree tree)
 {
     _tree = tree;
     // NOTE we're not interesting in parent node. However, tree walk is lazy and
     // holding reference will prevent GC to collect whole tree and its references.
     _tree.Parent = null;
     _opStack     = new OperationStack(_param);
 }
Exemple #4
0
        /// <summary>
        /// 定义撤销操作。
        /// </summary>
        /// <param name="operations"></param>
        /// <param name="recordTime"></param>
        private static void Recorder_Redoing(OperationStack operations, DateTime recordTime)
        {
            if (operations != null)
            {
                var clonedOps = new Stack <Operation>(operations);

                while (clonedOps.Count != 0)
                {
                    var operation = clonedOps.Pop();

                    if (operation.ChangeeObject is DialogueViewModel)
                    {
                        var dialogueViewModel = operation.ChangeeObject as DialogueViewModel;
                        switch (operation.Type)
                        {
                        case OperationType.Modify:
                        {
                            switch (operation.PropertyName)
                            {
                            case "Line":
                                dialogueViewModel.Line = (string)operation.NewValue;
                                break;

                            case "From":
                                dialogueViewModel.From = (TimeSpan)operation.NewValue;
                                break;

                            case "To":
                                dialogueViewModel.To = (TimeSpan)operation.NewValue;
                                break;
                            }
                        }
                        break;
                        }
                    }
                    else if (operation.ChangeeObject is Subtitle)
                    {
                        var subtitleViewModel = operation.ChangeeObject as Subtitle;
                        switch (operation.Type)
                        {
                        case OperationType.Add:
                        {
                            switch (operation.PropertyName)
                            {
                            case "Items":
                                subtitleViewModel.AddDialogue(operation.NewValue as Dialogue);
                                break;
                            }
                        }
                        break;
                        }
                    }
                }
            }
        }
Exemple #5
0
 /// <inheritdoc />
 public T Walk <T>(Model model)
 {
     // NOTE have to lock as this method is called from different threads
     lock (_lockObj)
     {
         _opStack = new OperationStack(model);
         var operation = _tree.Children[0] as CommonTree;
         VisitOperation(operation);
         return((T)_opStack.Pop());
     }
 }
Exemple #6
0
        private void Eval()
        {
            var op = OperationStack.Pop();

            if (Operations.ContainsKey(op))
            {
                object b = OperandStack.Pop();
                object a = OperandStack.Pop();
                OperandStack.Push(Operations[op](a, b));
            }

            if (FuncsSignatures.ContainsKey(op))
            {
                var list = new List <object>();
                for (int i = 0; i < FuncsSignatures[op]; i++)
                {
                    list.Add(OperandStack.Pop());
                }
                list.Reverse();
                OperandStack.Push(Funcs[op](list));
            }
        }
Exemple #7
0
 private void Work(string token)
 {
     if (FuncsSignatures.ContainsKey(token))
     {
         OperationStack.Push(token);
     }
     else if (token == "(" || token == "[")
     {
         OperationStack.Push(token);
     }
     else if (token == ",")
     {
     }
     else if (token == ")" || token == "]")
     {
         while (OperationStack.Peek() != "[" && OperationStack.Peek() != "(")
         {
             Eval();
         }
         Eval();
     }
     else if (Priorities.ContainsKey(token))
     {
         while (OperationStack.Count > 0 && GetPriority(OperationStack.Peek()) >= GetPriority(token))
         {
             Eval();
         }
         OperationStack.Push(token);
     }
     else if (owner.Variables.ContainsKey(token))
     {
         OperandStack.Push(owner.Variables[token].Value);
     }
     else
     {
         OperandStack.Push(Parser.ParseTypes(token));
     }
 }
 private void Recorder_Recorded(OperationStack operations, DateTime recordTime)
 {
     System.Diagnostics.Debug.WriteLine("Recorder_Recorded");
     UpdateButtonStatus(null, null);
 }
Exemple #9
0
 public static void StartOffsetOperation(this IAgentBroker broker)
 {
     OperationStack.StartOffset();
 }
Exemple #10
0
        public static OperationTiming <T> EndLogicalOperation <T>(this IAgentBroker broker)
        {
            var timing = OperationStack.PopOperation <T>();

            return(timing);
        }
Exemple #11
0
 public static void BeginLogicalOperation(this IAgentBroker broker, object message, DateTime dateTime)
 {
     OperationStack.PushOperation(message, dateTime);
 }
Exemple #12
0
 public static TimeSpan GetOffset(this IAgentBroker broker)
 {
     return(OperationStack.GetOffset());
 }
Exemple #13
0
 public static void StartOffsetOperation(this IAgentBroker broker, DateTime startTime)
 {
     OperationStack.StartOffset(startTime);
 }