private async static Task <(bool success, string message, SessionInfo sessionInfo)> Ping(SessionInfo sessionInfo) { bool success = false; string message = null; using (var client = new RequestSocket()) { client.Connect($"tcp://localhost:{sessionInfo.commandPortNumber}"); Console.WriteLine($"Pinging at port {sessionInfo.commandPortNumber}, Currency Pair Id = {sessionInfo.CurrencyPairId}, Session Id = {sessionInfo.SessionId}, Account Id = {sessionInfo.AccountId}"); client.SendFrame("Hello"); string reply; if (client.TryReceiveFrameString(new TimeSpan(0, 0, 3), out reply)) { message = $"Received {reply}"; success = true; } else { message = "No reply"; } } await Task.Delay(100); return(success, message, sessionInfo); }
public static void UpdateKeepAliveStatus(SQLiteConnection connection, bool success, SessionInfo sessionInfo) { var command = connection.CreateCommand(); if (success) { command.CommandText = "UPDATE Sessions SET isKeptAlive=1, keepAliveStatus=1, lastKeptAlive=$lastKeptAlive, dtUpdated=$dtUpdated " + "WHERE accountId=$accountId AND sessionId=$sessionId AND currencyPairId=$currencyPairId"; } else { command.CommandText = "UPDATE Sessions SET isKeptAlive=0, keepAliveStatus=$keepAliveStatus, lastKeptAlive=$lastKeptAlive, dtUpdated=$dtUpdated " + "WHERE accountId=$accountId AND sessionId=$sessionId AND currencyPairId=$currencyPairId"; var nextKeepAliveStatus = GetNewKeepAliveStatus(success, sessionInfo.KeepAliveStatus); command.Parameters.AddWithValue("$keepAliveStatus", nextKeepAliveStatus); } command.Parameters.AddWithValue("$lastKeptAlive", DateTime.UtcNow); command.Parameters.AddWithValue("$dtUpdated", DateTime.UtcNow); command.Parameters.AddWithValue("$accountId", sessionInfo.AccountId); command.Parameters.AddWithValue("$sessionId", sessionInfo.SessionId); command.Parameters.AddWithValue("$currencyPairId", sessionInfo.CurrencyPairId); command.ExecuteNonQuery(); }