/// <summary>
        /// Reads the vars file and reads if the user has requested to stop the data transfer.
        /// </summary>
        /// <remarks>Also saves the currently collected data if the user has requested to save the data.</remarks>
        /// <returns></returns>
        private async Task <bool> ReadVarsFileAndDetermineIfDataCollectionShouldStop()
        {
            LeagueAPI_Variables varsFile = await ReadLocalVarsFile();

            if (varsFile.WriteCurrentlyCollectedData)
            {
                WriteFiles(Matches);
                varsFile.WriteCurrentlyCollectedData = false;
                await UpdateLocalVarsFile(varsFile);
            }
            return(varsFile.StopCollectingData);
        }
 public static async Task UpdateLocalVarsFile(LeagueAPI_Variables aPIVars)
 {
     try
     {
         LeagueAPI_Variables.UpdateLocalVarsFile(aPIVars);
     }
     catch (IOException)
     {
         await Task.Delay(1000);
         await UpdateLocalVarsFile(aPIVars);
     }
 }
        public static async Task <LeagueAPI_Variables> ReadLocalVarsFile()
        {
            try
            {
                return(LeagueAPI_Variables.ReadLocalVarsFile());
            }
            catch (IOException)
            {
                await Task.Delay(1000);

                return(await ReadLocalVarsFile());
            }
        }
        /// <summary>Gets matches for a player account.</summary>
        /// <remarks>Run in a loop in <see cref="CollectMatchesData(int)"/>. Boolean result determines if we want to stop or continue collecting data.</remarks>
        /// <returns>Returns true if data collection is to be stopped, false if it is to continue.</returns>
        private async Task <bool> GetMatches(string playerAccountId)
        {
            int          initialMatchesCount = Matches.Count;
            MatchlistDto matchlist           = await LeagueAPIClient.GetMatchlist(playerAccountId);

            //Stop scanning this account if it has no history (but don't stop collecting from other accounts).
            if (matchlist.matches == null)
            {
                return(false);
            }

            HashSet <ParticipantIdentityDto> participantIdentities = new HashSet <ParticipantIdentityDto>();

            foreach (MatchReferenceDto matchRef in matchlist.matches)
            {
                if (matchRef.queue != QueueToLookFor || ScannedGameIds.Contains(matchRef.gameId))
                {
                    continue;
                }
                MatchDto match = await LeagueAPIClient.GetMatch(matchRef.gameId);

                ScannedGameIds.Add(matchRef.gameId);
                if (match == null || match.gameId == 0)
                {
                    continue;
                }
                int shouldScanContinueDependingOnGameVersion = ShouldScanContinueDependingOnGameVersion(match.gameVersion);
                if (shouldScanContinueDependingOnGameVersion == 2)
                {
                    break;
                }
                if (shouldScanContinueDependingOnGameVersion == 1)
                {
                    continue;
                }
                Matches.Add(match);
                Debug.WriteLine(Matches.Count);
                foreach (ParticipantIdentityDto identity in match.participantIdentities)
                {
                    participantIdentities.Add(identity);
                }
            }

            if (Matches.Count > initialMatchesCount)
            {
                //Record progress
                LeagueAPI_Variables apiVars = await ReadLocalVarsFile();

                string currentProgress = GetProgressMessage();
                apiVars.CurrentProgress = currentProgress;
                await UpdateLocalVarsFile(apiVars);
            }

            foreach (ParticipantIdentityDto participantIdentity in participantIdentities)
            {
                string playerAccount = participantIdentity.player.accountId;
                if (AccountsAddedForScanning.Contains(playerAccount))
                {
                    continue;
                }
                AccountsToScan.Enqueue(playerAccount);
                AccountsAddedForScanning.Add(playerAccount);
            }

            return(await ReadVarsFileAndDetermineIfDataCollectionShouldStop());
        }
Пример #5
0
 public static void UpdateLocalVarsFile(LeagueAPI_Variables aPIVars)
 {
     File.WriteAllText(varsFile, aPIVars.ToJson());
 }