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

Commit

Permalink
Consolidate module sample into one, and add reconnection logic (#151)
Browse files Browse the repository at this point in the history
* samples(iot-device): Consolidate module sample into one, and add reconnection logic
  • Loading branch information
abhipsaMisra authored Oct 6, 2020
1 parent c86bbff commit b757af5
Show file tree
Hide file tree
Showing 27 changed files with 715 additions and 322 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using System.Globalization;
using System.Linq;

namespace Microsoft.Azure.Devices.Client.Samples
namespace Microsoft.Azure.Devices.Logging
{
/// <summary>
/// The ILogger implementation for writing color log entries to console.
Expand All @@ -19,7 +19,6 @@ public class ColorConsoleLogger : ILogger
/// <summary>
/// Initializes an instance of <see cref="ColorConsoleLogger"/>.
/// </summary>
/// <param name="name">The category name for each <see cref="ILogger"/> instance. This is usually the class name where the logger is initialized.</param>
/// <param name="config">The <see cref="ColorConsoleLoggerConfiguration"/> settings to be used for logging.</param>
public ColorConsoleLogger(ColorConsoleLoggerConfiguration config)
{
Expand Down Expand Up @@ -64,7 +63,7 @@ public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Except
var color = _config.LogLevelToColorMapping[logLevel];
if (_config.EventIds.Contains(ColorConsoleLoggerConfiguration.DefaultEventId) || _config.EventIds.Contains(eventId.Id))
{
var initialColor = Console.ForegroundColor;
ConsoleColor initialColor = Console.ForegroundColor;

Console.ForegroundColor = ConsoleColor.Green;
Console.Write($"{DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss.fffffff", CultureInfo.InvariantCulture)}>> ");
Expand Down
11 changes: 11 additions & 0 deletions helpers/ColorConsoleLogger/ColorConsoleLogger.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.1.8" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System;
using System.Collections.Generic;

namespace Microsoft.Azure.Devices.Client.Samples
namespace Microsoft.Azure.Devices.Logging
{
/// <summary>
/// A color console logger configuration that creates different color console entries per log level, sets the default log level to Information and logs all events.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using Microsoft.Extensions.Logging;

namespace Microsoft.Azure.Devices.Client.Samples
namespace Microsoft.Azure.Devices.Logging
{
/// <summary>
/// Extension methods to help simplify creation of a new <see cref="ColorConsoleLoggerProvider"/> instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using Microsoft.Extensions.Logging;
using System.Collections.Concurrent;

namespace Microsoft.Azure.Devices.Client.Samples
namespace Microsoft.Azure.Devices.Logging
{
/// <summary>
/// The <see cref="ILoggerProvider"/> implementation that creates the <see cref="ColorConsoleLogger"/> instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.Extensions.Logging;
using System;
using System.Diagnostics.Tracing;
using System.Linq;

namespace System.Diagnostics.Tracing
namespace Microsoft.Azure.Devices.Logging
{
/// <summary>
/// Prints SDK events to Console output - the log level is set to TRACE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.8.0" />
<PackageReference Include="Microsoft.Azure.Devices.Client" Version="1.31.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.1.8" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\..\helpers\ColorConsoleLogger\ColorConsoleLogger.csproj" />
</ItemGroup>

</Project>
3 changes: 2 additions & 1 deletion iot-hub/Samples/device/DeviceReconnectionSample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using CommandLine;
using Microsoft.Azure.Devices.Logging;
using Microsoft.Extensions.Logging;
using System;
using System.Diagnostics.Tracing;
Expand Down Expand Up @@ -41,7 +42,7 @@ public static async Task<int> Main(string[] args)
var logger = loggerFactory.CreateLogger<Program>();

const string SdkEventProviderPrefix = "Microsoft-Azure-";
// Instantiating this seems to do all we need for outputing SDK events to our console log
// Instantiating this seems to do all we need for outputting SDK events to our console log
_ = new ConsoleEventListener(SdkEventProviderPrefix, logger);

// Run the sample
Expand Down
6 changes: 6 additions & 0 deletions iot-hub/Samples/device/IoTHubDeviceSamples.sln
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Thermostat", "PnpDeviceSamp
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PnpHelpers", "PnpDeviceSamples\PnpConvention\PnpHelpers.csproj", "{DCFC3AF8-5E7D-4ADD-A08E-D50B3768564F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ColorConsoleLogger", "..\..\..\helpers\ColorConsoleLogger\ColorConsoleLogger.csproj", "{0819BE3F-DC5D-4E0E-B415-DEAFC10B1A90}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -65,6 +67,10 @@ Global
{DCFC3AF8-5E7D-4ADD-A08E-D50B3768564F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DCFC3AF8-5E7D-4ADD-A08E-D50B3768564F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DCFC3AF8-5E7D-4ADD-A08E-D50B3768564F}.Release|Any CPU.Build.0 = Release|Any CPU
{0819BE3F-DC5D-4E0E-B415-DEAFC10B1A90}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0819BE3F-DC5D-4E0E-B415-DEAFC10B1A90}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0819BE3F-DC5D-4E0E-B415-DEAFC10B1A90}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0819BE3F-DC5D-4E0E-B415-DEAFC10B1A90}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
56 changes: 28 additions & 28 deletions iot-hub/Samples/module/IoTHubModuleSamples.sln
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26124.0
# Visual Studio Version 16
VisualStudioVersion = 16.0.30523.141
MinimumVisualStudioVersion = 15.0.26124.0
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ModuleClientMqttSample", "MessageSample\ModuleClientMqttSample.csproj", "{80EECD5A-E88A-4D18-B508-CFF6E8DB6A16}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ModuleSample", "ModuleSample\ModuleSample.csproj", "{4AF90C42-AD0A-4BB0-BFB6-CDD894A43252}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TwinSample", "TwinSample\TwinSample.csproj", "{934E4549-321F-4811-A36F-AA2489014008}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ColorConsoleLogger", "..\..\..\helpers\ColorConsoleLogger\ColorConsoleLogger.csproj", "{52140ADA-52E1-4C10-82BE-18AF86E02AC9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -17,30 +17,30 @@ Global
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{80EECD5A-E88A-4D18-B508-CFF6E8DB6A16}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{80EECD5A-E88A-4D18-B508-CFF6E8DB6A16}.Debug|Any CPU.Build.0 = Debug|Any CPU
{80EECD5A-E88A-4D18-B508-CFF6E8DB6A16}.Debug|x64.ActiveCfg = Debug|Any CPU
{80EECD5A-E88A-4D18-B508-CFF6E8DB6A16}.Debug|x64.Build.0 = Debug|Any CPU
{80EECD5A-E88A-4D18-B508-CFF6E8DB6A16}.Debug|x86.ActiveCfg = Debug|Any CPU
{80EECD5A-E88A-4D18-B508-CFF6E8DB6A16}.Debug|x86.Build.0 = Debug|Any CPU
{80EECD5A-E88A-4D18-B508-CFF6E8DB6A16}.Release|Any CPU.ActiveCfg = Release|Any CPU
{80EECD5A-E88A-4D18-B508-CFF6E8DB6A16}.Release|Any CPU.Build.0 = Release|Any CPU
{80EECD5A-E88A-4D18-B508-CFF6E8DB6A16}.Release|x64.ActiveCfg = Release|Any CPU
{80EECD5A-E88A-4D18-B508-CFF6E8DB6A16}.Release|x64.Build.0 = Release|Any CPU
{80EECD5A-E88A-4D18-B508-CFF6E8DB6A16}.Release|x86.ActiveCfg = Release|Any CPU
{80EECD5A-E88A-4D18-B508-CFF6E8DB6A16}.Release|x86.Build.0 = Release|Any CPU
{934E4549-321F-4811-A36F-AA2489014008}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{934E4549-321F-4811-A36F-AA2489014008}.Debug|Any CPU.Build.0 = Debug|Any CPU
{934E4549-321F-4811-A36F-AA2489014008}.Debug|x64.ActiveCfg = Debug|Any CPU
{934E4549-321F-4811-A36F-AA2489014008}.Debug|x64.Build.0 = Debug|Any CPU
{934E4549-321F-4811-A36F-AA2489014008}.Debug|x86.ActiveCfg = Debug|Any CPU
{934E4549-321F-4811-A36F-AA2489014008}.Debug|x86.Build.0 = Debug|Any CPU
{934E4549-321F-4811-A36F-AA2489014008}.Release|Any CPU.ActiveCfg = Release|Any CPU
{934E4549-321F-4811-A36F-AA2489014008}.Release|Any CPU.Build.0 = Release|Any CPU
{934E4549-321F-4811-A36F-AA2489014008}.Release|x64.ActiveCfg = Release|Any CPU
{934E4549-321F-4811-A36F-AA2489014008}.Release|x64.Build.0 = Release|Any CPU
{934E4549-321F-4811-A36F-AA2489014008}.Release|x86.ActiveCfg = Release|Any CPU
{934E4549-321F-4811-A36F-AA2489014008}.Release|x86.Build.0 = Release|Any CPU
{4AF90C42-AD0A-4BB0-BFB6-CDD894A43252}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4AF90C42-AD0A-4BB0-BFB6-CDD894A43252}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4AF90C42-AD0A-4BB0-BFB6-CDD894A43252}.Debug|x64.ActiveCfg = Debug|Any CPU
{4AF90C42-AD0A-4BB0-BFB6-CDD894A43252}.Debug|x64.Build.0 = Debug|Any CPU
{4AF90C42-AD0A-4BB0-BFB6-CDD894A43252}.Debug|x86.ActiveCfg = Debug|Any CPU
{4AF90C42-AD0A-4BB0-BFB6-CDD894A43252}.Debug|x86.Build.0 = Debug|Any CPU
{4AF90C42-AD0A-4BB0-BFB6-CDD894A43252}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4AF90C42-AD0A-4BB0-BFB6-CDD894A43252}.Release|Any CPU.Build.0 = Release|Any CPU
{4AF90C42-AD0A-4BB0-BFB6-CDD894A43252}.Release|x64.ActiveCfg = Release|Any CPU
{4AF90C42-AD0A-4BB0-BFB6-CDD894A43252}.Release|x64.Build.0 = Release|Any CPU
{4AF90C42-AD0A-4BB0-BFB6-CDD894A43252}.Release|x86.ActiveCfg = Release|Any CPU
{4AF90C42-AD0A-4BB0-BFB6-CDD894A43252}.Release|x86.Build.0 = Release|Any CPU
{52140ADA-52E1-4C10-82BE-18AF86E02AC9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{52140ADA-52E1-4C10-82BE-18AF86E02AC9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{52140ADA-52E1-4C10-82BE-18AF86E02AC9}.Debug|x64.ActiveCfg = Debug|Any CPU
{52140ADA-52E1-4C10-82BE-18AF86E02AC9}.Debug|x64.Build.0 = Debug|Any CPU
{52140ADA-52E1-4C10-82BE-18AF86E02AC9}.Debug|x86.ActiveCfg = Debug|Any CPU
{52140ADA-52E1-4C10-82BE-18AF86E02AC9}.Debug|x86.Build.0 = Debug|Any CPU
{52140ADA-52E1-4C10-82BE-18AF86E02AC9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{52140ADA-52E1-4C10-82BE-18AF86E02AC9}.Release|Any CPU.Build.0 = Release|Any CPU
{52140ADA-52E1-4C10-82BE-18AF86E02AC9}.Release|x64.ActiveCfg = Release|Any CPU
{52140ADA-52E1-4C10-82BE-18AF86E02AC9}.Release|x64.Build.0 = Release|Any CPU
{52140ADA-52E1-4C10-82BE-18AF86E02AC9}.Release|x86.ActiveCfg = Release|Any CPU
{52140ADA-52E1-4C10-82BE-18AF86E02AC9}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
28 changes: 0 additions & 28 deletions iot-hub/Samples/module/MessageSample/.vscode/launch.json

This file was deleted.

15 changes: 0 additions & 15 deletions iot-hub/Samples/module/MessageSample/.vscode/tasks.json

This file was deleted.

48 changes: 0 additions & 48 deletions iot-hub/Samples/module/MessageSample/MessageSample.cs

This file was deleted.

13 changes: 0 additions & 13 deletions iot-hub/Samples/module/MessageSample/ModuleClientMqttSample.csproj

This file was deleted.

48 changes: 0 additions & 48 deletions iot-hub/Samples/module/MessageSample/Program.cs

This file was deleted.

This file was deleted.

Loading

0 comments on commit b757af5

Please sign in to comment.