/// <summary> /// Main actions /// </summary> private void Run() { var pluginPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ServerConfig.Instance.PluginPath); pluginHandler = new PluginHandler(pluginPath); bool connected = false; if (pluginHandler.Init() == false) { return; } try { MqttClient = new MqttClient(ServerConfig.Instance.BrokerIP); MqttClient.MqttMsgPublishReceived += MqttDataRecieved; MqttClient.Connect(ServerConfig.Instance.ClientID); MqttClient.Subscribe(new string[] { ServerConfig.Instance.TopicData }, new byte[] { MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE }); connected = true; } catch (Exception e) { System.Console.WriteLine($"{nameof(Run)}: Cannot connect to broker [{ServerConfig.Instance.BrokerIP}] => [{e.Message}]"); } if (connected) { do { while (!System.Console.KeyAvailable) { TFUtils.WaitNMilliseconds(ServerConfig.Instance.Delay); } } while (System.Console.ReadKey(true).Key != ConsoleKey.Escape); } pluginHandler.Shutdown(); if (connected) { MqttClient.Disconnect(); } }
/// <summary> /// Main entry point /// </summary> private static void Main() { var pluginPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ClientConfig.Instance.PluginPath); var pluginHandler = new PluginHandler(pluginPath, ClientConfig.Instance.BrickDaemonIP, ClientConfig.Instance.BrickDaemonPort); if (pluginHandler.Init() == false) { return; } TFUtils.WaitUntilStart(); do { while (!System.Console.KeyAvailable) { pluginHandler.HandleValues(pluginHandler.ValuesRead()); TFUtils.WaitNMilliseconds(ClientConfig.Instance.Delay); } } while (System.Console.ReadKey(true).Key != ConsoleKey.Escape); pluginHandler.Shutdown(); Environment.Exit(0); }