public static Manifest ReadFrom(Stream stream, IPropertyProvider propertyProvider, bool validateSchema) { XDocument document = XmlUtility.LoadSafe(stream, ignoreWhiteSpace: true); string schemaNamespace = GetSchemaNamespace(document); foreach (var e in document.Descendants()) { // Assign the schema namespace derived to all nodes in the document. e.Name = XName.Get(e.Name.LocalName, schemaNamespace); } // Validate if the schema is a known one CheckSchemaVersion(document); if (validateSchema) { // Validate the schema ValidateManifestSchema(document, schemaNamespace); } // Deserialize it var manifest = ManifestReader.ReadManifest(document); return(manifest); }
internal static XDocument GetDocument(IFileSystem fileSystem, string path) { using (Stream configStream = fileSystem.OpenFile(path)) { return(XmlUtility.LoadSafe(configStream, LoadOptions.PreserveWhitespace)); } }
private XDocument GetDocument(bool createIfNotExists = false) { try { // If the file exists then open and return it if (_fileSystem.FileExists(_path)) { using (Stream stream = _fileSystem.OpenFile(_path)) { return(XmlUtility.LoadSafe(stream)); } } // If it doesn't exist and we're creating a new file then return a // document with an empty packages node if (createIfNotExists) { return(new XDocument(new XElement("packages"))); } return(null); } catch (XmlException e) { throw new InvalidOperationException( String.Format(CultureInfo.CurrentCulture, NuGetResources.ErrorReadingFile, FullPath), e); } }
private XDocument GetDocument(bool createIfNotExists = false) { XDocument document; try { if (!this._fileSystem.FileExists(this._path)) { if (!createIfNotExists) { document = null; } else { object[] content = new object[] { new XElement("packages") }; document = new XDocument(content); } } else { using (Stream stream = this._fileSystem.OpenFile(this._path)) { document = XmlUtility.LoadSafe(stream); } } } catch (XmlException exception) { object[] args = new object[] { this.FullPath }; throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, NuGetResources.ErrorReadingFile, args), exception); } return(document); }
internal static DataServiceMetadata ExtractMetadataFromSchema(Stream schemaStream) { XDocument document; if (schemaStream == null) { return(null); } try { document = XmlUtility.LoadSafe(schemaStream); } catch { return(null); } return(ExtractMetadataInternal(document)); }
private XDocument GetStoreDocument(bool createIfNotExists = false) { XDocument document; try { if (this._storeFileSystem.FileExists("repositories.config")) { Stream input = this._storeFileSystem.OpenFile("repositories.config"); try { return(XmlUtility.LoadSafe(input)); } catch (XmlException) { } finally { if (input != null) { input.Dispose(); } } } if (!createIfNotExists) { document = null; } else { object[] content = new object[] { new XElement("repositories") }; document = new XDocument(content); } } catch (Exception exception) { object[] args = new object[] { this._storeFileSystem.GetFullPath("repositories.config") }; throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, NuGetResources.ErrorReadingFile, args), exception); } return(document); }
internal static DataServiceMetadata ExtractMetadataFromSchema(Stream schemaStream) { if (schemaStream == null) { return(null); } XDocument schemaDocument; try { schemaDocument = XmlUtility.LoadSafe(schemaStream); } catch { // If the schema is malformed (for some reason) then just return empty list return(null); } return(ExtractMetadataInternal(schemaDocument)); }
public static Manifest ReadFrom(Stream stream, IPropertyProvider propertyProvider, bool validateSchema) { XDocument document; if (propertyProvider == NullPropertyProvider.Instance) { document = XmlUtility.LoadSafe(stream, ignoreWhiteSpace: true); } else { string content = Preprocessor.Process(stream, propertyProvider); document = XDocument.Parse(content); } string schemaNamespace = GetSchemaNamespace(document); foreach (var e in document.Descendants()) { // Assign the schema namespace derived to all nodes in the document. e.Name = XName.Get(e.Name.LocalName, schemaNamespace); } // Validate if the schema is a known one CheckSchemaVersion(document); if (validateSchema) { // Validate the schema ValidateManifestSchema(document, schemaNamespace); } // Deserialize it var manifest = ManifestReader.ReadManifest(document); // Validate before returning Validate(manifest); return(manifest); }
private XDocument GetStoreDocument(bool createIfNotExists = false) { try { // If the file exists then open and return it if (_storeFileSystem.FileExists(StoreFilePath)) { using (Stream stream = _storeFileSystem.OpenFile(StoreFilePath)) { try { return(XmlUtility.LoadSafe(stream)); } catch (XmlException) { // There was an error reading the file, but don't throw as a result } } } // If it doesn't exist and we're creating a new file then return a // document with an empty packages node if (createIfNotExists) { return(new XDocument(new XElement("repositories"))); } return(null); } catch (Exception e) { throw new InvalidOperationException( String.Format(CultureInfo.CurrentCulture, NuGetResources.ErrorReadingFile, _storeFileSystem.GetFullPath(StoreFilePath)), e); } }
internal static FrameworkName LoadSupportedFramework(Stream stream) { try { var document = XmlUtility.LoadSafe(stream); var root = document.Root; if (root.Name.LocalName.Equals("Framework", StringComparison.Ordinal)) { string identifer = root.GetOptionalAttributeValue("Identifier"); if (identifer == null) { return(null); } string versionString = root.GetOptionalAttributeValue("MinimumVersion"); if (versionString == null) { return(null); } Version version; if (!Version.TryParse(versionString, out version)) { return(null); } string profile = root.GetOptionalAttributeValue("Profile"); if (profile == null) { profile = ""; } if (profile.EndsWith("*", StringComparison.Ordinal)) { profile = profile.Substring(0, profile.Length - 1); // special case, if it was 'WindowsPhone7*', we want it to be WindowsPhone71 if (profile.Equals("WindowsPhone7", StringComparison.OrdinalIgnoreCase)) { profile = "WindowsPhone71"; } else if (identifer.Equals("Silverlight", StringComparison.OrdinalIgnoreCase) && profile.Equals("WindowsPhone", StringComparison.OrdinalIgnoreCase) && version == new Version(4, 0)) { // Since the beginning of NuGet, we have been using "SL3-WP" as the moniker to target WP7 project. // However, it's been discovered recently that the real TFM for WP7 project is "Silverlight, Version=4.0, Profile=WindowsPhone". // This is how the Portable Library xml describes a WP7 platform, as shown here: // // <Framework // Identifier="Silverlight" // Profile="WindowsPhone*" // MinimumVersion="4.0" // DisplayName="Windows Phone" // MinimumVersionDisplayName="7" /> // // To maintain consistent behavior with previous versions of NuGet, we want to change it back to "SL3-WP" nonetheless. version = new Version(3, 0); } } return(new FrameworkName(identifer, version, profile)); } } catch (XmlException) { } catch (IOException) { } catch (SecurityException) { } return(null); }
public static Manifest ReadFrom(Stream stream, IPropertyProvider propertyProvider, bool validateSchema) { XDocument document = !ReferenceEquals(propertyProvider, NullPropertyProvider.Instance) ? XDocument.Parse(Preprocessor.Process(stream, propertyProvider, true)) : XmlUtility.LoadSafe(stream, true); string schemaNamespace = GetSchemaNamespace(document); foreach (XElement local1 in document.Descendants()) { local1.Name = XName.Get(local1.Name.LocalName, schemaNamespace); } CheckSchemaVersion(document); if (validateSchema) { ValidateManifestSchema(document, schemaNamespace); } Manifest manifest = ManifestReader.ReadManifest(document); Validate(manifest); return(manifest); }
internal static FrameworkName LoadSupportedFramework(Stream stream) { try { XElement root = XmlUtility.LoadSafe(stream).Root; if (root.Name.LocalName.Equals("Framework", StringComparison.Ordinal)) { FrameworkName name; string str = root.GetOptionalAttributeValue("Identifier", null); if (str == null) { name = null; } else { string input = root.GetOptionalAttributeValue("MinimumVersion", null); if (input == null) { name = null; } else { Version version; if (!Version.TryParse(input, out version)) { name = null; } else { string str3 = root.GetOptionalAttributeValue("Profile", null); if (str3 == null) { str3 = ""; } if (str3.EndsWith("*", StringComparison.Ordinal)) { str3 = str3.Substring(0, str3.Length - 1); if (str3.Equals("WindowsPhone7", StringComparison.OrdinalIgnoreCase)) { str3 = "WindowsPhone71"; } else if (str.Equals("Silverlight", StringComparison.OrdinalIgnoreCase) && (str3.Equals("WindowsPhone", StringComparison.OrdinalIgnoreCase) && (version == new Version(4, 0)))) { version = new Version(3, 0); } } name = new FrameworkName(str, version, str3); } } } return(name); } } catch (XmlException) { } catch (IOException) { } catch (SecurityException) { } return(null); }