/// <summary>
 ///     This constructor sets user defined values to connect to FreeSwitch.
 /// </summary>
 /// <param name="address">FreeSwitch mod_event_socket IP address or hostname</param>
 /// <param name="port">FreeSwitch mod_event_socket Port number</param>
 /// <param name="messageEncoder">FreeSwitch message encoder</param>
 /// <param name="messageDecoder">FreeSwitch message decoder</param>
 /// <param name="freeSwitchEventFilter">FreeSwitch event filters</param>
 /// <param name="connectionTimeout">Connection Timeout</param>
 /// <param name="password">FreeSwitch mod_event_socket Password</param>
 public OutboundChannelSession(string address, int port, IMessageEncoder messageEncoder,
     IMessageDecoder messageDecoder, string freeSwitchEventFilter, TimeSpan connectionTimeout, string password) {
     Address = address;
     Port = port;
     MessageEncoder = messageEncoder;
     MessageDecoder = messageDecoder;
     FreeSwitchEventFilter = freeSwitchEventFilter;
     ConnectionTimeout = connectionTimeout;
     Password = password;
     _authenticated = false;
     _requestsQueue = new ConcurrentQueue<CommandAsyncEvent>();
     _channel = new TcpChannel(new BufferSlice(new byte[65535], 0, 65535), MessageEncoder, MessageDecoder);
     _channel.MessageReceived += OnMessageReceived;
     _channel.Disconnected += OnDisconnect;
     _channel.MessageSent += OnSendCompleted;
     _args.Completed += OnConnect;
     OnAuthentication += SendAuthentication;
 }
 /// <summary>
 ///     Disconnect from FreeSwitch mod_event_socket
 /// </summary>
 /// <returns></returns>
 /// <summary>
 ///     Wait for all messages to be sent and close the connection
 /// </summary>
 /// <returns>Async task</returns>
 public async Task CloseAsync() {
     await ShutdownGracefully();
     await _channel.CloseAsync();
     _authenticated = false;
     _channel = null;
 }
 /// <summary>
 ///     Default constructor. It uses the default FreeSwitch mod_event_socket settings for connectivity
 /// </summary>
 public OutboundChannelSession() {
     Address = "127.0.0.1";
     Port = 8021;
     ConnectionTimeout = TimeSpan.Zero;
     Password = "******";
     MessageEncoder = new FreeSwitchEncoder();
     MessageDecoder = new FreeSwitchDecoder();
     FreeSwitchEventFilter = "plain ALL";
     _authenticated = false;
     _requestsQueue = new ConcurrentQueue<CommandAsyncEvent>();
     _channel = new TcpChannel(new BufferSlice(new byte[65535], 0, 65535), MessageEncoder, MessageDecoder);
     _channel.MessageReceived += OnMessageReceived;
     _channel.Disconnected += OnDisconnect;
     _channel.MessageSent += OnSendCompleted;
     _args.Completed += OnConnect;
     OnAuthentication += SendAuthentication;
 }
 /// <summary>
 ///     Dispose()
 /// </summary>
 public void Dispose() {
     if (_channel == null)
         return;
     _channel.Close();
     _channel = null;
 }
 /// <summary>
 ///     Create a new channel
 /// </summary>
 /// <param name="readBuffer">Buffer which should be used when reading from the socket</param>
 /// <param name="encoder">Used to encode outgoing data</param>
 /// <param name="decoder">Used to decode incoming data</param>
 /// <returns>Created channel</returns>
 public ITcpChannel Create(IBufferSlice readBuffer, IMessageEncoder encoder, IMessageDecoder decoder) {
     var channel = new TcpChannel(readBuffer, encoder, decoder);
     if (OutboundMessageQueueFactory != null)
         channel.OutboundMessageQueue = OutboundMessageQueueFactory();
     return channel;
 }