public async Task <List <T> > GetAllAsync <T>(ITimeWatcher timer, SQLiteAsyncConnection cnt, bool cache) where T : TableBase, new() { using (var watch = timer.StartWatcher("GetAllAsync")) { watch?.Properties?.Add("type", typeof(T).Name); watch?.Properties?.Add("cache", cache.ToString()); var key = $"GetAllAsync:{typeof(T).FullName}"; if (cache) { var cacheValues = _cache.Get <List <T> >(timer, key); if (cacheValues != null) { return(cacheValues); } } cnt = cnt ?? await _database.GetConnection(timer); var rslt = await cnt.Table <T>().ToListAsync(); watch?.Properties?.Add("count", rslt.Count.ToString()); if (cache) { _cache.Set(timer, key, rslt); } return(rslt); } }
private async Task Initialize(ITimeWatcher timer) { if (IsInitialize) { return; } await _lock.WaitAsync(); if (IsInitialize) { _lock.Release(); return; } using (timer.StartWatcher("Database.Initialize")) { try { await _asyncConnection.CreateTableAsync <Host>(); await _asyncConnection.CreateTableAsync <CustomCommandSsh>(); await Migrate(); IsInitialize = true; } catch (Exception e) { _logger.Error(e); _telemetry.Exception(e); } } _lock.Release(); }
public async Task <T> FindAsync <T>(ITimeWatcher timer, long?id) where T : TableBase, new() { using (var watch = timer.StartWatcher("GetExploitationsAsync")) { watch?.Properties?.Add("type", typeof(T).Name); if (id == null) { return(default);
public async Task <int> CountAsync <T>(ITimeWatcher timer, SQLiteAsyncConnection cnt) where T : TableBase, new() { using (var watch = timer.StartWatcher("CountAsync")) { watch?.Properties?.Add("type", typeof(T).Name); cnt = cnt ?? await _database.GetConnection(timer); return(await cnt.Table <T>().CountAsync()); } }
private LoadingContext(string name, bool reinitializeLists, bool notifyUser, CancellationToken?token = null, ITimeWatcher timer = null, bool isValid = false) { _name = name; ReinitializeLists = reinitializeLists; NotifyUser = notifyUser; Token = token ?? CancellationToken.None; Timer = timer; IsValid = isValid; }
public Watcher(ITimeWatcher timeWatcher, string name, string key, bool telemetry, bool debug) { _timeWatcher = timeWatcher; Name = name; Key = key; Telemetry = telemetry; Debug = debug; Properties = new Dictionary <string, string>(); Measures = new Dictionary <string, double>(); }
public void Set(ITimeWatcher timer, string k, object value) { using (var watcher = timer.StartWatcher("RepositoryCache.Set")) { watcher?.Properties?.Add("key", k); if (k != null && value != null) { _cache.AddOrSet(k, value); } } }
public T Get <T>(ITimeWatcher timer, string k) { using (var watcher = timer.StartWatcher("RepositoryCache.Get")) { watcher?.Properties?.Add("key", k); if (k != null && _cache.ContainsKey(k)) { watcher?.Properties?.Add("exists", true.ToString()); return((T)_cache[k]); } watcher?.Properties?.Add("exists", false.ToString()); return(default);
public static LoadingContext Create(LoadingContext context, CancellationToken token, ITimeWatcher timer) { return(new LoadingContext(context._name, context.ReinitializeLists, context.NotifyUser, token, timer, true)); }
public DataProvider(IRepository repository) { _timer = new TimeWatcher(); _repository = repository; }
public async Task <SQLiteAsyncConnection> GetConnection(ITimeWatcher timer) { await Initialize(timer); return(_asyncConnection); }