public SQLiteLogTable(ITaskScheduler scheduler, LogDataCache cache, string fileName) { if (scheduler == null) throw new ArgumentNullException("scheduler"); if (cache == null) throw new ArgumentNullException("cache"); if (fileName == null) throw new ArgumentNullException("fileName"); _scheduler = scheduler; _cache = cache; _fileName = fileName; _listeners = new LogTableListenerCollection(this); _accessQueue = new LogDataAccessQueue<LogEntryIndex, LogEntry>(); _schema = new SQLiteSchema(string.Empty); _task = _scheduler.StartPeriodic(Update, ToString()); }
/// <summary> /// Reads the current schema from the given database and then forces a schema update /// of all listeners in case the schema has changed compared to the previous one. /// </summary> /// <param name="connection"></param> private void UpdateSchema(SQLiteConnection connection) { string tableName; if (TryFindTable(connection, out tableName)) { SQLiteSchema schema = GetSchema(connection, tableName); TryChangeSchema(schema); } else { Log.WarnFormat("Unable to find a fitting table in database {0}", _fileName); var schema = new SQLiteSchema(string.Empty); TryChangeSchema(schema); } }
/// <summary> /// Changes the schema of this table, if necessary. /// </summary> /// <param name="schema"></param> private void TryChangeSchema(SQLiteSchema schema) { if (!Equals(_schema, schema)) { Log.DebugFormat("Schema of {0} changed from {1} to {2}", _fileName, _schema, schema); _schema = schema; _rowCount = 0; _cache.Remove(this); _listeners.OnSchemaChanged(_schema); _listeners.OnRead(LogEntryIndex.Invalid, 0); } }