/// <summary> /// Writes out the project file to a given directory. /// </summary> /// <param name="directory">The directory to save the file.</param> public void Save(DirectoryInfo directory) { // Set up the project macros we'll be expanding. ProjectMacros macros = SetupMacros(directory); // Validate the state. string projectFilename = macros.ExpandMacros("{ProjectFilename}"); if (string.IsNullOrWhiteSpace(projectFilename)) { throw new InvalidOperationException( "Project filename is not defined in Settings property."); } // We need a write lock on the blocks to avoid changes. This also prevents // any background tasks from modifying the blocks during the save process. ProjectBlockCollection blocks = Project.Blocks; using (blocks.AcquireLock(RequestLock.Write)) { // Create a new project writer and write out the results. var projectWriter = new FilesystemPersistenceProjectWriter( Project, Settings, macros); var projectFile = new FileInfo(projectFilename); projectWriter.Write(projectFile); } }