Skip to content
This repository was archived by the owner on Nov 16, 2023. It is now read-only.

Commit 7aa6ca0

Browse files
authored
(gh-pages): Fixing scrip to conditionally generate docs (#173)
1 parent 042befa commit 7aa6ca0

File tree

6 files changed

+59
-45
lines changed

6 files changed

+59
-45
lines changed

iot-hub/Samples/device/DeviceStreamingSample/DeviceClientStreamingSample.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@
1616
</ItemGroup>
1717

1818
<ItemGroup>
19-
<PackageReference Include="Microsoft.Azure.Devices.Client" Version="1.29.0-preview-*" />
19+
<PackageReference Include="Microsoft.Azure.Devices.Client" Version="1.32.0-preview-001" />
2020
</ItemGroup>
2121
</Project>

iot-hub/Samples/device/DeviceStreamingSample/DeviceStreamSample.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public async Task RunSampleAsync(bool acceptDeviceStreamingRequest = true)
3838
await _deviceClient.AcceptDeviceStreamRequestAsync(streamRequest, cts.Token);
3939

4040
using ClientWebSocket webSocket = await DeviceStreamingCommon.GetStreamingClientAsync(
41-
streamRequest.Url,
41+
streamRequest.Uri,
4242
streamRequest.AuthorizationToken,
4343
cts.Token);
4444

iot-hub/Samples/service/DeviceStreamingSample/DeviceStreamSample.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,25 @@ public async Task RunSampleAsync()
2727
{
2828
var deviceStreamRequest = new DeviceStreamRequest("TestStream");
2929

30-
DeviceStreamResponse result = await _serviceClient.CreateStreamAsync(_deviceId, deviceStreamRequest).ConfigureAwait(false);
30+
DeviceStreamResponse result = await _serviceClient.CreateStreamAsync(_deviceId, deviceStreamRequest);
3131

3232
Console.WriteLine($"Stream response received: Name={deviceStreamRequest.StreamName} IsAccepted={result.IsAccepted}");
3333

3434
if (result.IsAccepted)
3535
{
3636
using var cts = new CancellationTokenSource(TimeSpan.FromMinutes(1));
37-
using ClientWebSocket stream = await DeviceStreamingCommon.GetStreamingClientAsync(result.Url, result.AuthorizationToken, cts.Token).ConfigureAwait(false);
37+
using ClientWebSocket stream = await DeviceStreamingCommon.GetStreamingClientAsync(result.Uri, result.AuthorizationToken, cts.Token);
3838

3939
byte[] sendBuffer = Encoding.UTF8.GetBytes("Streaming data over a stream...");
4040
byte[] receiveBuffer = new byte[1024];
4141

42-
await stream.SendAsync(sendBuffer, WebSocketMessageType.Binary, true, cts.Token).ConfigureAwait(false);
42+
await stream.SendAsync(sendBuffer, WebSocketMessageType.Binary, true, cts.Token);
4343
Console.WriteLine($"Sent stream data: {Encoding.UTF8.GetString(sendBuffer, 0, sendBuffer.Length)}");
4444

45-
var receiveResult = await stream.ReceiveAsync(receiveBuffer, cts.Token).ConfigureAwait(false);
45+
var receiveResult = await stream.ReceiveAsync(receiveBuffer, cts.Token);
4646
Console.WriteLine($"Received stream data: {Encoding.UTF8.GetString(receiveBuffer, 0, receiveResult.Count)}");
47+
48+
await stream.CloseAsync(WebSocketCloseStatus.NormalClosure, "Streaming completed", new CancellationToken());
4749
}
4850
else
4951
{
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using CommandLine;
2+
using Microsoft.Azure.Devices;
3+
4+
namespace ServiceClientStreamingSample
5+
{
6+
/// <summary>
7+
/// Parameters for the application.
8+
/// </summary>
9+
internal class Parameters
10+
{
11+
[Option(
12+
'c',
13+
"HubConnectionString",
14+
Required = true,
15+
HelpText = "The connection string of the IoT Hub instance to connect to.")]
16+
public string HubConnectionString { get; set; }
17+
18+
[Option(
19+
'd',
20+
"DeviceId",
21+
Required = true,
22+
HelpText = "The Id of the device to connect to.")]
23+
public string DeviceId { get; set; }
24+
25+
[Option(
26+
't',
27+
"TransportType",
28+
Default = TransportType.Amqp,
29+
Required = false,
30+
HelpText = "The transport to use to communicate with the IoT Hub. Possible values include Amqp and Amqp_WebSocket_Only.")]
31+
public TransportType TransportType { get; set; }
32+
}
33+
}

iot-hub/Samples/service/DeviceStreamingSample/Program.cs

Lines changed: 16 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,31 @@
11
// Copyright (c) Microsoft. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

4+
using CommandLine;
5+
using ServiceClientStreamingSample;
46
using System;
57
using System.Threading.Tasks;
68

79
namespace Microsoft.Azure.Devices.Samples
810
{
911
public static class Program
1012
{
11-
// The IoT Hub connection string. This is available under the "Shared access policies" in the Azure portal.
12-
13-
// For this sample either:
14-
// - pass this value as a command-prompt argument
15-
// - set the IOTHUB_CONN_STRING_CSHARP environment variable
16-
// - create a launchSettings.json (see launchSettings.json.template) containing the variable
17-
private static string s_connectionString = Environment.GetEnvironmentVariable("IOTHUB_CONN_STRING_CSHARP");
18-
19-
// ID of the device to interact with.
20-
// - pass this value as a command-prompt argument
21-
// - set the DEVICE_ID environment variable
22-
// - create a launchSettings.json (see launchSettings.json.template) containing the variable
23-
private static string s_deviceId = Environment.GetEnvironmentVariable("DEVICE_ID");
24-
25-
// Select one of the following transports used by ServiceClient to connect to IoT Hub.
26-
private static TransportType s_transportType = TransportType.Amqp;
27-
//private static TransportType s_transportType = TransportType.Amqp_WebSocket_Only;
28-
2913
public static async Task<int> Main(string[] args)
3014
{
31-
if (string.IsNullOrEmpty(s_connectionString) && args.Length > 0)
32-
{
33-
s_connectionString = args[0];
34-
}
35-
36-
if (string.IsNullOrEmpty(s_deviceId) && args.Length > 1)
37-
{
38-
s_deviceId = args[1];
39-
}
40-
41-
if (string.IsNullOrEmpty(s_connectionString) ||
42-
string.IsNullOrEmpty(s_deviceId))
43-
{
44-
Console.WriteLine("Please provide a connection string and device ID");
45-
Console.WriteLine("Usage: ServiceClientC2DStreamingSample [iotHubConnString] [deviceId]");
46-
return 1;
47-
}
48-
49-
using ServiceClient serviceClient = ServiceClient.CreateFromConnectionString(s_connectionString, s_transportType);
50-
var sample = new DeviceStreamSample(serviceClient, s_deviceId);
15+
// Parse application parameters
16+
Parameters parameters = null;
17+
Parser.Default.ParseArguments<Parameters>(args)
18+
.WithParsed(parsedParams =>
19+
{
20+
parameters = parsedParams;
21+
})
22+
.WithNotParsed(errors =>
23+
{
24+
Environment.Exit(1);
25+
});
26+
27+
using ServiceClient serviceClient = ServiceClient.CreateFromConnectionString(parameters.HubConnectionString, parameters.TransportType);
28+
var sample = new DeviceStreamSample(serviceClient, parameters.DeviceId);
5129
await sample.RunSampleAsync().ConfigureAwait(false);
5230

5331
Console.WriteLine("Done.\n");

iot-hub/Samples/service/DeviceStreamingSample/ServiceClientStreamingSample.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@
1111
</ItemGroup>
1212

1313
<ItemGroup>
14+
<PackageReference Include="CommandLineParser" Version="2.8.0" />
1415
<PackageReference Include="System.Net.WebSockets.Client" Version="4.3.2" />
1516
</ItemGroup>
1617

1718
<ItemGroup>
18-
<PackageReference Include="Microsoft.Azure.Devices" Version="1.27.0-preview-004" />
19+
<PackageReference Include="Microsoft.Azure.Devices" Version="1.28.0-preview-001" />
1920
</ItemGroup>
2021

2122
</Project>

0 commit comments

Comments
 (0)