Esempio n. 1
0
        /// <summary>
        /// This function is responsible for finding and loading in new replays
        /// </summary>
        public async Task InitialLoadAsync()
        {
            _log.Information("Starting initial load of replays");

            List <ReplayFileInfo> newFiles = new List <ReplayFileInfo>();

            // Get all files from all defined replay folders
            IReadOnlyCollection <ReplayFileInfo> allFiles = _fileSystem.GetAllReplayFileInfo();

            // Check if file exists in the database
            foreach (var file in allFiles)
            {
                if (_db.GetFileResult(file.Path) == null)
                {
                    newFiles.Add(file);
                }
            }

            _log.Information($"Discovered {newFiles.Count} new files");

            // Files not in the database are parsed and added
            foreach (var file in newFiles)
            {
                var parseResult = await _reader.ReadFile(file.Path).ConfigureAwait(false);

                FileResult newResult = new FileResult(file, parseResult)
                {
                    IsNewFile = false
                };

                _db.AddFileResult(newResult);
            }

            _log.Information("Initial load of replays complete");
        }