public static Repository<User> Create(UnitOfWork unitOfWork, IEventStoreConnection connection, UserCredentials credentials)
 {
     return new Repository<User>(() => User.Factory(), unitOfWork, connection,
                                 new EventReaderConfiguration(
                                     new SliceSize(512),
                                     new JsonDeserializer(),
                                     new PassThroughStreamNameResolver(),
                                     new FixedStreamUserCredentialsResolver(credentials)));
 }
        public void HandleUserCommands()
        {
            IEventStoreConnection connection = null;
            var credentials = new UserCredentials("admin", "changeit");
            var unitOfWork = new UnitOfWork();
            var repository = RepositoryFactory.Create(unitOfWork, connection, credentials);
            //ICommandHandler<CreateBasicUser> handler = new CreateBasicUserCommandHandler(connection, repository, unitOfWork);

            //handler.HandleCommand();
        }
Пример #3
0
 private static void AppendToStream(UserCredentials credentials, IEventStoreConnection connection, UnitOfWork unitOfWork)
 {
     var affected = unitOfWork.GetChanges().Single();
     connection.AppendToStream(
         affected.Identifier,
         affected.ExpectedVersion,
         affected.Root.GetChanges().
             Select(_ =>
                 new EventData(
                     Guid.NewGuid(),
                     _.GetType().Name,
                     true,
                     ToJsonByteArray(_),
                     new byte[0])),
         credentials);
 }
Пример #4
0
 public void Show()
 {
     //Somewhere in an application service wrapper
     var unitOfWork = new UnitOfWork();
     //Dependency of a domain service or application service
     var dogRepository = new Repository<Dog>(Dog.Factory, unitOfWork, new EmptyEventStreamReader());
     //Application service handler code
     var dog = new Dog(Guid.NewGuid(), "Sparky", DateTime.Today.AddYears(-1));
     dog.AdministerShotOf("Anti Diarrhea Medicine", DateTime.Today);
     dogRepository.Add(dog.DogId.ToString(), dog);
     //Back in the application service wrapper
     Console.WriteLine("We observed that:");
     foreach (var change in unitOfWork.GetChanges().SelectMany(aggregate => aggregate.Root.GetChanges()))
     {
         Console.WriteLine(change);
     }
 }
Пример #5
0
        static void Main()
        {
            //Make sure you start an instance of EventStore before running this!!

            var credentials = new UserCredentials("admin", "changeit");
            var connection = EventStoreConnection.Create(
                ConnectionSettings.Create().
                    UseConsoleLogger().
                    SetDefaultUserCredentials(
                        credentials),
                new IPEndPoint(IPAddress.Loopback, 1113),
                "EventStoreShopping");
            connection.Connect();

            var unitOfWork = new UnitOfWork();
            var repository = new Repository<ShoppingCart>(
                ShoppingCart.Factory,
                unitOfWork,
                connection,
                new EventReaderConfiguration(
                    new SliceSize(512),
                    new JsonDeserializer(),
                    new PassThroughStreamNameResolver(),
                    new FixedStreamUserCredentialsResolver(credentials)));

            //Handle Start Shopping command
            var id = new ShoppingCartId("shopping_at_boutique_" + DateTime.UtcNow.Ticks);
            repository.Add(id, new ShoppingCart(id));

            //Handle Add Item command
            var cart1 = repository.Get(id);
            cart1.AddItem(new ItemId("pair_of_socks"), 2);

            //Handle Add Item command
            var cart2 = repository.Get(id);
            cart2.AddItem(new ItemId("pair_of_shirts"), 4);

            //Handle Remove Item command
            var cart3 = repository.Get(id);
            cart3.RemoveItem(new ItemId("pair_of_socks"));

            //Handle Increment Item Count command
            var cart4 = repository.Get(id);
            cart4.IncrementItemCount(new ItemId("pair_of_shirts"));

            //Handle Checkout command
            var cart5 = repository.Get(id);
            cart5.Checkout();

            //Append to stream
            var affected = unitOfWork.GetChanges().Single();
            connection.AppendToStream(
                affected.Identifier,
                affected.ExpectedVersion,
                affected.Root.GetChanges().
                    Select(_ =>
                        new EventData(
                            Guid.NewGuid(),
                            _.GetType().Name,
                            true,
                            ToJsonByteArray(_),
                            new byte[0])),
                credentials);
        }
Пример #6
0
        static void Main()
        {
            //Make sure you start an instance of EventStore before running this!!
            var credentials = new UserCredentials("admin", "changeit");
            var connection = EventStoreConnection.Create(
                ConnectionSettings.Create().
                    UseConsoleLogger().
                    SetDefaultUserCredentials(
                        credentials),
                new IPEndPoint(IPAddress.Loopback, 1113),
                "EventStoreShopping");
            connection.Connect();

            var productUow = new UnitOfWork();
            var productRepository = new Repository<Product>(
                Product.Factory,
                productUow,
                connection,
                new EventReaderConfiguration(
                    new SliceSize(512),
                    new JsonDeserializer(),
                    new PassThroughStreamNameResolver(),
                    new FixedStreamUserCredentialsResolver(credentials)));

            var tenantId = new TenantId(Guid.NewGuid().ToString());
            var productId = new ProductId();
            productRepository.Add(productId.ToString(),
                new Product(tenantId,
                    productId,
                    "dolphin-tuna",
                    "non-dolphin free",
                    new ProductManager(Guid.NewGuid().ToString()),
                    new IssueAssigner(Guid.NewGuid().ToString())));

            var product = productRepository.Get(productId.ToString());

            List<Issue> issues = new List<Issue>();
            var issueId = new IssueId();
            issues.Add(product.ReportDefect(issueId, "shit be bad yo", "fo real"));
            issues.Add(product.ReportDefect(new IssueId(), "shit be bad yo", "fo real"));
            issues.Add(product.ReportDefect(new IssueId(), "shit be bad yo", "fo real"));
            issues.Add(product.ReportDefect(new IssueId(), "shit be bad yo", "fo real"));
            issues.Add(product.ReportDefect(new IssueId(), "shit be bad yo", "fo real"));

            DefectStatistics stats1 = new DefectStatistics(issues);

            var release1 = product.ScheduleRelease("new relased", stats1);

            var density = release1.CalculateDefectDensity(new KlocMEasurement(10));

            issues.Add(product.ReportDefect(new IssueId(), "shit be bad yo", "fo real"));
            issues.Add(product.ReportDefect(new IssueId(), "shit be bad yo", "fo real"));

            issues.First().Resolve("cool");

            DefectStatistics stats2 = new DefectStatistics(issues);

            var release2 = product.ScheduleRelease("new relased", stats2);

            var density2 = release2.CalculateDefectDensity(new KlocMEasurement(10));

            var product2 = productRepository.Get(productId.ToString());

            var issueIdForProduct2 = new IssueId();
            issues.Add(product2.ReportDefect(issueIdForProduct2, "shit be bad yo", "fo real"));
            issues.Add(product2.ReportDefect(new IssueId(), "shit be bad yo", "fo real"));
            issues.Add(product2.ReportDefect(new IssueId(), "shit be bad yo", "fo real"));
            issues.Add(product2.ReportDefect(new IssueId(), "shit be bad yo", "fo real"));
            issues.Add(product2.ReportDefect(new IssueId(), "shit be bad yo", "fo real"));

            ProductDefectivenessRanker ranker = new ProductDefectivenessRanker(issues);

            ProductDefectiveness mostDefective = ranker.MostDefectiveProductFrom(tenantId);
        }
        public void Handle(UnitOfWork unitOfWork)
        {
            var affected = unitOfWork.GetChanges().Single();

            Write(new[] {affected});
        }
Пример #8
0
        static void Main(string[] args)
        {
            string usersFilePath = null;

              var options = new OptionSet {
            {"i|input:", "Path to file that contains names and SIDs of users to be imported.", value => usersFilePath = value}
              };

              try {
            options.Parse(args);

            if (usersFilePath != null) {
              var watch = Stopwatch.StartNew();
              var identity = WindowsIdentity.GetCurrent();
              Log.Info("Importing {0} at {1} as {2}.",
                    usersFilePath,
                    XmlConvert.ToString(DateTime.Now, XmlDateTimeSerializationMode.Local),
                    identity != null ? identity.Name : "<unknown>");

              using (var connection = EventStoreConnection.Create()) {
            connection.Connect(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 1113));

            using (var file = File.OpenText(usersFilePath)) {
              string row;
              while ((row = file.ReadLine()) != null) {
                Record record;
                if (Record.TryParse(row, out record)) {
                  var unitOfWork = new UnitOfWork();

                  IRepository<User> userRepository =
                    new Repository<User>(User.Factory, unitOfWork, connection);
                  IRepository<Role> roleRepository =
                    new Repository<Role>(Role.Factory, unitOfWork, connection);
                  var service = new UserApplicationService(userRepository, roleRepository);
                  var command = record.ToCommand();
                  Console.WriteLine("Start handling command: {0} - {1}", command.GetType().Name, command.Identifier);
                  service.Handle(command);
                  if (unitOfWork.HasChanges()) {
                    const int sliceEventCount = 500;
                    var aggregate = unitOfWork.GetChanges().Single();
                    var eventIndex = 0;
                    var slices = from eventData in
                                   aggregate.Root.
                                             GetChanges().
                                             Select(change => new EventData(
                                                                Guid.NewGuid(),
                                                                change.GetType().AssemblyQualifiedName,
                                                                false,
                                                                SerializeEvent(change),
                                                                new byte[0]))
                                 group eventData by eventIndex++%sliceEventCount
                                 into slice
                                 select slice.AsEnumerable();
                    using (var transaction = connection.StartTransaction(
                      aggregate.Identifier,
                      aggregate.ExpectedVersion)) {
                      foreach (var slice in slices) {
                        transaction.Write(slice);
                      }
                      transaction.Commit();
                      Console.WriteLine("Committed events for command");
                    }
                  }

                } else {
                  Log.Error("Could not import the following row. Please make sure it's well formed: {0}", row);
                }
              }
            }
              }

              Log.Info("Completed import at {0} (took {1}ms).",
            XmlConvert.ToString(DateTime.Now, XmlDateTimeSerializationMode.Local),
            watch.ElapsedMilliseconds);
            } else {
              options.WriteOptionDescriptions(Console.Out);
            }
              } catch (OptionException exception) {
            Console.WriteLine(exception.Message);
              }
        }