Exemplo n.º 1
0
        /// <summary>
        /// Create ServiceClient from the specified connection string using specified Transport Type
        /// </summary>
        /// <param name="connectionString">Connection string for the iothub</param>
        /// <param name="transportType">Specifies whether Amqp or Amqp over Websocket transport is used</param>
        /// <returns></returns>
        public static ServiceClient CreateFromConnectionString(string connectionString, TransportType transportType)
        {
            var iotHubConnectionString = IotHubConnectionString.Parse(connectionString);
            var serviceClient          = new AmqpServiceClient(iotHubConnectionString, (transportType == TransportType.Amqp_WebSocket_Only) ? true : false);

            return(serviceClient);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Create ServiceClient from the specified connection string
        /// </summary>
        /// <param name="connectionString">Connection string for the iothub</param>
        /// <returns></returns>
        public static ServiceClient CreateFromConnectionString(string connectionString)
        {
            var iotHubConnectionString = IotHubConnectionString.Parse(connectionString);
            var serviceClient          = new AmqpServiceClient(iotHubConnectionString);

            return(serviceClient);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Create ServiceClient from the specified connection string using specified Transport Type
        /// </summary>
        /// <param name="connectionString">Connection string for the iothub</param>
        /// <param name="transportType">Specifies whether Amqp or Amqp over Websocket transport is used</param>
        /// <param name="transportSettings">Specifies the AMQP and HTTP proxy settings for Service Client</param>
        /// <returns></returns>
        public static ServiceClient CreateFromConnectionString(string connectionString, TransportType transportType, ServiceClientTransportSettings transportSettings)
        {
            var  iotHubConnectionString = IotHubConnectionString.Parse(connectionString);
            bool useWebSocketOnly       = (transportType == TransportType.Amqp_WebSocket_Only);
            var  serviceClient          = new AmqpServiceClient(iotHubConnectionString, useWebSocketOnly, transportSettings);

            return(serviceClient);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Create an instance of ServiceClient from the specified IoT Hub connection string using specified Transport Type and transport settings.
        /// </summary>
        /// <param name="connectionString">Connection string for the IoT Hub.</param>
        /// <param name="transportType">The <see cref="TransportType"/> used (Amqp or Amqp_WebSocket_Only).</param>
        /// <param name="transportSettings">Specifies the AMQP and HTTP proxy settings for Service Client.</param>
        /// <param name="options">The <see cref="ServiceClientOptions"/> that allow configuration of the service client instance during initialization.</param>
        /// <returns>An instance of ServiceClient.</returns>
        public static ServiceClient CreateFromConnectionString(string connectionString, TransportType transportType, ServiceClientTransportSettings transportSettings, ServiceClientOptions options = default)
        {
            if (transportSettings == null)
            {
                throw new ArgumentNullException(nameof(transportSettings));
            }

            var  iotHubConnectionString = IotHubConnectionString.Parse(connectionString);
            bool useWebSocketOnly       = transportType == TransportType.Amqp_WebSocket_Only;
            var  serviceClient          = new AmqpServiceClient(iotHubConnectionString, useWebSocketOnly, transportSettings, options);

            return(serviceClient);
        }
Exemplo n.º 5
0
        public async Task PurgeMessageQueueDeviceNotFoundTest()
        {
            // Arrange Moq
            var restOpMock = new Mock<IHttpClientHelper>();

            restOpMock.Setup(restOp => restOp.DeleteAsync<PurgeMessageQueueResult>(
                It.IsAny<Uri>(), It.IsAny<IDictionary<HttpStatusCode, Func<HttpResponseMessage, Task<Exception>>>>(), null, It.IsAny<CancellationToken>())
                ).Throws(new DeviceNotFoundException("device-id"));

            // Instantiate AmqpServiceClient with Mock IHttpClientHelper
            var authMethod = new ServiceAuthenticationWithSharedAccessPolicyKey("test", "CQN2K33r45/0WeIjpqmErV5EIvX8JZrozt3NEHCEkG8=");
            var builder = IotHubConnectionStringBuilder.Create("acme.azure-devices.net", authMethod);
            var serviceClient = new AmqpServiceClient(builder.ToIotHubConnectionString(), false, restOpMock.Object);

            // Execute method under test
            PurgeMessageQueueResult result = await serviceClient.PurgeMessageQueueAsync("TestDevice", CancellationToken.None);
        }
Exemplo n.º 6
0
 /// <summary>
 /// Create ServiceClient from the specified connection string using specified Transport Type
 /// </summary>
 /// <param name="connectionString">Connection string for the iothub</param>
 /// <param name="transportType">Specifies whether Amqp or Amqp over Websocket transport is used</param>
 /// <returns></returns>
 public static ServiceClient CreateFromConnectionString(string connectionString, TransportType transportType)
 {
     var iotHubConnectionString = IotHubConnectionString.Parse(connectionString);
     var serviceClient = new AmqpServiceClient(iotHubConnectionString, (transportType == TransportType.Amqp_WebSocket) ? true : false);
     return serviceClient;
 }
Exemplo n.º 7
0
 /// <summary>
 /// Create ServiceClient from the specified connection string
 /// </summary>
 /// <param name="connectionString">Connection string for the iothub</param>
 /// <returns></returns>
 public static ServiceClient CreateFromConnectionString(string connectionString)
 {
     var iotHubConnectionString = IotHubConnectionString.Parse(connectionString);
     var serviceClient = new AmqpServiceClient(iotHubConnectionString);
     return serviceClient;
 }
Exemplo n.º 8
0
        Tuple<Mock<IHttpClientHelper>, AmqpServiceClient, PurgeMessageQueueResult> SetupPurgeMessageQueueTests()
        {
            // Create expected return object
            var deviceId = "TestDevice";
            var expectedResult = new PurgeMessageQueueResult()
            {
                DeviceId = deviceId,
                TotalMessagesPurged = 1
            };

            // Mock IHttpClientHelper to return expected object on DeleteAsync
            var restOpMock = new Mock<IHttpClientHelper>();

            restOpMock.Setup(restOp => restOp.DeleteAsync<PurgeMessageQueueResult>(
                It.IsAny<Uri>(), It.IsAny<IDictionary<HttpStatusCode, Func<HttpResponseMessage, Task<Exception>>>>(), null, It.IsAny<CancellationToken>())
                ).ReturnsAsync(expectedResult);

            // Instantiate AmqpServiceClient with Mock IHttpClientHelper
            var authMethod = new ServiceAuthenticationWithSharedAccessPolicyKey("test", "CQN2K33r45/0WeIjpqmErV5EIvX8JZrozt3NEHCEkG8=");
            var builder = IotHubConnectionStringBuilder.Create("acme.azure-devices.net", authMethod);
            var serviceClient = new AmqpServiceClient(builder.ToIotHubConnectionString(), false, restOpMock.Object);

            return Tuple.Create(restOpMock, serviceClient, expectedResult);
        }