public Project ReadProject(FileInfo projectFile)
        {
            // Open up an XML reader to pull out the critical components we
            // need to finish loading the file.
            FilesystemPersistenceSettings settings = null;

            using (FileStream stream = projectFile.Open(FileMode.Open, FileAccess.Read))
            {
                using (XmlReader reader = XmlReader.Create(stream))
                {
                    // Read until we get the file-persistent-settings file.
                    while (reader.Read())
                    {
                        // Ignore everything but the settings object we need to read.
                        if (reader.NamespaceURI != XmlConstants.ProjectNamespace ||
                            reader.NodeType != XmlNodeType.Element ||
                            reader.LocalName != FilesystemPersistenceSettings.XmlElementName)
                        {
                            continue;
                        }

                        // Load the settings object into memory.
                        var serializer = new XmlSerializer(typeof(FilesystemPersistenceSettings));
                        settings = (FilesystemPersistenceSettings)serializer.Deserialize(reader);
                    }
                }
            }

            // If we finish reading the file without getting the settings, blow up.
            if (settings == null)
            {
                throw new FileLoadException("Cannot load project: " + projectFile);
            }

            // Populate the macros we'll be using.
            var macros = new ProjectMacros();

            macros.Substitutions["ProjectDirectory"]         = projectFile.Directory.FullName;
            macros.Substitutions["ProjectFile"]              = projectFile.FullName;
            macros.Substitutions["DataDirectory"]            = settings.DataDirectory;
            macros.Substitutions["InternalContentDirectory"] =
                settings.InternalContentDirectory;
            macros.Substitutions["ExternalSettingsDirectory"] =
                settings.ExternalSettingsDirectory;

            // Load the project starting with the project. We create the project
            // in batch mode to avoid excessive processing.
            var project             = new Project(ProjectProcessingState.Batch);
            var projectReaderWriter = new FilesystemPersistenceProjectReader(
                project, settings, macros);

            projectReaderWriter.Read(projectFile);

            // Since we created the project in batch mode, we need to change it
            // back to interactive mode.
            project.SetProcessingState(ProjectProcessingState.Interactive);

            // Trigger any missing block analysis.
            project.Plugins.ProcessBlockAnalysis();

            // Return the resulting project.
            return(project);
        }
        public Project ReadProject(FileInfo projectFile)
        {
            // Open up an XML reader to pull out the critical components we
            // need to finish loading the file.
            FilesystemPersistenceSettings settings = null;

            using (FileStream stream = projectFile.Open(FileMode.Open, FileAccess.Read))
            {
                using (XmlReader reader = XmlReader.Create(stream))
                {
                    // Read until we get the file-persistent-settings file.
                    while (reader.Read())
                    {
                        // Ignore everything but the settings object we need to read.
                        if (reader.NamespaceURI != XmlConstants.ProjectNamespace
                            || reader.NodeType != XmlNodeType.Element
                            || reader.LocalName != FilesystemPersistenceSettings.XmlElementName)
                        {
                            continue;
                        }

                        // Load the settings object into memory.
                        var serializer = new XmlSerializer(typeof (FilesystemPersistenceSettings));
                        settings = (FilesystemPersistenceSettings) serializer.Deserialize(reader);
                    }
                }
            }

            // If we finish reading the file without getting the settings, blow up.
            if (settings == null)
            {
                throw new FileLoadException("Cannot load project: " + projectFile);
            }

            // Populate the macros we'll be using.
            var macros = new ProjectMacros();

            macros.Substitutions["ProjectDirectory"] = projectFile.Directory.FullName;
            macros.Substitutions["ProjectFile"] = projectFile.FullName;
            macros.Substitutions["DataDirectory"] = settings.DataDirectory;
            macros.Substitutions["InternalContentDirectory"] =
                settings.InternalContentDirectory;
            macros.Substitutions["ExternalSettingsDirectory"] =
                settings.ExternalSettingsDirectory;

            // Load the project starting with the project. We create the project
            // in batch mode to avoid excessive processing.
            var project = new Project(ProjectProcessingState.Batch);
            var projectReaderWriter = new FilesystemPersistenceProjectReader(
                project, settings, macros);
            projectReaderWriter.Read(projectFile);

            // Since we created the project in batch mode, we need to change it
            // back to interactive mode.
            project.SetProcessingState(ProjectProcessingState.Interactive);

            // Trigger any missing block analysis.
            project.Plugins.ProcessBlockAnalysis();

            // Return the resulting project.
            return project;
        }