//private readonly MemoryStream _MemoryStream = new MemoryStream();

        public CmdletListener(DomainCommand command, ProgressRecord progress)
        {
            //_MemoryStream
            //base.Writer = new StreamWriter();
            _command  = command;
            _progress = progress;
        }
 static void OnAggregateSaved(CommandHandlerBase sender, IAggregate aggr, DomainCommand by)
 {
     if (by != null && aggr != null)
     {
         Console.WriteLine("[AGGR] {0} -> {1} -> {2}",
                           by.GetType().FullName,
                           aggr.GetType().FullName,
                           string.Join(", ", aggr.GetUncommittedEvents().OfType <object>().Select(e => e.GetType().FullName)));
     }
 }
        private async Task <bool> Validar(DomainCommand <Models.Colaborador> message)
        {
            if (!message.EhValido())
            {
                await NotificarErrosValidacao(message);

                return(false);
            }
            return(true);
        }
Esempio n. 4
0
        public void PublishCommand(DomainCommand command)
        {
            var json            = JsonConvert.SerializeObject(command);
            var body            = Encoding.UTF8.GetBytes(json);
            var basicProperties = Model.CreateBasicProperties();

            basicProperties.Type      = command.GetType().Name;
            basicProperties.Timestamp = new AmqpTimestamp(command.Timestamp);
            Model.BasicPublish(string.Empty, command.DestinationQueue, false, basicProperties, body);
        }
        private Models.Colaborador ObterColaboradorPorId(DomainCommand <Models.Colaborador> message, ref bool success)
        {
            var colaboradorDb = _colaboradorRepository.GetById(message.Data.Id);

            if (colaboradorDb == null)
            {
                _mediatorHandler.PublicarNotificacao(new DomainNotification(message.MessageType, $"Colaborador id:{message.Data.Id}- {message.Data.Nome} não foi localizado no banco de dados!")).Wait();
                success = false;
            }
            return(colaboradorDb);
        }
        private async Task <bool> TipoPagamentoExiste(IList <TipoPagamento> lista, DomainCommand <Models.Colaborador> message)
        {
            var result = new StringBuilder();

            foreach (var item in lista)
            {
                if (!_colaboradorRepository.TipoPagamentoExiste(item.Id))
                {
                    result.AppendLine($"Tipo de Pagamento {item.Id}- {item.Descricao} não foi encontrado no banco de dados!");
                }
            }
            if (result.Length > 0)
            {
                await _mediatorHandler.PublicarNotificacao(new DomainNotification(message.MessageType, result.ToString()));

                return(false);
            }
            return(true);
        }
        public async Task ExecuteAsync(string streamName, DomainCommand domainCommand,
                                       CancellationToken cancellationToken = default)
        {
            //Reading stream
            var eventStream = _eventStore.ReadStreamAsync(
                Direction.Forwards,
                streamName,
                StreamPosition.Start,
                cancellationToken: cancellationToken);

            //Checking if stream exists
            var streamNotFound = await eventStream.ReadState == ReadState.StreamNotFound;

            //Stream version for optimistic concurrency. We use it during appending.
            StreamRevision streamVersion = streamNotFound
                ? StreamRevision.None.ToUInt64()
                : (await eventStream.LastAsync(cancellationToken: cancellationToken)).Event.EventNumber.ToUInt64();

            //If stream not found our history is empty, if found - read events from event store as history
            var history = streamNotFound
                ? new List <IDomainEvent>()
                : await eventStream.Select(resolvedEvent => _eventSerializer.Deserialize(resolvedEvent))
                          .Where(@event => @event != null)
                          .Select(@event => @event !)
                          .ToListAsync(cancellationToken);

            //Execute domain operation, which takes history of events and produce new events (changes)
            var changes = domainCommand(history);

            //Serialize events to event store format
            var eventsToStore = changes.Select(change => _eventSerializer.Serialize(change));

            //Append new changes (events) to the stream
            await _eventStore.AppendToStreamAsync(streamName, streamVersion, eventsToStore.ToList(),
                                                  cancellationToken : cancellationToken);
        }
Esempio n. 8
0
 protected virtual void Save(IAggregate aggr, DomainCommand by, string bucketId)
 {
     if (OnSavedHook != null)
     {
         OnSavedHook(this, aggr, by);
     }
     foreach (DomainEvent evt in aggr.GetUncommittedEvents())
     {
         if (!evt.TenantId.HasValue)
         {
             evt.TenantId = @by.TenantId;
         }
         if (!evt.IssuedBy.HasValue)
         {
             evt.IssuedBy = @by.IssuedBy;
         }
         if (!evt.SagaId.HasValue)
         {
             evt.SagaId = @by.SagaId;
         }
         evt.Version = aggr.Version;
     }
     repo.Save(bucketId, aggr, @by.CommitId);
 }
Esempio n. 9
0
 internal override void BuildAction(string action)
 {
     base.BuildAction(action);
     this.domainCommand = new DomainCommand(this.CommandArguments, this.SessionService.Object, this.FilterService.Object);
 }
Esempio n. 10
0
        public static void Process(Message message)
        {
            var context = JsonConvert.DeserializeObject <TCommand>(message.Value);

            DomainCommand.Send <TCommand>(context);
        }
Esempio n. 11
0
        public static async Task <IActionResult> ProcessCommandAsync(IAggregateRoot ar, DomainCommand c)
        {
            var result = await ar.HandleGenericCommandAsync(c, CancellationToken.None);

            if (result.IsSuccess)
            {
                return(new OkResult());
            }
            else
            {
                return(new BadRequestObjectResult(result.Errors));
            }
        }
 public ProgressObserver(DomainCommand command, ProgressRecord progress)
 {
     _command  = command;
     _progress = progress;
 }