static void Main()
        {
            Console.WriteLine("Loading EventStore");

            EventStoreLoader.SetupEventStore();
            //Create a private copy of the Checkpoint file to support running multiple instances of the app in the same folder
            var privateCopy = Guid.NewGuid() + ".csv";

            if (File.Exists(ReadModelFile))
            {
                File.Copy(ReadModelFile, privateCopy);
            }

            _consoleView = new ConsoleView();

            _balanceRm = new BalanceReadModel(_consoleView, StreamName, privateCopy);

            _sessionStatsRm = new SessionStatsReadModel(_consoleView);

            _controller = new Controller(_consoleView, _balanceRm, StreamName, privateCopy);

            _controller.StartCommandLoop();

            //if we saved a checkpoint copy it back
            if (File.Exists(privateCopy))
            {
                File.Copy(privateCopy, ReadModelFile, true);
                File.Delete(privateCopy);
            }
        }
예제 #2
0
        static void Main()
        {
            Console.WriteLine("Loading EventStore...");

            EventStoreLoader.SetupEventStore();
            string privateCopy = CopyCheckpoint();

            _consoleView    = new ConsoleView();
            _balanceRm      = new BalanceReadModel(_consoleView, StreamName, privateCopy);
            _sessionStatsRm = new SessionStatsReadModel(_consoleView);
            _controller     = new Controller(_consoleView, _balanceRm, StreamName, privateCopy);

            _controller.StartCommandLoop();

            UpdateCheckpoint(privateCopy);
        }
        public void StartCommandLoop()
        {
            do //Command loop
            {
                var cmd = Console.ReadLine();
                if (string.IsNullOrWhiteSpace(cmd))
                {
                    _view.Redraw();
                    continue;
                }
                //Single token commands
                if (cmd.Equals("clean", StringComparison.OrdinalIgnoreCase))
                {
                    Console.WriteLine("Shutting down EventStore and Cleaning data");
                    EventStoreLoader.TeardownEventStore(false, true);
                    File.Delete(_localFile);
                    break;
                }
                if (cmd.Equals("exit", StringComparison.OrdinalIgnoreCase))
                {
                    Console.WriteLine("Disconnecting EventStore");
                    EventStoreLoader.TeardownEventStore();
                    break;
                }
                if (cmd.Equals("repeat", StringComparison.OrdinalIgnoreCase))
                {
                    RepeatLast();
                    continue;
                }
                if (cmd.Equals("undo", StringComparison.OrdinalIgnoreCase))
                {
                    ReverseLastTransaction();
                    continue;
                }
                if (cmd.Equals("list", StringComparison.OrdinalIgnoreCase))
                {
                    ListOperations();
                    continue;
                }
                if (cmd.Equals("rlist", StringComparison.OrdinalIgnoreCase))
                {
                    ListOperations(true);
                    continue;
                }
                //2 token commands
                var tokens = cmd.Split(' ');
                if (tokens.Length != 2)
                {
                    _view.ErrorMsg = "Unknown command or Invalid number of parameters.";
                    continue;
                }
                int parameter;
                if (!int.TryParse(tokens[1], out parameter))
                {
                    _view.ErrorMsg = "Command parameter not type int.";
                    continue;
                }
                switch (tokens[0].ToUpperInvariant())
                {
                case "CREDIT":
                    var jobject = new JObject();
                    jobject["amount"] = parameter;

                    EventStoreLoader.Connection.AppendToStreamAsync(
                        _streamName,
                        _rm.Checkpoint ?? ExpectedVersion.EmptyStream,
                        new EventData(
                            Guid.NewGuid(),
                            "CREDIT",
                            true,
                            Encoding.UTF8.GetBytes(jobject.ToString()),
                            new byte[] { }
                            )
                        );
                    break;

                case "DEBIT":
                    var jobject2 = new JObject();
                    jobject2["amount"] = parameter;

                    EventStoreLoader.Connection.AppendToStreamAsync(
                        _streamName,
                        _rm.Checkpoint ?? ExpectedVersion.EmptyStream,
                        new EventData(
                            Guid.NewGuid(),
                            "DEBIT",
                            true,
                            Encoding.UTF8.GetBytes(jobject2.ToString()),
                            new byte[] { }
                            )
                        );
                    break;

                case "REPEAT":
                    Repeat(parameter);
                    break;

                default:
                    _view.ErrorMsg = "Unknown Command";
                    break;
                }
            } while (true);
        }
예제 #4
0
 private void Clean()
 {
     Console.WriteLine("Shutting down EventStore and Cleaning data");
     EventStoreLoader.TeardownEventStore(false, true);
     File.Delete(_localFile);
 }
예제 #5
0
 private static void Exit()
 {
     Console.WriteLine("Disconnecting EventStore");
     EventStoreLoader.TeardownEventStore();
 }