| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | using System.Xml.Linq; |
| | 5 | |
|
| | 6 | | namespace Azure.Messaging.ServiceBus.Management |
| | 7 | | { |
| | 8 | | internal static class SqlRuleFilterExtensions |
| | 9 | | { |
| | 10 | | internal static RuleFilter ParseFromXElement(XElement xElement) |
| | 11 | | { |
| 16 | 12 | | var expression = xElement.Element(XName.Get("SqlExpression", ManagementClientConstants.ServiceBusNamespace)) |
| 16 | 13 | | if (string.IsNullOrWhiteSpace(expression)) |
| | 14 | | { |
| 0 | 15 | | return null; |
| | 16 | | } |
| | 17 | |
|
| 16 | 18 | | var filter = new SqlRuleFilter(expression); |
| | 19 | |
|
| 16 | 20 | | var parameters = xElement.Element(XName.Get("Parameters", ManagementClientConstants.ServiceBusNamespace)); |
| 16 | 21 | | if (parameters != null && parameters.HasElements) |
| | 22 | | { |
| 200 | 23 | | foreach (var param in parameters.Elements(XName.Get("KeyValueOfstringanyType", ManagementClientConstants |
| | 24 | | { |
| 84 | 25 | | var key = param.Element(XName.Get("Key", ManagementClientConstants.ServiceBusNamespace))?.Value; |
| 84 | 26 | | var value = XmlObjectConvertor.ParseValueObject(param.Element(XName.Get("Value", ManagementClientCon |
| 84 | 27 | | filter.Parameters.Add(key, value); |
| | 28 | | } |
| | 29 | | } |
| 16 | 30 | | return filter; |
| | 31 | | } |
| | 32 | |
|
| | 33 | | public static XElement Serialize(this SqlRuleFilter filter, string filterName) |
| | 34 | | { |
| 36 | 35 | | XElement parameterElement = null; |
| 36 | 36 | | if (filter.Parameters != null) |
| | 37 | | { |
| 36 | 38 | | parameterElement = new XElement(XName.Get("Parameters", ManagementClientConstants.ServiceBusNamespace)); |
| 160 | 39 | | foreach (var param in filter.Parameters) |
| | 40 | | { |
| 44 | 41 | | parameterElement.Add( |
| 44 | 42 | | new XElement(XName.Get("KeyValueOfstringanyType", ManagementClientConstants.ServiceBusNamespace) |
| 44 | 43 | | new XElement(XName.Get("Key", ManagementClientConstants.ServiceBusNamespace), param.Key), |
| 44 | 44 | | XmlObjectConvertor.SerializeObject(param.Value))); |
| | 45 | | } |
| | 46 | | } |
| | 47 | |
|
| 36 | 48 | | return new XElement( |
| 36 | 49 | | XName.Get("Filter", ManagementClientConstants.ServiceBusNamespace), |
| 36 | 50 | | new XAttribute(XName.Get("type", ManagementClientConstants.XmlSchemaInstanceNamespace), filterName), |
| 36 | 51 | | new XElement(XName.Get("SqlExpression", ManagementClientConstants.ServiceBusNamespace), filter.SqlExpres |
| 36 | 52 | | parameterElement); |
| | 53 | | } |
| | 54 | | } |
| | 55 | | } |