| | 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.Management |
| | 5 | | { |
| | 6 | | using System; |
| | 7 | | using System.Xml.Linq; |
| | 8 | | using System.Collections.Generic; |
| | 9 | |
|
| | 10 | | internal static class QueueRuntimeInfoExtensions |
| | 11 | | { |
| | 12 | | public static QueueRuntimeInfo ParseFromContent(string xml) |
| | 13 | | { |
| | 14 | | try |
| | 15 | | { |
| 0 | 16 | | var xDoc = XElement.Parse(xml); |
| 0 | 17 | | if (!xDoc.IsEmpty) |
| | 18 | | { |
| 0 | 19 | | if (xDoc.Name.LocalName == "entry") |
| | 20 | | { |
| 0 | 21 | | return ParseFromEntryElement(xDoc); |
| | 22 | | } |
| | 23 | | } |
| 0 | 24 | | } |
| 0 | 25 | | catch (Exception ex) when (!(ex is ServiceBusException)) |
| | 26 | | { |
| 0 | 27 | | throw new ServiceBusException(false, ex); |
| | 28 | | } |
| | 29 | |
|
| 0 | 30 | | throw new MessagingEntityNotFoundException("Queue was not found"); |
| 0 | 31 | | } |
| | 32 | |
|
| | 33 | | private static QueueRuntimeInfo ParseFromEntryElement(XElement xEntry) |
| | 34 | | { |
| 0 | 35 | | var name = xEntry.Element(XName.Get("title", ManagementClientConstants.AtomNamespace)).Value; |
| 0 | 36 | | var qRuntime = new QueueRuntimeInfo(name); |
| | 37 | |
|
| 0 | 38 | | var qdXml = xEntry.Element(XName.Get("content", ManagementClientConstants.AtomNamespace))? |
| 0 | 39 | | .Element(XName.Get("QueueDescription", ManagementClientConstants.ServiceBusNamespace)); |
| | 40 | |
|
| 0 | 41 | | if (qdXml == null) |
| | 42 | | { |
| 0 | 43 | | throw new MessagingEntityNotFoundException("Queue was not found"); |
| | 44 | | } |
| | 45 | |
|
| 0 | 46 | | foreach (var element in qdXml.Elements()) |
| | 47 | | { |
| 0 | 48 | | switch (element.Name.LocalName) |
| | 49 | | { |
| | 50 | | case "AccessedAt": |
| 0 | 51 | | qRuntime.AccessedAt = DateTime.Parse(element.Value); |
| 0 | 52 | | break; |
| | 53 | | case "CreatedAt": |
| 0 | 54 | | qRuntime.CreatedAt = DateTime.Parse(element.Value); |
| 0 | 55 | | break; |
| | 56 | | case "MessageCount": |
| 0 | 57 | | qRuntime.MessageCount = long.Parse(element.Value); |
| 0 | 58 | | break; |
| | 59 | | case "SizeInBytes": |
| 0 | 60 | | qRuntime.SizeInBytes = long.Parse(element.Value); |
| 0 | 61 | | break; |
| | 62 | | case "UpdatedAt": |
| 0 | 63 | | qRuntime.UpdatedAt = DateTime.Parse(element.Value); |
| 0 | 64 | | break; |
| | 65 | | case "CountDetails": |
| 0 | 66 | | qRuntime.MessageCountDetails = new MessageCountDetails(); |
| 0 | 67 | | foreach (var countElement in element.Elements()) |
| | 68 | | { |
| 0 | 69 | | switch (countElement.Name.LocalName) |
| | 70 | | { |
| | 71 | | case "ActiveMessageCount": |
| 0 | 72 | | qRuntime.MessageCountDetails.ActiveMessageCount = long.Parse(countElement.Value); |
| 0 | 73 | | break; |
| | 74 | | case "DeadLetterMessageCount": |
| 0 | 75 | | qRuntime.MessageCountDetails.DeadLetterMessageCount = long.Parse(countElement.Value) |
| 0 | 76 | | break; |
| | 77 | | case "ScheduledMessageCount": |
| 0 | 78 | | qRuntime.MessageCountDetails.ScheduledMessageCount = long.Parse(countElement.Value); |
| 0 | 79 | | break; |
| | 80 | | case "TransferMessageCount": |
| 0 | 81 | | qRuntime.MessageCountDetails.TransferMessageCount = long.Parse(countElement.Value); |
| 0 | 82 | | break; |
| | 83 | | case "TransferDeadLetterMessageCount": |
| 0 | 84 | | qRuntime.MessageCountDetails.TransferDeadLetterMessageCount = long.Parse(countElemen |
| | 85 | | break; |
| | 86 | | } |
| | 87 | | } |
| | 88 | | break; |
| | 89 | | } |
| | 90 | | } |
| | 91 | |
|
| 0 | 92 | | return qRuntime; |
| | 93 | | } |
| | 94 | |
|
| | 95 | | public static IList<QueueRuntimeInfo> ParseCollectionFromContent(string xml) |
| | 96 | | { |
| | 97 | | try |
| | 98 | | { |
| 0 | 99 | | var xDoc = XElement.Parse(xml); |
| 0 | 100 | | if (!xDoc.IsEmpty) |
| | 101 | | { |
| 0 | 102 | | if (xDoc.Name.LocalName == "feed") |
| | 103 | | { |
| 0 | 104 | | var queueList = new List<QueueRuntimeInfo>(); |
| | 105 | |
|
| 0 | 106 | | var entryList = xDoc.Elements(XName.Get("entry", ManagementClientConstants.AtomNamespace)); |
| 0 | 107 | | foreach (var entry in entryList) |
| | 108 | | { |
| 0 | 109 | | queueList.Add(ParseFromEntryElement(entry)); |
| | 110 | | } |
| | 111 | |
|
| 0 | 112 | | return queueList; |
| | 113 | | } |
| | 114 | | } |
| 0 | 115 | | } |
| 0 | 116 | | catch (Exception ex) when (!(ex is ServiceBusException)) |
| | 117 | | { |
| 0 | 118 | | throw new ServiceBusException(false, ex); |
| | 119 | | } |
| | 120 | |
|
| 0 | 121 | | throw new MessagingEntityNotFoundException("No queues were found"); |
| 0 | 122 | | } |
| | 123 | | } |
| | 124 | | } |