private void InitializeFromKeyValueManager(KeyValueConfigurationManager kvmManager)
        {
            try
            {
                // we should avoid caching KeyValueCofigurationManager because it internally
                // cache the connection string which might contain password information.
                kvmManager.Validate();

                // Endpoint
                var endpoint = kvmManager.connectionProperties[KeyValueConfigurationManager.EndpointConfigName];
                if (!string.IsNullOrEmpty(endpoint))
                {
                    this.Endpoint = new Uri(endpoint);
                }

                var sasKeyName = kvmManager.connectionProperties[KeyValueConfigurationManager.SharedAccessKeyName];
                if (!string.IsNullOrWhiteSpace(sasKeyName))
                {
                    this.SharedAccessKeyName = sasKeyName;
                }

                var sasValue = kvmManager.connectionProperties[KeyValueConfigurationManager.SharedAccessValueName];
                if (!string.IsNullOrWhiteSpace(sasValue))
                {
                    this.SharedAccessKey = sasValue;
                }
            }
            catch (Exception exception)
            {
                throw new ArgumentException(exception.Message, "connectionString", exception);
            }
        }
Exemple #2
0
        /// Initializes a new instance of <see cref="NamespaceManager"/> with settings
        /// <param name="connectionString">Namespace connection string</param>
        /// <param name="settings"> Namespace manager settings. </param>
        public NamespaceManager(string connectionString, NotificationHubSettings settings)
        {
            if (string.IsNullOrWhiteSpace(connectionString))
            {
                throw new ArgumentNullException(nameof(connectionString));
            }

            _tokenProvider = SharedAccessSignatureTokenProvider.CreateSharedAccessSignatureTokenProvider(connectionString);
            var configurationManager = new KeyValueConfigurationManager(connectionString);

            _baseUri = GetBaseUri(configurationManager);
            settings = settings ?? new NotificationHubSettings();

            if (settings.HttpClient != null)
            {
                _httpClient = settings.HttpClient;
            }
            else if (settings.MessageHandler != null)
            {
                var httpClientHandler = settings.MessageHandler;
                _httpClient = new HttpClient(httpClientHandler);
            }
            else if (settings.Proxy != null)
            {
                var httpClientHandler = new HttpClientHandler();
                httpClientHandler.UseProxy = true;
                httpClientHandler.Proxy    = settings.Proxy;
                _httpClient = new HttpClient(httpClientHandler);
            }
            else
            {
                _httpClient = new HttpClient();
            }

            if (settings.OperationTimeout == null)
            {
                OperationTimeout = TimeSpan.FromSeconds(60);
            }
            else
            {
                OperationTimeout = settings.OperationTimeout.Value;
            }

            _retryPolicy = settings.RetryOptions.ToRetryPolicy();

            _httpClient.Timeout = OperationTimeout;
            SetUserAgent();
        }
Exemple #3
0
        private static Uri GetBaseUri(KeyValueConfigurationManager manager)
        {
            var endpointString = manager.connectionProperties[KeyValueConfigurationManager.EndpointConfigName];

            return(new Uri(endpointString));
        }