GetOrCreateDocument() static private méthode

static private GetOrCreateDocument ( System.Xml.Linq.XName rootName, IFileSystem fileSystem, string path ) : System.Xml.Linq.XDocument
rootName System.Xml.Linq.XName
fileSystem IFileSystem
path string
Résultat System.Xml.Linq.XDocument
Exemple #1
0
        public virtual void TransformFile(IPackageFile file, string targetPath, IProjectSystem projectSystem)
        {
            XElement  xml      = GetXml(file, projectSystem);
            XDocument document = XmlUtility.GetOrCreateDocument(xml.Name, projectSystem, targetPath);

            document.Root.MergeWith(xml, this._nodeActions);
            projectSystem.AddFile(targetPath, new Action <Stream>(document.Save));
        }
Exemple #2
0
 public UserSettings(IFileSystem fileSystem)
 {
     if (fileSystem == null)
     {
         throw new ArgumentNullException("fileSystem");
     }
     _fileSystem = fileSystem;
     _config     = XmlUtility.GetOrCreateDocument("configuration", _fileSystem, ConfigFileName);
 }
Exemple #3
0
 public UserSettings(IFileSystem fileSystem)
 {
     if (fileSystem == null)
     {
         throw new ArgumentNullException("fileSystem");
     }
     _fileSystem     = fileSystem;
     _configLocation = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "NuGet", "NuGet.Config");
     _config         = XmlUtility.GetOrCreateDocument("configuration", _fileSystem, _configLocation);
 }
Exemple #4
0
        public virtual void RevertFile(IPackageFile file, string targetPath, IEnumerable <IPackageFile> matchingFiles, IProjectSystem projectSystem)
        {
            XElement  xml      = GetXml(file, projectSystem);
            XDocument document = XmlUtility.GetOrCreateDocument(xml.Name, projectSystem, targetPath);

            document.Root.Except(xml.Except(Enumerable.Aggregate <XElement, XElement>(from f in matchingFiles select GetXml(f, projectSystem), new XElement(xml.Name), (left, right) => left.MergeWith(right, this._nodeActions))));
            using (Stream stream = projectSystem.CreateFile(targetPath))
            {
                document.Save(stream);
            }
        }
Exemple #5
0
        public void TransformFile(IPackageFile file, string targetPath, IProjectSystem projectSystem)
        {
            // Get the xml fragment
            XElement xmlFragment = GetXml(file, projectSystem);

            XDocument transformDocument = XmlUtility.GetOrCreateDocument(xmlFragment.Name, projectSystem, targetPath);

            // Do a merge
            transformDocument.Root.MergeWith(xmlFragment, _nodeActions);

            projectSystem.AddFile(targetPath, transformDocument.Save);
        }
Exemple #6
0
 public Settings(IFileSystem fileSystem, string fileName)
 {
     if (fileSystem == null)
     {
         throw new ArgumentNullException("fileSystem");
     }
     if (String.IsNullOrEmpty(fileName))
     {
         throw new ArgumentException(CommonResources.Argument_Cannot_Be_Null_Or_Empty, "fileName");
     }
     _fileSystem = fileSystem;
     _fileName   = fileName;
     _config     = XmlUtility.GetOrCreateDocument("configuration", _fileSystem, _fileName);
 }
Exemple #7
0
        public void RevertFile(IPackageFile file, string targetPath, IEnumerable <IPackageFile> matchingFiles, IProjectSystem projectSystem)
        {
            // Get the xml snippet
            XElement xmlFragment = GetXml(file, projectSystem);

            XDocument document = XmlUtility.GetOrCreateDocument(xmlFragment.Name, projectSystem, targetPath);

            // Merge the other xml elements into one element within this xml hierarchy (matching the config file path)
            var mergedFragments = matchingFiles.Select(f => GetXml(f, projectSystem))
                                  .Aggregate(new XElement(xmlFragment.Name), (left, right) => left.MergeWith(right, _nodeActions));

            // Take the difference of the xml and remove it from the main xml file
            document.Root.Except(xmlFragment.Except(mergedFragments));

            // Save the new content to the file system
            projectSystem.AddFile(targetPath, document.Save);
        }
 public Settings(IFileSystem fileSystem, string fileName, bool isMachineWideSettings)
 {
     if (fileSystem == null)
     {
         throw new ArgumentNullException("fileSystem");
     }
     if (String.IsNullOrEmpty(fileName))
     {
         throw new ArgumentException(CommonResources.Argument_Cannot_Be_Null_Or_Empty, "fileName");
     }
     _fileSystem = fileSystem;
     _fileName = fileName;
     XDocument conf = null;
     ExecuteSynchronized(() => conf = XmlUtility.GetOrCreateDocument("configuration", _fileSystem, _fileName));
     _config = conf;
     _isMachineWideSettings = isMachineWideSettings;
 }