public static DebuggingStructureList FromXml(XmlTextReader reader)
        {
            DebuggingStructureList list = new DebuggingStructureList();

            if (reader.Name != "DebugStructs")
            {
                return(list);
            }

            if (reader.IsEmptyElement)
            {
                reader.MoveToNextElement();
                return(list);
            }

            reader.MoveToNextElement();
            while (reader.Name == "Enum")
            {
                var name       = reader.GetAttribute("Name");
                var enumValues = new Dictionary <byte, List <string> >();
                if (!reader.MoveToNextElement())
                {
                    break;
                }

                while (reader.Name == "EnumMask")
                {
                    var  maskList = new List <string>();
                    byte maskValue;
                    if (!byte.TryParse(reader.GetAttribute("Mask"), out maskValue))
                    {
                        continue;
                    }

                    while (reader.MoveToNextElement())
                    {
                        if (reader.Name != "EnumValue")
                        {
                            break;
                        }

                        maskList.Add(reader.ReadString());
                    }


                    enumValues.Add(maskValue, maskList);
                }

                var debugEnum = new DebuggingEnum(name, enumValues);
                list.DebugEnums.Add(debugEnum);
            }

            while (reader.Name == "Struct")
            {
                var name      = reader.GetAttribute("Name");
                var structure = new DebuggingStructure {
                    Name = name
                };
                while (reader.MoveToNextElement())
                {
                    if (reader.Name != "Prop")
                    {
                        break;
                    }

                    var model = new TreeStructureModel
                    {
                        Name = reader.GetAttribute("Name"),
                        Size = Convert.ToInt32(reader.GetAttribute("Size")),
                        Type = reader.GetAttribute("Type")
                    };

                    structure.Properties.Add(model);
                }

                list.DebugStructs.Add(structure);
            }

            return(list);
        }
        public void OpenProject(FilePath projectFile)
        {
            FileStream stream = null;

            try
            {
                stream = new FileStream(projectFile, FileMode.Open);
                using (XmlTextReader reader = new XmlTextReader(stream)
                {
                    WhitespaceHandling = WhitespaceHandling.None
                })
                {
                    stream = null;
                    reader.MoveToContent();
                    while (!reader.Name.Equals("WabbitcodeProject"))
                    {
                        if (!reader.MoveToNextElement())
                        {
                            throw new ArgumentException("Invalid XML Format");
                        }
                    }

                    string formatVersion = reader.GetAttribute("Version");
                    if (formatVersion != ProjectFileVersion)
                    {
                        throw new InvalidProjectVersionException();
                    }

                    ProjectName = reader.GetAttribute("Name");
                    reader.MoveToNextElement();
                    if (reader.Name != "Folder")
                    {
                        throw new ArgumentException("Invalid XML Format");
                    }
                    _mainFolder = new ProjectFolder(null, reader.GetAttribute("Name"));
                    RecurseReadFolders(reader, ref _mainFolder);
                    reader.MoveToNextElement();

                    _debuggingStructure = DebuggingStructureList.FromXml(reader);
                    var displayManager = VariableDisplayManager.Instance;
                    foreach (var debugEnum in _debuggingStructure.DebugEnums)
                    {
                        var enumController = new EnumVariableDisplayController(new ExpressionEvaluator(), debugEnum);
                        displayManager.RegisterVariableDisplayController(enumController);
                    }
                    foreach (var structure in _debuggingStructure.DebugStructs)
                    {
                        displayManager.RegisterVariableDisplayController(new CompositeVariableDisplayController(structure));
                    }

                    BuildSystem.ReadXML(reader);
                }
            }
            finally
            {
                if (stream != null)
                {
                    stream.Dispose();
                }
            }

            SetupWatcher();
        }