-
Notifications
You must be signed in to change notification settings - Fork 493
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2195 from Azure/abmisr/mergeFromMaster
Bring updates from main to preview feature branch
- Loading branch information
Showing
122 changed files
with
1,381 additions
and
886 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# Track1 .NET Azure IoT Hub and DPS SDKs | ||
|
||
* @drwill-ms @timtay-microsoft @abhipsaMisra @vinagesh @azabbasi @jamdavi | ||
* @drwill-ms @timtay-microsoft @abhipsaMisra @azabbasi @jamdavi @andykwong-ms |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System.IO; | ||
using System.Net.Http; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Microsoft.Azure.Devices.Shared | ||
{ | ||
/// <summary> | ||
/// Extensions added to simplify the usage of <see cref="HttpContent"/> APIs based on the .NET implementation used. | ||
/// </summary> | ||
internal static class HttpContentExtensions | ||
{ | ||
internal static async Task CopyToStreamAsync(this HttpContent content, Stream stream, CancellationToken cancellationToken) | ||
{ | ||
#if NET5_0 | ||
await content.CopyToAsync(stream, cancellationToken).ConfigureAwait(false); | ||
#else | ||
// .NET implementations < .NET 5.0 do not support CancellationTokens for HttpContent APIs, so we will discard it. | ||
_ = cancellationToken; | ||
|
||
await content.CopyToAsync(stream).ConfigureAwait(false); | ||
#endif | ||
} | ||
|
||
internal static Task<Stream> ReadHttpContentAsStream(this HttpContent httpContent, CancellationToken cancellationToken) | ||
{ | ||
#if NET5_0 | ||
return httpContent.ReadAsStreamAsync(cancellationToken); | ||
#else | ||
// .NET implementations < .NET 5.0 do not support CancellationTokens for HttpContent APIs, so we will discard it. | ||
_ = cancellationToken; | ||
|
||
return httpContent.ReadAsStreamAsync(); | ||
#endif | ||
} | ||
|
||
internal static Task<byte[]> ReadHttpContentAsByteArrayAsync(this HttpContent content, CancellationToken cancellationToken) | ||
{ | ||
#if NET5_0 | ||
return content.ReadAsByteArrayAsync(cancellationToken); | ||
#else | ||
// .NET implementations < .NET 5.0 do not support CancellationTokens for HttpContent APIs, so we will discard it. | ||
_ = cancellationToken; | ||
|
||
return content.ReadAsByteArrayAsync(); | ||
#endif | ||
} | ||
|
||
internal static Task<string> ReadHttpContentAsStringAsync(this HttpContent content, CancellationToken cancellationToken) | ||
{ | ||
#if NET5_0 | ||
return content.ReadAsStringAsync(cancellationToken); | ||
#else | ||
// .NET implementations < .NET 5.0 do not support CancellationTokens for HttpContent APIs, so we will discard it. | ||
_ = cancellationToken; | ||
|
||
return content.ReadAsStringAsync(); | ||
#endif | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System.Net.Http; | ||
using System.Text; | ||
using Newtonsoft.Json; | ||
|
||
#if NET451 | ||
using System.Net.Http.Formatting; | ||
#endif | ||
|
||
namespace Microsoft.Azure.Devices.Shared | ||
{ | ||
/// <summary> | ||
/// A helper class to simplify operations with Http messages based on the .NET implementation used. | ||
/// </summary> | ||
internal static class HttpMessageHelper | ||
{ | ||
#if NET451 | ||
private static readonly JsonMediaTypeFormatter s_jsonFormatter = new JsonMediaTypeFormatter(); | ||
#else | ||
private const string ApplicationJson = "application/json"; | ||
#endif | ||
|
||
internal static void SetHttpRequestMessageContent<T>(HttpRequestMessage requestMessage, T entity) | ||
{ | ||
#if NET451 | ||
requestMessage.Content = new ObjectContent<T>(entity, s_jsonFormatter); | ||
#else | ||
string str = JsonConvert.SerializeObject(entity); | ||
requestMessage.Content = new StringContent(str, Encoding.UTF8, ApplicationJson); | ||
#endif | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System.IO; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Microsoft.Azure.Devices.Shared | ||
{ | ||
/// <summary> | ||
/// Extensions added to simplify the usage of <see cref="Stream"/> APIs based on the .NET implementation used. | ||
/// </summary> | ||
internal static class StreamExtensions | ||
{ | ||
internal static async Task WriteToStreamAsync(this Stream stream, byte[] requestBytes, CancellationToken cancellationToken) | ||
{ | ||
#if NET451 || NET472 || NETSTANDARD2_0 | ||
await stream.WriteAsync(requestBytes, 0, requestBytes.Length, cancellationToken).ConfigureAwait(false); | ||
#else | ||
await stream.WriteAsync(requestBytes, cancellationToken).ConfigureAwait(false); | ||
#endif | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System.Threading.Tasks; | ||
|
||
namespace Microsoft.Azure.Devices.Shared | ||
{ | ||
/// <summary> | ||
/// A <see cref="TaskCompletionSource{boolean}"/> implementation that returns a <see cref="Task"/> when completed. | ||
/// </summary> | ||
/// <remarks> | ||
/// Represents the producer side of a <see cref="Task"/> unbound to a delegate, providing access to the consumer side through the <see cref="Task"/> property. | ||
/// This is used for .NET implementations lower than .NET 5.0, which lack a native implementation of the non-generic TaskCompletionSource. | ||
/// </remarks> | ||
internal sealed class TaskCompletionSource : TaskCompletionSource<bool> | ||
{ | ||
public TaskCompletionSource() | ||
{ | ||
} | ||
|
||
public bool TrySetResult() => TrySetResult(true); | ||
|
||
public void SetResult() => SetResult(true); | ||
|
||
public override string ToString() => $"TaskCompletionSource[status: {Task.Status}]"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.