Exemplo n.º 1
0
        public ObjectValue CreateObjectValue(bool withTimeout, EvaluationOptions options)
        {
            string type = ctx.Adapter.GetTypeName(ctx, exception.Type);

            ObjectValue excInstance = exception.CreateObjectValue(withTimeout, options);

            excInstance.Name = "Instance";

            ObjectValue messageValue = null;

            // Get the message

            if (withTimeout)
            {
                messageValue = ctx.Adapter.CreateObjectValueAsync("Message", ObjectValueFlags.None, delegate {
                    ValueReference mref = exception.GetChild("Message", options);
                    if (mref != null)
                    {
                        string val = (string)mref.ObjectValue;
                        return(ObjectValue.CreatePrimitive(null, new ObjectPath("Message"), "System.String", new EvaluationResult(val), ObjectValueFlags.Literal));
                    }
                    else
                    {
                        return(ObjectValue.CreateUnknown("Message"));
                    }
                });
            }
            else
            {
                ValueReference mref = exception.GetChild("Message", options);
                if (mref != null)
                {
                    string val = (string)mref.ObjectValue;
                    messageValue = ObjectValue.CreatePrimitive(null, new ObjectPath("Message"), "System.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 {
                    ValueReference inner = exception.GetChild("InnerException", options);
                    if (inner != null && !ctx.Adapter.IsNull(ctx, inner.Value))
                    {
                        Console.WriteLine("pp got child:" + type);
                        ExceptionInfoSource innerSource = new ExceptionInfoSource(ctx, inner);
                        ObjectValue res = innerSource.CreateObjectValue(false, options);
                        return(res);
                    }
                    else
                    {
                        return(ObjectValue.CreateUnknown("InnerException"));
                    }
                });
            }
            else
            {
                ValueReference inner = exception.GetChild("InnerException", options);
                if (inner != null && !ctx.Adapter.IsNull(ctx, inner.Value))
                {
                    Console.WriteLine("pp got child:" + type);
                    ExceptionInfoSource innerSource = new ExceptionInfoSource(ctx, inner);
                    childExceptionValue      = innerSource.CreateObjectValue(false, options);
                    childExceptionValue.Name = "InnerException";
                }
            }
            if (childExceptionValue == null)
            {
                childExceptionValue = ObjectValue.CreateUnknown("InnerException");
            }

            // Stack trace

            ObjectValue stackTraceValue;

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

            ObjectValue[] children = new ObjectValue [] { excInstance, messageValue, stackTraceValue, childExceptionValue };
            return(ObjectValue.CreateObject(null, new ObjectPath("InnerException"), type, "", ObjectValueFlags.None, children));
        }
		public ObjectValue CreateObjectValue (bool withTimeout, EvaluationOptions options)
		{
			string type = ctx.Adapter.GetTypeName (ctx, exception.Type);
			
			ObjectValue excInstance = exception.CreateObjectValue (withTimeout, options);
			excInstance.Name = "Instance";
			
			ObjectValue messageValue = null;
			
			// Get the message
			
			if (withTimeout) {
				messageValue = ctx.Adapter.CreateObjectValueAsync ("Message", ObjectValueFlags.None, delegate {
					ValueReference mref = exception.GetChild ("Message", options);
					if (mref != null)
						return mref.CreateObjectValue (false, options);
					else
						return ObjectValue.CreateUnknown ("Message");
				});
			} else {
				ValueReference mref = exception.GetChild ("Message", options);
				if (mref != null)
					messageValue = mref.CreateObjectValue (false, options);
			}
			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 {
					ValueReference inner = exception.GetChild ("InnerException", options);
					if (inner != null && !ctx.Adapter.IsNull (ctx, inner.Value)) {
						Console.WriteLine ("pp got child:" + type);
						ExceptionInfoSource innerSource = new ExceptionInfoSource (ctx, inner);
						ObjectValue res = innerSource.CreateObjectValue (false, options);
						return res;
					}
					else
						return ObjectValue.CreateUnknown ("InnerException");
				});
			} else {
				ValueReference inner = exception.GetChild ("InnerException", options);
				if (inner != null && !ctx.Adapter.IsNull (ctx, inner.Value)) {
					Console.WriteLine ("pp got child:" + type);
					ExceptionInfoSource innerSource = new ExceptionInfoSource (ctx, inner);
					childExceptionValue = innerSource.CreateObjectValue (false, options);
					childExceptionValue.Name = "InnerException";
				}
			}
			if (childExceptionValue == null)
				childExceptionValue = ObjectValue.CreateUnknown ("InnerException");
			
			// Stack trace
			
			ObjectValue stackTraceValue;
			if (withTimeout) {
				stackTraceValue = ctx.Adapter.CreateObjectValueAsync ("StackTrace", ObjectValueFlags.None, delegate {
					return GetStackTrace (options);
				});
			} else
				stackTraceValue = GetStackTrace (options);
			
			ObjectValue[] children = new ObjectValue [] { excInstance, messageValue, stackTraceValue, childExceptionValue };
			return ObjectValue.CreateObject (null, new ObjectPath ("InnerException"), type, "", ObjectValueFlags.None, children);
		}
        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));
        }
Exemplo n.º 4
0
        public ObjectValue CreateObjectValue(bool withTimeout, EvaluationOptions options)
        {
            string type = ctx.Adapter.GetTypeName (ctx, Exception.Type);

            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"), "System.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"), "System.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");

            // 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 };

            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));
        }