internal JobContext(CommandLineSandbox shell, CancellationToken cancellationToken, ProgressViewModel progress, HistoryEventVM eventVM, OutputVM output) { Shell = shell; Progress = progress; OutputVM = output; CancellationToken = cancellationToken; Information = new T(); DbConnection = AppDataManager.ConnectToSqlite(); try { HistoryVM = eventVM; eventVM.Insert(DbConnection); if (!HistoryVM.ID.HasValue) { throw new InvalidOperationException("No ID obtained for Job from DB."); } string logPath = AppDataManager.GetLogFilePath(HistoryVM.ID.Value); output.Cls(); output.StartWritingLog(logPath); } catch (Exception e) { log.ErrorFormat($"Exception while trying to setup context for command '{eventVM.Command}': {e.Message}"); DbConnection.Dispose(); throw; } }
protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); bool isSingleInstance = false; singleInstanceMutex = new Mutex(true, "BuilderSingleInstance", out isSingleInstance); if (!isSingleInstance) { MessageBox.Show("Another instance of this application is already running.", "Builder"); //Modal if (singleInstanceMutex != null) { singleInstanceMutex.Dispose(); } Shutdown(); return; } try { log.InfoFormat("Started new Session. Builder {0}, compiled on {1}", typeof(App).Assembly.GetName().Version.ToString(), LinkerTime.ToString("yyyy-MM-dd HH:mm:ss")); Stopwatch sw = new Stopwatch(); sw.Start(); var settings = Task.Run(() => AppDataManager.LoadSettings()); var environments = Task.Run(() => AppDataManager.LoadEnvironments()); Task.WaitAll(settings, environments); SettingsVM svm = CreateSettingsVM(settings.Result); var viewModel = new MainVM(svm, environments.Result); svm.RefreshAutomaticTCCPathAsync(); Exit += (sender, _) => GracefulShutdown(); SessionEnding += (sender, _) => GracefulShutdown(); notifyIcon = (TaskbarIcon)FindResource("NotifyIcon"); notifyIcon.DataContext = viewModel; sw.Stop(); log.InfoFormat("Startup took {0:0.0} seconds.", sw.Elapsed.TotalSeconds); if (settings.Result != null && settings.Result.StartInTray) { return; } sw.Restart(); viewModel.ShowUICommand.Execute(); sw.Stop(); log.InfoFormat("Opening Main UI took {0:0.0} seconds.", sw.Elapsed.TotalSeconds); } catch (Exception ex) { log.Error("Exception during startup.", ex); Shutdown(); } }
private void ShowSettings(object obj) { if (SettingsVM == null) { return; } SettingsDialog dialog = new SettingsDialog(); dialog.DataContext = SettingsVM.Copy(); var mainWindow = Application.Current.MainWindow; if (mainWindow != null) { dialog.Owner = mainWindow; } if (dialog.ShowDialog() == true) { var result = (SettingsVM)dialog.DataContext; if (result == null || !result.IsDirty) { return; } SettingsVM = result; ThemeHelper.ApplyTheme(result.Theme); AppDataManager.SaveSettings(result.Model); } }
private void BrowseAppData_Click(object sender, RoutedEventArgs e) { var directory = AppDataManager.GetAppDataPath(); if (!Directory.Exists(directory)) { MessageBox.Show(this, $"The application data directory '{directory}' does not exist. It has probably not been created, yet."); return; } Process.Start(directory); }
public void SaveEnvironmentsIfDirty() { if (!_environmentIsDirty) { return; } _environmentIsDirty = false; lock (SourceDirectories) { //rebuild the model tree AppDataManager.SaveEnvironments(SourceDirectories.Select(vm => vm.RegenerateModel()).ToList()); } }
private void NavigateTo(object obj) { Task.Run(() => { if (!ID.HasValue) { return; } var fileName = AppDataManager.GetLogFilePath(ID.Value); if (!File.Exists(fileName)) { return; } Process.Start(fileName); }); }