Example #1
0
        /// <summary>Retrieves an enumerable collection of all rules in the service namespace.</summary>
        /// <param name="topicName">The path of the topic relative to the service namespace base address.</param>
        /// <param name="subscriptionName">The name of the subscription.</param>
        /// <returns>An
        /// <see cref="T:System.Collections.Generic.IEnumerable`1" /> object that represents the collection of all rules in the service namespace or returns an empty collection if no rule exists.</returns>
        public IEnumerable <RuleDescription> GetRules(string topicName, string subscriptionName)
        {
            CheckNameLength(topicName, MAXPATHLENGTH, "description.Path");
            CheckNameLength(subscriptionName, MAXNAMELENGTH, "description.Name");
            string address, saddress;

            GetTopicFeedQueryAddresses(topicName, subscriptionName, 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?.RuleDescription)
                {
                    return(new RuleDescription[0]);
                }

                RuleDescription[] toReturn = new RuleDescription[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] = feed.entry[i].content.RuleDescription[0];
                }

                return(toReturn);
            }
        }
        public void ReadXml(XmlReader reader)
        {
            reader.MoveToContent();
            IEnumerable <XElement> authRules = RuleDescription.SimpleStreamAxis(reader, new string[] { "AuthorizationRule" }).ToArray();

            foreach (var authRule in authRules)
            {
                var actionTypeAttrib = authRule?.Attributes()?.FirstOrDefault(p => p.Name.LocalName.Equals("type"));
                switch (actionTypeAttrib?.Value?.ToLower())
                {
                case "sharedaccessauthorizationrule":
                    //var expression = authRule?.Elements(XName.Get("{http://schemas.microsoft.com/netservices/2010/10/servicebus/connect}AuthorizationRule"));
                    System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(SharedAccessAuthorizationRule));
                    var stringReader = new StringReader(authRule.ToString());
                    SharedAccessAuthorizationRule rule = (SharedAccessAuthorizationRule)xs.Deserialize(stringReader);
                    this.Add(rule);
                    break;
                }
            }
        }
Example #3
0
 /// <summary>Creates a new subscription in the service namespace with the specified subscription description and rule description.</summary>
 /// <param name="description">A
 /// <see cref="T:Microsoft.ServiceBus.Messaging.SubscriptionDescription" /> object describing the attributes with which the new subscription will be created.</param>
 /// <param name="ruleDescription">A
 /// <see cref="T:Microsoft.ServiceBus.Messaging.RuleDescription" /> object describing the attributes with which the messages are matched and acted upon.</param>
 /// <returns>The <see cref="T:Microsoft.ServiceBus.Messaging.SubscriptionDescription" /> of the newly created subscription.</returns>
 /// <remarks> A default rule will be created using data from <paramref name="ruleDescription" />.
 /// If <see cref="P:Microsoft.ServiceBus.Messaging.RuleDescription.Name" /> is null or white space, then the name of the rule
 /// created will be <see cref="F:Microsoft.ServiceBus.Messaging.RuleDescription.DefaultRuleName" />. </remarks>
 public SubscriptionDescription CreateSubscription(SubscriptionDescription description, RuleDescription ruleDescription)
 {
     description.xml.DefaultRuleDescription = ruleDescription;
     return(CreateSubscription(description));
 }
Example #4
0
        /// <summary>Creates a new subscription in the service namespace with the specified topic path, subscription name, and rule description.</summary>
        /// <param name="topicName">The topic path relative to the service namespace base address.</param>
        /// <param name="subscriptionName">The name of the subscription.</param>
        /// <param name="ruleDescription">A
        /// <see cref="T:Microsoft.ServiceBus.Messaging.RuleDescription" /> object describing the attributes with which the messages are matched and acted upon.</param>
        /// <returns>The <see cref="T:Microsoft.ServiceBus.Messaging.SubscriptionDescription" /> of the newly created subscription.</returns>
        /// <remarks> A default rule will be created using data from <paramref name="ruleDescription" />.
        /// If <see cref="P:Microsoft.ServiceBus.Messaging.RuleDescription.Name" /> is null or white space, then the name of the rule
        /// created will be <see cref="F:Microsoft.ServiceBus.Messaging.RuleDescription.DefaultRuleName" />. </remarks>
        public SubscriptionDescription CreateSubscription(string topicName, string subscriptionName, RuleDescription ruleDescription)
        {
            CheckNameLength(topicName, MAXPATHLENGTH, "description.Path");
            CheckNameLength(subscriptionName, MAXNAMELENGTH, "description.Name");
            SubscriptionDescription description = new SubscriptionDescription(topicName, subscriptionName);

            description.xml.DefaultRuleDescription = ruleDescription;
            return(CreateSubscription(description));
        }