Esempio n. 1
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();
        }