Exemple #1
0
        private void runNextStep(Action onCompletion, Action <Exception> onError, Func <StepButton, bool> stopCondition)
        {
            try
            {
                if (loadableStep != null)
                {
                    if (actionRepetition == 0)
                    {
                        Logger.Log($"🔸 Step #{actionIndex + 1} {loadableStep?.Text}");
                    }

                    scroll.ScrollIntoView(loadableStep);
                    loadableStep.PerformStep();
                }
            }
            catch (Exception e)
            {
                Logger.Log(actionRepetition > 0
                    ? $"💥 Failed (on attempt {actionRepetition:#,0})"
                    : "💥 Failed");

                LoadingComponentsLogger.LogAndFlush();
                onError?.Invoke(e);
                return;
            }

            actionRepetition++;

            if (actionRepetition > (loadableStep?.RequiredRepetitions ?? 1) - 1)
            {
                if (actionIndex >= 0 && actionRepetition > 1)
                {
                    Logger.Log($"✔️ {actionRepetition} repetitions");
                }

                actionIndex++;
                actionRepetition = 0;

                if (loadableStep != null && stopCondition?.Invoke(loadableStep) == true)
                {
                    return;
                }
            }

            if (actionIndex > StepsContainer.Children.Count - 1)
            {
                Logger.Log($"✅ {GetType().ReadableName()} completed");
                onCompletion?.Invoke();
                return;
            }

            if (Parent != null)
            {
                stepRunner = Scheduler.AddDelayed(() => runNextStep(onCompletion, onError, stopCondition), TimePerAction);
            }
        }
Exemple #2
0
        public LabelStep AddLabel(string description)
        {
            var step = new LabelStep
            {
                Text = description,
            };

            step.Action = () =>
            {
                Logger.Log($@"💨 {this} {description}");

                // kinda hacky way to avoid this doesn't get triggered by automated runs.
                if (step.IsHovered)
                {
                    RunAllSteps(startFromStep: step, stopCondition: s => s is LabelStep);
                }
            };

            AddStep(step);

            return(step);
        }
        public ActionResult PutDatabase(
            [FromQuery] string key,
            [FromQuery] bool drop
            )
        {
            if (key != Environment.GetEnvironmentVariable("PRIVATE_API_KEY"))
            {
                return(Unauthorized("Key is wrong!"));
            }

            if (drop)
            {
                _searchEngine.DeleteAllBeatmaps();
                using (var db = _contextFactory.GetForWrite()) {
                    db.Context.Database.ExecuteSqlCommand
                        ("SET FOREIGN_KEY_CHECKS = 0;" +
                        "TRUNCATE TABLE `Beatmaps`;" +
                        "ALTER TABLE `Beatmaps` AUTO_INCREMENT = 1;" +
                        "TRUNCATE TABLE `BeatmapSet`;" +
                        "ALTER TABLE `BeatmapSet` AUTO_INCREMENT = 1;" +
                        "SET FOREIGN_KEY_CHECKS = 1;");
                }
            }

            lock (_lock) {
                var f = Request.Form.Files["dump.piss"];

                using (var stream = f.OpenReadStream())
                    using (var sr = new MStreamReader(stream))
                        using (var db = _contextFactory.GetForWrite())
                        {
                            var count = sr.ReadInt32();
                            Logger.LogPrint($"Count: {count}");

                            for (var i = 0; i < count; i++)
                            {
                                var set = sr.ReadData <BeatmapSet>();

                                Logger.LogPrint($"Importing BeatmapSet {set.SetId} {set.Artist} - {set.Title} ({set.Creator}) of Index {i}", LoggingTarget.Database, LogLevel.Important);

                                if (!drop)
                                {
                                    if (db.Context.BeatmapSet.Any(s => s.SetId == set.SetId))
                                    {
                                        db.Context.BeatmapSet.Update(set);
                                    }
                                    else
                                    {
                                        db.Context.BeatmapSet.Add(set);
                                    }
                                }
                                else
                                {
                                    db.Context.BeatmapSet.Add(set);
                                }
                            }
                            Logger.LogPrint("Finish importing maps!");
                        }

                return(Ok("Success!"));
            }
        }
        public ActionResult Recovery(
            [FromQuery] string key,
            [FromQuery] RecoveryAction action
            )
        {
            if (key != Environment.GetEnvironmentVariable("PRIVATE_API_KEY"))
            {
                return(Unauthorized("Key is wrong!"));
            }

            switch (action)
            {
            case RecoveryAction.RepairElastic:
                Logger.LogPrint("Repairing ElasticSearch");
                _crawler.Stop();
                _reibe.Stop();

                _searchEngine.DeleteAllBeatmaps();

                foreach (var beatmapSet in _contextFactory.Get().BeatmapSet)
                {
                    beatmapSet.ChildrenBeatmaps = _contextFactory.Get().Beatmaps.Where(b => b.ParentSetId == beatmapSet.SetId).ToList();
                    _searchEngine.IndexBeatmap(beatmapSet);
                }

                if (Environment.GetEnvironmentVariable("CRAWLER_DISABLED") != "true")
                {
                    _crawler.BeginCrawling();
                }

                if (Environment.GetEnvironmentVariable("CHEESEGULL_CRAWLER_DISABLED") != "true")
                {
                    _reibe.BeginCrawling();
                }
                break;

            case RecoveryAction.RecrawlEverything:
                Logger.LogPrint("Recrawl Everything!");

                _crawler.Stop();
                _reibe.Stop();

                _searchEngine.DeleteAllBeatmaps();
                using (var db = _contextFactory.GetForWrite()) {
                    db.Context.Database.ExecuteSqlCommand("SET FOREIGN_KEY_CHECKS = 0;" +
                                                          "TRUNCATE TABLE `Beatmaps`;" +
                                                          "ALTER TABLE `Beatmaps` AUTO_INCREMENT = 1;" +
                                                          "TRUNCATE TABLE `BeatmapSet`;" +
                                                          "ALTER TABLE `BeatmapSet` AUTO_INCREMENT = 1;" +
                                                          "SET FOREIGN_KEY_CHECKS = 1;");
                }
                using (var cacheDb = _cache.GetForWrite())
                {
                    cacheDb.Context.Database.ExecuteSqlCommand(
                        "DELETE FROM `CacheBeatmaps`;" +
                        "DELETE FROM `CacheBeatmapSet`;");
                }
                if (Environment.GetEnvironmentVariable("CRAWLER_DISABLED") != "true")
                {
                    _crawler.BeginCrawling();
                }
                if (Environment.GetEnvironmentVariable("CHEESEGULL_CRAWLER_DISABLED") != "true")
                {
                    _reibe.BeginCrawling();
                }
                break;

            case RecoveryAction.RecrawlUnknown:
                Logger.LogPrint("Recrawl All unknown maps!");

                _crawler.Stop();
                using (var db = _contextFactory.GetForWrite()) {
                    for (var i = 0; i < db.Context.BeatmapSet.Last().SetId; i++)
                    {
                        if (!db.Context.BeatmapSet.Any(set => set.SetId == i))
                        {
                            _crawler.Crawl(i, db.Context);
                        }
                    }
                }
                _crawler.BeginCrawling();
                break;

            default:
                return(BadRequest("Unknown Action type!"));
            }

            return(Ok("Success!"));
        }