private void Window_Loaded(object sender, RoutedEventArgs e) { UIIntegration.Controller = new Controller(SettingsControls); UIIntegration.Controller.Initialize(this); EnableLog.IsChecked = NC.App.AppContext.Logging; logLevels.SelectedIndex = NC.App.AppContext.LevelAsUInt16; logResults.SelectedIndex = NC.App.AppContext.LogResults; ((Window)sender).Title = (NC.App.Name + " " + NC.App.Config.VersionString); // Find the WPF trace listener WPFTraceListener listener = null; foreach (LMLoggers.AppSection source in Enum.GetValues(typeof(LMLoggers.AppSection))) { foreach (TraceListener l in NC.App.Logger(source).TS.Listeners) { if (l is WPFTraceListener) { listener = (WPFTraceListener)l; break; } } } if (listener != null) { loggingListBox.DataContext = listener; } Splash pauseme = new NewUI.Splash(); pauseme.ShowDialog(); }
private void Window_Loaded(object sender, RoutedEventArgs e) { UIIntegration.Controller = new Controller(); if (UIIntegration.Controller.Initialize(this)) { EnableLog.IsChecked = NC.App.AppContext.Logging; logLevels.SelectedIndex = NC.App.AppContext.LevelAsUInt16; logResults.SelectedIndex = NC.App.AppContext.LogResults; ((Window)sender).Title = NCC.IntegrationHelpers.GetAppTitle(); // Find the WPF trace listener WPFTraceListener listener = null; foreach (LMLoggers.AppSection source in Enum.GetValues(typeof(LMLoggers.AppSection))) { foreach (TraceListener l in NC.App.Logger(source).TS.Listeners) { if (l is WPFTraceListener) { listener = (WPFTraceListener)l; break; } } } if (listener != null) { loggingListBox.DataContext = listener; } Splash pauseme = new Splash(); pauseme.ShowDialog(); } else { EnableLog.IsEnabled = false; System.Windows.Controls.DockPanel d = ((System.Windows.Controls.DockPanel)Content); System.Windows.Controls.Menu m = (System.Windows.Controls.Menu)d.Children[0]; m.IsEnabled = false; System.Windows.MessageBox.Show(DateTimeOffset.Now.ToString("yyyy-MM-dd HH:mm:ss") + " App Error\r\n" + NC.App.Pest.IsItThereStr, "ERROR"); } }
/// <summary> /// An optional custom setup to override /// </summary> /// <param name="args">The launch arguments</param> /// <returns>The task</returns> protected override async Task OnSetupAsync(string[] args) { LogStartupTime("RCP setup is starting"); // Load the user data try { JsonConvert.PopulateObject(File.ReadAllText(CommonPaths.AppUserDataPath), RCPServices.Data); RL.Logger?.LogInformationSource($"The app user data has been loaded"); } catch (Exception ex) { ex.HandleError($"Loading app user data"); // NOTE: This is not localized due to the current culture not having been set at this point MessageBox.Show($"An error occurred reading saved app data. Some settings have been reset to their default values.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); // Reset the user data RCPServices.Data.Reset(); } Data = RCPServices.Data; LogStartupTime("User data has been loaded"); // Set the theme this.SetTheme(Data.DarkMode, Data.SyncTheme); // Apply the current culture if defaulted if (Data.CurrentCulture == LocalizationManager.DefaultCulture.Name) { LocalizationManager.SetCulture(LocalizationManager.DefaultCulture.Name); } // Listen to data binding logs WPFTraceListener.Setup(LogLevel.Warning); StartupComplete += BaseApp_StartupComplete_Miscellaneous_Async; StartupComplete += App_StartupComplete_Updater_Async; Data.PropertyChanged += Data_PropertyChangedAsync; // Run basic startup await BasicStartupAsync(); RL.Logger?.LogInformationSource($"Current version is {RCPServices.App.CurrentAppVersion}"); // Check if it's a new version if (Data.LastVersion < RCPServices.App.CurrentAppVersion) { // Run post-update code await PostUpdateAsync(); LogStartupTime("Post update has run"); // Update the last version Data.LastVersion = RCPServices.App.CurrentAppVersion; } // Check if it's a lower version than previously recorded else if (Data.LastVersion > RCPServices.App.CurrentAppVersion) { RL.Logger?.LogWarningSource($"A newer version ({Data.LastVersion}) has been recorded in the application data"); if (!Data.DisableDowngradeWarning) { await Services.MessageUI.DisplayMessageAsync(String.Format(Metro.Resources.DowngradeWarning, RCPServices.App.CurrentAppVersion, Data.LastVersion), Metro.Resources.DowngradeWarningHeader, MessageType.Warning); } } }