Пример #1
0
        /// <summary>
        /// Save the project to the provided TextWriter, whether or not it is dirty.
        /// Uses the encoding of the TextWriter.
        /// Clears the Dirty flag.
        /// </summary>
        public void Save(TextWriter writer)
        {
            using (ProjectWriter projectWriter = new ProjectWriter(writer))
            {
                projectWriter.Initialize(XmlDocument);
                XmlDocument.Save(projectWriter);
            }

            _versionOnDisk = Version;
        }
Пример #2
0
        /// <summary>
        /// Save the project to the file system, if dirty.
        /// Creates any necessary directories.
        /// May throw IO-related exceptions.
        /// Clears the dirty flag.
        /// </summary>
        public void Save(Encoding saveEncoding)
        {
            ErrorUtilities.VerifyThrowInvalidOperation(_projectFileLocation != null, "OM_MustSetFileNameBeforeSave");

#if MSBUILDENABLEVSPROFILING 
            try
            {
                string beginProjectSave = String.Format(CultureInfo.CurrentCulture, "Save Project {0} To File - Begin", projectFileLocation.File);
                DataCollection.CommentMarkProfile(8810, beginProjectSave);
#endif

            Directory.CreateDirectory(DirectoryPath);
#if (!STANDALONEBUILD)
            using (new CodeMarkerStartEnd(CodeMarkerEvent.perfMSBuildProjectSaveToFileBegin, CodeMarkerEvent.perfMSBuildProjectSaveToFileEnd))
#endif
            {
                if (HasUnsavedChanges || saveEncoding != Encoding)
                {
                    using (ProjectWriter projectWriter = new ProjectWriter(_projectFileLocation.File, saveEncoding))
                    {
                        projectWriter.Initialize(XmlDocument);
                        XmlDocument.Save(projectWriter);
                    }

                    _encoding = saveEncoding;

                    FileInfo fileInfo = FileUtilities.GetFileInfoNoThrow(_projectFileLocation.File);

                    // If the file was deleted by a race with someone else immediately after it was written above
                    // then we obviously can't read the write time. In this obscure case, we'll retain the 
                    // older last write time, which at worst would cause the next load to unnecessarily 
                    // come from disk.
                    if (fileInfo != null)
                    {
                        _lastWriteTimeWhenRead = fileInfo.LastWriteTime;
                    }

                    _versionOnDisk = Version;
                }
            }
#if MSBUILDENABLEVSPROFILING 
            }
            finally
            {
                string endProjectSave = String.Format(CultureInfo.CurrentCulture, "Save Project {0} To File - End", projectFileLocation.File);
                DataCollection.CommentMarkProfile(8811, endProjectSave);
            }
#endif
        }