Пример #1
0
        public MessageResponse Insert(MessageRequest request)
        {
            var entityToSave = _messageMapper.Parse(request);

            entityToSave.Sms = RandomNumberGenerator.GetRandom(6, 7).ToString("D6");
            Insert(entityToSave);
            return(_messageMapper.Map(entityToSave));
        }
        public async Task <MessageResponse> AddMessageAsync(AddMessageResquest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException();
            }
            var messageItem = _messageMapper.Map(request);
            var result      = _messageRepository.Add(messageItem);
            await _messageRepository.UnitOfWork.SaveChangesAsync();

            return(_messageMapper.Map(result));
        }
Пример #3
0
 public void Send(string systemName, string actorPath, JObject message)
 {
     try
     {
         var messageToActor = _messageMapper.Map((JObject)(message["payload"]));
         GetActorSystem(systemName).TellActor(actorPath, messageToActor);
     }
     catch (ActorNotFoundException)
     {
         SendNotFoundMessageToClient(ExtractGuid(message));
     }
     catch (Exception e)
     {
         Debug.Write(e);
     }
 }
Пример #4
0
        public async Task ReceiveAsync(IContext context)
        {
            switch (context.Message)
            {
            case ReceiveCommands receive:
            {
                var commands = await _sqsClient.ReceiveCommandBatchAsync(receive.NumberOfCommands);

                if (commands.Count() > 0)
                {
                    foreach (var command in commands)
                    {
                        var handler = _factory.GetActor(command);
                        var message = _mapper.Map(command);
                        handler.Tell(message);
                    }

                    context.Self.Tell(new ReceiveCommands());
                }
                else
                {
                    context.Self.Tell(new BackOff());
                }
            }
            break;

            case BackOff backOff:
            {
                await Task.Delay(TimeSpan.FromSeconds(backOff.DelayInSeconds));

                context.Self.Tell(new ReceiveCommands());
            }
            break;
            }
        }
        private async Task <IEnumerable <StorageItem> > GenerateStorageItems(string message)
        {
            if (!await validator.IsValid(message))
            {
                return(Enumerable.Empty <StorageItem>());
            }

            return((await mapper.Map(message))?.Where(x => x != null) ?? Enumerable.Empty <StorageItem>());
        }