//Retriving and populating the cummulative server data private static async void LoadCumulativeServerstats(CancellationToken cancellationToken = default) { Console.WriteLine("cumulative server metric loading... "); int frag = 0, uptime = 0, totalConnections = 0, httpRecCount = 0; bool fallbackready = true; for (int i = 0; i < cookiekeys.Length; i++) { cookieData = await GetServerStats(cookies[i], cancellationToken); norkonServerInfo = PopulateServerInfo(cookieData); frag += norkonServerInfo.frag; uptime += norkonServerInfo.uptime; totalConnections += norkonServerInfo.totalConnected; httpRecCount += norkonServerInfo.httpRecCount; fallbackready = fallbackready & norkonServerInfo.fallbackReady; } norkonServerInfo.frag = frag; norkonServerInfo.uptime = uptime; norkonServerInfo.totalConnected = totalConnections; norkonServerInfo.httpRecCount = httpRecCount; norkonServerInfo.fallbackReady = fallbackready; norkonServerInfo.serverName = "ALL"; DisplayServerStats(norkonServerInfo); }
//Populating the Server info in Serverinfo object private static NorkonServerInfo PopulateServerInfo(string cookieValue) { JObject jObject = JObject.Parse(cookieValue); NorkonServerInfo serverInfo = new NorkonServerInfo(); serverInfo.serverName = jObject["result"]["server"].ToString().Substring(0, 4); serverInfo.frag = (int)jObject["result"]["updates"]["frag"]; serverInfo.fallbackReady = (bool)jObject["result"]["fallbackMgr"]["fallbackReady"]; serverInfo.httpRecCount = (int)jObject["result"]["reqCount"]["http"]; serverInfo.uptime = (int)jObject["result"]["process"]["uptime"]; serverInfo.totalConnected = (int)jObject["result"]["quantHubs"]["connected"]; return(serverInfo); }
//Timer call back call at the interval of 1 second private static async void TimerCallback(Object o) { Console.WriteLine("Refreshing..."); if (Counter == 0) { LoadCumulativeServerstats(); } else { cookieData = await GetServerStats(cookies[Counter - 1]); norkonServerInfo = PopulateServerInfo(cookieData); DisplayServerStats(norkonServerInfo); } GC.Collect(); }
//Displaying the Server info on the console private static void DisplayServerStats(NorkonServerInfo serverInfo) { Console.Clear(); if (serverInfo.serverName.ToUpper() == "ALL") { Console.ForegroundColor = ConsoleColor.Black; Console.BackgroundColor = ConsoleColor.White; Console.Write(serverInfo.serverName + " "); Console.ResetColor(); } else { Console.Write("ALL "); } foreach (string cookieKey in cookiekeys) { if (cookieKey.Substring(6, 4).ToUpper() == serverInfo.serverName.ToUpper()) { Console.ForegroundColor = ConsoleColor.Black; Console.BackgroundColor = ConsoleColor.White; Console.Write(cookieKey.Substring(6, 4) + " ", ConsoleColor.Green); Console.ResetColor(); } else { Console.Write(cookieKey.Substring(6, 4) + " "); } } Console.WriteLine(""); Console.WriteLine("Server Name: " + serverInfo.serverName); Console.WriteLine("Connection Count: " + serverInfo.totalConnected.ToString()); TimeSpan timespan = TimeSpan.FromSeconds(serverInfo.uptime); string Uptime = string.Format("{0:D2}:{1:D2}:{2:D2}:{2:D2}", timespan.Hours, timespan.Minutes, timespan.Seconds, timespan.Milliseconds); Console.WriteLine("Uptime: " + Uptime); Console.WriteLine("Fragment Updates : " + serverInfo.frag); Console.WriteLine("Http Request Count : " + serverInfo.httpRecCount.ToString()); Console.WriteLine("Fallback ready : " + serverInfo.fallbackReady.ToString()); Console.WriteLine(""); Console.WriteLine("use only <- or -> to toggle between servers or ESC to exit "); }
private static async void LoadNextOrPreviousServerStats(CancellationToken cancellationToken = default) { if (Counter == 0) { Console.Clear(); LoadCumulativeServerstats(cancellationToken); } else { var s = await GetServerStats(cookies[Counter - 1], cancellationToken); norkonServerInfo = PopulateServerInfo(s); Console.Clear(); DisplayServerStats(norkonServerInfo); } var keyStroke = Console.ReadKey(false); HandleToggleKeys(keyStroke.Key); }