Exemplo n.º 1
0
        // obsluha události
        public void ModuleLoadNotifyHandler(object sender, ModuleLoadedEventArgs e)
        {
            _apiDictionary = _modulesControl.GetModules();


            if (e.Error)
            {
                ModulesError++;
            }
            else
            {
                ModulesOk++;
            }

            // přepis GUI z jiného vlákna
            if (Application.Current.Dispatcher != null)
            {
                Application.Current.Dispatcher.Invoke(() =>
                {
                    comboBox.ItemsSource = _apiDictionary;
                    tbOk.Text            = ModulesOk.ToString();
                    tbError.Text         = ModulesError.ToString();
                });
            }
        }
Exemplo n.º 2
0
        protected virtual void OnModuleLoaded(ModuleLoadedEventArgs e)
        {
            EventHandler <ModuleLoadedEventArgs> handler = Changed;

            if (Changed != null)
            {
                Changed(this, e);
            }
        }
Exemplo n.º 3
0
        public void LoadModules()
        {
            Debug.WriteLine($"ModulesControl.LoadModules()");
            foreach (var file in _moduleFiles)
            {
                try
                {
                    Debug.WriteLine($"Nahravam modul {file}.");
                    var asm = Assembly.LoadFrom(file);

                    var typeExchangeRates = asm.GetType("wpfapp.ExchangeRates");
                    if (typeExchangeRates.GetInterface("IExchangeRates") == null)
                    {
                        Trace.WriteLine($"Chyba v modulu {file}. Neni naimplementovano pozadovane rozhrani.");
                        ModuleLoadedEventArgs argsE = new ModuleLoadedEventArgs()
                        {
                            Error = true
                        };
                        OnModuleLoaded(argsE);
                    }

                    var propApiName = typeExchangeRates.GetProperty("ApiName");

                    IExchangeRates exRates = (IExchangeRates)Activator.CreateInstance(typeExchangeRates, _httpClient);
                    string         apiName = (string)propApiName.GetValue(exRates, null);

                    if (apiName == null)
                    {
                        Trace.WriteLine($"Chyba v modulu {file}. Knihovna nema nastavene jmeno.");
                        ModuleLoadedEventArgs argsE = new ModuleLoadedEventArgs()
                        {
                            Error = true
                        };
                        OnModuleLoaded(argsE);
                    }

                    _apiDictionary.Add(apiName, exRates);

                    // vyvoláme událost OK
                    Trace.WriteLine($"Modul {file} byl uspesne nacten.");
                    ModuleLoadedEventArgs argsOK = new ModuleLoadedEventArgs()
                    {
                        Error = false
                    };
                    OnModuleLoaded(argsOK);
                }
                catch (Exception ex)
                {
                    Trace.WriteLine($"Knihovnu '{file}' nelze načíst.");

                    // vyvoláme událost ERROR
                    ModuleLoadedEventArgs args = new ModuleLoadedEventArgs()
                    {
                        Error = true
                    };
                    OnModuleLoaded(args);
                }

                // umělé čekání
                Thread.Sleep(1500);
            }
            Debug.WriteLine($"ModulesControl.LoadModules() - KONEC");
        }