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

Commit

Permalink
(gh-pages): Fixing scrip to conditionally generate docs (#173)
Browse files Browse the repository at this point in the history
  • Loading branch information
vinagesh authored Dec 10, 2020
1 parent 042befa commit 7aa6ca0
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Devices.Client" Version="1.29.0-preview-*" />
<PackageReference Include="Microsoft.Azure.Devices.Client" Version="1.32.0-preview-001" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public async Task RunSampleAsync(bool acceptDeviceStreamingRequest = true)
await _deviceClient.AcceptDeviceStreamRequestAsync(streamRequest, cts.Token);

using ClientWebSocket webSocket = await DeviceStreamingCommon.GetStreamingClientAsync(
streamRequest.Url,
streamRequest.Uri,
streamRequest.AuthorizationToken,
cts.Token);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,25 @@ public async Task RunSampleAsync()
{
var deviceStreamRequest = new DeviceStreamRequest("TestStream");

DeviceStreamResponse result = await _serviceClient.CreateStreamAsync(_deviceId, deviceStreamRequest).ConfigureAwait(false);
DeviceStreamResponse result = await _serviceClient.CreateStreamAsync(_deviceId, deviceStreamRequest);

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

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

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

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

var receiveResult = await stream.ReceiveAsync(receiveBuffer, cts.Token).ConfigureAwait(false);
var receiveResult = await stream.ReceiveAsync(receiveBuffer, cts.Token);
Console.WriteLine($"Received stream data: {Encoding.UTF8.GetString(receiveBuffer, 0, receiveResult.Count)}");

await stream.CloseAsync(WebSocketCloseStatus.NormalClosure, "Streaming completed", new CancellationToken());
}
else
{
Expand Down
33 changes: 33 additions & 0 deletions iot-hub/Samples/service/DeviceStreamingSample/Parameters.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using CommandLine;
using Microsoft.Azure.Devices;

namespace ServiceClientStreamingSample
{
/// <summary>
/// Parameters for the application.
/// </summary>
internal class Parameters
{
[Option(
'c',
"HubConnectionString",
Required = true,
HelpText = "The connection string of the IoT Hub instance to connect to.")]
public string HubConnectionString { get; set; }

[Option(
'd',
"DeviceId",
Required = true,
HelpText = "The Id of the device to connect to.")]
public string DeviceId { get; set; }

[Option(
't',
"TransportType",
Default = TransportType.Amqp,
Required = false,
HelpText = "The transport to use to communicate with the IoT Hub. Possible values include Amqp and Amqp_WebSocket_Only.")]
public TransportType TransportType { get; set; }
}
}
54 changes: 16 additions & 38 deletions iot-hub/Samples/service/DeviceStreamingSample/Program.cs
Original file line number Diff line number Diff line change
@@ -1,53 +1,31 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using CommandLine;
using ServiceClientStreamingSample;
using System;
using System.Threading.Tasks;

namespace Microsoft.Azure.Devices.Samples
{
public static class Program
{
// The IoT Hub connection string. This is available under the "Shared access policies" in the Azure portal.

// For this sample either:
// - pass this value as a command-prompt argument
// - set the IOTHUB_CONN_STRING_CSHARP environment variable
// - create a launchSettings.json (see launchSettings.json.template) containing the variable
private static string s_connectionString = Environment.GetEnvironmentVariable("IOTHUB_CONN_STRING_CSHARP");

// ID of the device to interact with.
// - pass this value as a command-prompt argument
// - set the DEVICE_ID environment variable
// - create a launchSettings.json (see launchSettings.json.template) containing the variable
private static string s_deviceId = Environment.GetEnvironmentVariable("DEVICE_ID");

// Select one of the following transports used by ServiceClient to connect to IoT Hub.
private static TransportType s_transportType = TransportType.Amqp;
//private static TransportType s_transportType = TransportType.Amqp_WebSocket_Only;

public static async Task<int> Main(string[] args)
{
if (string.IsNullOrEmpty(s_connectionString) && args.Length > 0)
{
s_connectionString = args[0];
}

if (string.IsNullOrEmpty(s_deviceId) && args.Length > 1)
{
s_deviceId = args[1];
}

if (string.IsNullOrEmpty(s_connectionString) ||
string.IsNullOrEmpty(s_deviceId))
{
Console.WriteLine("Please provide a connection string and device ID");
Console.WriteLine("Usage: ServiceClientC2DStreamingSample [iotHubConnString] [deviceId]");
return 1;
}

using ServiceClient serviceClient = ServiceClient.CreateFromConnectionString(s_connectionString, s_transportType);
var sample = new DeviceStreamSample(serviceClient, s_deviceId);
// Parse application parameters
Parameters parameters = null;
Parser.Default.ParseArguments<Parameters>(args)
.WithParsed(parsedParams =>
{
parameters = parsedParams;
})
.WithNotParsed(errors =>
{
Environment.Exit(1);
});

using ServiceClient serviceClient = ServiceClient.CreateFromConnectionString(parameters.HubConnectionString, parameters.TransportType);
var sample = new DeviceStreamSample(serviceClient, parameters.DeviceId);
await sample.RunSampleAsync().ConfigureAwait(false);

Console.WriteLine("Done.\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.8.0" />
<PackageReference Include="System.Net.WebSockets.Client" Version="4.3.2" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Devices" Version="1.27.0-preview-004" />
<PackageReference Include="Microsoft.Azure.Devices" Version="1.28.0-preview-001" />
</ItemGroup>

</Project>

0 comments on commit 7aa6ca0

Please sign in to comment.