Пример #1
0
        /// <summary>
        /// Start uploading and watching for new replays
        /// </summary>
        public async void Start(IMonitor monitor, IAnalyzer analyzer, IUploader uploader)
        {
            if (_initialized)
            {
                return;
            }
            _initialized = true;

            _uploader = uploader;
            _analyzer = analyzer;
            _monitor  = monitor;

            var replays = ScanReplays();

            Files.AddRange(replays);
            replays.Where(x => x.UploadStatus == UploadStatus.None).Reverse().Map(x => processingQueue.Add(x));

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

                var replay = new ReplayFile(e.Data);
                Files.Insert(0, replay);
                processingQueue.Add(replay);
            };
            _monitor.Start();

            _analyzer.MinimumBuild = await _uploader.GetMinimumBuild();

            for (int i = 0; i < MaxThreads; i++)
            {
                Task.Run(UploadLoop).Forget();
            }
        }
Пример #2
0
        /// <summary>
        /// Start uploading and watching for new replays
        /// </summary>
        public async void Start(IMonitor monitor, PreMatchIMonitor prematch_monitor, IAnalyzer analyzer, IUploader uploader)
        {
            if (_initialized)
            {
                return;
            }
            _initialized = true;

            _uploader         = uploader;
            _analyzer         = analyzer;
            _monitor          = monitor;
            _prematch_monitor = prematch_monitor;

            var replays = ScanReplays();

            Files.AddRange(replays);
            replays.Where(x => x.UploadStatus == UploadStatus.None).Reverse().Map(x => processingQueue.Add(x));



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

                var replay = new ReplayFile(e.Data);
                Files.Insert(0, replay);
                processingQueue.Add(replay);
                if (PreMatchPage)
                {
                    _prematch_monitor.Start();
                }
            };
            _monitor.Start();

            /*
             * _prematch_monitor.TempBattleLobbyCreated += async (_, e) => {
             *  if (PreMatchPage) {
             *      prematch_id = 0;
             *      _prematch_monitor.Stop();
             *      Thread.Sleep(1000);
             *      var tmpPath = Path.GetTempFileName();
             *      await SafeCopy(e.Data, tmpPath, true);
             *      byte[] bytes = System.IO.File.ReadAllBytes(tmpPath);
             *      Replay replay = MpqBattlelobby.Parse(bytes);
             *      await runPreMatch(replay);
             *  }
             * };
             * _prematch_monitor.Start();
             */

            _analyzer.MinimumBuild = await _uploader.GetMinimumBuild();

            for (int i = 0; i < MaxThreads; i++)
            {
                Task.Run(UploadLoop).Forget();
            }
        }