public static void SetOptions(LogOptions options) { _options = options; if (options.ExecuteAsync) { _queue = new AutoQueueExecutor(); } else if (_queue != null) { _queue.Dispose(); _queue = null; } if (options.SaveLog) { _log = new StringBuilder(); if (!Directory.Exists("logs")) { Directory.CreateDirectory("logs"); } if (options.SaveLogTimerMs < LogOptions.MinimumSaveTimer) { options.SaveLogTimerMs = LogOptions.MinimumSaveTimer; } } }
protected NetworkProtocol() { if (PooledExecution) { AsyncQueue = new AutoQueueExecutor(); } }
static SqlManager() { _databases = new Dictionary <Type, Database>(); _queue = new AutoQueueExecutor(); var typedTb = new Dictionary <Type, List <Type> >(); try { var assemblys = AppDomain.CurrentDomain.GetAssemblies(); foreach (var assembly in assemblys) { foreach (var type in assembly.GetTypes()) { if (type.IsAbstract || !type.IsClass) { continue; } if (type.IsSubclassOf(typeof(Database))) { var db = (Database)Activator.CreateInstance(type); if (!_databases.ContainsKey(type)) { _databases.Add(type, db); db.TryCreateItSelf(); } else { throw new DatabaseAlreadyInitializedException(db.Name); } } else if (type.IsSubclassOf(typeof(Table))) { var link = type.GetCustomAttribute <TableLink>(false); if (link != null) { if (link.DatabaseType != null) { if (typedTb.TryGetValue(link.DatabaseType, out List <Type> types)) { types.Add(type); } else { typedTb.Add(link.DatabaseType, new List <Type> { type }); } } } } } } foreach (var pair in typedTb) { if (TrySearchDatabase(pair.Key, out Database db) && db.AutoGenerateTable) { RegisterTablesTo(db, pair.Value); } } void RegisterTablesTo(Database db, List <Type> types) { foreach (var type in types) { var table = (Table)Activator.CreateInstance(type); db.Create(table); } db.IsInitialized = true; db.OnInitialized(); } } catch (Exception ex) { _databases.Clear(); throw new InitializationFailedException(ex.ToString()); } }