private void MessageParsingFailedInvoke(string contactId, string message, Exception exception) { MessageParsingFailed?.Invoke( this, new MessageParsingFailedEventArgs { ContactId = contactId, Message = message, ParsingException = exception }); }
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 }); } }; }