private TwilioWorkState DeserializeStep(IReceivedData receivedData) { var state = new TwilioWorkState { ReceivedData = receivedData }; try { state.TextMessage = state.ReceivedData.ContentType switch { Constants.HeaderValueForLetter => _serializationProvider .Deserialize <TextMessage>(state.ReceivedData.Letter.Body), _ => _serializationProvider .Deserialize <TextMessage>(state.ReceivedData.Data) }; if (state.ReceivedData.Data.Length > 0 && (state.TextMessage != null || state.ReceivedData.Letter != null)) { state.DeserializeStepSuccess = true; } } catch { state.DeserializeStepSuccess = false; } return(state); }
private async Task <TwilioWorkState> ProcessMessageStepAsync(TwilioWorkState state) { if (state.DeserializeStepSuccess) { await SendMessageAsync( state.TextMessage.Message, state.TextMessage.ToNumber, state.TextMessage.FromNumber).ConfigureAwait(false); state.ProcessStepSuccess = true; } else { // Park Failed Deserialize Steps var failed = await _rabbitService .Publisher .PublishAsync("", _errorQueue, state.ReceivedData.Data, null) .ConfigureAwait(false); if (failed) { _logger?.LogError($"{DateTime.Now:yyyy/MM/dd hh:mm:ss.fff} - This failed to deserialize and publish to ErrorQueue!"); } else { _logger?.LogError($"{DateTime.Now:yyyy/MM/dd hh:mm:ss.fff} - This failed to deserialize. Published to ErrorQueue ({_errorQueue})!"); // So we ack the message state.ProcessStepSuccess = true; } } return(state); }
private async Task <TwilioWorkState> DeserializeStepAsync(IReceivedData receivedData) { var state = new TwilioWorkState { ReceivedData = receivedData }; try { state.TextMessage = state.ReceivedData.ContentType switch { Constants.HeaderValueForLetter => await receivedData .GetTypeFromJsonAsync <TextMessage>() .ConfigureAwait(false), _ => await receivedData .GetTypeFromJsonAsync <TextMessage>(decrypt : false, decompress : false) .ConfigureAwait(false), }; if (state.ReceivedData.Data.Length > 0 && (state.TextMessage != null || state.ReceivedData.Letter != null)) { state.DeserializeStepSuccess = true; } } catch { state.DeserializeStepSuccess = false; } return(state); }
private TwilioWorkState AckMessage(TwilioWorkState state) { if (state.ProcessStepSuccess) { if (state.ReceivedData.AckMessage()) { state.AcknowledgeStepSuccess = true; } } else { if (state.ReceivedData.NackMessage(true)) { state.AcknowledgeStepSuccess = true; } } return(state); }