Exemplo n.º 1
0
        private static void SendTest(string sas)
        {
            var tokenProvider = SharedAccessSignatureTokenProvider.CreateSharedAccessSignatureTokenProvider(sas);

            var settings = new MessagingFactorySettings
            {
                TransportType = TransportType.Amqp,
                TokenProvider = tokenProvider
            };

            Uri runtimeUri = ServiceBusEnvironment.CreateServiceUri("sb", EventHubServiceNamespace, string.Empty);

            var mf = MessagingFactory.Create(runtimeUri, settings);

            var client = mf.CreateEventHubClient(EventHubName);

            var data = new EventData()
            {
                PartitionKey = "a"
            };

            // Set user properties if needed
            data.Properties.Add("Type", "Telemetry_" + DateTime.Now.ToLongTimeString());

            client.Send(data);
        }
Exemplo n.º 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();
        }