public static RuleFilter ParseFromXElement(XElement xElement)
        {
            var correlationRuleFilter = new CorrelationRuleFilter();

            foreach (var element in xElement.Elements())
            {
                switch (element.Name.LocalName)
                {
                case "CorrelationId":
                    correlationRuleFilter.CorrelationId = element.Value;
                    break;

                case "MessageId":
                    correlationRuleFilter.MessageId = element.Value;
                    break;

                case "To":
                    correlationRuleFilter.To = element.Value;
                    break;

                case "ReplyTo":
                    correlationRuleFilter.ReplyTo = element.Value;
                    break;

                case "Label":
                    correlationRuleFilter.Label = element.Value;
                    break;

                case "SessionId":
                    correlationRuleFilter.SessionId = element.Value;
                    break;

                case "ReplyToSessionId":
                    correlationRuleFilter.ReplyToSessionId = element.Value;
                    break;

                case "ContentType":
                    correlationRuleFilter.ContentType = element.Value;
                    break;

                case "Properties":
                    foreach (var prop in element.Elements(XName.Get("KeyValueOfstringanyType", ManagementClientConstants.ServiceBusNamespace)))
                    {
                        var key   = prop.Element(XName.Get("Key", ManagementClientConstants.ServiceBusNamespace))?.Value;
                        var value = XmlObjectConvertor.ParseValueObject(prop.Element(XName.Get("Value", ManagementClientConstants.ServiceBusNamespace)));
                        correlationRuleFilter.Properties.Add(key, value);
                    }
                    break;

                default:
                    ServiceBusEventSource.Log.ManagementSerializationException(
                        $"{nameof(CorrelationRuleFilterExtensions)}_{nameof(ParseFromXElement)}",
                        element.ToString());
                    break;
                }
            }

            return(correlationRuleFilter);
        }
Beispiel #2
0
        private static RuleAction ParseFromXElementSqlRuleAction(XElement xElement)
        {
            var expression = xElement.Element(XName.Get("SqlExpression", ManagementClientConstants.ServiceBusNamespace))?.Value;

            if (string.IsNullOrWhiteSpace(expression))
            {
                return(null);
            }

            var action = new SqlRuleAction(expression);

            var parameters = xElement.Element(XName.Get("Parameters", ManagementClientConstants.ServiceBusNamespace));

            if (parameters != null && parameters.HasElements)
            {
                foreach (var param in parameters.Elements(XName.Get("KeyValueOfstringanyType", ManagementClientConstants.ServiceBusNamespace)))
                {
                    var key   = param.Element(XName.Get("Key", ManagementClientConstants.ServiceBusNamespace))?.Value;
                    var value = XmlObjectConvertor.ParseValueObject(param.Element(XName.Get("Value", ManagementClientConstants.ServiceBusNamespace)));
                    action.Parameters.Add(key, value);
                }
            }
            return(action);
        }