Пример #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);
            }
        }
Пример #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();
        }
Пример #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);
Пример #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());
            }
        }
Пример #5
0
 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;
 }
Пример #6
0
 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>();
 }
Пример #7
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);
                }
            }
        }
Пример #8
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);
Пример #9
0
 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;
 }
Пример #11
0
        public async Task <SQLiteAsyncConnection> GetConnection(ITimeWatcher timer)
        {
            await Initialize(timer);

            return(_asyncConnection);
        }