Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
        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();
        }
Exemplo n.º 3
0
        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);
Exemplo n.º 4
0
        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());
            }
        }
Exemplo n.º 5
0
        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);
                }
            }
        }
Exemplo n.º 6
0
        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);