| | 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 CorrelationFilterExtensions |
| | 11 | | { |
| | 12 | | public static Filter ParseFromXElement(XElement xElement) |
| | 13 | | { |
| 0 | 14 | | var correlationFilter = new CorrelationFilter(); |
| 0 | 15 | | foreach (var element in xElement.Elements()) |
| | 16 | | { |
| 0 | 17 | | switch (element.Name.LocalName) |
| | 18 | | { |
| | 19 | | case "CorrelationId": |
| 0 | 20 | | correlationFilter.CorrelationId = element.Value; |
| 0 | 21 | | break; |
| | 22 | | case "MessageId": |
| 0 | 23 | | correlationFilter.MessageId = element.Value; |
| 0 | 24 | | break; |
| | 25 | | case "To": |
| 0 | 26 | | correlationFilter.To = element.Value; |
| 0 | 27 | | break; |
| | 28 | | case "ReplyTo": |
| 0 | 29 | | correlationFilter.ReplyTo = element.Value; |
| 0 | 30 | | break; |
| | 31 | | case "Label": |
| 0 | 32 | | correlationFilter.Label = element.Value; |
| 0 | 33 | | break; |
| | 34 | | case "SessionId": |
| 0 | 35 | | correlationFilter.SessionId = element.Value; |
| 0 | 36 | | break; |
| | 37 | | case "ReplyToSessionId": |
| 0 | 38 | | correlationFilter.ReplyToSessionId = element.Value; |
| 0 | 39 | | break; |
| | 40 | | case "ContentType": |
| 0 | 41 | | correlationFilter.ContentType = element.Value; |
| 0 | 42 | | break; |
| | 43 | | case "Properties": |
| 0 | 44 | | foreach (var prop in element.Elements(XName.Get("KeyValueOfstringanyType", ManagementClientConst |
| | 45 | | { |
| 0 | 46 | | var key = prop.Element(XName.Get("Key", ManagementClientConstants.ServiceBusNamespace))?.Val |
| 0 | 47 | | var value = XmlObjectConvertor.ParseValueObject(prop.Element(XName.Get("Value", ManagementCl |
| 0 | 48 | | correlationFilter.Properties.Add(key, value); |
| | 49 | | } |
| | 50 | | break; |
| | 51 | | default: |
| 0 | 52 | | MessagingEventSource.Log.ManagementSerializationException( |
| 0 | 53 | | $"{nameof(CorrelationFilterExtensions)}_{nameof(ParseFromXElement)}", |
| 0 | 54 | | element.ToString()); |
| | 55 | | break; |
| | 56 | | } |
| | 57 | | } |
| | 58 | |
|
| 0 | 59 | | return correlationFilter; |
| | 60 | | } |
| | 61 | |
|
| | 62 | | public static XElement Serialize(this CorrelationFilter filter) |
| | 63 | | { |
| 0 | 64 | | XElement parameterElement = null; |
| 0 | 65 | | if (filter.properties != null) |
| | 66 | | { |
| 0 | 67 | | parameterElement = new XElement(XName.Get("Properties", ManagementClientConstants.ServiceBusNamespace)); |
| 0 | 68 | | foreach (var param in filter.properties) |
| | 69 | | { |
| 0 | 70 | | parameterElement.Add( |
| 0 | 71 | | new XElement(XName.Get("KeyValueOfstringanyType", ManagementClientConstants.ServiceBusNamespace) |
| 0 | 72 | | new XElement(XName.Get("Key", ManagementClientConstants.ServiceBusNamespace), param.Key), |
| 0 | 73 | | XmlObjectConvertor.SerializeObject(param.Value))); |
| | 74 | | } |
| | 75 | | } |
| | 76 | |
|
| 0 | 77 | | return new XElement( |
| 0 | 78 | | XName.Get("Filter", ManagementClientConstants.ServiceBusNamespace), |
| 0 | 79 | | new XAttribute(XName.Get("type", ManagementClientConstants.XmlSchemaInstanceNamespace), nameof(Correlati |
| 0 | 80 | | string.IsNullOrWhiteSpace(filter.CorrelationId) ? null : |
| 0 | 81 | | new XElement(XName.Get("CorrelationId", ManagementClientConstants.ServiceBusNamespace), filter.Corre |
| 0 | 82 | | string.IsNullOrWhiteSpace(filter.MessageId) ? null : |
| 0 | 83 | | new XElement(XName.Get("MessageId", ManagementClientConstants.ServiceBusNamespace), filter.MessageId |
| 0 | 84 | | string.IsNullOrWhiteSpace(filter.To) ? null : |
| 0 | 85 | | new XElement(XName.Get("To", ManagementClientConstants.ServiceBusNamespace), filter.To), |
| 0 | 86 | | string.IsNullOrWhiteSpace(filter.ReplyTo) ? null : |
| 0 | 87 | | new XElement(XName.Get("ReplyTo", ManagementClientConstants.ServiceBusNamespace), filter.ReplyTo), |
| 0 | 88 | | string.IsNullOrWhiteSpace(filter.Label) ? null : |
| 0 | 89 | | new XElement(XName.Get("Label", ManagementClientConstants.ServiceBusNamespace), filter.Label), |
| 0 | 90 | | string.IsNullOrWhiteSpace(filter.SessionId) ? null : |
| 0 | 91 | | new XElement(XName.Get("SessionId", ManagementClientConstants.ServiceBusNamespace), filter.SessionId |
| 0 | 92 | | string.IsNullOrWhiteSpace(filter.ReplyToSessionId) ? null : |
| 0 | 93 | | new XElement(XName.Get("ReplyToSessionId", ManagementClientConstants.ServiceBusNamespace), filter.Re |
| 0 | 94 | | string.IsNullOrWhiteSpace(filter.ContentType) ? null : |
| 0 | 95 | | new XElement(XName.Get("ContentType", ManagementClientConstants.ServiceBusNamespace), filter.Content |
| 0 | 96 | | parameterElement); |
| | 97 | | } |
| | 98 | | } |
| | 99 | | } |