Пример #1
0
        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);
            }
        }