Beispiel #1
0
        /// <returns>An <see cref="ObjectElement"/> of type 'Root'</returns>
        internal ObjectElement ExploreException(Exception exception)
        {
            System.Diagnostics.Debug.Assert(VisitedObjects == null, "VisitedObjects should be reset at the exit of this method");
            try
            {
                // Create root
                VisitedObjects = new Dictionary <object, ObjectElement>();
                var root = ObjectElement.CreateRoot();

                // Create element for each InnerException
                for (var current = exception; current != null; current = current.InnerException)
                {
                    var element = Explore("", typeof(Exception).ToString(), current, 0);
                    root.Children.Insert(0, element);
                }

                return(root);
            }
            finally
            {
                if (VisitedObjects != null)
                {
                    VisitedObjects = null;
                }
            }
        }
Beispiel #2
0
        /// <returns>The root element of the tree</returns>
        public static ObjectElement RecreateObjectTree(SerializableNode[] nodes)
        {
            // Recreate all objects
            ObjectElement root     = null;
            var           elements = new Dictionary <int, ObjectElement>();

            foreach (var obj in nodes)
            {
                ObjectElement element;
                switch (obj.Type)
                {
                case ObjectElement.Types.Root:
                    element = ObjectElement.CreateRoot();
                    if (root != null)
                    {
                        throw new ApplicationException("There is more than 1 root element in the XML document.");
                    }
                    root = element;
                    break;

                case ObjectElement.Types.Exception: {
                    string str;
                    if (obj.ValueTranslatable != null)
                    {
                        element = ObjectElement.CreateException(obj.ValueTranslatable.CreateTranslatableElement(), obj.Class, obj.StackTrace);
                    }
                    else if ((str = obj.ValuePrimitive.Value as string) != null)
                    {
                        element = ObjectElement.CreateException(str, obj.Class, obj.StackTrace);
                    }
                    else
                    {
                        System.Diagnostics.Debug.Fail("Unsupported element type '" + obj.ValuePrimitive.Value.GetType().FullName + "'");
                        continue;
                    }
                    break;
                }

                case ObjectElement.Types.Object:
                    if (obj.NameTranslatable != null)
                    {
                        element = ObjectElement.CreateObject(obj.NameTranslatable.CreateTranslatableElement(), obj.Class);
                    }
                    else
                    {
                        element = ObjectElement.CreateObject(obj.NameString, obj.Class);
                    }
                    break;

                case ObjectElement.Types.Field:
                    if (obj.NameTranslatable != null)
                    {
                        element = ObjectElement.CreateField(obj.NameTranslatable.CreateTranslatableElement(), obj.Class, obj.ValuePrimitive != null ? obj.ValuePrimitive.Value : obj.ValueTranslatable);
                    }
                    else
                    {
                        element = ObjectElement.CreateField(obj.NameString, obj.Class, obj.ValuePrimitive != null ? obj.ValuePrimitive.Value : obj.ValueTranslatable);
                    }
                    break;

                default:
                    throw new NotImplementedException("The object type '" + obj.Type.ToString() + "' is not supported");
                }
                elements.Add(obj.ID, element);
            }
            if (root == null)
            {
                throw new ApplicationException("There is no root element in the XML document.");
            }

            // Recreate parent/child links between objects
            foreach (var obj in nodes)
            {
                var parentElement = elements[obj.ID];
                if (obj.Children != null)
                {
                    foreach (var childObj in obj.Children)
                    {
                        parentElement.Children.Add(elements[childObj]);
                    }
                }
            }

            return(root);
        }