private void Authenticate() { //get a session AppKeyAndSession appKeyAndSession = _sessionProvider.GetOrCreateNewSession(); try { WaitFor(_processor.Authenticate(new AuthenticationMessage() { AppKey = appKeyAndSession.AppKey, Session = appKeyAndSession.Session })); } catch (StatusException statusException) { //force expire if session is invalid if (statusException.ErrorCode == StatusMessage.ErrorCodeEnum.InvalidSessionInformation) { _sessionProvider.ExpireTokenNow(); } else { throw statusException; } } }
/// <summary> /// Disconnects previous socket and then: /// 1) Creates a session. /// 2) Creates a socket. /// 3) Forms SSL layer. /// </summary> private void ConnectSocket() { LastConnectTime = DateTime.UtcNow; //Disconnect socket Disconnect(); //pre-fetch the session (as auth will follow) AppKeyAndSession appKeyAndSession = _sessionProvider.GetOrCreateNewSession(); //create socket Trace.TraceInformation("ESAClient: Opening socket to: {0}:{1}", _hostName, _port); _client = new TcpClient(_hostName, _port); _client.ReceiveBufferSize = 1024 * 1000 * 2; //shaves about 20s off firehose image. _client.SendTimeout = (int)Timeout.TotalMilliseconds; _client.ReceiveTimeout = (int)Timeout.TotalMilliseconds; Stream stream = _client.GetStream(); if (_port == 443) { //SSL is on Trace.TraceInformation("ESAClient: Opening ssl stream to: {0}:{1}", _hostName, _port); // Create an SSL stream that will close the client's stream. SslStream sslStream = new SslStream(stream, false); //Setup ssl sslStream.AuthenticateAsClient(_hostName); stream = sslStream; } //Setup reader / writer _reader = new StreamReader(stream, Encoding.UTF8, false, _client.ReceiveBufferSize); _writer = new StreamWriter(stream, Encoding.UTF8); }
public void TestValidSession() { AppKeyAndSession session = ValidSessionProvider.GetOrCreateNewSession(); Assert.IsNotNull(session); }