Example #1
0
        public async Task AddAsync(IEnumerable <IFileRecord> records)
        {
            var contentToRefresh = new List <ContentTag>();

            foreach (var record in records)
            {
                await AddRecord(record);

                if (contentToRefresh.Contains(record.Tag))
                {
                    continue;
                }

                contentToRefresh.Add(record.Tag);

                _cache.Remove(record.Tag);
            }

            var indexedRecords = await _indexedDbMgr.GetRecords <FileRecord>(StoreName);

            foreach (var content in contentToRefresh)
            {
                var taggedRecords = indexedRecords.Where(o => o.Tag == content);

                var orderedCache = new OrderedFileRecords();
                orderedCache.Add(taggedRecords);

                _cache.Add(content, orderedCache);
            }

            InvokeChange();
        }
Example #2
0
        public async Task InitializeAsync()
        {
            _cache = new SortedDictionary <ContentTag, IOrderedRecords <IFileRecord> >();

            var records = await _indexedDbMgr.GetRecords <FileRecord>(StoreName);

            foreach (var record in records)
            {
                if (_cache.ContainsKey(record.Tag))
                {
                    _cache.GetValueOrDefault(record.Tag).Add(record, false);
                    continue;
                }

                var orderedRecords = new OrderedFileRecords();
                orderedRecords.Add(record, false);

                _cache.Add(record.Tag, orderedRecords);
            }

            foreach (var orderedFileRecords in _cache.Values)
            {
                orderedFileRecords.Order();
            }

            IsInitialized = true;
        }
Example #3
0
        public async Task ReplaceAsync(IFileRecord oldRecord, IFileRecord newRecord)
        {
            if (!_cache.ContainsKey(newRecord.Tag))
            {
                var orderedRecords = new OrderedFileRecords();
                _cache.Add(newRecord.Tag, orderedRecords);
            }

            if (oldRecord.Tag != newRecord.Tag)
            {
                if (_cache.TryGetValue(oldRecord.Tag, out var cachedOld))
                {
                    cachedOld.Remove(oldRecord);
                }

                if (_cache.TryGetValue(newRecord.Tag, out var cachedNew))
                {
                    cachedNew.Add(newRecord);
                }
            }
            else
            {
                if (_cache.TryGetValue(newRecord.Tag, out var cached))
                {
                    cached.Remove(oldRecord, false);
                    cached.Add(newRecord);
                }
            }

            await UpdateRecord(newRecord);

            InvokeChange();
        }
Example #4
0
        public async Task AddAsync(IFileRecord record)
        {
            await AddRecord(record);

            _cache.Remove(record.Tag);

            var records = await _indexedDbMgr.GetRecords <FileRecord>(StoreName);

            var taggedRecords = records.Where(o => o.Tag == record.Tag);

            var orderedCache = new OrderedFileRecords();

            orderedCache.Add(taggedRecords);

            _cache.Add(record.Tag, orderedCache);

            InvokeChange();
        }