/// <summary>
        /// Read the MSFS 2020 XML Config file to find all permitted connection types
        /// </summary>
        /// <returns>List of connection configurations</returns>
        private static List <SimConnectConfig> GetLocalFSConnections()
        {
            WriteLog("Start GetLocalFSConnections()");
            List <SimConnectConfig> configs = new List <SimConnectConfig>();

            try
            {
                var         fileContent = File.ReadAllText(GetSimVarXMLPath()); // Load the file content instead of loading as XML - overcomes limitation with encoding
                XmlDocument xml         = new XmlDocument();
                xml.LoadXml(fileContent);
                XmlNodeList xmlNodeList = xml.SelectNodes("/SimBase.Document/SimConnect.Comm");
                foreach (XmlNode xmlNode in xmlNodeList)
                {
                    try
                    {
                        SimConnectConfig config = GetConfigFromXml(xmlNode);
                        configs.Add(config);
                    }
                    catch (Exception ex)
                    {
                        WriteLog(string.Format("Unable to parse XML Connection: {0}", ex.Message), EventLogEntryType.Warning);
                    }
                }
            }
            catch (Exception ex)
            {
                WriteLog(string.Format("Unable to open XML config: {0}", ex.Message), EventLogEntryType.Error);
            }
            WriteLog("End GetLocalFSConnections()");
            return(configs);
        }
        private static void CreateConfigFile(SimConnectConfig config = null)
        {
            WriteLog("Start CreateConfigFile(SimConnectConfig)");
            if (config == null)
            {
                config = new SimConnectConfig
                {
                    Descr   = "Dynamic Config",
                    Address = ((IPEndPoint)endPoint).Address.ToString(),
                    Port    = ((IPEndPoint)endPoint).Port.ToString()
                }
            }
            ;
            var filePath = GetConfigFilePath();

            File.WriteAllText(filePath, config.ConfigFileText);
            WriteLog("End CreateConfigFile(SimConnectConfig)");
        }
 public static void Connect(SimConnectConfig config)
 {
     WriteLog("Start Connect(SimConnectConfig)");
     if (source != null)
     {
         Disconnect();
     }
     Connection = config;
     CreateConfigFile(config);
     source = new CancellationTokenSource();
     token  = source.Token;
     token.ThrowIfCancellationRequested();
     messagePump = new Task(RunMessagePump, token);
     messagePump.Start();
     messagePumpRunning = new AutoResetEvent(false);
     messagePumpRunning.WaitOne();
     WriteLog("End Connect(SimConnectConfig)");
 }