/// <summary> /// Create DeviceClient from the specified connection string using a prioritized list of transports /// </summary> /// <param name="connectionString">Connection string for the IoT hub (with DeviceId)</param> /// <param name="transportSettings">Prioritized list of transports</param> /// <returns>DeviceClient</returns> public static DeviceClient CreateFromConnectionString(string connectionString, [System.Runtime.InteropServices.WindowsRuntime.ReadOnlyArrayAttribute] ITransportSettings[] transportSettings) { if (connectionString == null) { throw new ArgumentNullException("connectionString"); } if (transportSettings == null) { throw new ArgumentNullException("transportSettings"); } if (transportSettings.Length == 0) { throw new ArgumentOutOfRangeException("connectionString", "Must specify at least one TransportSettings instance"); } var iotHubConnectionString = IotHubConnectionString.Parse(connectionString); foreach (var transportSetting in transportSettings) { switch (transportSetting.GetTransportType()) { case TransportType.Amqp_WebSocket_Only: case TransportType.Amqp_Tcp_Only: if (!(transportSetting is AmqpTransportSettings)) { throw new InvalidOperationException("Unknown implementation of ITransportSettings type"); } break; case TransportType.Http1: if (!(transportSetting is Http1TransportSettings)) { throw new InvalidOperationException("Unknown implementation of ITransportSettings type"); } break; #if !WINDOWS_UWP case TransportType.Mqtt: if (!(transportSetting is MqttTransportSettings)) { throw new InvalidOperationException("Unknown implementation of ITransportSettings type"); } break; #endif default: throw new InvalidOperationException("Unsupported Transport Type {0}".FormatInvariant(transportSetting.GetTransportType())); } } // Defer concrete DeviceClient creation to OpenAsync return(new DeviceClient(iotHubConnectionString, transportSettings)); }
/// <summary> /// Create DeviceClient from the specified connection string /// </summary> /// <param name="connectionString">Connection string for the IoT hub</param> /// <returns>DeviceClient</returns> public static HttpDeviceClient CreateFromConnectionString(string connectionString) { if (connectionString == null) { throw new ArgumentNullException("connectionString"); } var iotHubConnectionString = IotHubConnectionString.Parse(connectionString); return(new HttpDeviceClient(iotHubConnectionString)); }
/// <summary> /// Create DeviceClient from the specified connection string /// </summary> /// <param name="connectionString">Connection string for the IoT hub</param> /// <returns>DeviceClient</returns> public static AmqpDeviceClient CreateFromConnectionString(string connectionString) { if (connectionString == null) { throw new ArgumentNullException("connectionString"); } var iotHubConnectionString = IotHubConnectionString.Parse(connectionString); return(new AmqpDeviceClient(iotHubConnectionString, new AmqpTransportSettings(TransportType.Amqp_Tcp_Only))); }
/// <summary> /// Create DeviceClient from the specified connection string using the specified transport type /// (PCL) Only Http transport is allowed /// </summary> /// <param name="connectionString">Connection string for the IoT hub (including DeviceId)</param> /// <param name="transportType">Specifies whether Amqp or Http transport is used</param> /// <returns>DeviceClient</returns> public static DeviceClient CreateFromConnectionString(string connectionString, TransportType transportType) { if (connectionString == null) { throw new ArgumentNullException("connectionString"); } switch (transportType) { case TransportType.Amqp: #if PCL throw new NotImplementedException("Amqp protocol is not supported"); #else return(CreateFromConnectionString(connectionString, new ITransportSettings[] { new AmqpTransportSettings(TransportType.Amqp_Tcp_Only), new AmqpTransportSettings(TransportType.Amqp_WebSocket_Only) })); #endif case TransportType.Mqtt: #if WINDOWS_UWP || PCL throw new NotImplementedException("Mqtt protocol is not supported"); #else return(CreateFromConnectionString(connectionString, new ITransportSettings[] { new MqttTransportSettings(transportType) })); #endif case TransportType.Amqp_WebSocket_Only: case TransportType.Amqp_Tcp_Only: #if PCL throw new NotImplementedException("Amqp protocol is not supported"); #else return(CreateFromConnectionString(connectionString, new ITransportSettings[] { new AmqpTransportSettings(transportType) })); #endif case TransportType.Http1: #if PCL var iotHubConnectionString = IotHubConnectionString.Parse(connectionString); return(new DeviceClient(new HttpTransportHandler(iotHubConnectionString), TransportType.Http1)); #else return(CreateFromConnectionString(connectionString, new ITransportSettings[] { new Http1TransportSettings() })); #endif default: #if !PCL throw new InvalidOperationException("Unsupported Transport Type {0}".FormatInvariant(transportType)); #else throw new InvalidOperationException(string.Format("Unsupported Transport Type {0}", transportType)); #endif } }
/// <summary> /// Create DeviceClient from the specified connection string using the specified transport type /// (WinRT) Only Http transport is allowed /// </summary> /// <param name="connectionString">Connection string for the IoT hub (including DeviceId)</param> /// <param name="transportType">Specifies whether Amqp or Http transport is used</param> /// <returns>DeviceClient</returns> public static DeviceClient CreateFromConnectionString(string connectionString, TransportType transportType) { if (connectionString == null) { throw new ArgumentNullException("connectionString"); } var iotHubConnectionString = IotHubConnectionString.Parse(connectionString); if (transportType == TransportType.Http1) { return(new DeviceClient(new HttpDeviceClient(iotHubConnectionString))); } else { throw new NotImplementedException(); } throw new InvalidOperationException("Unsupported Transport Type " + transportType.ToString()); }
/// <summary> /// Create DeviceClient from the specified connection string using the specified transport type /// (WinRT) Only Http transport is allowed /// </summary> /// <param name="connectionString">Connection string for the IoT hub (including DeviceId)</param> /// <param name="transportType">Specifies whether Amqp or Http transport is used</param> /// <returns>DeviceClient</returns> public static DeviceClient CreateFromConnectionString(string connectionString, TransportType transportType) { if (connectionString == null) { throw new ArgumentNullException("connectionString"); } var iotHubConnectionString = IotHubConnectionString.Parse(connectionString); if (transportType == TransportType.Amqp) { #if WINDOWS_UWP throw new NotImplementedException(); #else return(new DeviceClient(new AmqpDeviceClient(iotHubConnectionString))); #endif } else if (transportType == TransportType.Http1) { return(new DeviceClient(new HttpDeviceClient(iotHubConnectionString))); } throw new InvalidOperationException("Unsupported Transport Type {0}".FormatInvariant(transportType)); }