public static PublicConfigFile LoadFromData(string data) { var stream = data.ToStream(); var doc = new XmlDocument(); using (stream) { using (var tr = new XmlTextReader(stream)) { tr.Namespaces = false; doc.Load(tr); } } if (!doc.HasChildNodes) { throw new ConfigFileParseException(); } if (!ConfigFileXmlHelper.TryGetAddress(doc, out var address)) { throw new ConfigFileParseException(); } if (!ConfigFileXmlHelper.TryGetSyncMode(doc, out var syncMode)) { throw new ConfigFileParseException(); } var severity = ConfigFileXmlHelper.GetSeverity(doc); var extensions = MetadataXmlHelper.GetExtensions(doc, $"{RootNodeName}/{ExtensionsListNodeName}/{MetadataConstants.ExtensionMetadataXmlNodeName}"); return(new PublicConfigFile(address, syncMode, severity, extensions)); }
private static AvailableExtensionsList FromXml(XmlDocument document, IReadOnlyCollection <ISharperCryptoApiExtensionMetadata> availableExtensions) { var extensions = MetadataXmlHelper.GetExtensions(document, $"{RootNode}/{MetadataConstants.ExtensionMetadataXmlNodeName}"); var localExtensions = new AvailableExtensionsList(); foreach (var extension in availableExtensions) { localExtensions.Add(extension); } foreach (var extension in extensions) { if (availableExtensions.Any(x => x.Equals(extension)) || extension.External) { localExtensions.Add(extension); } //If there is a version mismatch between current and latest version we still want to keep the source property var t = localExtensions.FirstOrDefault(x => x.Name.Equals(extension.Name) && x.InstallPath.Equals(extension.InstallPath)); if (t != null) { //TODO: Special handle .zip files as the file does not have a file verison attribute. var index = localExtensions.IndexOf(t); var update = new SharperCryptoApiExtensionMetadata(t.Name, extension.Type, t.InstallPath, t.InstallExtension, t.Summary, extension.Author, extension.Description, t.Version, extension.Source, t.External); localExtensions.Update(index, update); } } return(localExtensions); }