コード例 #1
0
        protected override void DoSetUp()
        {
            var mongoDatabase = MongoHelper.InitializeTestDatabase();


            //Brett

            _cirqus = CreateCommandProcessor(config => config
                                             .EventStore(e => e.UseMongoDb(mongoDatabase, "events"))
                                             .AggregateRootRepository(r => r.Register(c => {
                _aggregateRootRepository =
                    new DefaultAggregateRootRepository((IEventStore)c.GetService(typeof(IEventStore)), (IDomainEventSerializer)c.GetService(typeof(IDomainEventSerializer)), (IDomainTypeNameMapper)c.GetService(typeof(IDomainTypeNameMapper)));
                return(_aggregateRootRepository);
            }))
                                             .EventDispatcher(e => e.UseConsoleOutEventDispatcher()));

            //Orig
            //_cirqus = CommandProcessor.With()
            //    .EventStore(e => e.UseMongoDb(mongoDatabase, "events"))
            //    .AggregateRootRepository(r => r.Register(c =>
            //    {
            //        _aggregateRootRepository = new DefaultAggregateRootRepository(
            //            c.Get<IEventStore>(),
            //            c.Get<IDomainEventSerializer>(),
            //            c.Get<IDomainTypeNameMapper>());

            //        return _aggregateRootRepository;
            //    }))
            //    .EventDispatcher(e => e.UseConsoleOutEventDispatcher())
            //    .Create();

            RegisterForDisposal(_cirqus);
        }
コード例 #2
0
 /// <summary>
 /// Creates the view context with the given repository and type name mapper, storing the given event batch to be able to look up events in case it could make sense
 /// </summary>
 public DefaultViewContext(IAggregateRootRepository aggregateRootRepository, IDomainTypeNameMapper domainTypeNameMapper, IEnumerable <DomainEvent> eventBatch)
 {
     Items = new Dictionary <string, object>();
     _aggregateRootRepository = aggregateRootRepository;
     _eventBatch     = eventBatch.OrderBy(e => e.GetGlobalSequenceNumber()).ToList();
     _realUnitOfWork = new RealUnitOfWork(_aggregateRootRepository, domainTypeNameMapper);
 }
コード例 #3
0
 internal TestUnitOfWork(IAggregateRootRepository aggregateRootRepository, IEventStore eventStore, IEventDispatcher eventDispatcher, IDomainEventSerializer domainEventSerializer, IDomainTypeNameMapper domainTypeNameMapper)
 {
     _eventStore            = eventStore;
     _eventDispatcher       = eventDispatcher;
     _domainEventSerializer = domainEventSerializer;
     _realUnitOfWork        = new RealUnitOfWork(aggregateRootRepository, domainTypeNameMapper);
 }
コード例 #4
0
 public CachingAggregateRootRepositoryDecorator(IAggregateRootRepository innerAggregateRootRepository, ISnapshotCache snapshotCache, IEventStore eventStore, IDomainEventSerializer domainEventSerializer)
 {
     _innerAggregateRootRepository = innerAggregateRootRepository;
     _snapshotCache         = snapshotCache;
     _eventStore            = eventStore;
     _domainEventSerializer = domainEventSerializer;
 }
コード例 #5
0
        public SetupModule(IAggregateRootRepository repository,
                           IAccountRepository accountRepository,
                           IIdGenerator idGenerator)
            :base("/setup")
        {
            Get["/"] = _ =>
            {
                if (accountRepository.Count() > 0)
                    return HttpStatusCode.NotFound;

                return View["Index"];
            };

            Post["/"] = _ =>
            {
                var model = this.Bind<CreateModel>();

                if (accountRepository.Count() > 0)
                    return HttpStatusCode.NotFound;

                var account = new Domain.Account(idGenerator.NextGuid(),
                    model.Name, model.FirstName, model.LastName, model.Email);

                account.ChangePassword(model.Password);
                account.MakeAdmin();

                repository.Save(account);

                return Response.AsRedirect("/");
            };
        }
コード例 #6
0
        public Repository_Tests()
        {
            _aggregateRootRepository = The <IAggregateRootRepository <OrderState> >();

            SeedOrder().ConfigureAwait(false)
            .GetAwaiter().GetResult();
        }
コード例 #7
0
 public ApiResourceStoreBase(IAggregateRootRepository <ApiResource, Guid> apiResourceRepository, IAggregateRootRepository <IdentityResource, Guid> identityResourceRepository, IAggregateRootRepository <ApiScope, Guid> apiScopeRepository, ILogger <ApiResourceStoreBase> logger)
 {
     _apiResourceRepository      = apiResourceRepository;
     _identityResourceRepository = identityResourceRepository;
     _apiScopeRepository         = apiScopeRepository;
     _logger = logger;
 }
コード例 #8
0
 public NewSnapshottingAggregateRootRepositoryDecorator(IAggregateRootRepository aggregateRootRepository, IEventStore eventStore, IDomainEventSerializer domainEventSerializer, ISnapshotStore snapshotStore, TimeSpan preparationThreshold)
 {
     _aggregateRootRepository = aggregateRootRepository;
     _eventStore            = eventStore;
     _domainEventSerializer = domainEventSerializer;
     _snapshotStore         = snapshotStore;
     _preparationThreshold  = preparationThreshold;
 }
コード例 #9
0
 public DayAssignCommandHandler(IAggregateRootRepository <DayAssignDomain> repository,
                                IDayAssignProvider dayAssignProvider,
                                IAppSettingHelper appSettingHelper)
 {
     this.repository        = repository;
     this.dayAssignProvider = dayAssignProvider;
     this.appSettingHelper  = appSettingHelper;
 }
コード例 #10
0
        public AdminModule(IAggregateRootRepository repository,
                           IIdGenerator idGenerator)
            : base("/write/admin")
        {
            this.RequiresAuthentication();
            this.RequiresClaims(new[] { "Admin" });

            Post["/account/create"] = parameters =>
            {
                var model = this.Bind<EditableAccount>();
                var account = new Domain.Account(idGenerator.NextGuid(),
                    model.Name, model.FirstName, model.LastName, model.Email);

                var password = account.GeneratePassword();

                repository.Save(account);

                return Json(new
                {
                    Account = new Account(account),
                    Password = password
                });
            };

            Post["/account/update/{id:guid}"] = parameters =>
            {
                var model = this.Bind<EditableAccount>();
                var account = repository.GetById<Domain.Account>((Guid)parameters.id);

                if (account != null)
                {
                    account.ChangeDetails(model.Name, model.FirstName, model.LastName, model.Email);

                    repository.Save(account);

                    return Json(new
                    {
                        Account = new Account(account)
                    });
                }

                return null;
            };

            Post["/account/{id:guid}/newpassword"] = parameters =>
            {
                var model = this.Bind<AccountNewPassword>();
                var account = repository.GetById<Domain.Account>((Guid)parameters.id);

                if (account != null)
                {
                    account.ChangePassword(model.Password);
                    repository.Save(account);
                }

                return null;
            };
        }
コード例 #11
0
        public static TAggregateRoot Get <TAggregateRoot>(
            this IAggregateRootRepository repo,
            string aggregateRootId)
            where TAggregateRoot : AggregateRoot, new()
        {
            var aggregateRoot = repo.Get <TAggregateRoot>(aggregateRootId, new InMemoryUnitOfWork(repo, new DefaultDomainTypeNameMapper()), createIfNotExists: true);

            return((TAggregateRoot)aggregateRoot);
        }
コード例 #12
0
ファイル: CommandHandler.cs プロジェクト: luonghongthuan/cqrs
 protected CommandHandler(IUnitOfWorkManager unitOfWorkManager, IAggregateRootRepository aggregateRootRepository)
 {
     if (unitOfWorkManager == null)
     {
         throw new ArgumentNullException(nameof(unitOfWorkManager));
     }
     _aggregateRootRepository = aggregateRootRepository ?? throw new ArgumentNullException(nameof(aggregateRootRepository));
     _unitOfWork = unitOfWorkManager.CurrentUnitOfWork();
 }
コード例 #13
0
        public Concurrency_Tests()
        {
            _aggregateRootRepository = The <IAggregateRootRepository <CarState> >();

            _fakeCarId = Guid.NewGuid().ToString();

            SeedCar().ConfigureAwait(false)
            .GetAwaiter().GetResult();
        }
コード例 #14
0
 internal TestContext(InMemoryEventStore eventStore, IAggregateRootRepository aggregateRootRepository, IEventDispatcher eventDispatcher,
                      IDomainEventSerializer domainEventSerializer, ICommandMapper commandMapper, IDomainTypeNameMapper domainTypeNameMapper)
 {
     _eventStore = eventStore;
     _aggregateRootRepository = aggregateRootRepository;
     _eventDispatcher         = eventDispatcher;
     _domainEventSerializer   = domainEventSerializer;
     _testCommandMapper       = commandMapper;
     _domainTypeNameMapper    = domainTypeNameMapper;
 }
コード例 #15
0
        public CosmosDbConnection_Tests()
        {
            _cosmosDBConnection      = The <ICosmosDBConnection>();
            _aggregateRootRepository = The <IAggregateRootRepository <CarState> >();
            _streamNameProvider      = The <IStreamNameProvider>();
            _fakeCarId = Guid.NewGuid().ToString();

            SeedCar().ConfigureAwait(false)
            .GetAwaiter().GetResult();
        }
コード例 #16
0
        public BasketCommandHandler(IBus bus, IAggregateRootRepository <BasketBase> repository)
        {
            _bus        = bus;
            _repository = repository;

            Register <Command <CreateBasket>, PendingBasket>(CreateBasketHandler);
            Register <Command <AddItemToBasket>, PendingBasket>(AddItemToBasketHandler);
            Register <Command <RemoveItemFromBasket>, PendingBasket>(RemoveItemFromBasketHandler);
            Register <Command <CancelBasket>, CancelledBasket>(CancelBasketHandler);
            Register <Command <CheckOutBasket>, CheckedOutBasket>(CheckOutBasketHandler);
        }
コード例 #17
0
 public InMemoryViewEventDispatcher(
     IEventStore eventStore,
     IAggregateRootRepository aggregateRootRepository,
     IDomainEventSerializer domainEventSerializer,
     IDomainTypeNameMapper domainTypeNameMapper)
 {
     _eventStore = eventStore;
     _aggregateRootRepository = aggregateRootRepository;
     _domainEventSerializer   = domainEventSerializer;
     _domainTypeNameMapper    = domainTypeNameMapper;
 }
コード例 #18
0
 public SnapshotterCosmosDB(IAggregateRootRepository <TAggregateRoot> rootRepository,
                            IAggregateChangeTracker changeTracker,
                            ICosmosDBClient cosmosDbClient,
                            ICosmosDBConfigurations cosmosDBConfigurations,
                            IEventSerializer eventSerializer)
 {
     _rootRepository         = rootRepository ?? throw new ArgumentNullException(nameof(rootRepository));
     _changeTracker          = changeTracker ?? throw new ArgumentNullException(nameof(changeTracker));
     _cosmosDbClient         = cosmosDbClient ?? throw new ArgumentNullException(nameof(cosmosDbClient));
     _cosmosDBConfigurations = cosmosDBConfigurations ?? throw new ArgumentNullException(nameof(cosmosDBConfigurations));
     _eventSerializer        = eventSerializer ?? throw new ArgumentNullException(nameof(eventSerializer));
 }
コード例 #19
0
        public SynchronousViewManagerEventDispatcher(
            IAggregateRootRepository aggregateRootRepository,
            IDomainEventSerializer domainEventSerializer,
            IDomainTypeNameMapper domainTypeNameMapper,
            params IViewManager[] viewManagers)
        {
            this.viewManagers = viewManagers.ToList();

            _aggregateRootRepository = aggregateRootRepository;
            _domainEventSerializer = domainEventSerializer;
            _domainTypeNameMapper = domainTypeNameMapper;
        }
コード例 #20
0
        public ProductCommandHandler(IBus bus, IAggregateRootRepository <Product> repository)
        {
            _bus        = bus;
            _repository = repository;

            Register <Command <CreateProduct>, Product>(CreateProductHandler);
            Register <Command <SetProductQuantity>, Product>(SetProductQuantityHandler);
            Register <Command <AddProductToStock>, Product>(AddProductToStockHandler);
            Register <Command <RemoveProductFromStock>, Product>(RemoveProductFromStockHandler);
            Register <Command <ReserveProduct>, Product>(ReserveProductHandler);
            Register <Command <CancelProductReservation>, Product>(CancelProductReservationHandler);
            Register <Command <PurchaseReservedProduct>, Product>(PurchaseReservedProductHandler);
        }
コード例 #21
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AggregateRootOfflineSnapshotService"/> class.
 /// </summary>
 /// <param name="repository">The repository.</param>
 /// <param name="snaphotQuery">The snaphot query.</param>
 public AggregateRootOfflineSnapshotService(IAggregateRootRepository repository, IOfflineSnaphotQuery snaphotQuery)
 {
     if (repository == null)
     {
         throw new ArgumentNullException("repository");
     }
     if (snaphotQuery == null)
     {
         throw new ArgumentNullException("snaphotQuery");
     }
     _repository   = repository;
     _snaphotQuery = snaphotQuery;
 }
コード例 #22
0
        protected override void DoSetUp()
        {
            _cirqus = CreateCommandProcessor(config => config
                                             .EventStore(e => _eventStore = e.UseInMemoryEventStore())
                                             .AggregateRootRepository(r => r.Register(c =>
            {
                _aggregateRootRepository = new DefaultAggregateRootRepository(c.GetService <IEventStore>(), c.GetService <IDomainEventSerializer>(), c.GetService <IDomainTypeNameMapper>());

                return(_aggregateRootRepository);
            }))
                                             .EventDispatcher(e => e.UseConsoleOutEventDispatcher()));

            RegisterForDisposal(_cirqus);
        }
        public SynchronousViewManagerEventDispatcher(
            IEventStore eventStore,
            IAggregateRootRepository aggregateRootRepository,
            IDomainEventSerializer domainEventSerializer,
            IDomainTypeNameMapper domainTypeNameMapper,
            params IViewManager[] viewManagers)
        {
            this.viewManagers = viewManagers.ToList();

            _eventStore = eventStore;
            _aggregateRootRepository = aggregateRootRepository;
            _domainEventSerializer   = domainEventSerializer;
            _domainTypeNameMapper    = domainTypeNameMapper;
        }
コード例 #24
0
        /// <summary>
        /// Bad design, circular dependency :(
        /// </summary>
        /// <param name="dataStoreConnectionFactory"></param>
        public void Initialize(
            IDataStoreConnectionFactory dataStoreConnectionFactory,
            IAggregateRootRepository repository,
            ISessionTracker sessionTracker)
        {
            _dataStoreConnectionFactory = dataStoreConnectionFactory;
            _repository     = repository;
            _sessionTracker = sessionTracker;

            // Todo: Why did I load all prior sessions into memory here?
            //sessionTracker.Initialize();

            _initialized = true;
        }
コード例 #25
0
 public SnapshotEventStore(IAggregateRootRepository <TAggregateRoot> rootRepository,
                           IAggregateChangeTracker changeTracker,
                           IStreamNameProvider streamNameProvider,
                           IEventStoreConnection connection,
                           IEventSerializer eventSerializer,
                           Func <ResolvedEvent, bool> strategy)
 {
     _rootRepository     = rootRepository ?? throw new ArgumentNullException(nameof(rootRepository));
     _changeTracker      = changeTracker ?? throw new ArgumentNullException(nameof(changeTracker));
     _streamNameProvider = streamNameProvider ?? throw new ArgumentNullException(nameof(streamNameProvider));
     _connection         = connection ?? throw new ArgumentNullException(nameof(connection));
     _eventSerializer    = eventSerializer ?? throw new ArgumentNullException(nameof(eventSerializer));
     _strategy           = strategy ?? throw new ArgumentNullException(nameof(strategy));
 }
コード例 #26
0
        /// <summary>
        /// Behaves as.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="service">The service.</param>
        /// <returns></returns>
        public static T BehaveAs <T>(this IAggregateRootRepository service)
            where T : class, IAggregateRootRepository
        {
            IServiceWrapper <IAggregateRootRepository> serviceWrapper;

            do
            {
                serviceWrapper = (service as IServiceWrapper <IAggregateRootRepository>);
                if (serviceWrapper != null)
                {
                    service = serviceWrapper.Parent;
                }
            } while (serviceWrapper != null);
            return(service as T);
        }
コード例 #27
0
ファイル: TestContext.cs プロジェクト: kaleyroy/Cirqus
        internal TestContext(InMemoryEventStore eventStore, IAggregateRootRepository aggregateRootRepository, IEventDispatcher eventDispatcher,
                             IDomainEventSerializer domainEventSerializer, ICommandMapper commandMapper, IDomainTypeNameMapper domainTypeNameMapper)
        {
            _eventStore = eventStore;
            _aggregateRootRepository = aggregateRootRepository;
            _eventDispatcher         = eventDispatcher;
            _domainEventSerializer   = domainEventSerializer;
            _testCommandMapper       = commandMapper;
            _domainTypeNameMapper    = domainTypeNameMapper;

            _viewManagerEventDispatcher = eventDispatcher as ViewManagerEventDispatcher;
            if (_viewManagerEventDispatcher != null)
            {
                _waitHandle.Register(_viewManagerEventDispatcher);
            }
        }
コード例 #28
0
        /// <summary>
        /// Constructs the event dispatcher
        /// </summary>
        public DependentViewManagerEventDispatcher(IEnumerable <IViewManager> dependencies, IEnumerable <IViewManager> viewManagers, IEventStore eventStore, IDomainEventSerializer domainEventSerializer, IAggregateRootRepository aggregateRootRepository, IDomainTypeNameMapper domainTypeNameMapper, Dictionary <string, object> viewContextItems)
        {
            _dependencies            = dependencies.ToList();
            _viewManagers            = viewManagers.ToList();
            _eventStore              = eventStore;
            _domainEventSerializer   = domainEventSerializer;
            _aggregateRootRepository = aggregateRootRepository;
            _domainTypeNameMapper    = domainTypeNameMapper;
            _viewContextItems        = viewContextItems;
            _workerThread            = new Thread(DoWork)
            {
                IsBackground = true
            };

            _automaticCatchUpTimer.Elapsed += (o, ea) => _work.Enqueue(new Work());
            _automaticCatchUpTimer.Interval = 1000;
            _maxDomainEventsPerBatch        = 100;
        }
コード例 #29
0
        public ViewManagerEventDispatcher(IAggregateRootRepository aggregateRootRepository, IEventStore eventStore,
                                          IDomainEventSerializer domainEventSerializer, IDomainTypeNameMapper domainTypeNameMapper, params IViewManager[] viewManagers)
        {
            if (aggregateRootRepository == null)
            {
                throw new ArgumentNullException("aggregateRootRepository");
            }
            if (eventStore == null)
            {
                throw new ArgumentNullException("eventStore");
            }
            if (domainEventSerializer == null)
            {
                throw new ArgumentNullException("domainEventSerializer");
            }
            if (domainTypeNameMapper == null)
            {
                throw new ArgumentNullException("domainTypeNameMapper");
            }
            if (viewManagers == null)
            {
                throw new ArgumentNullException("viewManagers");
            }

            _aggregateRootRepository = aggregateRootRepository;
            _eventStore            = eventStore;
            _domainEventSerializer = domainEventSerializer;
            _domainTypeNameMapper  = domainTypeNameMapper;

            viewManagers.ToList().ForEach(view => _viewManagers.Enqueue(view));

            _worker = new Thread(DoWork)
            {
                IsBackground = true
            };

            _automaticCatchUpTimer.Elapsed += delegate
            {
                _work.Enqueue(PieceOfWork.FullCatchUp(false));
            };

            AutomaticCatchUpInterval = TimeSpan.FromSeconds(1);
        }
コード例 #30
0
        public CommandProcessor(
            IEventStore eventStore, IAggregateRootRepository aggregateRootRepository, IEventDispatcher eventDispatcher,
            IDomainEventSerializer domainEventSerializer, ICommandMapper commandMapper, IDomainTypeNameMapper domainTypeNameMapper,
            Options options)
        {
            if (eventStore == null)
            {
                throw new ArgumentNullException("eventStore");
            }
            if (aggregateRootRepository == null)
            {
                throw new ArgumentNullException("aggregateRootRepository");
            }
            if (eventDispatcher == null)
            {
                throw new ArgumentNullException("eventDispatcher");
            }
            if (domainEventSerializer == null)
            {
                throw new ArgumentNullException("domainEventSerializer");
            }
            if (commandMapper == null)
            {
                throw new ArgumentNullException("commandMapper");
            }
            if (domainTypeNameMapper == null)
            {
                throw new ArgumentNullException("domainTypeNameMapper");
            }
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            _eventStore = eventStore;
            _aggregateRootRepository = aggregateRootRepository;
            _eventDispatcher         = eventDispatcher;
            _domainEventSerializer   = domainEventSerializer;
            _commandMapper           = commandMapper;
            _domainTypeNameMapper    = domainTypeNameMapper;
            _options = options;
        }
コード例 #31
0
        protected override void DoSetUp()
        {
            var mongoDatabase = MongoHelper.InitializeTestDatabase();

            _cirqus = CommandProcessor.With()
                      .EventStore(e => e.UseMongoDb(mongoDatabase, "events"))
                      .AggregateRootRepository(r => r.Register(c =>
            {
                _aggregateRootRepository = new DefaultAggregateRootRepository(
                    c.Get <IEventStore>(),
                    c.Get <IDomainEventSerializer>(),
                    c.Get <IDomainTypeNameMapper>());

                return(_aggregateRootRepository);
            }))
                      .EventDispatcher(e => e.UseConsoleOutEventDispatcher())
                      .Create();

            RegisterForDisposal(_cirqus);
        }
コード例 #32
0
        public ClientModule(IAggregateRootRepository repository,
                            IIdGenerator idGenerator)
            :base("/write/client")
        {
            this.RequiresAuthentication();

            Post["/create"] = parameters =>
            {
                var model = this.Bind<EditableClient>();

                var client = new Domain.Client(idGenerator.NextGuid(), model.Name);

                repository.Save(client);

                return Json(new
                {
                    Client = new Client(client)
                });
            };

            Post["/update/{id:guid}"] = parameters =>
            {
                var model = this.Bind<EditableClient>();

                var client = repository.GetById<Domain.Client>((Guid)parameters.id);

                if (client != null)
                {
                    client.ChangeDetails(model.Name);

                    repository.Save(client);

                    return Json(new
                    {
                        Client = new Client(client)
                    });
                }

                return null;
            };
        }
コード例 #33
0
ファイル: CommandProcessor.cs プロジェクト: RichieYang/Cirqus
        public CommandProcessor(
            IEventStore eventStore, IAggregateRootRepository aggregateRootRepository, IEventDispatcher eventDispatcher,
            IDomainEventSerializer domainEventSerializer, ICommandMapper commandMapper, IDomainTypeNameMapper domainTypeNameMapper,
            Options options)
        {
            if (eventStore == null) throw new ArgumentNullException("eventStore");
            if (aggregateRootRepository == null) throw new ArgumentNullException("aggregateRootRepository");
            if (eventDispatcher == null) throw new ArgumentNullException("eventDispatcher");
            if (domainEventSerializer == null) throw new ArgumentNullException("domainEventSerializer");
            if (commandMapper == null) throw new ArgumentNullException("commandMapper");
            if (domainTypeNameMapper == null) throw new ArgumentNullException("domainTypeNameMapper");
            if (options == null) throw new ArgumentNullException("options");

            _eventStore = eventStore;
            _aggregateRootRepository = aggregateRootRepository;
            _eventDispatcher = eventDispatcher;
            _domainEventSerializer = domainEventSerializer;
            _commandMapper = commandMapper;
            _domainTypeNameMapper = domainTypeNameMapper;
            _options = options;
        }
コード例 #34
0
ファイル: CommandHandlers.cs プロジェクト: LenFon/Bifrost
 public CommandHandlers(IAggregateRootRepository<Employee> repository)
 {
     _repository = repository;
 }
コード例 #35
0
        public TimeRegistrationModule(IAggregateRootRepository repository,
                                      IIdGenerator idGenerator)
            : base("/write/timeregistration")
        {
            this.RequiresAuthentication();

            Post["/create"] = parameters =>
            {
                var model = this.Bind<EditableTimeRegistration>();

                var client = repository.GetById<Domain.Client>(model.ClientId);
                var project = repository.GetById<Domain.Project>(model.ProjectId);
                var task = project.FindTask(model.Task);

                var date = Date.Parse(model.Date);
                var from = Time.Parse(model.From);
                var to = Time.Parse(model.To);

                var timeRegistration = new Domain.TimeRegistration(idGenerator.NextGuid(),
                    client, project, task,
                    model.Description, date, from, to);

                if (model.CorrectedIncome.HasValue)
                    timeRegistration.CorrectIncome(model.CorrectedIncome.Value, model.CorrectedIncomeMessage);

                repository.Save(timeRegistration);

                return Json(new
                {
                    TimeRegistration = new TimeRegistration(timeRegistration, client, project)
                });
            };

            Post["/update/{id:guid}"] = parameters =>
            {
                var model = this.Bind<EditableTimeRegistration>();

                var timeRegistration = repository.GetById<Domain.TimeRegistration>((Guid)parameters.id);

                if (timeRegistration != null)
                {
                    var client = repository.GetById<Domain.Client>(model.ClientId);
                    var project = repository.GetById<Domain.Project>(model.ProjectId);
                    var task = project.FindTask(model.Task);

                    var date = Date.Parse(model.Date);
                    var from = Time.Parse(model.From);
                    var to = Time.Parse(model.To);

                    timeRegistration.ChangeDetails(client, project, task,
                        model.Description, date, from, to);

                    if (model.CorrectedIncome.HasValue)
                        timeRegistration.CorrectIncome(model.CorrectedIncome.Value, model.CorrectedIncomeMessage);
                    else
                        timeRegistration.ClearCorrectedIncome();

                    if (model.RefreshRate)
                        timeRegistration.RefreshRate(task);

                    repository.Save(timeRegistration);

                    return Json(new
                    {
                        TimeRegistration = new TimeRegistration(timeRegistration, client, project)
                    });
                }

                return null;
            };

            Post["/delete/{id:guid}"] = parameters =>
            {
                var timeRegistration = repository.GetById<Domain.TimeRegistration>((Guid)parameters.id);

                if (timeRegistration != null)
                {
                    timeRegistration.Delete();

                    repository.Save(timeRegistration);
                }

                return null;
            };
        }
コード例 #36
0
 public ExcelService(IAggregateRootRepository aggregateRootRepository,
                     IIdGenerator idGenerator)
 {
     _aggregateRootRepository = aggregateRootRepository;
     _idGenerator = idGenerator;
 }
コード例 #37
0
ファイル: CommandHandlers.cs プロジェクト: dolittle/Chirp
 public CommandHandlers(IAggregateRootRepository<User> userAggregateRootRepository, IUserService userService)
 {
     _userAggregateRootRepository = userAggregateRootRepository;
     _userService = userService;
 }
コード例 #38
0
        public ProjectModule(IAggregateRootRepository repository,
                             IIdGenerator idGenerator)
            :base("/write/project")
        {
            this.RequiresAuthentication();

            Post["/create"] = parameters =>
            {
                var model = this.Bind<EditableProject>();

                var client = repository.GetById<Domain.Client>(model.ClientId);
                var project = new Domain.Project(idGenerator.NextGuid(), model.Name, model.Description, client);

                repository.Save(project);

                return Json(new
                {
                    Project = new Project(client, project)
                });
            };

            Post["/update/{id:guid}"] = parameters =>
            {
                var model = this.Bind<EditableProject>();

                var project = repository.GetById<Domain.Project>((Guid)parameters.id);

                if (project != null)
                {
                    project.ChangeDetails(model.Name, model.Description);

                    if (model.Hidden)
                        project.Hide();
                    else project.Unhide();

                    repository.Save(project);

                    var client = repository.GetById<Domain.Client>(project.ClientId);

                    return Json(new
                    {
                        Project = new Project(client, project)
                    });
                }

                return null;
            };

            Post["/updatetasks/{id:guid}"] = parameters =>
            {
                var model = this.Bind<EditableProjectTasks>();

                var project = repository.GetById<Domain.Project>((Guid)parameters.id);

                if (project != null)
                {
                    project.ChangeTasks(model.Tasks.Select(t => new Domain.ValueObjects.Task { Name = t.Name, Rate = t.Rate }).ToArray());

                    repository.Save(project);

                    var client = repository.GetById<Domain.Client>(project.ClientId);

                    return Json(new
                    {
                        Project = new Project(client, project)
                    });
                }

                return null;
            };
        }
コード例 #39
0
ファイル: CommandHandlers.cs プロジェクト: LenFon/Bifrost
 public CommandHandlers(IAggregateRootRepository<EventStore> repository)
 {
     _repository = repository;
 }
コード例 #40
0
 public CommandHandlers(IAggregateRootRepository<Transaction> repository)
 {
     _repository = repository;
 }
コード例 #41
0
ファイル: ChirpCommandHandler.cs プロジェクト: dolittle/Chirp
 public ChirpCommandHandler(IAggregateRootRepository<ChirpStream> streamRepository)
 {
     _streamRepository = streamRepository;
 }
コード例 #42
0
 public AssignStoryCommandHandler(IAggregateRootRepository <StoryAggregateRoot> aggregateRootRepository)
 {
     _aggregateRootRepository = aggregateRootRepository;
 }
コード例 #43
0
 public FollowCommandHandler(IAggregateRootRepository<Following> subscriptionsRepository)
 {
     _subscriptionsRepository = subscriptionsRepository;
 }
コード例 #44
0
 public ProductSubscribedEventHandler(IAggregateRootRepository aggregateRootRepository)
 {
     _aggregateRootRepository = aggregateRootRepository ?? throw new ArgumentNullException(nameof(aggregateRootRepository));
 }
コード例 #45
0
        public TimeRegistrationModule(IProjectRepository projectRepository, 
                                      IClientRepository clientRepository, 
                                      ITimeRegistrationRepository timeRegistrationRepository, 
                                      IIdGenerator idGenerator, 
                                      IAggregateRootRepository aggregateRootRepository,
                                      IRootPathProvider rootPathProvider,
                                      IExcelService excelService)
            : base("/timeregistration")
        {
            this.RequiresAuthentication();

            Get["/"] = _ => View["Index"];

            Get["/overview"] = _ => View["Overview"];

            Get["/report"] = _ => View["Report"];

            Get["/import"] = _ => View["Import"];

            Post["/importupload"] = _ =>
            {
                var fileName = Guid.NewGuid().ToString("N").Substring(0, 4) + "_" + Path.GetFileName((string)Request.Files.First().Name);
                var path = Path.Combine(rootPathProvider.GetRootPath(), "App_Data", "Uploads", fileName);
               
                using (var fileStream = new FileStream(path, FileMode.Create))
                {
                    Request.Files.First().Value.CopyTo(fileStream);
                }

                return Response.AsRedirect("~/timeregistration/importmap/" + HttpUtility.UrlEncode(fileName));
            };

            Get["/importmap/{url*}"] = parameters =>
            {
                var viewModel = new ImportViewModel();

                viewModel.ServerFile = Path.Combine(rootPathProvider.GetRootPath(), "App_Data", "Uploads", parameters.url);
                var excelPackage = new ExcelPackage(new FileInfo(viewModel.ServerFile));
                var worksheet = excelPackage.Workbook.Worksheets.First();

                viewModel.ColumnNames = new List<ImportViewModel.ColumnInfo>();
                foreach (var firstRowCell in worksheet.Cells[worksheet.Dimension.Start.Row, worksheet.Dimension.Start.Column, 1, worksheet.Dimension.End.Column])
                    viewModel.ColumnNames.Add(new ImportViewModel.ColumnInfo { Column = firstRowCell.Start.Column, Name = firstRowCell.Text });

                return View["ImportMap", viewModel];
            };

            Post["/import"] = _ =>
            {
                var viewModel = this.Bind<ImportViewModel>();

                var result = excelService.Import(viewModel.ServerFile, viewModel.ProjectIdColumn, viewModel.TaskColumn,
                                                 viewModel.DateColumn, viewModel.FromColumn, viewModel.ToColumn, 
                                                 viewModel.RateColumn, viewModel.DescriptionColumn);

                return View["ImportResult", result];
            };

            Get["/export/{fromDate}/{toDate}"] = parameters =>
            {
                var min = ((DateTime)parameters.fromDate).GetNumericValue();
                var max = ((DateTime)parameters.toDate).AddDays(1).GetNumericValue();

                var items = timeRegistrationRepository
                    .Where(t => t.Date.Numeric >= min && t.Date.Numeric < max)
                    .OrderBy(t => t.Date.Numeric)
                    .ThenBy(t => t.From.Numeric)
                    .ToList();

                return Response.AsExcel(items);
            };
        }