Пример #1
0
        public CommandNotification Validate()
        {
            var notifications = new List <Notification>();

            if (id <= 0)
            {
                notifications.Add(new Notification(property: nameof(id), message: "Invalid id"));
            }

            if (string.IsNullOrWhiteSpace(provider))
            {
                notifications.Add(new Notification(property: nameof(provider), message: "Invalid provider"));
            }

            if (string.IsNullOrWhiteSpace(push_message))
            {
                notifications.Add(new Notification(property: nameof(provider), message: "Invalid push_message"));
            }

            var targetValidations = targeting.Select(target => target.Validate()).ToArray();

            var result = new CommandNotification(notifications);

            result.AddNotifications(targetValidations);
            return(result);
        }
Пример #2
0
        private async Task HandleMessage(IMessageSource source, Message msg)
        {
            foreach (var pair in Modules.Select(m => new { Module = m, Commands = m.GetMatchingCommands(msg) }))
            {
                foreach (var command in pair.Commands)
                {
                    var notification = new CommandNotification()
                    {
                        CallId  = Random.Next(),
                        Id      = command.Id,
                        Trigger = command.Triggers.First(t => t.Matches(msg.Contents)),
                        Message = msg
                    };

                    WaitingCalls[notification.CallId] = new WaitingCommandCall(notification, source);
                    pair.Module.Connection.Send(notification);
                }
            }
        }
Пример #3
0
        public ActionResult PostBatch([FromBody] IEnumerable <Campaign> campaigns)
        {
            var validations       = campaigns.Select(campaign => campaign.Validate()).ToArray();
            var summaryValidation = new CommandNotification(validations);

            if (summaryValidation.IsInvalid)
            {
                return(StatusCode(500, summaryValidation.Notifications));
            }

            var entities = campaigns.Select(model => CampaignMapper.ToEntity(model)).ToList();
            var result   = _campaignManager.Load(entities);

            if (result.IsInvalid)
            {
                return(StatusCode(500, result.Notifications));
            }

            return(Ok());
        }
Пример #4
0
 public WaitingCommandCall(CommandNotification notification, IMessageSource source)
 {
     Notification = notification;
     Source       = source;
 }
Пример #5
0
 public CommandHandlerEventArgs(CommandNotification notification)
 {
     Notification = notification;
     Arguments    = Trigger.RemoveMatch(Contents);
 }