public void CreateTextMessages()
        {
            var _col1 = _database.GetCollection <CaseReport>("CaseReport");
            var _col2 = _database.GetCollection <CaseReportFromUnknownDataCollector>("CaseReportFromUnknownDataCollector");
            var _col3 = _database.GetCollection <InvalidCaseReport>("InvalidCaseReport");
            var _col4 = _database.GetCollection <InvalidCaseReportFromUnknownDataCollector>("InvalidCaseReportFromUnknownDataCollector");
            var _col5 = _database.GetCollection <CaseReportForListing>("CaseReportForListing");

            _col1.DeleteMany(v => true);
            _col2.DeleteMany(v => true);
            _col3.DeleteMany(v => true);
            _col4.DeleteMany(v => true);
            _col5.DeleteMany(v => true);

            var textMessagesEvents = JsonConvert.DeserializeObject <TextMessage[]>(System.IO.File.ReadAllText("./TestData/TextMessages.json"));

            foreach (var message in textMessagesEvents)
            {
                try
                {
                    _textMessageProcessors.Process(message);
                }
                catch (Exception ex)
                {
                    Console.Error.WriteLine(ex.ToString());
                }
            }
        }
        async Task NewMessagReceivedHandler(Message msg, CancellationToken cancellationToken)
        {
            try
            {
                if (!_processors.HasProcessors)
                {
                    await _receiver.DeferAsync(msg.SystemProperties.LockToken);

                    _logger.Warning("TextMessage listner is configured, but no ICanHandleTextMessage is registred-");
                    return;
                }

                var content = Encoding.UTF8.GetString(msg.Body);
                var sms     = JsonConvert.DeserializeObject <TextMessage>(content);
                _logger.Information($"SMS recieved from {sms.OriginNumber} | '{sms.FullMessage}'");

                _processors.Process(sms);

                if (msg.SystemProperties.IsLockTokenSet && !msg.SystemProperties.IsReceived)
                {
                    _logger.Information(JsonConvert.SerializeObject(msg.SystemProperties, Formatting.Indented));
                    await _receiver.CompleteAsync(msg.SystemProperties.LockToken);
                }
            }
            catch (Exception ex)
            {
                _logger.Error($"Failed when processing IncommingSms: {ex.Message}");
                await _receiver.AbandonAsync(msg.SystemProperties.LockToken);

                throw;
            }
        }
Beispiel #3
0
 void MessageReceived(Topic topic, string json)
 {
     try
     {
         var message = _serializer.FromJson <TextMessage>(json);
         _logger.Information($"SMS received from '{message.OriginNumber}' - with message '{message.Message}'");
         _processors.Process(message);
     }
     catch (Exception ex)
     {
         _logger.Error(ex, "Problems processing SMS");
     }
 }
        public void CreateTextMessages()
        {
            var _caseReportsCollection = _database.GetCollection <CaseReport>("CaseReport");

            _caseReportsCollection.DeleteMany(v => true);

            var textMessagesEvents = JsonConvert.DeserializeObject <TextMessage[]>(System.IO.File.ReadAllText("./TestData/TextMessages.json"));

            foreach (var message in textMessagesEvents)
            {
                try
                {
                    _textMessageProcessors.Process(message);
                }
                catch (Exception ex)
                {
                    Console.Error.WriteLine(ex.ToString());
                }
            }
        }
Beispiel #5
0
 public void Post([FromBody] TextMessage message)
 {
     _textMessageProcessors.Process(message);
 }
Beispiel #6
0
        void MessageReceived(Topic topic, string json)
        {
            var message = _serializer.FromJson <TextMessage>(json);

            _processors.Process(message);
        }