public int Execute(RecordOptions options) { Debug.Assert(consoleFormatter != null, nameof(consoleFormatter) + " != null"); Debug.Assert(sessionManager != null, nameof(sessionManager) + " != null"); Debug.Assert(commandLine != null, nameof(commandLine) + " != null"); Debug.Assert(messageLoop != null, nameof(messageLoop) + " != null"); if (options == null) { return(-1); } try { consoleFormatter.IsVerbose = options.IsVerbose; // Load Configuration File consoleFormatter.PrintDebug(loadedFileMessage); var configPath = new FilePath(Path.GetFullPath(options.ConfigPath)); // Load Session Manager consoleFormatter.PrintDebug(sessionManagerMessage); // Start Recording consoleFormatter.PrintDebug(startRecordingMessage); sessionManager.StartRecording(); // If the user cancels via the command line we need to stop the message loop. commandLine.Launch(messageLoop.Stop); // Run message loop required for Windows hooks messageLoop.Start(); // To prevent the generated video file from becoming corrupted, recording needs to be stopped manually sessionManager.StopRecording(); Console.WriteLine(stopRecordingMessage); GlobalHook.FreeLibrary(); return(0); } catch (Exception exception) // I know this is not a recommend way to deal with exception, however this method receives a arbitrary amount of exception types. { consoleFormatter.PrintError(exception); return(-1); } }
public int Execute(ValidateOptions options) { Debug.Assert(consoleFormatter != null, nameof(consoleFormatter) + " != null"); Debug.Assert(bootstrapper != null, nameof(bootstrapper) + " != null"); if (options == null) { return(-1); } try { consoleFormatter.IsVerbose = options.IsVerbose; // Load Configuration File consoleFormatter.PrintDebug(loadedFileMessage); var filePath = new FilePath(Path.GetFullPath(options.ConfigPath)); // Start Configuration Manager and Bootstrapper consoleFormatter.PrintDebug(assemblyMessage); bootstrapper.ComposeImports(configurationManager); // Resolve Configuration File consoleFormatter.PrintDebug(resolveConfigMessage); configurationManager.LoadConfiguration(filePath); Console.WriteLine(successMessage); return(0); } catch (InvalidConfigurationException exception) { consoleFormatter.PrintError(exception); Console.WriteLine(failureMessage); return(1); } catch (Exception exception) { consoleFormatter.PrintError(exception); return(-1); } }