internal static void InitGlobalDatabase(GlobalDatabase globalDatabase) { if (globalDatabase == null) { Logger.LogNullError(nameof(globalDatabase)); return; } if (GlobalDatabase != null) { return; } GlobalDatabase = globalDatabase; }
internal static async Task Init() { Mainpage1 = new mainpage1(); WebBrowser = new WebBrowser(Logger, true); //await RegisterBots().ConfigureAwait(false); var globalDatabaseFile = Path.Combine(MainPage.MainDir, GetFilePath(Bot.EFileType.Database)); if (string.IsNullOrEmpty(globalDatabaseFile)) { Logger.LogNullError(nameof(globalDatabaseFile)); return; } GlobalDatabase globalDatabase = GlobalDatabase.CreateOrLoad(globalDatabaseFile); if (globalDatabase == null) { Logger.LogGenericError(string.Format(Strings.ErrorDatabaseInvalid, globalDatabaseFile)); await Task.Delay(5 * 1000).ConfigureAwait(false); //await Exit(1).ConfigureAwait(false); return; } InitGlobalDatabase(globalDatabase); if (Debugging.IsUserDebugging) { if (Debugging.IsDebugConfigured) { Logger.LogGenericDebug(globalDatabaseFile + ": " + JsonConvert.SerializeObject(GlobalDatabase, Formatting.Indented)); } //todo Logging.EnableTraceLogging(); DebugLog.AddListener(new Debugging.DebugListener()); DebugLog.Enabled = sc.GlobalConfig.Debug; if (Directory.Exists(Path.Combine(MainPage.MainDir, SharedInfo.DebugDirectory))) { try { Directory.Delete(Path.Combine(MainPage.MainDir, SharedInfo.DebugDirectory), true); await Task.Delay(1000) .ConfigureAwait(false); // Dirty workaround giving Windows some time to sync } catch (Exception e) { Logger.LogGenericException(e); } } try { Directory.CreateDirectory(Path.Combine(MainPage.MainDir, SharedInfo.DebugDirectory)); } catch (Exception e) { Logger.LogGenericException(e); } } WebBrowser.Init(); }
internal static void InitializeGlobalConfigAndDatabase() { InitGlobalConfig(GlobalConfig.CreateOrLoad(Path.Combine(MainPage.MainDir, "config.json"))); InitGlobalDatabase(GlobalDatabase.CreateOrLoad(Path.Combine(MainPage.MainDir, "db.json"))); }