//instantitate by loading the application's settings from a database
        public SimulationRunningConfig(XMLAppSettings settings)
            : base()
        {
            APP_ID = Guid.NewGuid().ToString().Replace("-", "").Substring(0, 10).ToUpper();
            APP_ROLE = ROLE_PARTICIPANT;

            AppSettings = settings;

            //load network settings from AppSettings
            UDP_NETWORK_ADDRESS = settings.NetworkSettings.UDPNetworkAddress;
            UDP_NETWORK_BROADCAST_ADDRESS = settings.NetworkSettings.UDPNetworkBroadcastAddress;
            UDP_SIMULATION_APP_PORT = settings.NetworkSettings.UDPAppPort;
            TCP_SIMULATION_APP_PORT = settings.NetworkSettings.TCPAppPort;
        }
        public XMLAppSettings loadAppSettings()
        {
            if (dbConnect == null) throw new NullReferenceException("AppLoader: Unable to load application settings - database connection is null or empty");
            System.Console.WriteLine("AppLoader: Building system profile");

            //1. Get application settings
            string appSettingsQuery = "SELECT * FROM AppSettings WHERE 1";

            SQLiteConnection connect = dbConnect.Connect(dbConnectString);
            SQLiteDataReader query = dbConnect.ExecuteQuery(appSettingsQuery);

            _appSettings = new XMLAppSettings();

            while (query.Read())
            {
                _appSettings.RetrieveHardwareProfile = (string)query["Retrieve_Hardware_Profile"];

            }

            //2. Retrieve network settings
            string networkSettingsQuery = "SELECT * FROM NetworkSettings WHERE 1";
            query = dbConnect.ExecuteQuery(networkSettingsQuery);
            _appSettings.NetworkSettings = new XMLNetworkSettings();

            while (query.Read())
            {
                _appSettings.NetworkSettings.TCPAppPort = (int)query["TCP_App_Port"];
                _appSettings.NetworkSettings.UDPAppPort = (int)query["UDP_App_Port"];
                _appSettings.NetworkSettings.UDPNetworkAddress = (string)query["UDP_Network_Address"];
                _appSettings.NetworkSettings.UDPNetworkBroadcastAddress = (string)query["UDP_Network_Broadcast_Address"];
                _appSettings.NetworkSettings.SIMMessageHeartbeatInterval = (int)query["SIM_Message_Heartbeat_Interval"];
                _appSettings.NetworkSettings.SIMSetupHeartbeatInterval = (int)query["SIM_Setup_Heartbeat_Interval"];
            }

            //3a. System profile needs to be retrieved (due to either first run, or something changed)
            if (String.Equals(_appSettings.RetrieveHardwareProfile, "YES"))
            {
                //build system profile from Windows Management Instrumentation
                _appSettings.SystemProfile = buildXMLSystemProfile();
                updateDatabaseSystemProfile(dbConnect, _appSettings.SystemProfile);

                //set retrieve hardware profile to 'NO' since it is now up to date
                //this way it will not run multitple times since buildXMLSystemProfile() is expensive
                string noRetrieveUpdate = "UPDATE AppSettings SET Retrieve_Hardware_Profile ='NO' WHERE 1";
                dbConnect.ExecuteUpdate(noRetrieveUpdate);
            }

            //3b. System profile is already in the database, so just load from db
            else
            {
                _appSettings.SystemProfile = loadSystemProfileFromDatabase(dbConnect);
            }

            dbConnect.CloseConnection();

            return _appSettings;
        }