示例#1
0
 private void When(CustomerCreated @event)
 {
     Id     = new CustomerId(@event.Id);
     Name   = @event.CustomerName;
     _users = new List <User>();
 }
示例#2
0
 public Customer(CustomerId id, string customerName) : this()
 {
     ApplyChange(new CustomerCreated(id, customerName));
 }
示例#3
0
 private void When(CustomerCreated @event)
 {
     Id = new CustomerId(@event.Id);
     Name = @event.CustomerName;
     _users = new List<User>();
 }
示例#4
0
        public void Work()
        {
            var credentials = new UserCredentials("admin", "changeit");
            var connection  = EventStoreConnection.Create(
                ConnectionSettings.Create().UseConsoleLogger().SetDefaultUserCredentials(credentials),
                new IPEndPoint(IPAddress.Loopback, 1113),
                "SampleEventSourcing");

            connection.ConnectAsync();
            //Thread.Sleep(1000);

            ConfigureProjections(connection);

            var configuration = new EventReaderConfiguration(
                new SliceSize(512),
                new JsonDeserializer(),
                new PassThroughStreamNameResolver(),
                new FixedStreamUserCredentialsResolver(credentials));

            while (true)
            {
                WriteLine("Choose an option:");
                WriteLine("1) Create new customer");
                WriteLine("2) Change customer name");
                WriteLine("3) Add user");
                WriteLine("4) Change user name");
                WriteLine("q) Quit");
                Write("Your choice: ");
                var choice = ReadLine();
                if (choice == "q")
                {
                    break;
                }

                var unitOfWork = new EventStoreUnitOfWork(connection);
                var repository = new EventStoreRepository <Customer>(unitOfWork, configuration);

                switch (choice)
                {
                case "1":
                {
                    Write("Enter customer name: ");
                    var id       = new CustomerId(Guid.NewGuid());
                    var customer = new Customer(id, ReadLine());
                    repository.Add(id.ToString(), customer);
                }
                break;

                case "2":
                {
                    Write("Enter customer id: ");
                    var customer = repository.Get(new CustomerId(Guid.Parse(ReadLine())).ToString());
                    Write("Enter new customer name: ");
                    customer.ChangeName(ReadLine());
                }
                break;

                case "3":
                {
                    Write("Enter customer id: ");
                    var customer = repository.Get(new CustomerId(Guid.Parse(ReadLine())).ToString());
                    Write("Enter user name: ");
                    customer.AddUser(new UserId(Guid.NewGuid()), ReadLine());
                }
                break;

                case "4":
                {
                    Write("Enter customer id: ");
                    var customer = repository.Get(new CustomerId(Guid.Parse(ReadLine())).ToString());
                    Write("Enter user id: ");
                    var userId = new UserId(Guid.Parse(ReadLine()));
                    Write("Enter new user name: ");
                    customer.ChangeUserName(userId, ReadLine());
                }
                break;
                }

                unitOfWork.Commit();
                WriteLine("Saved, press enter to continue");
                ReadLine();
            }
        }
示例#5
0
 public Customer(CustomerId id, string customerName)
     : this()
 {
     ApplyChange(new CustomerCreated(id, customerName));
 }