public void ExpandValue()
        {
            // Arrange
            var macros = new ProjectMacros();

            macros.Substitutions["ProjectDir"] = "pd";

            // Act
            string results = macros.ExpandMacros("{ProjectDir}");

            // Assert
            Assert.AreEqual("pd", results);
        }
示例#2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Project"/> class.
        /// </summary>
        public Project(
			ProjectProcessingState initialProcessingState =
				ProjectProcessingState.Interactive)
        {
            // Set up the initial states.
            ProcessingState = initialProcessingState;

            // We need the settings set up first since it may contribute
            // to the loading of other components of the project.
            Settings = new ProjectSettings();
            Properties = new PropertiesDictionary();
            BlockTypes = new BlockTypeSupervisor(this);
            Blocks = new ProjectBlockCollection(this);
            Commands = new BlockCommandSupervisor(this);
            Plugins = new PluginSupervisor(this);
            Macros = new ProjectMacros();
        }
        /// <summary>
        /// Setups the macros.
        /// </summary>
        /// <param name="directory">The directory.</param>
        /// <returns>The populated macros object.</returns>
        private ProjectMacros SetupMacros(DirectoryInfo directory)
        {
            // Create the macros and substitute the values.
            var macros = new ProjectMacros();

            macros.Substitutions["ProjectDirectory"] = directory.FullName;
            macros.Substitutions["ProjectFilename"] = Settings.ProjectFilename;
            macros.Substitutions["DataDirectory"] = Settings.DataDirectory;
            macros.Substitutions["InternalContentDirectory"] =
                Settings.InternalContentDirectory;
            macros.Substitutions["ExternalSettingsDirectory"] =
                Settings.ExternalSettingsDirectory;

            // Return the resulting macros.
            return macros;
        }
        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;
        }