generated from arcus-azure/arcus.github.template
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: deprecate iot hub project in favor of dedicated parsing (#508)
- Loading branch information
1 parent
ae12777
commit 9f2af44
Showing
7 changed files
with
394 additions
and
9 deletions.
There are no files selected for viewing
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
37 changes: 37 additions & 0 deletions
37
src/Arcus.Observability.Telemetry.Core/Iot/IotHubConnectionStringParser.cs
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,37 @@ | ||
using System; | ||
using System.Linq; | ||
using GuardNet; | ||
|
||
namespace Arcus.Observability.Telemetry.Core.Iot | ||
{ | ||
/// <summary> | ||
/// Represents the instance to parse the IoT Hub connection string to a strongly-typed <see cref="IotHubConnectionStringParserResult"/>. | ||
/// </summary> | ||
internal static class IotHubConnectionStringParser | ||
{ | ||
/// <summary> | ||
/// Parses the incoming IoT Hub <paramref name="connectionString"/> to a strongly-typed result of IoT Hub properties. | ||
/// </summary> | ||
/// <param name="connectionString">The connection string based on the hostname of the IoT Hub service.</param> | ||
/// <exception cref="ArgumentException">Thrown when the <paramref name="connectionString"/> is blank.</exception> | ||
internal static IotHubConnectionStringParserResult Parse(string connectionString) | ||
{ | ||
Guard.NotNullOrWhitespace(connectionString, nameof(connectionString), "Requires a non-blank connection string based on the hostname of the IoT Hub service"); | ||
|
||
string hostNameProperty = | ||
connectionString.Split(';', StringSplitOptions.RemoveEmptyEntries) | ||
.FirstOrDefault(part => part.StartsWith("HostName", StringComparison.OrdinalIgnoreCase)); | ||
|
||
if (hostNameProperty is null) | ||
{ | ||
throw new FormatException( | ||
"Cannot parse IoT Hub connection string because cannot find 'HostName' in IoT Hub connection string"); | ||
} | ||
|
||
string hostName = | ||
string.Join("", hostNameProperty.SkipWhile(ch => ch != '=').Skip(1)); | ||
|
||
return new IotHubConnectionStringParserResult(hostName); | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/Arcus.Observability.Telemetry.Core/Iot/IotHubConnectionStringParserResult.cs
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 @@ | ||
using System; | ||
using GuardNet; | ||
|
||
namespace Arcus.Observability.Telemetry.Core.Iot | ||
{ | ||
/// <summary> | ||
/// Represents the result of the <see cref="IotHubConnectionStringParser"/> when parsing an IoT Hub connection string. | ||
/// </summary> | ||
internal class IotHubConnectionStringParserResult | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="IotHubConnectionStringParserResult" /> class. | ||
/// </summary> | ||
/// <param name="hostName">The fully-qualified DNS hostname of the IoT Hub service.</param> | ||
/// <exception cref="ArgumentException">Thrown when the <paramref name="hostName"/> is blank.</exception> | ||
internal IotHubConnectionStringParserResult(string hostName) | ||
{ | ||
Guard.NotNullOrWhitespace(hostName, nameof(hostName), "Requires a non-blank fully-qualified DNS hostname of the IoT Hub service"); | ||
HostName = hostName; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the value of the fully-qualified DNS hostname of the IoT Hub service. | ||
/// </summary> | ||
internal string HostName { get; } | ||
} | ||
} |
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
Oops, something went wrong.