private void CheckListOfPossiblePlayerIDs(List <double> idList, int retryCount) { runningAsyncs++; WebClient client = new WebClient(); client.Encoding = Encoding.UTF8; client.Proxy = null; client.DownloadStringCompleted += Client_PlayerIDs_DownloadStringCompleted; string requestURL = $@"https://api.worldoftanks.{MoEStatic.GetAPISuffix(serverID)}/wot/account/info/?application_id={appID}&fields=last_battle_time&account_id={String.Join("%2C", idList)}"; Log.AddInfo($"Sending request to API: {requestURL}"); client.DownloadStringAsync(new Uri(requestURL), new object[] { idList, retryCount }); }
private void Client_PlayerIDs_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) { runningAsyncs--; object[] paramsArray = (object[])e.UserState; List <double> idList = (List <double>)paramsArray[0]; int retryCount = (int)paramsArray[1]; bool hasToRetryIDList = false; if (idList == null) { Log.AddError("Encountered null idList in async string download completed event"); return; } if (idList.Count == 0) { Log.AddError("Encountered empty idList in async string download completed event"); return; } string listIdentifier = GetIdentifier(idList); if (e.Cancelled) { Log.AddError($"Request for IDs in {listIdentifier} was cancelled!"); return; } Log.AddInfo($"Request answer received for IDlist {listIdentifier}"); if (e.Error != null) { Log.AddError($"An error occuring in the request for idList {listIdentifier}", e.Error); hasToRetryIDList = true; } else { try { if (!String.IsNullOrEmpty(e.Result) && e.Result != "{}") { currentRequests++; processingsRequestCount++; #region parse data string jsonstring = e.Result; JObject jobj = JObject.Parse(jsonstring); List <string> playerIDsToCheck = new List <string>(); foreach (double d in idList) { string id = d.ToString(); if (jobj["data"] != null && jobj["data"][id] != null) { if (jobj["data"][id].GetType() == typeof(JObject)) { double timeStamp = Convert.ToDouble(jobj["data"][id]["last_battle_time"]); DateTime lastBattleDateTime = GetDateTimeFromTimeStamp(timeStamp); if (MoEStatic.PlayedAfterMoEIntroduction(lastBattleDateTime, serverID)) { playerIDsToCheck.Add(id); } } } else { //failedIDs.Add(id); Log.AddError($"Failed to get/parse data for player {id}, json is null"); if (jobj["error"] != null) { Log.AddError($"Error trying to get player's account data: {jobj["error"]}"); } } } InsertPlayerIDsToDB(playerIDsToCheck); #endregion ReportRequestProgress($"Checked IDs in {listIdentifier}"); processingsRequestCount--; } else { Log.AddError($"Invalid Result for IDlist {listIdentifier}"); hasToRetryIDList = true; } } catch (Exception excp) { Log.AddError($"Failed to get/parse data for idList {listIdentifier}", excp); hasToRetryIDList = true; } } Log.AddInfo($"Finished string download event for idList {listIdentifier}"); if (hasToRetryIDList && retryCount < maxRetryCount) { Log.AddWarning($"Checking {listIdentifier} again, retry {retryCount++}/{maxRetryCount}"); CheckListOfPossiblePlayerIDs(idList, retryCount++); } }
public static bool PlayedAfterMoEIntroduction(DateTime lastBattleDateTime, string serverID) { DateTime moeIntroductionDateTime = MoEStatic.GetMoEIntroductionDateTimeFromServerID(serverID); return(DateTime.Compare(lastBattleDateTime, moeIntroductionDateTime) >= 0); }