コード例 #1
0
        public override async Task <bool> Start()
        {
            var log = LoggerFactory.CreateLogger <BiosSubscriberPlugin>();

            PluginConfiguration pluginConfig;

            try
            {
                pluginConfig = await GetConfiguration();
            }
            catch (JsonSerializationException ex)
            {
                log.LogError("Encountered error while loading configuration for DcsBiosReader. Skipping...");
                log.LogDebug(ex, "Exception:");
                return(false);
            }

            var client = new BiosUdpClient(pluginConfig.Export !.Ip, pluginConfig.Export !.SendPort, pluginConfig.Export !.ReceivePort, LoggerFactory.CreateLogger <BiosUdpClient>());

            client.OpenConnection();

            var biosListener = new BiosListener(client, new Translator(LoggerFactory.CreateLogger <Translator>(), SendData, SendString), LoggerFactory.CreateLogger <BiosListener>());

            var configsLoaded = 0;

            foreach (var config in await AircraftBiosConfiguration.AllConfigurations(pluginConfig.AliasesFileName, LoggerFactory.CreateLogger <AircraftBiosConfiguration>(), pluginConfig.ConfigLocations.ToArray()))
            {
                biosListener.RegisterConfiguration(config);
                configsLoaded++;
            }

            if (configsLoaded == 0)
            {
                var configPaths = string.Join(", ", pluginConfig.ConfigLocations);
                log.LogWarning("No configuration files found at {ConfigPaths} - check config.json", configPaths);
            }

            log.LogInformation("Starting bios listener...");

            biosListener.Start();
            return(true);
        }
コード例 #2
0
        public static async Task Run(ILoggerFactory loggerFactory)
        {
            var appConfig = ApplicationConfiguration.Get();
            var log       = loggerFactory.CreateLogger <Worker>();

            if (appConfig is null)
            {
                log.LogWarning("No configuration detected; creating default config.json");
                ApplicationConfiguration.CreateNewConfiguration();
                log.LogInformation("Edit osc.configLocations and osc.devices in accordance with your setup, and then restart TouchDCS");
                Console.ReadKey(true);
                return;
            }

            var oscSenders    = SetUpOscSenders(appConfig, loggerFactory);
            var biosUdpClient = SetUpBiosUdpClient(appConfig, loggerFactory.CreateLogger <BiosUdpClient>());

            var aircraftBiosConfigs = await AircraftBiosConfiguration.AllConfigurations(appConfig.DcsBios.AliasFileName,
                                                                                        loggerFactory.CreateLogger <AircraftBiosConfiguration>(), appConfig.DcsBios.ConfigLocations.ToArray());

            var translator = new BiosOscTranslator(oscSenders.ToList(), biosUdpClient, aircraftBiosConfigs,
                                                   appConfig.CommonModules ?? new HashSet <string>(), loggerFactory.CreateLogger <BiosOscTranslator>());

            var biosListener = new BiosListener(biosUdpClient, translator, loggerFactory.CreateLogger <BiosListener>());

            foreach (var config in aircraftBiosConfigs)
            {
                biosListener.RegisterConfiguration(config);
            }
            biosListener.Start();

            var _ = SetUpOscReceivers(appConfig, translator, loggerFactory);

            log.LogInformation("Ready!");

            await Task.Delay(-1);
        }