Пример #1
0
        /// <summary>
        /// Analyze replay locally before uploading
        /// </summary>
        /// <param name="file">Replay file</param>
        public Replay Analyze(ReplayFile file)
        {
            try {
                var result      = DataParser.ParseReplay(file.Filename, false, false, false);
                var replay      = result.Item2;
                var parseResult = result.Item1;
                var status      = GetPreStatus(replay, parseResult);

                if (status != null)
                {
                    file.HotsWeekUploadStatus = file.HotsApiUploadStatus = status.Value;
                }

                if (parseResult != DataParser.ReplayParseResult.Success)
                {
                    return(null);
                }

                file.Fingerprint = GetFingerprint(replay);
                return(replay);
            }
            catch (Exception e) {
                _log.Warn(e, $"Error analyzing file {file}");
                return(null);
            }
        }
Пример #2
0
        private async Task UploadHotsBpHelper(ReplayFile file)
        {
            await _bpHelperUploader.CheckDuplicate(file);

            if (App.Debug)
            {
                Log.Trace($"Pre-preparsing file {file.Filename} + {file.GameMode}");
            }

            if (file.GameMode != GameMode.QuickMatch &&
                file.GameMode != GameMode.HeroLeague &&
                file.GameMode != GameMode.TeamLeague &&
                file.GameMode != GameMode.UnrankedDraft &&
                file.GameMode != GameMode.StormLeague)
            {
                file.HotsweekUploadStatus = UploadStatus.AiDetected;
            }
            // test if replay is eligible for upload (not AI, PTR, Custom, etc)
            Log.Trace($"Pre-parsing file {file.Filename} : { file.HotsweekUploadStatus }");

            while (SuspendUpload)
            {
                await Task.Delay(1000);
            }

            if (file.HotsweekUploadStatus == UploadStatus.InProgress)
            {
                // if it is, upload it

                await _bpHelperUploader.Upload(file);
            }
        }
Пример #3
0
        private async Task UploadHotsApi(ReplayFile file)
        {
            if (file.HotsApiUploadStatus == UploadStatus.InProgress)
            {
                // if it is, upload it
                while (SuspendUpload)
                {
                    await Task.Delay(1000);
                }

                await _hotsApiUploader.Upload(file);
            }
        }
Пример #4
0
        /// <summary>
        ///     Start uploading and watching for new replays
        /// </summary>
        public void Start()
        {
            if (_initialized)
            {
                return;
            }

            _initialized = true;

            _bpHelperUploader = new BpHelperUploader(_restApi);
            _hotsApiUploader  = new HotsApiUploader();

            _analyzer = new Analyzer();
            _monitor  = new Monitor();

            var replays = ScanReplays();

            Files.AddRange(replays.OrderByDescending(l => l.Created));
            if (replays.Any())
            {
                Monitor.LatestReplayTime = replays.Max(l => l.Created);
            }
            _uploadStrategy   = App.CustomConfigurationSettings.UploadStrategy;
            _uploadToHotsApi  = UploadToHotsApi;
            _uploadToHotsweek = UploadToHotsweek;
            if (App.CustomConfigurationSettings.UploadStrategy == UploadStrategy.UploadAll)
            {
                replays.Where(x => x.NeedHotsApiUpdate()).Reverse().Map(x => _hotsApiProcessingQueue[x]   = ProcessingStatus.None);
                replays.Where(x => x.NeedHotsweekUpdate()).Reverse().Map(x => _hotsweekProcessingQueue[x] = ProcessingStatus.None);
            }

            _monitor.ReplayAdded += async(_, e) =>
            {
                await EnsureFileAvailable(e.Data, 3000);

                var replay = new ReplayFile(e.Data);
                Files.Insert(0, replay);

                _hotsApiProcessingQueue[replay]  = ProcessingStatus.None;
                _hotsweekProcessingQueue[replay] = ProcessingStatus.None;

                OnReplayFileStatusChanged(new EventArgs <ReplayFile>(replay));
                OnStatusChanged();
            };

            _monitor.Start();

            _analyzer.MinimumBuild = Const.ReplayMinimumBuild;
            Task.Run(UploadHotsApiLoop).Forget();
            Task.Run(UploadHotsweekLoop).Forget();
        }
Пример #5
0
        private async Task UploadHotsBpHelper(ReplayFile file)
        {
            // test if replay is eligible for upload (not AI, PTR, Custom, etc)
            if (file.HotsWeekUploadStatus == UploadStatus.InProgress)
            {
                // if it is, upload it
                while (SuspendUpload)
                {
                    await Task.Delay(1000);
                }

                await _bpHelperUploader.Upload(file);
            }
        }
Пример #6
0
 /// <summary>
 /// Upload replay
 /// </summary>
 /// <param name="file"></param>
 public override async Task Upload(ReplayFile file)
 {
     file.HotsApiUploadStatus = UploadStatus.InProgress;
     if (file.Fingerprint != null && await CheckDuplicate(file.Fingerprint))
     {
         if (App.Debug)
         {
             _log.Debug($"File {file} marked as duplicate");
         }
         file.HotsApiUploadStatus = UploadStatus.Duplicate;
     }
     else
     {
         file.HotsApiUploadStatus = await Upload(file.Filename);
     }
 }
Пример #7
0
        public UploadStatus?GetPreStatus(ReplayFile file, Replay replay, DataParser.ReplayParseResult parseResult)
        {
            switch (parseResult)
            {
            case DataParser.ReplayParseResult.ComputerPlayerFound:
            case DataParser.ReplayParseResult.TryMeMode:
                return(UploadStatus.AiDetected);

            case DataParser.ReplayParseResult.PTRRegion:
                return(UploadStatus.PtrRegion);

            case DataParser.ReplayParseResult.Incomplete:
                return(UploadStatus.Incomplete);

            case DataParser.ReplayParseResult.Exception:
                if ((DateTime.Now - file.Created).Days > 7)
                {
                    return(UploadStatus.Incomplete);
                }
                return(UploadStatus.UploadError);

            case DataParser.ReplayParseResult.PreAlphaWipe:
                return(UploadStatus.TooOld);
            }

            if (parseResult != DataParser.ReplayParseResult.Success)
            {
                return(null);
            }

            if (replay.GameMode == GameMode.Custom)
            {
                return(UploadStatus.CustomGame);
            }

            if (replay.ReplayBuild < MinimumBuild)
            {
                return(UploadStatus.TooOld);
            }

            return(null);
        }
        /// <summary>
        /// Upload replay
        /// </summary>
        /// <param name="file"></param>
        public override async Task Upload(ReplayFile file)
        {
            var result = DataParser.ParseReplayFull(file.Filename, false, false, false);
            FilePath tempPath = Path.GetTempFileName();
            tempPath = tempPath.GetDirPath() + tempPath.GetFileNameWithoutExtension() + ".json";
            try
            {
                if (result.Item2 == null)
                    throw new NullReferenceException();

                var resultText = JsonConvert.SerializeObject(result.Item2);
                File.WriteAllText(tempPath, resultText);
            }
            catch (Exception)
            {
                file.HotsweekUploadStatus = UploadStatus.UploadError;
                return;
            }

            file.HotsweekUploadStatus = await Upload(tempPath, file.Fingerprint);
        }
        /// <summary>
        /// Mass check replay fingerprints against database to detect duplicates
        /// </summary>
        public async Task CheckDuplicate(ReplayFile file)
        {
            var fileIds = new List<ReplayIdentity>();

            if (file.Created < App.UploadMinimumAcceptableTime)
            {
                file.HotsweekUploadStatus = UploadStatus.TooOld;
                return;
            }

            await Task.Delay(1000);

            if (App.Debug)
                _log.Trace($"Check file {file.Filename} + {file.HotsweekUploadStatus}");

            fileIds.Add(new ReplayIdentity()
            {
                FingerPrint = file.Fingerprint,
                Md5 = CalculateMD5(file.Filename),
                Size = new FileInfo(file.Filename).Length
            });
            
            
            var checkStatus = await CheckDuplicate(fileIds);

            var fingerPrintInfo = checkStatus.Status.FirstOrDefault();
            if (fingerPrintInfo == null)
            {
                file.HotsweekUploadStatus = UploadStatus.UploadError;
                return;
            }

            if (fingerPrintInfo.Access == FingerPrintStatus.Reserved)
                file.HotsweekUploadStatus = UploadStatus.Reserved;

            if (fingerPrintInfo.Access == FingerPrintStatus.Duplicated)
                file.HotsweekUploadStatus = UploadStatus.HotsweekDuplicate;
                
            //  replays.Where(x => exists.Contains(x.Fingerprint)).Map(x => x.UploadStatus = UploadStatus.Duplicate);
        }
Пример #10
0
        /// <summary>
        /// Analyze replay locally before uploading
        /// </summary>
        /// <param name="file">Replay file</param>
        public bool Analyze(ReplayFile file)
        {
            try
            {
                if (!string.IsNullOrEmpty(file.Fingerprint))
                {
                    return(true);
                }

                var result      = DataParser.ParseReplay(file.Filename, false, false, false);
                var replay      = result.Item2;
                var parseResult = result.Item1;
                var status      = GetPreStatus(file, replay, parseResult);

                if (status != null)
                {
                    file.HotsweekUploadStatus = file.HotsApiUploadStatus = status.Value;
                }
                else if (parseResult != DataParser.ReplayParseResult.Success)
                {
                    file.HotsweekUploadStatus = file.HotsApiUploadStatus = UploadStatus.Incomplete;
                }

                if (parseResult != DataParser.ReplayParseResult.Success)
                {
                    return(false);
                }

                file.Fingerprint = GetFingerprint(replay);
                file.GameMode    = replay.GameMode;

                return(true);
            }
            catch (Exception e) {
                _log.Warn(e, $"Error analyzing file {file}");
                return(false);
            }
        }
Пример #11
0
 /// <summary>
 /// Upload replay
 /// </summary>
 /// <param name="file"></param>
 public abstract Task Upload(ReplayFile file);
Пример #12
0
 /// <summary>
 /// Upload replay
 /// </summary>
 /// <param name="file"></param>
 public override async Task Upload(ReplayFile file)
 {
     file.HotsWeekUploadStatus = await Upload(file.Filename);
 }