Example #1
0
        private async Task HandleDemoParsing()
        {
            var parsedFolders = new List <string>();
            var parsingWork   = new List <Task>();

            foreach (var game in _gameInfo.Where(x => x.DownloadSuccess && x.UnzipSuccess))
            {
                //Did we already parse this source folder?
                if (!parsedFolders.Contains(game.GetBaseTempPath()))
                {
                    if (_dataService.RSettings.ProgramSettings.Debug)
                    {
                        await _log.LogMessage($"Starting Parser Instance for {game.GetBaseTempPath()}", false,
                                              color : LOG_COLOR);
                    }

                    //Make sure we don't parse this folder again
                    parsedFolders.Add(game.GetBaseTempPath());

                    //The destination for the parsed demo
                    var destination = Path.GetDirectoryName(game.GetPathLocalJson());

                    Directory.CreateDirectory(destination);

                    //Spawn the parser
                    parsingWork.Add(DemoParser.ParseFaceitDemos(game.GetBaseTempPath().TrimEnd('\\'), destination));
                }

                //8 Parser instances max
                if (parsingWork.Count >= 16)
                {
                    await Task.WhenAny(parsingWork);

                    //Remove all finished tasks so we can spawn more
                    parsingWork.RemoveAll(x => x.IsCompleted);
                }
            }

            //Wait for all the finish
            await Task.WhenAll(parsingWork);
        }