public void LoadInstrument()
 {
     instrument = new Generic_Instrument(300, 300, _config);
     instrument.UpdateFrequency = 3;
     instrument.LogMessage     += DebugMessage;
     this.Controls.Add(instrument.Control);
     dgSimVarValues.Rows.Clear();
     foreach (var simVar in instrument.RequiredValues.OrderBy(x => x.Name))
     {
         dgSimVarValues.Rows.Add(simVar.Name, simVar.Unit);
     }
 }
        private List <ICockpitInstrument> GetPlugIns(List <Assembly> assemblies)
        {
            List <Type> availableTypes = new List <Type>();
            string      message        = string.Format("Fetching Custom plugins");

            ConsoleLog(message);
            foreach (Assembly currentAssembly in assemblies)
            {
                try
                {
                    availableTypes.AddRange(currentAssembly.GetTypes());
                }
                catch (Exception ex) {
                    ConsoleLog(string.Format("GetPlugIns (Assemblies) Error: {0}", ex.Message));
                }
            }

            List <Type> instrumentsList = availableTypes.FindAll(delegate(Type t)
            {
                List <Type> interfaceTypes = new List <Type>(t.GetInterfaces());
                return(interfaceTypes.Contains(typeof(ICockpitInstrument)));
            });
            var customInstruments = instrumentsList.ConvertAll <ICockpitInstrument>(delegate(Type t) {
                try {
                    return(Activator.CreateInstance(t) as ICockpitInstrument);
                }
                catch (Exception ex) {
                    ConsoleLog(string.Format("Unable to build Cockpit Instrument: {0}\rError: {1}", t.Name, ex.Message));
                    return(null);
                }
            }).Where(x => x != null).ToList();

            message = string.Format("Fetching Generic plugins");
            ConsoleLog(message);
            foreach (var instrumentDefinition in Directory.GetFiles(Path.Combine(appDataFolder, ".\\GenericInstruments")))
            {
                if (instrumentDefinition?.ToLower().EndsWith(".json") == true)
                {
                    try
                    {
                        var genericInstrument = new Generic_Instrument(100, 100, instrumentDefinition);
                        customInstruments.Add(genericInstrument);
                    }
                    catch (Exception ex)
                    {
                        ConsoleLog(string.Format("GetPlugIns (Generic Instrument).\rInstrument: {0}.\rError: {0}", instrumentDefinition, ex.Message));
                    }
                }
            }
            // convert the list of Objects to an instantiated list of ICalculators
            return(customInstruments);
        }