Beispiel #1
0
        public AggregateRoot(Guid instanceId, IEsRepository repo)
        {
            AggregateInfo = this.GetType().GetTypeInfo().GetCustomAttribute <AggregateRootAttribute>();
            if (AggregateInfo == null)
            {
                throw new Exception("AggregateRoot Attribute has not set");
            }

            this.repo     = repo;
            this.Resource = new ResourceInfo
            {
                TypeId       = AggregateInfo.ResourceTypeId,
                TypeName     = AggregateInfo.ResourceTypeDescription,
                InstanceId   = instanceId,
                InstanceName = $"ID:{instanceId}"
            };

            int   mutationsCount;
            ulong version;

            State   = CreateState(out version, out mutationsCount);
            Version = version;

            if (mutationsCount > AggregateInfo.SnapshotInterval)
            {
                MakeSnapshot();
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="UpdateDailyMiningHyconHandler"/> class.
 /// </summary>
 /// <param name="repository">Aggregate repository</param>
 /// <param name="addressHandler">Address info handler</param>
 /// <param name="messageQueue">Messaging service</param>
 /// <param name="handler">JSON handler</param>
 /// <param name="mineHandler">Modify balance handler</param>
 /// <param name="blockListV2Handler">JSON block list handler</param>
 /// <param name="blockInfoV2Handler">JSON block info handler</param>
 /// <param name="log">Log service</param>
 public UpdateDailyMiningHyconHandler(IEsRepository <IAggregate> repository, ICommandHandler <RequestJson <AddressInfo> > addressHandler, IMessageQueue messageQueue, ICommandHandler <RequestJson <MinedResults> > handler, ICommandHandler <RetroactiveCommand <MineCoin> > mineHandler, ICommandHandler <RequestJson <BlockListV2> > blockListV2Handler, ICommandHandler <RequestJson <BlockInfoV2> > blockInfoV2Handler, ILog log)
     : base(repository, mineHandler)
 {
     _addressHandler     = addressHandler;
     _messageQueue       = messageQueue;
     _handler            = handler;
     _blockListV2Handler = blockListV2Handler;
     _blockInfoV2Handler = blockInfoV2Handler;
     _log = log;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="UpdateDailyOutflowHyconHandler"/> class.
 /// </summary>
 /// <param name="repository">Aggregate repository</param>
 /// <param name="handler">Tx list JSON handler</param>
 /// <param name="messageQueue">Messaging service</param>
 /// <param name="balanceHandler">Wallet balance change handler</param>
 /// <param name="addressHandler">Address JSON handler</param>
 /// <param name="blockListV2Handler">Block list JSON handler</param>
 /// <param name="blockInfoV2Handler">Block info JSON handler</param>
 /// <param name="log">Logging service</param>
 public UpdateDailyOutflowHyconHandler(IEsRepository <IAggregate> repository, ICommandHandler <RequestJson <TxResults> > handler, IMessageQueue messageQueue, ICommandHandler <RetroactiveCommand <ChangeWalletBalance> > balanceHandler, ICommandHandler <RequestJson <AddressInfo> > addressHandler, ICommandHandler <RequestJson <BlockListV2> > blockListV2Handler, ICommandHandler <RequestJson <BlockInfoV2> > blockInfoV2Handler, ILog log)
     : base(repository, balanceHandler)
 {
     _handler            = handler;
     _messageQueue       = messageQueue;
     _addressHandler     = addressHandler;
     _blockListV2Handler = blockListV2Handler;
     _blockInfoV2Handler = blockInfoV2Handler;
     _log = log;
 }
Beispiel #4
0
            /// <summary>
            /// Initializes a new instance of the <see cref="SagaFlow"/> class.
            /// </summary>
            /// <param name="repository">Saga repository</param>
            /// <param name="log">Log service</param>
            /// <param name="messageQueue">Message queue service</param>
            public SagaFlow(IEsRepository <ISaga> repository, ILog log, IMessageQueue messageQueue)
                : base(Configuration.DataflowOptions)
            {
                _repository = repository;
                _log        = log;

                var block = new ActionBlock <IEvent>(
                    async e =>
                {
                    await Handle(e);
                    await messageQueue.CompleteMessage(e);
                }, DataflowOptions.ToDataflowBlockOptions(false));     // .ToExecutionBlockOption());

                RegisterChild(block);
                InputBlock = block;
            }
Beispiel #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Retroactive"/> class.
 /// </summary>
 /// <param name="eventStore">Event store</param>
 /// <param name="sagaStore">Saga store</param>
 /// <param name="graph">Graph</param>
 /// <param name="manager">Branch manager</param>
 /// <param name="streamLocator">Stream locator</param>
 /// <param name="repository">Aggregate repository</param>
 /// <param name="sagaRepository">Saga repository</param>
 /// <param name="log">Log service</param>
 /// <param name="commandRegistry">Command registry</param>
 public Retroactive(
     IEventStore<IAggregate> eventStore,
     IEventStore<ISaga> sagaStore,
     IGraph graph,
     IBranchManager manager,
     IStreamLocator streamLocator,
     IEsRepository<IAggregate> repository,
     IEsRepository<ISaga> sagaRepository,
     ILog log, 
     ICommandRegistry commandRegistry)
 {
     _eventStore = eventStore;
     _graph = graph;
     _manager = manager;
     _streamLocator = streamLocator;
     _sagaStore = sagaStore;
     _repository = repository;
     _sagaRepository = sagaRepository;
     _log = log;
     _commandRegistry = commandRegistry;
 }
        public AggregateRoot(IEsRepository repo, Resource resource, byte detalizationLevel)
        {
            AggregateInfo = Attribute.GetCustomAttribute(this.GetType(), typeof(AggregateRootAttribute)) as AggregateRootAttribute;
            if (AggregateInfo == null)
            {
                throw new Exception("AggregateRoot Attribute has not set");
            }

            this.repo              = repo;
            this.Resource          = resource;
            this.DetalizationLevel = detalizationLevel;

            List <ulong> versions;
            int          mutationsCount;

            State    = CreateState(detalizationLevel, out versions, out mutationsCount);
            Versions = versions;

            if (mutationsCount > AggregateInfo.SnapshotInterval)
            {
                MakeSnapshot();
            }
        }
Beispiel #7
0
 /// <summary>
 /// Repeated repository access until the aggregate root is found or timeout is reached
 /// </summary>
 /// <param name="repository">Aggregate root repository</param>
 /// <param name="id">Aggregate root id</param>
 /// <param name="predicate">Stop condition</param>
 /// <param name="timeout">Execution timeout</param>
 /// <param name="delay">Delay between repeating the bus calls</param>
 /// <typeparam name="T">Aggregate root type</typeparam>
 /// <returns>Task representing the asynchronous repeated find</returns>
 public static async Task <T> FindUntil <T>(this IEsRepository <IAggregate> repository, string id, Func <T, bool> predicate = null, TimeSpan timeout = default(TimeSpan), TimeSpan delay = default(TimeSpan))
     where T : class, IAggregate, new()
 {
     return(await RetryUntil(async() => await repository.Find <T>(id)));
 }
Beispiel #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CommandHandlerBase{TCommand, TRoot}"/> class.
 /// </summary>
 /// <param name="repository">ES repository</param>
 protected CommandHandlerBase(IEsRepository <IAggregate> repository)
 {
     _repository = repository;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="UpdateQuoteHandler"/> class.
 /// </summary>
 /// <param name="repository">Aggregate repository</param>
 /// <param name="handlers">Quote handlers</param>
 public UpdateQuoteHandler(IEsRepository <IAggregate> repository, ICollection <ICommandHandler <UpdateQuote> > handlers)
     : base(repository)
 {
     _repository = repository;
     _handlers   = handlers;
 }
Beispiel #10
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="esRepository">The (injected) Elastic Search repository instance</param>
 public EsMyProductsController(IEsRepository esRepository)
     : base(esRepository)
 {
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="esRepository">The (injected) Elastic Search repository instance</param>
 public ApiWithEsControllerBase(IEsRepository esRepository)
 {
     EsRepository = esRepository;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="UpdateDailyMiningHandler"/> class.
 /// </summary>
 /// <param name="repository">ES repository</param>
 /// <param name="mineHandler">Wallet balance handler</param>
 protected UpdateDailyMiningHandler(IEsRepository <IAggregate> repository, ICommandHandler <RetroactiveCommand <MineCoin> > mineHandler)
     : base(repository)
 {
     _repository  = repository;
     _mineHandler = mineHandler;
 }
Beispiel #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CreateSnapshotHandler{TRoot}"/> class.
 /// </summary>
 /// <param name="repository">ES repository</param>
 public CreateSnapshotHandler(IEsRepository <IAggregate> repository)
     : base(repository)
 {
     ComputeHash = true;
 }
Beispiel #14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UpdateDailyOutflowHandler"/> class.
 /// </summary>
 /// <param name="repository">Aggregate repository</param>
 /// <param name="balanceHandler">Change balance handler</param>
 public UpdateDailyOutflowHandler(IEsRepository <IAggregate> repository, ICommandHandler <RetroactiveCommand <ChangeWalletBalance> > balanceHandler)
     : base(repository)
 {
     _repository     = repository;
     _balanceHandler = balanceHandler;
 }
Beispiel #15
0
        public Journal(Guid instanceId, ICollectionsRepository collectionsRepo, IEsRepository esRepo) : base(instanceId, esRepo)
        {
            this.collectionsRepo = collectionsRepo;

            this.OnMutationEventPushed += (e => UpdateJournalState());
        }