예제 #1
0
        public static IAzureServiceBusEndpointAddress Parse(Uri address, IConnectionSettings connectionSettings = null)
        {
            Guard.AgainstNull(address, "address");

            if (string.Compare(Constants.Scheme, address.Scheme, StringComparison.OrdinalIgnoreCase) != 0)
            {
                throw new EndpointException(address, "The invalid scheme was specified: " + address.Scheme);
            }

            string name = address.AbsolutePath.TrimStart('/');

            var endpoint = new UriBuilder("sb", address.Host, 0, name).Uri;

            string keyName = null;
            string key     = null;

            if (!address.UserInfo.IsEmpty())
            {
                if (address.UserInfo.Contains(":"))
                {
                    string[] parts = address.UserInfo.Split(':');
                    keyName = parts[0];
                    key     = parts[1];
                }
            }

            string issuer = address.Query.GetValueFromQueryString("KeyName");

            if (!string.IsNullOrWhiteSpace(issuer))
            {
                keyName = issuer;
            }

            string value = address.Query.GetValueFromQueryString("Key");

            if (!string.IsNullOrWhiteSpace(value))
            {
                key = value;
            }

            bool        topic       = address.Query.GetValueFromQueryString("topic", false);
            AddressType addressType = topic
                                          ? AddressType.Topic
                                          : AddressType.Queue;

            VerifyQueueOrTopicNameAreLegal(address, name);

            int prefetchCount = address.Query.GetValueFromQueryString("prefetch", 100);

            string ns = address.Host;

            if (keyName == null && connectionSettings != null)
            {
                keyName = connectionSettings.KeyName;
            }

            if (key == null && connectionSettings != null)
            {
                key = connectionSettings.Key;
            }

            if (keyName == null || key == null)
            {
                throw new ArgumentException("The Key or KeyName was not specified");
            }

            var settings = new SharedAccessSignatureConnectionSettings(keyName, key);

            return(new AzureServiceBusEndpointAddress(addressType, ns, name, settings, prefetchCount));
        }
        public static IAzureServiceBusEndpointAddress Parse(Uri address, IConnectionSettings connectionSettings = null)
        {
            Guard.AgainstNull(address, "address");

            if (string.Compare(Constants.Scheme, address.Scheme, StringComparison.OrdinalIgnoreCase) != 0)
                throw new EndpointException(address, "The invalid scheme was specified: " + address.Scheme);

            string name = address.AbsolutePath.TrimStart('/');

            var endpoint = new UriBuilder("sb", address.Host, 0, name).Uri;

            string keyName = null;
            string key = null;

            if (!address.UserInfo.IsEmpty())
            {
                if (address.UserInfo.Contains(":"))
                {
                    string[] parts = address.UserInfo.Split(':');
                    keyName = parts[0];
                    key = parts[1];
                }
            }

            string issuer = address.Query.GetValueFromQueryString("KeyName");
            if (!string.IsNullOrWhiteSpace(issuer))
                keyName = issuer;

            string value = address.Query.GetValueFromQueryString("Key");
            if (!string.IsNullOrWhiteSpace(value))
                key = value;

            bool topic = address.Query.GetValueFromQueryString("topic", false);
            AddressType addressType = topic
                                          ? AddressType.Topic
                                          : AddressType.Queue;

            VerifyQueueOrTopicNameAreLegal(address, name);

            int prefetchCount = address.Query.GetValueFromQueryString("prefetch", 100);

            string ns = address.Host;

            if (keyName == null && connectionSettings != null)
                keyName = connectionSettings.KeyName;

            if (key == null && connectionSettings != null)
                key = connectionSettings.Key;

            if (keyName == null || key == null)
                throw new ArgumentException("The Key or KeyName was not specified");

            var settings = new SharedAccessSignatureConnectionSettings(keyName, key);

            return new AzureServiceBusEndpointAddress(addressType, ns, name, settings, prefetchCount);
        }