Exemple #1
0
        public SubscriptionDescription UpdateSubscription(SubscriptionDescription description)
        {
            if (String.IsNullOrWhiteSpace(description.TopicPath))
            {
                throw new NullReferenceException("Topic Path was null or empty");
            }

            if (String.IsNullOrWhiteSpace(description.Name))
            {
                throw new NullReferenceException("Name was null or empty");
            }


            CheckNameLength(description.TopicPath, MAXPATHLENGTH, "description.Path");
            CheckNameLength(description.Name, MAXNAMELENGTH, "description.Name");

            string address, saddress;

            GetAddressesNeeded(description.TopicPath, description.Name, out address, out saddress, true);

            entry toXml = entry.Build(endpointAddresses.First(), description.Name, saddress);

            toXml.content.SubscriptionDescription = description.xml;

            using (System.Net.WebClient request = new WebClient())
            {
                request.AddCommmonHeaders(provider, address, true, true, true);
                var t = request.UploadEntryXml(saddress, toXml);
                return(new SubscriptionDescription(description.TopicPath, description.Name, t?.content?.SubscriptionDescription));
            }
        }
Exemple #2
0
        public bool ConsumerGroupExists(string eventHubName, string consumerGroupName, out ConsumerGroupDescription cgd)
        {
            CheckNameLength(eventHubName, MAXPATHLENGTH, "description.Path");
            CheckNameLength(consumerGroupName, MAXNAMELENGTH, "description.Name");
            cgd = null;
            string address, saddress;

            GetConsumerGroupAddressNeeded(eventHubName, consumerGroupName, out address, out saddress);
            using (System.Net.WebClient request = new WebClient())
            {
                try
                {
                    request.AddCommmonHeaders(provider, address);
                    var t = request.DownloadEntryXml(saddress);
                    cgd = t?.content?.ConsumerGroupDescription;
                }
                catch (System.Net.WebException we)
                {
                    if ((we.Response as HttpWebResponse).StatusCode == HttpStatusCode.NotFound)
                    {
                        return(false);
                    }
                }
            }
            return(cgd != null);
        }
Exemple #3
0
        /// <summary>Retrieves an enumerable collection of all subscriptions in the service namespace.</summary>
        /// <param name="topicPath">The path of the topic relative to the service namespace base address.</param>
        /// <returns>An
        /// <see cref="T:System.Collections.Generic.IEnumerable`1" /> object that represents the collection of all subscriptions in the service namespace or returns an empty collection if no subscription exists.</returns>
        public IEnumerable <SubscriptionDescription> GetSubscriptions(string topicName)
        {
            CheckNameLength(topicName, MAXPATHLENGTH, "description.Path");
            string address, saddress;

            GetTopicFeedQueryAddresses(topicName, null, out address, out saddress);

            using (System.Net.WebClient request = new WebClient())
            {
                request.AddCommmonHeaders(provider, address, true, false);
                var t = request.DownloadString(saddress);
                System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(feed));
                var feed = (feed)xs.Deserialize(new StringReader(t));

                if (null == feed || null == feed.entry || 0 == feed.entry.Length || null == feed?.entry[0].content?.SubscriptionDescription)
                {
                    return(new SubscriptionDescription[0]);
                }

                SubscriptionDescription[] toReturn = new SubscriptionDescription[feed.entry.Length];

                for (int i = 0; i < toReturn.Length; ++i)
                {
                    string path = feed?.entry[i].title.Value;
                    //string path = feed?.entry?.content?.SubscriptionDescription[i].Name;
                    toReturn[i] = new SubscriptionDescription(topicName, path, feed.entry[i].content.SubscriptionDescription[i]);
                }

                return(toReturn);
            }
        }
Exemple #4
0
        /// <summary>Determines whether a subscription exists in the service namespace.</summary>
        /// <param name="topicPath">The path of the topic relative to the service namespace base address.</param>
        /// <param name="name">The name of the subscription.</param>
        /// <returns>true if a subscription exists in the service namespace; otherwise, false.</returns>
        public bool SubscriptionExists(string topicName, string subscriptionName)
        {
            CheckNameLength(topicName, MAXPATHLENGTH, "description.Path");
            CheckNameLength(subscriptionName, MAXNAMELENGTH, "description.Name");
            SubscriptionDescription sd = null;
            string address, saddress;

            GetAddressesNeeded(topicName, subscriptionName, out address, out saddress);
            using (System.Net.WebClient request = new WebClient())
            {
                request.AddCommmonHeaders(provider, address);
                try
                {
                    var t = request.DownloadEntryXml(saddress);
                    sd = new SubscriptionDescription(topicName, subscriptionName, t?.content?.SubscriptionDescription);
                }
                catch (WebException we)
                {
                    if ((we.Response as HttpWebResponse).StatusCode == HttpStatusCode.NotFound)
                    {
                        return(false);
                    }
                }
            }
            // build up the url like this:
            return(sd.xml != null);
        }
Exemple #5
0
 private entryContent Create(string xml, string address, string saddress)
 {
     using (System.Net.WebClient request = new WebClient())
     {
         request.AddCommmonHeaders(provider, address, true, true);
         var t = request.UploadEntryXml(saddress, xml);
         return(t?.content);
     }
 }
Exemple #6
0
        /// <summary>Deletes the topic described by path relative to the service namespace base address.</summary>
        /// <param name="topicName">The path of the topic relative to the service namespace base address.</param>
        public void DeleteTopic(string topicName)
        {
            CheckNameLength(topicName, MAXPATHLENGTH, "description.Path");
            string address, saddress;

            GetAddressesNeeded(topicName, out address, out saddress);
            using (System.Net.WebClient request = new WebClient())
            {
                request.AddCommmonHeaders(provider, address, false);
                request.UploadValues(saddress, "DELETE", new NameValueCollection());
            }
        }
Exemple #7
0
        //
        // Summary:
        //     Deletes a consumer group.
        //
        // Parameters:
        //   eventHubPath:
        //     The path to the Event Hub.
        //
        //   name:
        //     The name of the consumer group to delete.
        public void DeleteConsumerGroup(string eventHubName, string consumerGroupName)
        {
            CheckNameLength(eventHubName, MAXPATHLENGTH, "description.Path");
            CheckNameLength(consumerGroupName, MAXNAMELENGTH, "description.Name");
            string address, saddress;

            GetConsumerGroupAddressNeeded(eventHubName, consumerGroupName, out address, out saddress);
            using (System.Net.WebClient request = new WebClient())
            {
                request.AddCommmonHeaders(provider, address, false);
                request.UploadValues(saddress, "DELETE", new NameValueCollection());
            }
        }
Exemple #8
0
        /// <summary>Indicates whether or not an Event Hub exists.</summary>
        /// <param name="eventHubName">The path to the Event Hub.</param>
        /// <returns>Returns true if the Event Hub exists; otherwise, false.</returns>
        public bool EventHubExists(string eventHubName, out EventHubDescription qd)
        {
            string address, saddress;

            GetAddressesNeeded(eventHubName, out address, out saddress);
            using (System.Net.WebClient request = new WebClient())
            {
                request.AddCommmonHeaders(provider, address);
                var t = request.DownloadEntryXml(saddress);
                qd = t?.content?.EventHubDescription;
            }
            return(qd != null);
        }
Exemple #9
0
        /// <summary>Creates a new Event Hub using default values, for the given input path.</summary>
        /// <param name="eventHubName">The path to the Event Hub.</param>
        public EventHubDescription CreateEventHub(string eventHubName)
        {
            CheckNameLength(eventHubName, MAXPATHLENGTH, "description.Path");
            string defaultEventHubDescription = "<?xml version=\"1.0\" encoding=\"utf-8\"?><entry xmlns=\"http://www.w3.org/2005/Atom\"><id>uuid:84922a04-fd86-4062-be51-7d9732be9d4b;id=1</id><title type=\"text\"></title><updated>2018-05-02T07:10:21Z</updated><content type=\"application/atom+xml;type=entry;charset=utf-8\"><EventHubDescription xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://schemas.microsoft.com/netservices/2010/10/servicebus/connect\" /></content></entry>";
            string address, saddress;

            GetAddressesNeeded(eventHubName, out address, out saddress);
            using (System.Net.WebClient request = new WebClient())
            {
                request.AddCommmonHeaders(provider, address, true, true);
                var t = request.UploadEntryXml(saddress, defaultEventHubDescription);
                return(t?.content?.EventHubDescription);
            }
        }
Exemple #10
0
        /// <summary>Determines whether a queue exists in the service namespace.</summary>
        /// <param name="path">The path of the queue relative to the service namespace base address.</param>
        /// <returns>true if a queue exists in the service namespace; otherwise, false.</returns>
        public bool QueueExists(string queueName, out QueueDescription qd)
        {
            CheckNameLength(queueName, MAXPATHLENGTH, "description.Path");
            string address, saddress;

            GetAddressesNeeded(queueName, out address, out saddress);
            using (System.Net.WebClient request = new WebClient())
            {
                request.AddCommmonHeaders(provider, address);
                var t = request.DownloadEntryXml(saddress);
                qd = new QueueDescription(queueName, t?.content?.QueueDescription);
            }
            return(qd.xml != null);
        }
Exemple #11
0
        public bool PartitionExists(string eventHubName, string consumerGroupName, string partitionId, out PartitionDescription pd)
        {
            CheckNameLength(eventHubName, MAXPATHLENGTH, "description.Path");
            CheckNameLength(consumerGroupName, MAXNAMELENGTH, "description.Name");
            string address, saddress;

            GetConsumerGroupAddressNeeded(eventHubName, consumerGroupName, partitionId, out address, out saddress);
            using (System.Net.WebClient request = new WebClient())
            {
                request.AddCommmonHeaders(provider, address);
                var t = request.DownloadEntryXml(saddress);
                pd = t?.content?.PartitionDescription;
            }
            return(pd != null);
        }
Exemple #12
0
        //
        // Summary:
        //     Creates an Event Hubs consumer group using default values, with the specified
        //     Event Hubs path and a name for the consumer group.
        //
        // Parameters:
        //   eventHubPath:
        //     The path to the Event Hub.
        //
        //   name:
        //     The name of the consumer group.
        //
        // Returns:
        //     Returns Microsoft.ServiceBus.Messaging.ConsumerGroupDescription.
        public ConsumerGroupDescription CreateConsumerGroup(string eventHubName, string consumerGroup)
        {
            CheckNameLength(eventHubName, MAXPATHLENGTH, "description.Path");
            CheckNameLength(consumerGroup, MAXNAMELENGTH, "description.Name");
            string defaultConsumerGroupDescription = "<?xml version=\"1.0\" encoding=\"utf-8\"?><entry xmlns=\"http://www.w3.org/2005/Atom\"><id>uuid:271cb9d0-4bfa-427c-b474-b6172e46a0e2;id=2</id><title type=\"text\"></title><updated>2018-05-08T01:58:43Z</updated><content type=\"application/atom+xml;type=entry;charset=utf-8\"><ConsumerGroupDescription xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://schemas.microsoft.com/netservices/2010/10/servicebus/connect\" /></content></entry>";
            string address, saddress;

            GetConsumerGroupAddressNeeded(eventHubName, consumerGroup, out address, out saddress);
            using (System.Net.WebClient request = new WebClient())
            {
                request.AddCommmonHeaders(provider, address, true, true);
                var t = request.UploadEntryXml(saddress, defaultConsumerGroupDescription);
                return(t?.content?.ConsumerGroupDescription);
            }
        }
Exemple #13
0
        /// <summary>Determines whether a topic exists in the service namespace.</summary>
        /// <param name="path">The path of the topic relative to the service namespace base address.</param>
        /// <returns>true if a topic exists in the service namespace; otherwise, false.</returns>
        public bool TopicExists(string topicName)
        {
            CheckNameLength(topicName, MAXPATHLENGTH, "description.Path");
            TopicDescription td = null;
            string           address, saddress;

            GetAddressesNeeded(topicName, out address, out saddress);
            using (System.Net.WebClient request = new WebClient())
            {
                request.AddCommmonHeaders(provider, address);
                var t = request.DownloadEntryXml(saddress);
                td = new TopicDescription(topicName, t?.content?.TopicDescription);
            }
            // build up the url like this:
            return(td.xml != null);
        }