From 5a0caafda65993da116af0545178349ce83f841d Mon Sep 17 00:00:00 2001 From: Azad Abbasi Date: Wed, 9 Dec 2020 10:53:16 -0800 Subject: [PATCH 1/2] Fix QuickStart samples build --- .../device/DeviceLocalProxyStreamingSample.csproj | 4 ++-- .../device/DeviceStreamSample.cs | 14 +++++++------- .../device-streams-proxy/device/Program.cs | 4 ++-- .../service/DeviceStreamSample.cs | 12 ++++++------ .../device-streams-proxy/service/Program.cs | 2 +- .../ServiceLocalProxyStreamingSample.csproj | 4 ++-- 6 files changed, 20 insertions(+), 20 deletions(-) diff --git a/iot-hub/Quickstarts/device-streams-proxy/device/DeviceLocalProxyStreamingSample.csproj b/iot-hub/Quickstarts/device-streams-proxy/device/DeviceLocalProxyStreamingSample.csproj index 9539ad07..39cfed8e 100644 --- a/iot-hub/Quickstarts/device-streams-proxy/device/DeviceLocalProxyStreamingSample.csproj +++ b/iot-hub/Quickstarts/device-streams-proxy/device/DeviceLocalProxyStreamingSample.csproj @@ -14,7 +14,7 @@ - + - + diff --git a/iot-hub/Quickstarts/device-streams-proxy/device/DeviceStreamSample.cs b/iot-hub/Quickstarts/device-streams-proxy/device/DeviceStreamSample.cs index 6dac5491..4407d864 100644 --- a/iot-hub/Quickstarts/device-streams-proxy/device/DeviceStreamSample.cs +++ b/iot-hub/Quickstarts/device-streams-proxy/device/DeviceStreamSample.cs @@ -14,11 +14,11 @@ namespace Microsoft.Azure.Devices.Client.Samples { public class DeviceStreamSample { - private DeviceClient _deviceClient; - private String _host; - private int _port; + private readonly DeviceClient _deviceClient; + private readonly string _host; + private readonly int _port; - public DeviceStreamSample(DeviceClient deviceClient, String host, int port) + public DeviceStreamSample(DeviceClient deviceClient, string host, int port) { _deviceClient = deviceClient; _host = host; @@ -44,7 +44,7 @@ private static async Task HandleOutgoingDataAsync(NetworkStream localStream, Cli while (localStream.CanRead) { int receiveCount = await localStream.ReadAsync(buffer, 0, buffer.Length).ConfigureAwait(false); - + await remoteStream.SendAsync(new ArraySegment(buffer, 0, receiveCount), WebSocketMessageType.Binary, true, cancellationToken).ConfigureAwait(false); } } @@ -75,7 +75,7 @@ public async Task RunSampleAsync(bool acceptDeviceStreamingRequest, Cancellation { await _deviceClient.AcceptDeviceStreamRequestAsync(streamRequest, cancellationTokenSource.Token).ConfigureAwait(false); - using (ClientWebSocket webSocket = await DeviceStreamingCommon.GetStreamingClientAsync(streamRequest.Url, streamRequest.AuthorizationToken, cancellationTokenSource.Token).ConfigureAwait(false)) + using (ClientWebSocket webSocket = await DeviceStreamingCommon.GetStreamingClientAsync(streamRequest.Uri, streamRequest.AuthorizationToken, cancellationTokenSource.Token).ConfigureAwait(false)) { using (TcpClient tcpClient = new TcpClient()) { @@ -93,7 +93,7 @@ await Task.WhenAny( } } - await webSocket.CloseAsync(WebSocketCloseStatus.NormalClosure, String.Empty, cancellationTokenSource.Token).ConfigureAwait(false); + await webSocket.CloseAsync(WebSocketCloseStatus.NormalClosure, string.Empty, cancellationTokenSource.Token).ConfigureAwait(false); } } else diff --git a/iot-hub/Quickstarts/device-streams-proxy/device/Program.cs b/iot-hub/Quickstarts/device-streams-proxy/device/Program.cs index b27caab8..a8b65fd2 100644 --- a/iot-hub/Quickstarts/device-streams-proxy/device/Program.cs +++ b/iot-hub/Quickstarts/device-streams-proxy/device/Program.cs @@ -9,7 +9,7 @@ namespace Microsoft.Azure.Devices.Client.Samples { public static class Program { - // String containing Hostname, Device Id & Device Key in one of the following formats: + // String containing Host Name, Device Id & Device Key in one of the following formats: // "HostName=;DeviceId=;SharedAccessKey=" // "HostName=;CredentialType=SharedAccessSignature;DeviceId=;SharedAccessSignature=SharedAccessSignature sr=/devices/&sig=&se="; @@ -32,7 +32,7 @@ public static class Program private static string s_port = Environment.GetEnvironmentVariable("REMOTE_PORT"); // Select one of the following transports used by DeviceClient to connect to IoT Hub. - private static TransportType s_transportType = TransportType.Amqp; + private static readonly TransportType s_transportType = TransportType.Amqp; //private static TransportType s_transportType = TransportType.Mqtt; //private static TransportType s_transportType = TransportType.Amqp_WebSocket_Only; //private static TransportType s_transportType = TransportType.Mqtt_WebSocket_Only; diff --git a/iot-hub/Quickstarts/device-streams-proxy/service/DeviceStreamSample.cs b/iot-hub/Quickstarts/device-streams-proxy/service/DeviceStreamSample.cs index 38bd04c0..282e8a22 100644 --- a/iot-hub/Quickstarts/device-streams-proxy/service/DeviceStreamSample.cs +++ b/iot-hub/Quickstarts/device-streams-proxy/service/DeviceStreamSample.cs @@ -14,11 +14,11 @@ namespace Microsoft.Azure.Devices.Samples { public class DeviceStreamSample { - private ServiceClient _serviceClient; - private String _deviceId; - private int _localPort; + private readonly ServiceClient _serviceClient; + private readonly string _deviceId; + private readonly int _localPort; - public DeviceStreamSample(ServiceClient deviceClient, String deviceId, int localPort) + public DeviceStreamSample(ServiceClient deviceClient, string deviceId, int localPort) { _serviceClient = deviceClient; _deviceId = deviceId; @@ -66,7 +66,7 @@ private static async void HandleIncomingConnectionsAndCreateStreams(string devic try { using (var cancellationTokenSource = new CancellationTokenSource()) - using (var remoteStream = await DeviceStreamingCommon.GetStreamingClientAsync(result.Url, result.AuthorizationToken, cancellationTokenSource.Token).ConfigureAwait(false)) + using (var remoteStream = await DeviceStreamingCommon.GetStreamingClientAsync(result.Uri, result.AuthorizationToken, cancellationTokenSource.Token).ConfigureAwait(false)) { Console.WriteLine("Starting streaming"); @@ -75,7 +75,7 @@ await Task.WhenAny( HandleOutgoingDataAsync(localStream, remoteStream, cancellationTokenSource.Token)).ConfigureAwait(false); } - Console.WriteLine("Done streaming"); + Console.WriteLine("Done streaming"); } catch (Exception ex) { diff --git a/iot-hub/Quickstarts/device-streams-proxy/service/Program.cs b/iot-hub/Quickstarts/device-streams-proxy/service/Program.cs index 1f5c9a7b..8b30864a 100644 --- a/iot-hub/Quickstarts/device-streams-proxy/service/Program.cs +++ b/iot-hub/Quickstarts/device-streams-proxy/service/Program.cs @@ -29,7 +29,7 @@ public static class Program private static string s_port = Environment.GetEnvironmentVariable("LOCAL_PORT"); // Select one of the following transports used by ServiceClient to connect to IoT Hub. - private static TransportType s_transportType = TransportType.Amqp; + private static readonly TransportType s_transportType = TransportType.Amqp; //private static TransportType s_transportType = TransportType.Amqp_WebSocket_Only; public static int Main(string[] args) diff --git a/iot-hub/Quickstarts/device-streams-proxy/service/ServiceLocalProxyStreamingSample.csproj b/iot-hub/Quickstarts/device-streams-proxy/service/ServiceLocalProxyStreamingSample.csproj index 603664bd..c012dc6e 100644 --- a/iot-hub/Quickstarts/device-streams-proxy/service/ServiceLocalProxyStreamingSample.csproj +++ b/iot-hub/Quickstarts/device-streams-proxy/service/ServiceLocalProxyStreamingSample.csproj @@ -10,9 +10,9 @@ - + - + From 6765560823006bf0b05a60ab40eebba6130aeae6 Mon Sep 17 00:00:00 2001 From: Azad Abbasi Date: Wed, 9 Dec 2020 11:03:35 -0800 Subject: [PATCH 2/2] Address comments --- iot-hub/Quickstarts/device-streams-proxy/device/Program.cs | 6 +++--- iot-hub/Quickstarts/device-streams-proxy/service/Program.cs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/iot-hub/Quickstarts/device-streams-proxy/device/Program.cs b/iot-hub/Quickstarts/device-streams-proxy/device/Program.cs index a8b65fd2..e67d6f4c 100644 --- a/iot-hub/Quickstarts/device-streams-proxy/device/Program.cs +++ b/iot-hub/Quickstarts/device-streams-proxy/device/Program.cs @@ -33,9 +33,9 @@ public static class Program // Select one of the following transports used by DeviceClient to connect to IoT Hub. private static readonly TransportType s_transportType = TransportType.Amqp; - //private static TransportType s_transportType = TransportType.Mqtt; - //private static TransportType s_transportType = TransportType.Amqp_WebSocket_Only; - //private static TransportType s_transportType = TransportType.Mqtt_WebSocket_Only; + //private static readonly TransportType s_transportType = TransportType.Mqtt; + //private static readonly TransportType s_transportType = TransportType.Amqp_WebSocket_Only; + //private static readonly TransportType s_transportType = TransportType.Mqtt_WebSocket_Only; public static int Main(string[] args) { diff --git a/iot-hub/Quickstarts/device-streams-proxy/service/Program.cs b/iot-hub/Quickstarts/device-streams-proxy/service/Program.cs index 8b30864a..b4ebcc45 100644 --- a/iot-hub/Quickstarts/device-streams-proxy/service/Program.cs +++ b/iot-hub/Quickstarts/device-streams-proxy/service/Program.cs @@ -30,7 +30,7 @@ public static class Program // Select one of the following transports used by ServiceClient to connect to IoT Hub. private static readonly TransportType s_transportType = TransportType.Amqp; - //private static TransportType s_transportType = TransportType.Amqp_WebSocket_Only; + //private static readonly TransportType s_transportType = TransportType.Amqp_WebSocket_Only; public static int Main(string[] args) {