public void CreateSubscriptionIfMissing(string topicName, string subscriptionName, Type messageType) { var @namespace = NamespaceUtils.GetNamespace(_settings); CreateTopicIfMissing(topicName, messageType, @namespace); var topic = @namespace.Topics.List().FirstOrDefault(x => x.Name == topicName); if (topic == null) { throw new InvalidOperationException($"Cannot find topic '{topicName}' from topics '{string.Join(", ", @namespace.Topics.List().Select(x => x.Name))}'"); } if (!topic.Subscriptions.List().Any(x => x.Name == subscriptionName)) { _settings.AzureSubscriptionBuilder(topic.Subscriptions.Define(subscriptionName), messageType); } }
public async Task <CapabilitiesInfo> GetCapabilities() { var response = await esclClient.GetAsync(endpoint); var xml = response.Content; var namespaceManager = NamespaceUtils.CreateNamespaceManager(xml); var extractor = new Extractor(xml, namespaceManager); return(new CapabilitiesInfo { Model = extractor.Extract("/scan:ScannerCapabilities/pwg:MakeAndModel"), MinWidth = extractor.ExtractInt("/scan:ScannerCapabilities/scan:Platen/scan:PlatenInputCaps/scan:MinWidth"), MaxWidth = extractor.ExtractInt("/scan:ScannerCapabilities/scan:Platen/scan:PlatenInputCaps/scan:MaxWidth"), MinHeight = extractor.ExtractInt("/scan:ScannerCapabilities/scan:Platen/scan:PlatenInputCaps/scan:MinHeight"), MaxHeight = extractor.ExtractInt("/scan:ScannerCapabilities/scan:Platen/scan:PlatenInputCaps/scan:MaxHeight"), DocumentFormatExtensions = extractor.ExtractList("/scan:ScannerCapabilities/scan:Platen/scan:PlatenInputCaps/scan:SettingProfiles/scan:SettingProfile/scan:DocumentFormats/scan:DocumentFormatExt"), Resolutions = extractor.ExtractNodes("/scan:ScannerCapabilities/scan:Platen/scan:PlatenInputCaps/scan:SettingProfiles/scan:SettingProfile/scan:SupportedResolutions/scan:DiscreteResolutions/scan:DiscreteResolution") .Select(node => new Resolution { X = node.SelectSingleNode("./scan:XResolution", namespaceManager).InnerText.ParseIntOrDefault(0), Y = node.SelectSingleNode("./scan:YResolution", namespaceManager).InnerText.ParseIntOrDefault(0) }).ToList() }); }
static void Main(string[] args) { /* * Change this.... * xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" * xmlns:ns2="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2" * xmlns:ns3="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" * xmlns:ns4="urn:oasis:names:specification:ubl:schema:xsd:CreditNote-2" * * To this.... * xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" * xmlns:cec="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2" * xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" * xmlns="urn:oasis:names:specification:ubl:schema:xsd:CreditNote-2" * */ try { //manually setting parameter NamespaceDocList NamespaceDocList nsDocs = new NamespaceDocList { new NamespaceDoc() { RootNamespace = "urn:oasis:names:specification:ubl:schema:xsd:Invoice-2", Namespaces = new NamespaceUriAliasList { new NamespaceUriAlias() { Alias = "", Uri = "urn:oasis:names:specification:ubl:schema:xsd:Invoice-2" }, new NamespaceUriAlias() { Alias = "cbc", Uri = "urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" }, new NamespaceUriAlias() { Alias = "cec", Uri = "urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2" }, new NamespaceUriAlias() { Alias = "cac", Uri = "urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" } } }, new NamespaceDoc() { RootNamespace = "urn:oasis:names:specification:ubl:schema:xsd:CreditNote-2", Namespaces = new NamespaceUriAliasList { new NamespaceUriAlias() { Alias = "", Uri = "urn:oasis:names:specification:ubl:schema:xsd:CreditNote-2" }, new NamespaceUriAlias() { Alias = "cbc", Uri = "urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" }, new NamespaceUriAlias() { Alias = "cec", Uri = "urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2" }, new NamespaceUriAlias() { Alias = "cac", Uri = "urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" } } }, }; string outputSuffix = "_output"; List <string> testFiles = Directory.GetFiles(@".\TestFiles", "*.xml", SearchOption.TopDirectoryOnly).ToList(); //ChangeNameSpaceAlias using NamespaceDocList parameter foreach (var testFile in testFiles) { if (Path.GetFileNameWithoutExtension(testFile).EndsWith(outputSuffix, StringComparison.InvariantCultureIgnoreCase)) { continue; } string inputXML = testFile; string outputXML = Path.Combine(Path.GetDirectoryName(testFile), Path.GetFileNameWithoutExtension(testFile) + outputSuffix + Path.GetExtension(testFile)); File.Delete(outputXML); NamespaceUtils.ChangeNameSpaceAlias(inputXML, outputXML, nsDocs); } testFiles = Directory.GetFiles(@".\TestFiles", "*.xml", SearchOption.TopDirectoryOnly).ToList(); //ChangeNameSpaceAlias using saved parameter file //When file is missing a default file will be created in the application folder. Filename, [running application]_XMLUtilitiesModel.xml foreach (var testFile in testFiles) { if (Path.GetFileNameWithoutExtension(testFile).EndsWith(outputSuffix, StringComparison.InvariantCultureIgnoreCase)) { continue; } string inputXML = testFile; string outputXML = Path.Combine(Path.GetDirectoryName(testFile), Path.GetFileNameWithoutExtension(testFile) + outputSuffix + Path.GetExtension(testFile)); File.Delete(outputXML); NamespaceUtils.ChangeNameSpaceAlias(inputXML, outputXML); } } catch (Exception ex) { Console.Write(ex.Message); } }
public void CreateTopicIfMissing(string topicName, Type messageType) { var @namespace = NamespaceUtils.GetNamespace(_settings); CreateTopicIfMissing(topicName, messageType, @namespace); }