コード例 #1
0
        static void Main(string[] args)
        {
            //Setup code...
            Console.WriteLine("Connecting to EventStore...");

            EventStoreLoader.SetupEventStore(EventStoreLoader.StartConflictOption.Connect);

            //create instance of the user service
            userService = new UserService(new EsAggregateStore(EventStoreLoader.Connection));

            //read models and projections
            var items = new List <UserReadModel>();

            projectionManager = new ProjectionManager(EventStoreLoader.Connection, items);

            //command and query handlers
            userCommands = new UserCommandHandler(userService);
            userQueries  = new UserQueryHandler(items, userService); //need list of read model items

            Console.WriteLine("EventStore was setup successfully!");

            DisplayUserCommands();
            StartCommandLoop();
        }
コード例 #2
0
        public static void StartCommandLoop()
        {
            do //Command loop, runs until user shuts down program or EventStore
            {
                var cmd = Console.ReadLine();

                if (string.IsNullOrWhiteSpace(cmd))
                {
                    DisplayUserCommands();
                    continue;
                }

                string streamName = string.Empty;

                switch (cmd.ToLower())
                {
                case "exit":
                    Console.WriteLine("Disconnecting from EventStore");
                    EventStoreLoader.TeardownEventStore();
                    break;

                case "1t":
                    Console.Write("Please enter stream name (New or existing): ");
                    streamName = Console.ReadLine();
                    Console.WriteLine("Adding 3 events to stream " + streamName + "...\n");
                    CreateAndRunTestStream(streamName);
                    continue;

                case "2t":
                    Console.Write("Please enter existing stream name: ");
                    streamName = Console.ReadLine();
                    CreatePersistentSubscription(streamName);
                    Console.WriteLine("Persistent Subscription for stream \"" + streamName + "\" has been created!");
                    continue;

                case "3t":
                    Console.Write("Please enter existing stream name: ");
                    streamName = Console.ReadLine();
                    ConnectPersistentSubscription(streamName);
                    Console.WriteLine("Connection to Persistent Subscription for stream \"" + streamName + "\" has been created!");
                    Console.WriteLine("Waiting for new events...");
                    continue;

                case "4t":
                    Console.Write("Please enter stream name: ");
                    streamName = Console.ReadLine();
                    Console.Write("Read events reversed? (y/n): ");
                    string answer   = Console.ReadLine();
                    bool   reversed = answer == "y" ? true : false;
                    Console.WriteLine("Listing all events from stream...\n");
                    ListOperations(streamName, reversed);
                    continue;

                case "1d":
                    Console.Write("Please input username: "******"User with username \"" + userName + "\" has been saved to the Event Store!\n");
                    continue;

                case "2d":
                    Console.Write("Please input ID of user to update: ");
                    string userID = Console.ReadLine();
                    Console.Write("Please input new user name: ");
                    string userNameUpdated = Console.ReadLine();
                    userCommands.UpdateUserName(new Contracts.UpdateUserName()
                    {
                        UserId = Guid.Parse(userID), Name = userNameUpdated
                    });
                    Console.WriteLine("User " + userID + " has been updated with new username \"" + userNameUpdated + "\"");
                    continue;

                case "3d":
                    Console.WriteLine("Creating and connecting to Catch Up subscription for the $all stream...");
                    projectionManager.Start();
                    break;

                case "4d":
                    Console.Write("Please input ID of user to display: ");
                    string        userId      = Console.ReadLine();
                    UserReadModel queriedUser = userQueries.GetSingleUser(new UserQueryModels.GetUser()
                    {
                        UserId = Guid.Parse(userId)
                    });
                    Console.WriteLine("Success, user was found!\n--------------------------------------------\nUserID: " + queriedUser.UserId + "\nUsername: "******"5d":
                    Console.WriteLine("Fetching all users aggregates from Event Store...\n");
                    List <UserReadModel> userReadModels = userQueries.GetAllUsers();
                    foreach (var urm in userReadModels)
                    {
                        Console.WriteLine("UserID: " + urm.UserId + "\nUsername: "******"\n--------------------------------------------");
                    }
                    break;
                }
            } while (true);
        }