Ejemplo n.º 1
0
        private MessagingFactory CreateFactory(IEnumerable <Uri> endpoints, IEnumerable <Uri> stsEndpoints, string operationTimeout, string issuerName, string issuerKey, string sasKeyName, string sasKey, string windowsDomain, string windowsUser, SecureString windowsPassword, string oauthDomain, string oauthUser, SecureString oauthPassword, string transportType)
        {
            MessagingFactory messagingFactory;

            try
            {
                MessagingFactorySettings messagingFactorySetting = new MessagingFactorySettings();
                if (!string.IsNullOrWhiteSpace(transportType))
                {
                    messagingFactorySetting.TransportType = (Microsoft.ServiceBus.Messaging.TransportType)Enum.Parse(typeof(Microsoft.ServiceBus.Messaging.TransportType), transportType);
                }
                messagingFactorySetting.TokenProvider = KeyValueConfigurationManager.CreateTokenProvider(stsEndpoints, issuerName, issuerKey, sasKeyName, sasKey, windowsDomain, windowsUser, windowsPassword, oauthDomain, oauthUser, oauthPassword);
                if (!string.IsNullOrEmpty(operationTimeout))
                {
                    messagingFactorySetting.OperationTimeout = TimeSpan.Parse(operationTimeout, CultureInfo.CurrentCulture);
                }
                messagingFactory = MessagingFactory.Create(endpoints, messagingFactorySetting);
            }
            catch (ArgumentException argumentException1)
            {
                ArgumentException argumentException = argumentException1;
                throw new ConfigurationErrorsException(SRClient.AppSettingsCreateFactoryWithInvalidConnectionString(argumentException.Message), argumentException);
            }
            catch (UriFormatException uriFormatException1)
            {
                UriFormatException uriFormatException = uriFormatException1;
                throw new ConfigurationErrorsException(SRClient.AppSettingsCreateFactoryWithInvalidConnectionString(uriFormatException.Message), uriFormatException);
            }
            return(messagingFactory);
        }
Ejemplo n.º 2
0
 private void Initialize(string connection, Microsoft.ServiceBus.Messaging.TransportType?transportType)
 {
     this.connectionString = connection;
     if (transportType.HasValue)
     {
         ServiceBusConnectionStringBuilder serviceBusConnectionStringBuilder = new ServiceBusConnectionStringBuilder(this.connectionString)
         {
             TransportType = transportType.Value
         };
         this.connectionString = serviceBusConnectionStringBuilder.ToString();
     }
     this.connectionProperties = KeyValueConfigurationManager.CreateNameValueCollectionFromConnectionString(this.connectionString);
 }
Ejemplo n.º 3
0
        public NamespaceManager CreateNamespaceManager()
        {
            NamespaceManager namespaceManager;

            this.Validate();
            string            item = this.connectionProperties["OperationTimeout"];
            IEnumerable <Uri> endpointAddresses = KeyValueConfigurationManager.GetEndpointAddresses(this.connectionProperties["Endpoint"], this.connectionProperties["ManagementPort"]);
            IEnumerable <Uri> uris            = KeyValueConfigurationManager.GetEndpointAddresses(this.connectionProperties["StsEndpoint"], null);
            string            str             = this.connectionProperties["SharedSecretIssuer"];
            string            item1           = this.connectionProperties["SharedSecretValue"];
            string            str1            = this.connectionProperties["SharedAccessKeyName"];
            string            item2           = this.connectionProperties["SharedAccessKey"];
            string            str2            = this.connectionProperties["WindowsDomain"];
            string            item3           = this.connectionProperties["WindowsUsername"];
            SecureString      windowsPassword = this.GetWindowsPassword();
            string            str3            = this.connectionProperties["OAuthDomain"];
            string            item4           = this.connectionProperties["OAuthUsername"];
            SecureString      oAuthPassword   = this.GetOAuthPassword();

            try
            {
                TokenProvider tokenProvider = KeyValueConfigurationManager.CreateTokenProvider(uris, str, item1, str1, item2, str2, item3, windowsPassword, str3, item4, oAuthPassword);
                if (!string.IsNullOrEmpty(item))
                {
                    NamespaceManagerSettings namespaceManagerSetting = new NamespaceManagerSettings()
                    {
                        OperationTimeout = TimeSpan.Parse(item, CultureInfo.CurrentCulture),
                        TokenProvider    = tokenProvider
                    };
                    namespaceManager = new NamespaceManager(endpointAddresses, namespaceManagerSetting);
                }
                else
                {
                    namespaceManager = new NamespaceManager(endpointAddresses, tokenProvider);
                }
            }
            catch (ArgumentException argumentException1)
            {
                ArgumentException argumentException = argumentException1;
                throw new ConfigurationErrorsException(SRClient.AppSettingsCreateManagerWithInvalidConnectionString(argumentException.Message), argumentException);
            }
            catch (UriFormatException uriFormatException1)
            {
                UriFormatException uriFormatException = uriFormatException1;
                throw new ConfigurationErrorsException(SRClient.AppSettingsCreateManagerWithInvalidConnectionString(uriFormatException.Message), uriFormatException);
            }
            return(namespaceManager);
        }
Ejemplo n.º 4
0
        internal TokenProvider CreateTokenProvider()
        {
            IEnumerable <Uri> endpointAddresses = KeyValueConfigurationManager.GetEndpointAddresses(this.connectionProperties["StsEndpoint"], null);
            string            item            = this.connectionProperties["SharedSecretIssuer"];
            string            str             = this.connectionProperties["SharedSecretValue"];
            string            item1           = this.connectionProperties["SharedAccessKeyName"];
            string            str1            = this.connectionProperties["SharedAccessKey"];
            string            item2           = this.connectionProperties["WindowsDomain"];
            string            str2            = this.connectionProperties["WindowsUsername"];
            SecureString      windowsPassword = this.GetWindowsPassword();
            string            item3           = this.connectionProperties["OAuthDomain"];
            string            str3            = this.connectionProperties["OAuthUsername"];
            SecureString      oAuthPassword   = this.GetOAuthPassword();

            return(KeyValueConfigurationManager.CreateTokenProvider(endpointAddresses, item, str, item1, str1, item2, str2, windowsPassword, item3, str3, oAuthPassword));
        }
Ejemplo n.º 5
0
        private MessagingFactory GetOrUpdateFactory(IEnumerable <Uri> endpoints, IEnumerable <Uri> stsEndpoints, string operationTimeout, string issuerName, string issuerKey, string sasKeyName, string sasKey, string windowsDomain, string windowsUser, SecureString windowsPassword, string oauthDomain, string oauthUser, SecureString oauthPassword, string transportType)
        {
            MessagingFactory messagingFactory;

            lock (KeyValueConfigurationManager.CachedFactories.Value)
            {
                MessagingFactory messagingFactory1 = this.CreateFactory(endpoints, stsEndpoints, operationTimeout, issuerName, issuerKey, sasKeyName, sasKey, windowsDomain, windowsUser, windowsPassword, oauthDomain, oauthUser, oauthPassword, transportType);
                MessagingFactory orAdd             = KeyValueConfigurationManager.CachedFactories.Value.GetOrAdd("Microsoft.ServiceBus.ConnectionString", messagingFactory1);
                if (!KeyValueConfigurationManager.FactoryEquals(orAdd, messagingFactory1) || orAdd.IsClosedOrClosing)
                {
                    KeyValueConfigurationManager.CachedFactories.Value["Microsoft.ServiceBus.ConnectionString"] = messagingFactory1;
                    messagingFactory = messagingFactory1;
                }
                else
                {
                    messagingFactory = orAdd;
                }
            }
            return(messagingFactory);
        }
Ejemplo n.º 6
0
        public MessagingFactory CreateMessagingFactory(bool useCachedFactory)
        {
            this.Validate();
            string            item = this.connectionProperties["OperationTimeout"];
            IEnumerable <Uri> endpointAddresses = this.GetEndpointAddresses();
            IEnumerable <Uri> uris            = KeyValueConfigurationManager.GetEndpointAddresses(this.connectionProperties["StsEndpoint"], null);
            string            str             = this.connectionProperties["SharedSecretIssuer"];
            string            item1           = this.connectionProperties["SharedSecretValue"];
            string            str1            = this.connectionProperties["SharedAccessKeyName"];
            string            item2           = this.connectionProperties["SharedAccessKey"];
            string            str2            = this.connectionProperties["WindowsDomain"];
            string            item3           = this.connectionProperties["WindowsUsername"];
            SecureString      windowsPassword = this.GetWindowsPassword();
            string            str3            = this.connectionProperties["OAuthDomain"];
            string            item4           = this.connectionProperties["OAuthUsername"];
            SecureString      oAuthPassword   = this.GetOAuthPassword();
            string            str4            = this.connectionProperties["TransportType"];

            if (!useCachedFactory)
            {
                return(this.CreateFactory(endpointAddresses, uris, item, str, item1, str1, item2, str2, item3, windowsPassword, str3, item4, oAuthPassword, str4));
            }
            return(this.GetOrUpdateFactory(endpointAddresses, uris, item, str, item1, str1, item2, str2, item3, windowsPassword, str3, item4, oAuthPassword, str4));
        }
Ejemplo n.º 7
0
 internal IList <Uri> GetEndpointAddresses()
 {
     return(KeyValueConfigurationManager.GetEndpointAddresses(this.connectionProperties["Endpoint"], this.connectionProperties["RuntimePort"]));
 }