public ObjectValue Run(string name, ObjectValueFlags flags, ObjectEvaluatorDelegate evaluator)
        {
            string id;
            int    tid;

            lock (asyncCallbacks) {
                tid = asyncCounter++;
                id  = tid.ToString();
            }

            ObjectValue val  = null;
            bool        done = runner.Run(delegate {
                if (tid >= cancelTimestamp)
                {
                    val = evaluator();
                }
            },
                                          delegate {
                if (tid >= cancelTimestamp)
                {
                    OnEvaluationDone(id, val);
                }
            });

            if (done)
            {
                return(val);
            }
            else
            {
                return(ObjectValue.CreateEvaluating(this, new ObjectPath(id, name), flags));
            }
        }
예제 #2
0
        public ObjectValue Run(string name, ObjectValueFlags flags, ObjectEvaluatorDelegate evaluator)
        {
            string id;
            int    tid;

            lock (asyncCallbacks) {
                tid = asyncCounter++;
                id  = tid.ToString();
            }

            ObjectValue val  = null;
            bool        done = runner.Run(delegate {
                if (tid >= cancelTimestamp)
                {
                    val = evaluator();
                }
            },
                                          delegate {
                if (tid >= cancelTimestamp)
                {
                    OnEvaluationDone(id, val);
                }
            });

            if (done)
            {
                // 'val' may be null if the timed evaluator is disposed while evaluating
                return(val ?? ObjectValue.CreateUnknown(name));
            }

            return(ObjectValue.CreateEvaluating(this, new ObjectPath(id, name), flags));
        }
		public ObjectValue Run (string name, ObjectValueFlags flags, ObjectEvaluatorDelegate evaluator)
		{
			string id;
			int tid;
			lock (asyncCallbacks) {
				tid = asyncCounter++;
				id = tid.ToString ();
			}
			
			ObjectValue val = null;
			bool done = runner.Run (delegate {
					if (tid >= cancelTimestamp)
						val = evaluator ();
			},
			delegate {
				if (tid >= cancelTimestamp)
					OnEvaluationDone (id, val);
			});
			
			if (done) {
				// 'val' may be null if the timed evaluator is disposed while evaluating
				return val ?? ObjectValue.CreateUnknown (name);
			}

			return ObjectValue.CreateEvaluating (this, new ObjectPath (id, name), flags);
		}
        public ObjectValue Run(string name, ObjectValueFlags flags, ObjectEvaluatorDelegate evaluator)
        {
            string id;
            int    tid;

            lock (asyncCallbacks) {
                tid = asyncCounter++;
                id  = tid.ToString();
            }

            ObjectValue val  = null;
            bool        done = runner.Run(delegate {
                if (tid >= cancelTimestamp)
                {
                    var session = Session;
                    if (session == null || (flags == ObjectValueFlags.EvaluatingGroup))
                    {
                        // Cannot report timing if session is null. If a group is being
                        // evaluated then individual timings are not possible and must
                        // be done elsewhere.
                        val = evaluator();
                    }
                    else
                    {
                        using (var timer = session.EvaluationStats.StartTimer(name)) {
                            val = evaluator();
                            timer.Stop(val);
                        }
                    }
                }
            },
                                          delegate {
                if (tid >= cancelTimestamp)
                {
                    OnEvaluationDone(id, val);
                }
            });

            if (done)
            {
                // 'val' may be null if the timed evaluator is disposed while evaluating
                return(val ?? ObjectValue.CreateUnknown(name));
            }

            return(ObjectValue.CreateEvaluating(this, new ObjectPath(id, name), flags));
        }
		public ObjectValue Run (string name, ObjectValueFlags flags, ObjectEvaluatorDelegate evaluator)
		{
			string id;
			int tid;
			lock (asyncCallbacks) {
				tid = asyncCounter++;
				id = tid.ToString ();
			}
			
			ObjectValue val = null;
			bool done = runner.Run (delegate {
					if (tid >= cancelTimestamp)
						val = evaluator ();
			},
			delegate {
				if (tid >= cancelTimestamp)
					OnEvaluationDone (id, val);
			});
			
			if (done)
				return val;
			else
				return ObjectValue.CreateEvaluating (this, new ObjectPath (id, name), flags);
		}
예제 #6
0
		public ObjectValue CreateObjectValueAsync (string name, ObjectValueFlags flags, ObjectEvaluatorDelegate evaluator)
		{
			return asyncEvaluationTracker.Run (name, flags, evaluator);
		}
예제 #7
0
 public ObjectValue CreateObjectValueAsync(string name, ObjectValueFlags flags, ObjectEvaluatorDelegate evaluator)
 {
     return(asyncEvaluationTracker.Run(name, flags, evaluator));
 }
        public ObjectValue CreateObjectValue(bool withTimeout, EvaluationOptions options)
        {
            options = options.Clone();
            options.EllipsizeStrings  = false;
            options.AllowTargetInvoke = true;
            ctx = ctx.WithOptions(options);
            string type = ctx.Adapter.GetValueTypeName(ctx, Exception.ObjectValue);

            var excInstance = Exception.CreateObjectValue(withTimeout, options);

            excInstance.Name = "Instance";

            ObjectValue messageValue  = null;
            ObjectValue helpLinkValue = null;
            var         exceptionType = ctx.Adapter.GetValueType(ctx, Exception.Value);

            // Get the message

            if (withTimeout)
            {
                messageValue = ctx.Adapter.CreateObjectValueAsync("Message", ObjectValueFlags.None, delegate {
                    var mref = ctx.Adapter.GetMember(ctx, Exception, exceptionType, Exception.Value, "Message");
                    if (mref != null)
                    {
                        string val = (string)mref.ObjectValue;
                        return(ObjectValue.CreatePrimitive(null, new ObjectPath("Message"), "string", new EvaluationResult(val), ObjectValueFlags.Literal));
                    }

                    return(ObjectValue.CreateUnknown("Message"));
                });
            }
            else
            {
                var mref = ctx.Adapter.GetMember(ctx, Exception, exceptionType, Exception.Value, "Message");
                if (mref != null)
                {
                    string val = (string)mref.ObjectValue;
                    messageValue = ObjectValue.CreatePrimitive(null, new ObjectPath("Message"), "string", new EvaluationResult(val), ObjectValueFlags.Literal);
                }
            }

            if (messageValue == null)
            {
                messageValue = ObjectValue.CreateUnknown("Message");
            }

            messageValue.Name = "Message";

            // Get the help link

            if (withTimeout)
            {
                helpLinkValue = ctx.Adapter.CreateObjectValueAsync("HelpLink", ObjectValueFlags.None, delegate {
                    var mref = ctx.Adapter.GetMember(ctx, Exception, exceptionType, Exception.Value, "HelpLink");
                    if (mref != null)
                    {
                        string val = (string)mref.ObjectValue;
                        return(ObjectValue.CreatePrimitive(null, new ObjectPath("HelpLink"), "string", new EvaluationResult(val), ObjectValueFlags.Literal));
                    }

                    return(ObjectValue.CreateUnknown("HelpLink"));
                });
            }
            else
            {
                var mref = ctx.Adapter.GetMember(ctx, Exception, exceptionType, Exception.Value, "HelpLink");
                if (mref != null)
                {
                    string val = (string)mref.ObjectValue;
                    helpLinkValue = ObjectValue.CreatePrimitive(null, new ObjectPath("HelpLink"), "string", new EvaluationResult(val), ObjectValueFlags.Literal);
                }
            }

            if (helpLinkValue == null)
            {
                helpLinkValue = ObjectValue.CreateUnknown("HelpLink");
            }

            helpLinkValue.Name = "HelpLink";

            // Inner exception

            ObjectValue childExceptionValue = null;

            if (withTimeout)
            {
                childExceptionValue = ctx.Adapter.CreateObjectValueAsync("InnerException", ObjectValueFlags.None, delegate {
                    var inner = ctx.Adapter.GetMember(ctx, Exception, exceptionType, Exception.Value, "InnerException");
                    if (inner != null && !ctx.Adapter.IsNull(ctx, inner.Value))
                    {
                        //Console.WriteLine ("pp got child:" + type);
                        var innerSource = new ExceptionInfoSource(ctx, inner);
                        var res         = innerSource.CreateObjectValue(false, options);
                        return(res);
                    }

                    return(ObjectValue.CreateUnknown("InnerException"));
                });
            }
            else
            {
                var inner = ctx.Adapter.GetMember(ctx, Exception, exceptionType, Exception.Value, "InnerException");
                if (inner != null && !ctx.Adapter.IsNull(ctx, inner.Value))
                {
                    //Console.WriteLine ("pp got child:" + type);
                    var innerSource = new ExceptionInfoSource(ctx, inner);
                    childExceptionValue      = innerSource.CreateObjectValue(false, options);
                    childExceptionValue.Name = "InnerException";
                }
            }

            if (childExceptionValue == null)
            {
                childExceptionValue = ObjectValue.CreateUnknown("InnerException");
            }

            // Inner exceptions in case of AgregatedException

            ObjectValue             childExceptionsValue       = null;
            ObjectEvaluatorDelegate getInnerExceptionsDelegate = delegate {
                var inner = ctx.Adapter.GetMember(ctx, Exception, exceptionType, Exception.Value, "InnerExceptions");
                if (inner != null && !ctx.Adapter.IsNull(ctx, inner.Value))
                {
                    var obj          = inner.GetValue(ctx);
                    var objType      = ctx.Adapter.GetValueType(ctx, obj);
                    var count        = (int)ctx.Adapter.GetMember(ctx, null, obj, "Count").ObjectValue;
                    var childrenList = new List <ObjectValue>();
                    for (int i = 0; i < count; i++)
                    {
                        childrenList.Add(new ExceptionInfoSource(ctx, ctx.Adapter.GetIndexerReference(ctx, obj, objType, new object[] { ctx.Adapter.CreateValue(ctx, i) })).CreateObjectValue(withTimeout, ctx.Options));
                    }
                    return(ObjectValue.CreateObject(null, new ObjectPath("InnerExceptions"), "", "", ObjectValueFlags.None, childrenList.ToArray()));
                }

                return(ObjectValue.CreateUnknown("InnerExceptions"));
            };

            if (withTimeout)
            {
                childExceptionsValue = ctx.Adapter.CreateObjectValueAsync("InnerExceptions", ObjectValueFlags.None, getInnerExceptionsDelegate);
            }
            else
            {
                childExceptionsValue = getInnerExceptionsDelegate();
            }

            if (childExceptionsValue == null)
            {
                childExceptionsValue = ObjectValue.CreateUnknown("InnerExceptions");
            }

            // Stack trace

            ObjectValue stackTraceValue;

            if (withTimeout)
            {
                stackTraceValue = ctx.Adapter.CreateObjectValueAsync("StackTrace", ObjectValueFlags.None, delegate {
                    var stackTrace = ctx.Adapter.GetMember(ctx, Exception, exceptionType, Exception.Value, "StackTrace");
                    if (stackTrace == null)
                    {
                        return(ObjectValue.CreateUnknown("StackTrace"));
                    }
                    return(GetStackTrace(stackTrace.ObjectValue as string));
                });
            }
            else
            {
                var stackTrace = ctx.Adapter.GetMember(ctx, Exception, exceptionType, Exception.Value, "StackTrace");
                if (stackTrace == null)
                {
                    return(ObjectValue.CreateUnknown("StackTrace"));
                }
                stackTraceValue = GetStackTrace(stackTrace.ObjectValue as string);
            }

            var children = new ObjectValue [] { excInstance, messageValue, helpLinkValue, stackTraceValue, childExceptionValue, childExceptionsValue };

            return(ObjectValue.CreateObject(null, new ObjectPath("InnerException"), type, "", ObjectValueFlags.None, children));
        }
        public ObjectValue CreateObjectValue(bool withTimeout, EvaluationOptions options)
        {
            options = options.Clone();
            options.EllipsizeStrings = false;
            string type = ctx.Adapter.GetValueTypeName(ctx, Exception.ObjectValue);

            var excInstance = Exception.CreateObjectValue(withTimeout, options);

            excInstance.Name = "Instance";

            ObjectValue messageValue = null;

            // Get the message

            if (withTimeout)
            {
                messageValue = ctx.Adapter.CreateObjectValueAsync("Message", ObjectValueFlags.None, delegate {
                    var mref = Exception.GetChild("Message", options);
                    if (mref != null)
                    {
                        string val = (string)mref.ObjectValue;
                        return(ObjectValue.CreatePrimitive(null, new ObjectPath("Message"), "string", new EvaluationResult(val), ObjectValueFlags.Literal));
                    }

                    return(ObjectValue.CreateUnknown("Message"));
                });
            }
            else
            {
                var mref = Exception.GetChild("Message", options);
                if (mref != null)
                {
                    string val = (string)mref.ObjectValue;
                    messageValue = ObjectValue.CreatePrimitive(null, new ObjectPath("Message"), "string", new EvaluationResult(val), ObjectValueFlags.Literal);
                }
            }

            if (messageValue == null)
            {
                messageValue = ObjectValue.CreateUnknown("Message");
            }

            messageValue.Name = "Message";

            // Inner exception

            ObjectValue childExceptionValue = null;

            if (withTimeout)
            {
                childExceptionValue = ctx.Adapter.CreateObjectValueAsync("InnerException", ObjectValueFlags.None, delegate {
                    var inner = Exception.GetChild("InnerException", options);
                    if (inner != null && !ctx.Adapter.IsNull(ctx, inner.Value))
                    {
                        //Console.WriteLine ("pp got child:" + type);
                        var innerSource = new ExceptionInfoSource(ctx, inner);
                        var res         = innerSource.CreateObjectValue(false, options);
                        return(res);
                    }

                    return(ObjectValue.CreateUnknown("InnerException"));
                });
            }
            else
            {
                var inner = Exception.GetChild("InnerException", options);
                if (inner != null && !ctx.Adapter.IsNull(ctx, inner.Value))
                {
                    //Console.WriteLine ("pp got child:" + type);
                    var innerSource = new ExceptionInfoSource(ctx, inner);
                    childExceptionValue      = innerSource.CreateObjectValue(false, options);
                    childExceptionValue.Name = "InnerException";
                }
            }

            if (childExceptionValue == null)
            {
                childExceptionValue = ObjectValue.CreateUnknown("InnerException");
            }

            // Inner exceptions in case of AgregatedException

            ObjectValue             childExceptionsValue       = null;
            ObjectEvaluatorDelegate getInnerExceptionsDelegate = delegate {
                var inner = Exception.GetChild("InnerExceptions", options);
                if (inner != null && !ctx.Adapter.IsNull(ctx, inner.Value))
                {
                    var obj            = inner.GetValue(ctx);
                    var objType        = ctx.Adapter.GetValueType(ctx, obj);
                    var enumerator     = ctx.Adapter.RuntimeInvoke(ctx, objType, obj, "GetEnumerator", new object[0], new object[0]);
                    var enumeratorType = ctx.Adapter.GetImplementedInterfaces(ctx, ctx.Adapter.GetValueType(ctx, enumerator)).First(f => ctx.Adapter.GetTypeName(ctx, f) == "System.Collections.IEnumerator");
                    var childrenList   = new List <ObjectValue> ();
                    while ((bool)ctx.Adapter.TargetObjectToObject(ctx, ctx.Adapter.RuntimeInvoke(ctx, enumeratorType, enumerator, "MoveNext", new object[0], new object[0])))
                    {
                        var valCurrent = ctx.Adapter.GetMember(ctx, null, enumeratorType, enumerator, "Current");
                        childrenList.Add(new ExceptionInfoSource(ctx, valCurrent).CreateObjectValue(withTimeout, ctx.Options));
                    }
                    return(ObjectValue.CreateObject(null, new ObjectPath("InnerExceptions"), "", "", ObjectValueFlags.None, childrenList.ToArray()));
                }

                return(ObjectValue.CreateUnknown("InnerExceptions"));
            };

            if (withTimeout)
            {
                childExceptionsValue = ctx.Adapter.CreateObjectValueAsync("InnerExceptions", ObjectValueFlags.None, getInnerExceptionsDelegate);
            }
            else
            {
                childExceptionsValue = getInnerExceptionsDelegate();
            }

            if (childExceptionsValue == null)
            {
                childExceptionsValue = ObjectValue.CreateUnknown("InnerExceptions");
            }

            // Stack trace

            ObjectValue stackTraceValue;

            if (withTimeout)
            {
                stackTraceValue = ctx.Adapter.CreateObjectValueAsync("StackTrace", ObjectValueFlags.None, delegate {
                    return(GetStackTrace(options));
                });
            }
            else
            {
                stackTraceValue = GetStackTrace(options);
            }

            var children = new ObjectValue [] { excInstance, messageValue, stackTraceValue, childExceptionValue, childExceptionsValue };

            return(ObjectValue.CreateObject(null, new ObjectPath("InnerException"), type, "", ObjectValueFlags.None, children));
        }