Пример #1
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            _options.Decoding = true;
            BulkInsertArgs arg = new BulkInsertArgs();
            await Task.Run(() =>
            {
                DateTime t = DateTime.UtcNow;

                var jsonfile = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\sc2dsstats_web\\data.json";

                if (!File.Exists(jsonfile))
                {
                    return;
                }

                using (FileStream fs = File.OpenRead(jsonfile))
                {
                    arg.Total = CountLinesMaybe(fs);
                }

                using (var md5 = MD5.Create())
                {
                    foreach (var line in File.ReadAllLines(jsonfile))
                    {
                        dsreplay rep = JsonSerializer.Deserialize <dsreplay>(line);
                        if (rep != null)
                        {
                            rep.Init();
                            rep.GenHash();

                            string reppath = Status.ReplayFolder.Where(x => x.Value == rep.REPLAY.Substring(0, 47)).FirstOrDefault().Key;
                            reppath       += "/" + rep.REPLAY.Substring(48);
                            reppath       += ".SC2Replay";
                            rep.REPLAY     = reppath;
                            DSReplay Rep   = Map.Rep(rep);

                            _db.SaveReplay(Rep, true);

                            arg.Count++;
                            OnReplayProcessed(arg);
                        }
                    }
                }
                _db.SaveContext();
                Console.WriteLine((DateTime.UtcNow - t).TotalSeconds);
            });

            arg.Done = true;
            OnReplayProcessed(arg);
            _options.Decoding = false;
        }
Пример #2
0
        protected virtual void OnReplayProcessed(BulkInsertArgs e)
        {
            EventHandler handler = ReplayProcessed;

            handler?.Invoke(this, e);
        }