private async void OnMessageReceived(ITcpChannel channel, object message) { // Here we validate the channel. if (!channel.ChannelId.Equals(_channel.ChannelId)) { return; } var decodedMessage = message as EslDecodedMessage; // Handle decoded message. if (decodedMessage?.Headers == null || !decodedMessage.Headers.HasKeys()) { return; } var headers = decodedMessage.Headers; object response; var contentType = headers["Content-Type"]; if (string.IsNullOrEmpty(contentType)) { return; } contentType = contentType.ToLowerInvariant(); switch (contentType) { case "command/reply": var reply = new CommandReply(headers, decodedMessage.OriginalMessage); response = reply; break; case "api/response": var apiResponse = new ApiResponse(decodedMessage.BodyText); response = apiResponse; break; case "text/event-plain": var parameters = decodedMessage.BodyLines.AllKeys.ToDictionary(key => key, key => decodedMessage.BodyLines[key]); var @event = new EslEvent(parameters); response = @event; break; case "log/data": var logdata = new LogData(headers, decodedMessage.BodyText); response = logdata; break; case "text/disconnect-notice": var notice = new DisconnectNotice(decodedMessage.BodyText); response = notice; break; case "text/rude-rejection": await _channel.CloseAsync(); var reject = new RudeRejection(decodedMessage.BodyText); response = reject; break; default: // Here we are handling an unknown message var msg = new EslMessage(decodedMessage.Headers, decodedMessage.OriginalMessage); response = msg; break; } await HandleResponse(response); }
public EslRudeRejectionEventArgs(RudeRejection notice) { _notice = notice; }
/// <summary> /// Fired when a decoded message is received by the channel. /// </summary> /// <param name="channel">Receiving channel</param> /// <param name="message">Decoded message received</param> private async void OnMessageReceived(ITcpChannel channel, object message) { var decodedMessage = message as EslDecodedMessage; // Handle decoded message. if (decodedMessage?.Headers == null || !decodedMessage.Headers.HasKeys()) return; var headers = decodedMessage.Headers; object response = null; var contentType = headers["Content-Type"]; if (string.IsNullOrEmpty(contentType)) return; contentType = contentType.ToLowerInvariant(); switch (contentType) { case "auth/request": if (OnAuthentication != null) await OnAuthentication(this, EventArgs.Empty).ConfigureAwait(false); break; case "command/reply": var reply = new CommandReply(headers, decodedMessage.OriginalMessage); response = reply; break; case "api/response": var apiResponse = new ApiResponse(decodedMessage.BodyText); response = apiResponse; break; case "text/event-plain": var parameters = decodedMessage.BodyLines.AllKeys.ToDictionary(key => key, key => decodedMessage.BodyLines[key]); var @event = new EslEvent(parameters); response = @event; break; case "log/data": var logdata = new LogData(headers, decodedMessage.BodyText); response = logdata; break; case "text/rude-rejection": await _channel.CloseAsync(); var reject = new RudeRejection(decodedMessage.BodyText); response = reject; break; case "text/disconnect-notice": var notice = new DisconnectNotice(decodedMessage.BodyText); response = notice; break; default: // Here we are handling an unknown message var msg = new EslMessage(decodedMessage.Headers, decodedMessage.OriginalMessage); response = msg; break; } await HandleResponse(response).ConfigureAwait(false); }
public EslRudeRejectionEventArgs(RudeRejection notice) { _notice = notice; }