static void Main(string[] args) { try { ColoredConsole.WriteTitle("MoviePlaybackSystem.Remote.PlaybackStatisticsActor: Running Akka.NET demo..."); // Start ActorSystem MoviePlaybackSystemHelper.StartActorSystem(false); ActorPaths.LogAllActorPaths(); // Wait for user input to terminate the application ColoredConsole.WriteUserPrompt($" Press ENTER key to terminate '{MoviePlaybackSystemHelper.ActorSystemName}' ActorSystem..."); Console.ReadLine(); // Terminate ActorSystem // MoviePlaybackSystemHelper.TerminateActorSystem(); ColoredConsole.WriteTitle("MoviePlaybackSystem.Remote.PlaybackStatisticsActor: Quitting Akka.NET demo."); } catch (Exception ex) { ColoredConsole.WriteError($"MoviePlaybackSystem.Remote.PlaybackStatisticsActor: Exception occurred (type: '{ex.GetType().Name}')"); ColoredConsole.WriteError(ex.Message); ColoredConsole.WriteError(ex.StackTrace); } finally { // Terminate ActorSystem MoviePlaybackSystemHelper.TerminateActorSystem(); } }
private static void RunUserInteractiveSession() { bool quit = false; // Create Command Line parser ColoredConsole.WriteUserInstructions("HELP: 'help' to list commands. 'help <command>' to get a help for specific command."); // var parser = new CommandLine.Parser(with => with.HelpWriter = null); var parser = CommandLine.Parser.Default; do { try { PauseFor(); Console.WriteLine(); Console.ForegroundColor = ConsoleColor.Gray; ColoredConsole.WriteUserPrompt("Enter a command: "); var commandLineArray = Console.ReadLine().Split(CommandSeparator); parser.ParseArguments <CommandParser.StartMovieOptions, CommandParser.StopMovieOptions, CommandParser.QuitOptions>(commandLineArray) .MapResult( (CommandParser.StartMovieOptions options) => { return(MoviePlaybackSystemHelper.StartPlayingMovie(new PlayMovieMessage(options.MovieTitle, options.UserId))); }, (CommandParser.StopMovieOptions options) => { return(MoviePlaybackSystemHelper.StopPlayingMovie(new StopMovieMessage(options.UserId))); }, (CommandParser.QuitOptions options) => { quit = true; return(0); }, errs => { return(1); } ); } catch (Exception ex) { ColoredConsole.WriteError($"Exception occurred (type: '{ex.GetType().Name}')"); ColoredConsole.WriteError(ex.Message); ColoredConsole.WriteError(ex.StackTrace); } } while (quit == false); }