| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | using System.Collections.Generic; |
| | 5 | | using System.Xml.Linq; |
| | 6 | | using Azure.Messaging.ServiceBus.Diagnostics; |
| | 7 | |
|
| | 8 | | namespace Azure.Messaging.ServiceBus.Management |
| | 9 | | { |
| | 10 | | internal static class CorrelationRuleFilterExtensions |
| | 11 | | { |
| | 12 | | public static RuleFilter ParseFromXElement(XElement xElement) |
| | 13 | | { |
| 20 | 14 | | var correlationRuleFilter = new CorrelationRuleFilter(); |
| 336 | 15 | | foreach (var element in xElement.Elements()) |
| | 16 | | { |
| 148 | 17 | | switch (element.Name.LocalName) |
| | 18 | | { |
| | 19 | | case "CorrelationId": |
| 16 | 20 | | correlationRuleFilter.CorrelationId = element.Value; |
| 16 | 21 | | break; |
| | 22 | | case "MessageId": |
| 16 | 23 | | correlationRuleFilter.MessageId = element.Value; |
| 16 | 24 | | break; |
| | 25 | | case "To": |
| 16 | 26 | | correlationRuleFilter.To = element.Value; |
| 16 | 27 | | break; |
| | 28 | | case "ReplyTo": |
| 16 | 29 | | correlationRuleFilter.ReplyTo = element.Value; |
| 16 | 30 | | break; |
| | 31 | | case "Label": |
| 16 | 32 | | correlationRuleFilter.Label = element.Value; |
| 16 | 33 | | break; |
| | 34 | | case "SessionId": |
| 16 | 35 | | correlationRuleFilter.SessionId = element.Value; |
| 16 | 36 | | break; |
| | 37 | | case "ReplyToSessionId": |
| 16 | 38 | | correlationRuleFilter.ReplyToSessionId = element.Value; |
| 16 | 39 | | break; |
| | 40 | | case "ContentType": |
| 16 | 41 | | correlationRuleFilter.ContentType = element.Value; |
| 16 | 42 | | break; |
| | 43 | | case "Properties": |
| 96 | 44 | | foreach (var prop in element.Elements(XName.Get("KeyValueOfstringanyType", ManagementClientConst |
| | 45 | | { |
| 28 | 46 | | var key = prop.Element(XName.Get("Key", ManagementClientConstants.ServiceBusNamespace))?.Val |
| 28 | 47 | | var value = XmlObjectConvertor.ParseValueObject(prop.Element(XName.Get("Value", ManagementCl |
| 28 | 48 | | correlationRuleFilter.Properties.Add(key, value); |
| | 49 | | } |
| | 50 | | break; |
| | 51 | | default: |
| 0 | 52 | | ServiceBusEventSource.Log.ManagementSerializationException( |
| 0 | 53 | | $"{nameof(CorrelationRuleFilterExtensions)}_{nameof(ParseFromXElement)}", |
| 0 | 54 | | element.ToString()); |
| | 55 | | break; |
| | 56 | | } |
| | 57 | | } |
| | 58 | |
|
| 20 | 59 | | return correlationRuleFilter; |
| | 60 | | } |
| | 61 | |
|
| | 62 | | public static XElement Serialize(this CorrelationRuleFilter filter, string filterName) |
| | 63 | | { |
| 12 | 64 | | XElement parameterElement = new XElement( |
| 12 | 65 | | XName.Get( |
| 12 | 66 | | "Properties", |
| 12 | 67 | | ManagementClientConstants.ServiceBusNamespace)); |
| | 68 | |
|
| 64 | 69 | | foreach (KeyValuePair<string, object> param in filter.Properties) |
| | 70 | | { |
| 20 | 71 | | parameterElement.Add( |
| 20 | 72 | | new XElement(XName.Get("KeyValueOfstringanyType", ManagementClientConstants.ServiceBusNamespace), |
| 20 | 73 | | new XElement(XName.Get("Key", ManagementClientConstants.ServiceBusNamespace), param.Key), |
| 20 | 74 | | XmlObjectConvertor.SerializeObject(param.Value))); |
| | 75 | | } |
| | 76 | |
|
| 12 | 77 | | return new XElement( |
| 12 | 78 | | XName.Get("Filter", ManagementClientConstants.ServiceBusNamespace), |
| 12 | 79 | | new XAttribute(XName.Get("type", ManagementClientConstants.XmlSchemaInstanceNamespace), filterName), |
| 12 | 80 | | string.IsNullOrWhiteSpace(filter.CorrelationId) ? null : |
| 12 | 81 | | new XElement(XName.Get("CorrelationId", ManagementClientConstants.ServiceBusNamespace), filter.Corre |
| 12 | 82 | | string.IsNullOrWhiteSpace(filter.MessageId) ? null : |
| 12 | 83 | | new XElement(XName.Get("MessageId", ManagementClientConstants.ServiceBusNamespace), filter.MessageId |
| 12 | 84 | | string.IsNullOrWhiteSpace(filter.To) ? null : |
| 12 | 85 | | new XElement(XName.Get("To", ManagementClientConstants.ServiceBusNamespace), filter.To), |
| 12 | 86 | | string.IsNullOrWhiteSpace(filter.ReplyTo) ? null : |
| 12 | 87 | | new XElement(XName.Get("ReplyTo", ManagementClientConstants.ServiceBusNamespace), filter.ReplyTo), |
| 12 | 88 | | string.IsNullOrWhiteSpace(filter.Label) ? null : |
| 12 | 89 | | new XElement(XName.Get("Label", ManagementClientConstants.ServiceBusNamespace), filter.Label), |
| 12 | 90 | | string.IsNullOrWhiteSpace(filter.SessionId) ? null : |
| 12 | 91 | | new XElement(XName.Get("SessionId", ManagementClientConstants.ServiceBusNamespace), filter.SessionId |
| 12 | 92 | | string.IsNullOrWhiteSpace(filter.ReplyToSessionId) ? null : |
| 12 | 93 | | new XElement(XName.Get("ReplyToSessionId", ManagementClientConstants.ServiceBusNamespace), filter.Re |
| 12 | 94 | | string.IsNullOrWhiteSpace(filter.ContentType) ? null : |
| 12 | 95 | | new XElement(XName.Get("ContentType", ManagementClientConstants.ServiceBusNamespace), filter.Content |
| 12 | 96 | | parameterElement); |
| | 97 | | } |
| | 98 | | } |
| | 99 | | } |