public static XDocument Serialize(this SubscriptionDescription description) { return(new XDocument( new XElement(XName.Get("entry", ManagementClientConstants.AtomNs), new XElement(XName.Get("content", ManagementClientConstants.AtomNs), new XAttribute("type", "application/xml"), new XElement(XName.Get("SubscriptionDescription", ManagementClientConstants.SbNs), new XElement(XName.Get("LockDuration", ManagementClientConstants.SbNs), XmlConvert.ToString(description.LockDuration)), new XElement(XName.Get("RequiresSession", ManagementClientConstants.SbNs), XmlConvert.ToString(description.RequiresSession)), description.DefaultMessageTimeToLive != TimeSpan.MaxValue ? new XElement(XName.Get("DefaultMessageTimeToLive", ManagementClientConstants.SbNs), XmlConvert.ToString(description.DefaultMessageTimeToLive)) : null, new XElement(XName.Get("DeadLetteringOnMessageExpiration", ManagementClientConstants.SbNs), XmlConvert.ToString(description.EnableDeadLetteringOnMessageExpiration)), new XElement(XName.Get("DeadLetteringOnFilterEvaluationExceptions", ManagementClientConstants.SbNs), XmlConvert.ToString(description.EnableDeadLetteringOnFilterEvaluationExceptions)), description.DefaultRuleDescription != null ? description.DefaultRuleDescription.SerializeRule("DefaultRuleDescription") : null, new XElement(XName.Get("MaxDeliveryCount", ManagementClientConstants.SbNs), XmlConvert.ToString(description.MaxDeliveryCount)), new XElement(XName.Get("EnableBatchedOperations", ManagementClientConstants.SbNs), XmlConvert.ToString(description.EnableBatchedOperations)), new XElement(XName.Get("Status", ManagementClientConstants.SbNs), description.Status.ToString()), description.ForwardTo != null ? new XElement(XName.Get("ForwardTo", ManagementClientConstants.SbNs), description.ForwardTo) : null, description.UserMetadata != null ? new XElement(XName.Get("UserMetadata", ManagementClientConstants.SbNs), description.UserMetadata) : null, description.ForwardDeadLetteredMessagesTo != null ? new XElement(XName.Get("ForwardDeadLetteredMessagesTo", ManagementClientConstants.SbNs), description.ForwardDeadLetteredMessagesTo) : null, description.AutoDeleteOnIdle != TimeSpan.MaxValue ? new XElement(XName.Get("AutoDeleteOnIdle", ManagementClientConstants.SbNs), XmlConvert.ToString(description.AutoDeleteOnIdle)) : null )) ))); }
private static SubscriptionDescription ParseFromEntryElement(string topicName, XElement xEntry) { var name = xEntry.Element(XName.Get("title", ManagementClientConstants.AtomNamespace)).Value; var subscriptionDesc = new SubscriptionDescription(topicName, name); var qdXml = xEntry.Element(XName.Get("content", ManagementClientConstants.AtomNamespace))? .Element(XName.Get("SubscriptionDescription", ManagementClientConstants.ServiceBusNamespace)); if (qdXml == null) { throw new MessagingEntityNotFoundException("Subscription was not found"); } foreach (var element in qdXml.Elements()) { switch (element.Name.LocalName) { case "RequiresSession": subscriptionDesc.RequiresSession = bool.Parse(element.Value); break; case "DeadLetteringOnMessageExpiration": subscriptionDesc.EnableDeadLetteringOnMessageExpiration = bool.Parse(element.Value); break; case "DeadLetteringOnFilterEvaluationExceptions": subscriptionDesc.EnableDeadLetteringOnFilterEvaluationExceptions = bool.Parse(element.Value); break; case "LockDuration": subscriptionDesc.LockDuration = XmlConvert.ToTimeSpan(element.Value); break; case "DefaultMessageTimeToLive": subscriptionDesc.DefaultMessageTimeToLive = XmlConvert.ToTimeSpan(element.Value); break; case "MaxDeliveryCount": subscriptionDesc.MaxDeliveryCount = int.Parse(element.Value); break; case "Status": subscriptionDesc.Status = (EntityStatus)Enum.Parse(typeof(EntityStatus), element.Value); break; case "EnableBatchedOperations": subscriptionDesc.EnableBatchedOperations = bool.Parse(element.Value); break; case "UserMetadata": subscriptionDesc.UserMetadata = element.Value; break; case "AutoDeleteOnIdle": subscriptionDesc.AutoDeleteOnIdle = XmlConvert.ToTimeSpan(element.Value); break; case "ForwardTo": if (!string.IsNullOrWhiteSpace(element.Value)) { subscriptionDesc.ForwardTo = element.Value; } break; case "ForwardDeadLetteredMessagesTo": if (!string.IsNullOrWhiteSpace(element.Value)) { subscriptionDesc.ForwardDeadLetteredMessagesTo = element.Value; } break; case "AccessedAt": case "CreatedAt": case "MessageCount": case "SizeInBytes": case "UpdatedAt": case "CountDetails": // Ignore known properties // Do nothing break; default: // For unknown properties, keep them as-is for forward proof. if (subscriptionDesc.UnknownProperties == null) { subscriptionDesc.UnknownProperties = new List <object>(); } subscriptionDesc.UnknownProperties.Add(element); break; } } return(subscriptionDesc); }
private static SubscriptionDescription ParseFromEntryElement(string topicName, XElement xEntry) { var name = xEntry.Element(XName.Get("title", ManagementClientConstants.AtomNs)).Value; var subscriptionDesc = new SubscriptionDescription(topicName, name); var qdXml = xEntry.Element(XName.Get("content", ManagementClientConstants.AtomNs))? .Element(XName.Get("SubscriptionDescription", ManagementClientConstants.SbNs)); if (qdXml == null) { throw new MessagingEntityNotFoundException("Subscription was not found"); } foreach (var element in qdXml.Elements()) { switch (element.Name.LocalName) { case "RequiresSession": subscriptionDesc.RequiresSession = bool.Parse(element.Value); break; case "DeadLetteringOnMessageExpiration": subscriptionDesc.EnableDeadLetteringOnMessageExpiration = bool.Parse(element.Value); break; case "DeadLetteringOnFilterEvaluationExceptions": subscriptionDesc.EnableDeadLetteringOnFilterEvaluationExceptions = bool.Parse(element.Value); break; case "LockDuration": subscriptionDesc.LockDuration = XmlConvert.ToTimeSpan(element.Value); break; case "DefaultMessageTimeToLive": subscriptionDesc.DefaultMessageTimeToLive = XmlConvert.ToTimeSpan(element.Value); break; case "MaxDeliveryCount": subscriptionDesc.MaxDeliveryCount = int.Parse(element.Value); break; case "Status": subscriptionDesc.Status = (EntityStatus)Enum.Parse(typeof(EntityStatus), element.Value); break; case "EnableBatchedOperations": subscriptionDesc.EnableBatchedOperations = bool.Parse(element.Value); break; case "UserMetadata": subscriptionDesc.UserMetadata = element.Value; break; case "AutoDeleteOnIdle": subscriptionDesc.AutoDeleteOnIdle = XmlConvert.ToTimeSpan(element.Value); break; case "ForwardTo": if (!string.IsNullOrWhiteSpace(element.Value)) { subscriptionDesc.ForwardTo = element.Value; } break; case "ForwardDeadLetteredMessagesTo": if (!string.IsNullOrWhiteSpace(element.Value)) { subscriptionDesc.ForwardDeadLetteredMessagesTo = element.Value; } break; } } return(subscriptionDesc); }