示例#1
0
 private void Clean()
 {
     Console.WriteLine("Shutting down EventStore and Cleaning data");
     EventStoreLoader.TeardownEventStore(false, true);
     File.Delete(_localFile);
 }
        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);
        }
示例#3
0
 private static void Exit()
 {
     Console.WriteLine("Disconnecting EventStore");
     EventStoreLoader.TeardownEventStore();
 }