public InitialisationService(ILogger <InitialisationService> logger, IWebHostEnvironment environment, IServiceProvider provider, LexiconLoader loader, ConfigDownloader <ILexiconConfig> lexiconDownloader) { this.logger = logger ?? throw new ArgumentNullException(nameof(logger)); this.environment = environment ?? throw new ArgumentNullException(nameof(environment)); this.provider = provider ?? throw new ArgumentNullException(nameof(provider)); this.loader = loader ?? throw new ArgumentNullException(nameof(loader)); this.lexiconDownloader = lexiconDownloader; }
protected bool DownloadConfig() { // download config - if needed or if could not be loaded ConfigDownloader dl = new ConfigDownloader(GardenConfig.Instance); configDownloadThread = new ThreadedTask(dl); if (dl.IsDownloadNeeded()) { // start the task configDownloadThread.Start(); // then wait for a short while until success of the task thread long timer = 0; long blockingWaitPeriodTicks = System.TimeSpan.TicksPerSecond * 0; // TODO const in config if (!GardenConfig.Instance.IsValid()) { blockingWaitPeriodTicks = System.TimeSpan.TicksPerSecond * 30; // TODO const in config } if (blockingWaitPeriodTicks > 0) { while (configDownloadThread.Status() == ITaskStatus.CREATED) { // block until in RUNNING state } while (configDownloadThread.Status() == ITaskStatus.RUNNING && timer < blockingWaitPeriodTicks) { Thread.Sleep(100); timer += (System.TimeSpan.TicksPerMillisecond * 100); } switch (dl.Status()) { case ITaskStatus.SUCCESS: GardenConfig.Instance = dl.NewConfig; break; case ITaskStatus.FAIL: initError = new Exception(dl.StatusMsg()); break; case ITaskStatus.CREATED: case ITaskStatus.RUNNING: // let the downloading simply finish in the background. Load it another time. break; } } } // if still not ok after attempted download, warn the user and exit // a missing config counts as a valid one (then uses default params to create a new config) if (!GardenConfig.Instance.IsValid()) { IsMouseVisible = true; MsgBox.Show("Could not load configuration", "Could not load configuration file. Is it missing or corrupted?"); return(false); } return(true); }
void Start() { s_instance = this; }