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