-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathProgram.cs
33 lines (30 loc) · 1.34 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using Microsoft.Extensions.Configuration;
using System.Threading;
using Microsoft.ApplicationInsights;
using Microsoft.ApplicationInsights.Extensibility;
using System;
using System.Threading.Tasks;
namespace SimulatedDevice
{
class Program
{
static TelemetryClient client;
static async Task<int> Main(string[] args)
{
// Adding all environment variables into IConfiguration
IConfiguration config = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) //Only used for dev environment
.AddJsonFile("/secrets/IoTHubCredentials.json", optional: true) //Only present when in kubernetes
.AddEnvironmentVariables() //Container Parameters
.Build();
Console.WriteLine($"Pod Name is: {config["POD_NAME"]}");
Console.WriteLine($"Application Insights Key: {config["APPINSIGHTS_INSTRUMENTATIONKEY"]}");
Console.WriteLine($"Image delay is: {config["ImageDelay"]}");
Console.WriteLine($"Readings delay is: {config["ReadingsDelay"]}");
string devicekeyPath = $"IoTHubCreds:{config["POD_NAME"]}";
Console.WriteLine($"IoT Credentials are: {config[devicekeyPath]}");
Thread.Sleep(Timeout.Infinite);
return 0;
}
}
}