private void UserControl_Loaded(object sender, RoutedEventArgs e) { if (DataContext is Biller.UI.ViewModel.MainWindowViewModel) { var settings = new Biller.Core.Database.AppSettings(); settings.Database = "538BAA9C-D630-486D-BD61-02706C09E2A9"; settings.Save(); } }
public async Task LoadData(bool CompanyChanged = false) { if (!CompanyChanged) { var assemblyLocation = (Assembly.GetExecutingAssembly().Location).Replace(System.IO.Path.GetFileName(Assembly.GetExecutingAssembly().Location), ""); UpdateManager.Register(new Core.Models.AppModel() { Title = "Biller", Description = "Hauptprogramm", GuID = ((GuidAttribute)Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(GuidAttribute), true)[0]).Value.ToLower(), Version = 2.0020140826, UpdateSource = "https://raw.githubusercontent.com/LastElb/BillerV2/master/update.json" }); logger.Info("Assembly location is: " + assemblyLocation); ProfileOptimization.SetProfileRoot(assemblyLocation); ProfileOptimization.StartProfile("DataLoading.Profile"); foreach (var currentfile in Directory.GetFiles(assemblyLocation, "*@Biller.dll")) { var plugin = LoadAssembly(currentfile); if (plugin == null) continue; try { plugin.Activate(); SettingsTabViewModel.RegisteredPlugins.Add(plugin); } catch (Exception e) { logger.Fatal("Error integrating plugin " + plugin.Name, e); NotificationManager.ShowNotification("Fehler beim Laden von " + plugin.Name, "Das Plugin konnte nicht geladen werden. Eine genaue Fehlerbeschreibung wurde in die Logdatei geschrieben."); } } var settings = new Biller.Core.Database.AppSettings(); settings.Load(); if (String.IsNullOrEmpty(settings.Database)) { // We need to setup a database // Something with ShowDialog so we can resume from a later point var setup = new StartUp.StartUpWindow(this); window.Hide(); setup.ShowDialog(); settings.Load(); window.Show(); NotificationManager.ShowNotification("Hilfe & Erste Schritte", "Klicken Sie auf den Hilfebutton oben rechts, um sich über die ersten Schritte in Biller zu informieren"); } logger.Debug("Connecting to database"); var databases = SettingsTabViewModel.RegisteredDatabases; Database = databases.FirstOrDefault(x => x.Database.GuID == settings.Database).Database; if (Database == null) { logger.Error("We could not load the database. It was not registered. Starting a new database setup!"); settings.Database = ""; settings.DatabaseOptions = ""; var setup = new StartUp.StartUpWindow(this); window.Hide(); setup.ShowDialog(); settings.Load(); window.Show(); } } if (await Database.Connect() == true) { logger.Info("Connection to database established"); if (Database.IsFirstLoad) RibbonFactory.OpenBackstage(); TabContentViewModels.Clear(); RibbonFactory.ClearRibbonTabItems(); AddTabContentViewModel(DocumentTabViewModel); AddTabContentViewModel(ArticleTabViewModel); AddTabContentViewModel(CustomerTabViewModel); AddTabContentViewModel(SettingsTabViewModel); DocumentTabViewModel.RibbonTabItem.IsSelected = true; SelectedContent = DocumentTabViewModel.TabContent; foreach (var plugin in SettingsTabViewModel.RegisteredPlugins) foreach (UI.Interface.IViewModel vm in plugin.ViewModels()) await vm.LoadData(); await SettingsTabViewModel.LoadData(); await ArticleTabViewModel.LoadData(); await CustomerTabViewModel.LoadData(); await DocumentTabViewModel.LoadData(); await BackstageViewModel.LoadData(); } else if (Database.IsFirstLoad) RibbonFactory.OpenBackstage(); else { // Show an exception } UpdateManager.CheckForUpdatesCompleted += UpdateManager_CheckForUpdatesCompleted; UpdateManager.CheckForUpdates(); }