using System; using System.Runtime.InteropServices; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using hass_workstation_service.Communication; using Microsoft.Extensions.Configuration; using MQTTnet.Client.Options; using hass_workstation_service.Data; namespace hass_workstation_service { public class Program { public static void Main(string[] args) { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { CreateHostBuilder(args).Build().Run(); } else { // we only support MS Windows for now throw new NotImplementedException("Your platform is not yet supported"); } } public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) .ConfigureServices((hostContext, services) => { IConfiguration configuration = hostContext.Configuration; IConfigurationSection mqttSection = configuration.GetSection("MqttBroker"); var mqttClientOptions = new MqttClientOptionsBuilder() .WithTcpServer(mqttSection.GetValue("Host")) // .WithTls() .WithCredentials(mqttSection.GetValue("Username"), mqttSection.GetValue("Password")) .Build(); var deviceConfig = new DeviceConfigModel { Name = Environment.MachineName, Identifiers = "hass-workstation-service", Manufacturer = Environment.UserName, Model = Environment.OSVersion.ToString(), Sw_version = "0.0.5" }; services.AddSingleton(configuration); services.AddSingleton(deviceConfig); services.AddSingleton(mqttClientOptions); services.AddSingleton(); services.AddSingleton(); services.AddHostedService(); }); } }