private static void Main(string[] args) { Console.WriteLine("======================================================================="); Console.WriteLine(AssemblyInformationHelper.HeaderMessage); Console.WriteLine("======================================================================="); Console.WriteLine(">> Loading configurations...."); try { //Configuration var builder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) .AddJsonFile("devicesettings.json", optional: false, reloadOnChange: true) .AddJsonFile("modulessettings.json", optional: true, reloadOnChange: true) .AddEnvironmentVariables(); _environmentName = Environment.GetEnvironmentVariable("ENVIRONMENT"); if (string.IsNullOrWhiteSpace(_environmentName)) { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("No environment platform has been found. Default setting: Development."); _environmentName = "Development"; Console.ResetColor(); } try { ConfigurationHelpers.CheckEnvironmentConfigurationFiles(_environmentName); } catch (MissingEnvironmentConfigurationFileException ex) { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine(ex.Message); Console.ResetColor(); Console.WriteLine("Execution will continue with default settings in appsettings.json, devicesettings.json and modulessettings.json."); } builder.AddJsonFile($"appsettings.{_environmentName}.json", optional: true, reloadOnChange: true); builder.AddJsonFile($"devicesettings.{_environmentName}.json", optional: true, reloadOnChange: true); builder.AddJsonFile($"modulessettings.{_environmentName}.json", optional: true, reloadOnChange: true); Configuration = builder.Build(); //Service provider and DI IServiceCollection services = new ServiceCollection(); ConfigureServices(services); var deviceSettings = Configuration.Get <DeviceSettings>(); if (deviceSettings == null) { throw new ArgumentException("No device settings have been configured."); } if (deviceSettings.SimulationSettings == null) { throw new ArgumentException("No device simulation settings have been configured."); } if (deviceSettings.SimulationSettings.EnableDevice || deviceSettings.SimulationSettings.EnableModules) { //If any of the simulators is enabled, messaging services will be required to build the messages. RegisterMessagingServices(services); } if (deviceSettings.SimulationSettings.EnableDevice) { RegisterDeviceSimulators(services); } if (deviceSettings.SimulationSettings.EnableModules) { RegisterModuleSimulators(deviceSettings, services); } IServiceProvider serviceProvider = services.BuildServiceProvider(); //Logger var logger = serviceProvider.GetService <ILoggerFactory>().CreateLogger <Program>(); logger.LogDebug("PROGRAM::Settings, DI and logger configured and ready to use."); //Simulators if (!deviceSettings.SimulationSettings.EnableDevice && !deviceSettings.SimulationSettings.EnableModules) { logger.LogDebug("PROGRAM:: No simulator has been configured."); } else { if (deviceSettings.SimulationSettings.EnableDevice) { StartDevicesSimulators(serviceProvider, logger); } if (deviceSettings.SimulationSettings.EnableModules) { StartModulesSimulators(serviceProvider, logger); } } } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(ex.Message); Console.ResetColor(); } finally { Console.ReadLine(); } }