Пример #1
0
        private void ReceiverOnMessageReceived(
            object sender, MessageReceivedEventArgs e)
        {
            var o = MessageParser.Parse(e.Message);

            if (o == null)
            {
                ParsingFailed?.Invoke(
                    this,
                    new ParsingFailedEventArgs(e.ContactId, e.Message));
                return;
            }

            var item = new ReminderItem(o.Date, o.Message, e.ContactId, ReminderItemStatus.Awaiting);

            try
            {
                _storage.Add(item);

                AddingSucceeded?.Invoke(
                    this,
                    new AddingSucceededEventArgs(new AddReminderModel(item)));
            }
            catch (Exception exception)
            {
                AddingFailed?.Invoke(
                    this,
                    new AddingFailedEventArgs(new AddReminderModel(item), exception));
            }
        }
Пример #2
0
        private void Receiver_MessageReceived(object sender, Receiver.Core.MessageReceivedEventArgs e)
        {
            MessageReceivedInvoke(e.ContactId, e.Message);
            ParsedMessage parsedMessage;

            try
            {
                parsedMessage = MessageParser.Parse(e.Message);
                MessageParsingSucceddedInvoke(e.ContactId, parsedMessage.Date, parsedMessage.Message);
            }
            catch (Exception ex)
            {
                MessageParsingFailedInvoke(e.ContactId, e.Message, ex);
                return;
            }

            var item = new ReminderItem(
                parsedMessage.Date,
                parsedMessage.Message,
                e.ContactId);

            try
            {
                _storage.Add(item);
                AddingToStorageSucceddedInvoke(item);
            }
            catch (Exception ex)
            {
                AddingToStorageFailedInvoke(item, ex);
            }
        }
Пример #3
0
        private void OnReceiverMessageReceived(object sender, MessageReceivedEventArgs e)
        {
            ReminderItem reminderItem = null;

            try
            {
                MessageParser.Parse(
                    e.Message,
                    out DateTimeOffset date,
                    out string replyMessage);
                reminderItem = new ReminderItem(
                    date,
                    replyMessage,
                    e.ContactId,
                    ReminderItemStatus.Awaiting);
            }
            catch (Exception exception)
            {
                _sender.Send(e.ContactId, "Invalid input string format, try again!");
            }
            if (reminderItem == null)
            {
                return;
            }
            try
            {
                _storage.Add(reminderItem);
                OnAddingSucceeded(this, new AddingSucceededEventArgs(reminderItem));
            }
            catch (Exception exception)
            {
                OnAddingFailed(this, new AddingFailedEventArgs(reminderItem, exception));
            }
        }
Пример #4
0
        private void ReminderReceiver_MessageReceived(
            object sender,
            MessageReceivedEventArgs e)
        {
            var parsedMessage = MessageParser.Parse(e.Message);

            if (parsedMessage != null)
            {
                var reminder = new ReminderItem
                {
                    ContactId = e.ContactId,
                    Message   = parsedMessage.Message,
                    Date      = parsedMessage.Date,
                    Status    = ReminderItemStatus.Awaiting
                };

                _storage.Add(reminder);

                AddingSuccedded?.Invoke(
                    this,
                    new AddingSuccededEventArgs(
                        new AddReminderModel(
                            reminder.ContactId,
                            reminder.Message,
                            reminder.Date)));
            }
        }
Пример #5
0
        private void OnMessageReceived(object sender, MessageReceivedEventArgs args)
        {
            var item = new ReminderItem(
                Guid.NewGuid(),
                args.ContactId,
                args.Message.Text,
                args.Message.Datetime);

            _storage.Add(item);
        }
Пример #6
0
 public void Add(AddReminderModel addReminderModel)
 {
     _storage.Add(new ReminderItem
     {
         Date      = addReminderModel.Date,
         ContactId = addReminderModel.ContactId,
         Message   = addReminderModel.Message,
         Status    = ReminderItemStatus.Awaiting
     });
 }
        public IActionResult CreateReminder([FromBody] ReminderItemCreateModel reminder)
        {
            if (reminder == null || !ModelState.IsValid)
            {
                return(BadRequest());
            }

            var  reminderItem = reminder.ToReminderItem();
            Guid id           = _reminderStorage.Add(reminderItem);

            return(CreatedAtRoute("GetReminder", new { id }, new ReminderItemGetModel(id, reminderItem)));
        }
        public IActionResult Create([FromBody] CreateReminderItemViewModel model)
        {
            var itemId = Guid.TryParse(model.Id, out var id) ? id : Guid.NewGuid();
            var item   = new ReminderItem(
                itemId,
                model.ContactId,
                model.Message,
                DateTimeOffset.FromUnixTimeMilliseconds(model.DateTimeUtc));

            _storage.Add(item);
            return(CreatedAtRoute(nameof(GetById), new { item.Id }, new ReminderItemViewModel(item)));
        }
Пример #9
0
        public void Add(AddReminderItemModel model)
        {
            ReminderItem item = new ReminderItem()
            {
                Id        = Guid.NewGuid(),
                Date      = model.date,
                Message   = model.Message,
                ContactId = model.contactId,
                Status    = ReminderStatus.Awaiting
            };

            storage.Add(item.Id, item);
        }
Пример #10
0
        public void Add(AddReminderItemModel model)
        {
            ReminderItem item = new ReminderItem()
            {
                Id        = Guid.NewGuid(),
                date      = model.date,
                Message   = model.Message,
                contactId = model.contactId,
                _status   = ReminderStatus.Awaiting
            };

            storage.Add(item.Id, item);
            OnSuccesAdd?.Invoke(this, model);
        }
Пример #11
0
        public IActionResult Add([FromBody] ReminderItemAddModel model)
        {
            if (model == null && !ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var reminderItem = model.ConvertToReminderItem();

            _reminderStorage.Add(reminderItem);

            return(Created(
                       $"api/reminders/{reminderItem.Id}",
                       new ReminderItemGetModel(reminderItem)));
        }
Пример #12
0
        private void OnMessageReceived(object sender, MessageReceivedEventArgs args)
        {
            _logger.LogDebug("Received message from receiver");

            var item = new ReminderItem(
                Guid.NewGuid(),
                ReminderItemStatus.Created,
                args.Message.DateTime,
                args.Message.Text,
                args.ContactId
                );

            _storage.Add(item);
            _logger.LogInformation($"Created reminder {item.Id:N}");
        }
        public IActionResult Add([FromBody] ReminderItemAddModel reminderItemAddModel)
        {
            if (reminderItemAddModel == null)
            {
                return(BadRequest());
            }

            ReminderItemRestricted reminderItemRestricted = reminderItemAddModel.ToReminderItemRestricted();
            Guid id = _storage.Add(reminderItemRestricted);

            return(CreatedAtRoute(
                       "GetReminderItemById",
                       new { id },
                       new ReminderItemGetModel(reminderItemRestricted.ToReminderItem(id))));
        }
Пример #14
0
        private void ReminderReceiver_MessageReceived(
            object sender,
            MessageReceivedEventArgs e)
        {
            if (e.Message.ToLower() == "help")
            {
                _sender.Send(e.ContactId, MessageParser.GetHelpMessage());
                return;
            }

            var parsedMessage = MessageParser.Parse(e.Message);

            if (parsedMessage != null)
            {
                var reminder = new ReminderItemRestricted
                {
                    ContactId = e.ContactId,
                    Message   = parsedMessage.Message,
                    Date      = parsedMessage.Date,
                    Status    = ReminderItemStatus.Awaiting
                };

                _storage.Add(reminder);

                _sender.Send(e.ContactId, "Ок, напомню");

                AddingSuccedded?.Invoke(
                    this,
                    new AddingSuccededEventArgs(
                        new AddReminderModel(
                            reminder.ContactId,
                            reminder.Message,
                            reminder.Date)));
            }
            else
            {
                _sender.Send(
                    e.ContactId,
                    "Не понимаю =(");
                _sender.Send(
                    e.ContactId,
                    "Для помощи введите help");
            }
        }
Пример #15
0
        private void Receiver_MessageReceived(object sender, Receiver.Core.MessageReceivedEventArgs e)
        {
            MessageReceivedInvoke(e.ContactId, e.Message);
            ParsedMessage parsedMessage;

            try
            {
                parsedMessage = MessageParser.Parse(e.Message);
                MessageParsingSucceddedInvoke(e.ContactId, parsedMessage.Date, parsedMessage.Message);
            }
            catch (Exception ex)
            {
                MessageParsingFailedInvoke(e.ContactId, e.Message, ex);
                return;
            }

            Guid id;

            try
            {
                id = _storage.Add(
                    parsedMessage.Date,
                    parsedMessage.Message,
                    e.ContactId,
                    ReminderItemStatus.Awaiting);

                AddingToStorageSucceddedInvoke(
                    id,
                    parsedMessage.Date,
                    parsedMessage.Message,
                    e.ContactId,
                    ReminderItemStatus.Awaiting);
            }
            catch (Exception ex)
            {
                AddingToStorageFailedInvoke(
                    parsedMessage.Date,
                    parsedMessage.Message,
                    e.ContactId,
                    ReminderItemStatus.Awaiting,
                    ex);
            }
        }
        public IActionResult Add([FromBody] ReminderItemAddModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            ReminderItem reminderItem = new ReminderItem(
                model.Date,
                model.Message,
                model.ContactId,
                model.Status);

            _storage.Add(reminderItem);
            return(CreatedAtAction(
                       nameof(Get),
                       new { id = reminderItem.Id },
                       new ReminderItemGetModel(reminderItem)));
        }
        public IActionResult Add([FromBody] ReminderItemAddModel model)
        {
            _logger.LogInformation($"{nameof(Add)} called");

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            ReminderItemRestricted reminderItemRestricted = new ReminderItemRestricted(
                model.Date,
                model.Message,
                model.AccountId,
                model.Status
                );

            Guid id = _storage.Add(reminderItemRestricted);

            return(CreatedAtAction(nameof(Get), new { id }, new ReminderItemGetModel(reminderItemRestricted.ToReminderItem(id))));
        }
Пример #18
0
        private void OnReceiverMessageReceived(object sender, MessageReceivedEventArgs e)
        {
            ReminderItemRestricted reminderItemRestricted = null;

            try
            {
                MessageParser.Parse(
                    e.Message,
                    out DateTimeOffset date,
                    out string replyMessage);

                reminderItemRestricted = new ReminderItemRestricted(
                    date,
                    replyMessage,
                    e.ContactId,
                    ReminderItemStatus.Awaiting);
            }
            catch (Exception exception)
            {
                _sender.Send(e.ContactId, $"Invalid input string format, try again! Exception: {exception}");
            }

            if (reminderItemRestricted == null)
            {
                return;
            }

            try
            {
                Guid id = _storage.Add(reminderItemRestricted);
                OnAddingSucceeded(
                    this,
                    new AddingSucceededEventArgs(reminderItemRestricted.ToReminderItem(id)));
            }
            catch (Exception exception)
            {
                OnAddingFailed(
                    this,
                    new AddingFailedEventArgs(reminderItemRestricted.ToReminderItem(Guid.Empty), exception));
            }
        }
        public IActionResult Create([FromBody] CreateReminderItemViewModel model)
        {
            if (model == default)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var item = new ReminderItem(
                model.Id ?? Guid.NewGuid(),
                model.ContactId,
                model.Message,
                model.DateTimeUtc);

            _storage.Add(item);

            return(CreatedAtRoute(nameof(GetById), new { item.Id }, new ReminderItemViewModel(item)));
        }
Пример #20
0
        public IActionResult Add([FromBody] ReminderItemAddModel model)
        {
            if (model == null && !ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Guid id = _reminderStorage.Add(
                model.Date,
                model.Message,
                model.ContactId,
                model.Status);

            return(Created(
                       $"api/reminders/{id}",
                       new ReminderItemGetModel
            {
                Id = id,
                Date = model.Date,
                Message = model.Message,
                ContactId = model.ContactId,
                Status = model.Status
            }));
        }
Пример #21
0
 // public ReminderDomain(IReminderStorage storage)
 // {
 //    _storage = storage;
 // }
 public void AddReminder(ReminderItem Item)
 {
     _storage.Add(Item);
 }
Пример #22
0
        public ReminderDomain(
            IReminderStorage storage,
            IReminderReceiver receiver,
            TimeSpan awaitingRemindersCheckingPeriod,
            TimeSpan readyRemindersSendingPeriod)
        {
            _storage  = storage;
            _receiver = receiver;
            _awaitingRemindersCheckingPeriod = awaitingRemindersCheckingPeriod;
            _readyRemindersSendingPeriod     = readyRemindersSendingPeriod;

            _receiver.MessageReceived += (s, e) =>
            {
                MessageReceived?.Invoke(
                    this,
                    new MessageReceivedEventArgs
                {
                    ContactId = e.ContactId,
                    Message   = e.Message
                });

                ParsedMessage parsedMessage;

                try
                {
                    parsedMessage = MessageParser.Parse(e.Message);

                    MessageParsingSuccedded?.Invoke(
                        this,
                        new MessageParsingSucceddedEventArgs
                    {
                        ContactId = e.ContactId,
                        Date      = parsedMessage.Date,
                        Message   = parsedMessage.Message
                    });
                }
                catch (Exception ex)
                {
                    MessageParsingFailed?.Invoke(
                        this,
                        new MessageParsingFailedEventArgs
                    {
                        ContactId        = e.ContactId,
                        Message          = e.Message,
                        ParsingException = ex
                    });

                    return;
                }

                var item = new ReminderItem(
                    parsedMessage.Date,
                    parsedMessage.Message,
                    e.ContactId);

                try
                {
                    storage.Add(item);
                    AddingToStorageSucceeded?.Invoke(
                        this,
                        new AddingToStorageSucceddedEventArgs
                    {
                        ContactId = e.ContactId,
                        Message   = e.Message
                    });
                }
                catch (Exception ex)
                {
                    AddingToStorageFailed?.Invoke(
                        this,
                        new AddingToStorageFailedEventArgs
                    {
                        ContactId       = e.ContactId,
                        Message         = e.Message,
                        AddingException = ex
                    });
                }
            };
        }