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; } }
public MainVM(SettingsVM settings, ICollection <SourceDirectory> sourceDirectories) { Guard.NotNull(settings); _ts = TaskScheduler.FromCurrentSynchronizationContext(); HistoryVM = new HistoryVM(this); OutputVM = new OutputVM(this); SettingsVM = settings; WireupCommands(); if (sourceDirectories != null) { foreach (var src in sourceDirectories) { SourceDirectories.Add(new SourceDirectoryVM(this, src)); } } System.Windows.Data.BindingOperations.EnableCollectionSynchronization(SourceDirectories, SourceDirectories); ThemeHelper.ApplyTheme(SettingsVM.Theme); }
public void Dispose() { OutputVM.EndWritingLog(); DbConnection.Dispose(); }