Пример #1
0
 public async Task <IReadOnlyList <T> > SelectEntities <T>(ICollection <TEntityId> ids, ILoadEntityLogger logger, TContext context, Func <EntityWithId <TEntityId, TEntity>, T> selector)
 {
     return(await _chunkedExecutor.ExecuteAsync(
                new List <T>(),
                ids,
                async (chunk, transformedEntities) =>
     {
         var entites = CacheOrClenaup(await _repository.Get(chunk, logger, context));
         transformedEntities.AddRange(entites.Select(selector));
     }));
 }
Пример #2
0
        public async Task <IEnumerable <IdWithType <TId> > > GetVCardTypesAndCleanupCache <TId> (IEnumerable <TId> allIdsInRepository)
            where TId : IEntity <WebResourceName>
        {
            var cachedTypesById = _vcardTypeCache.GetEntries();
            Dictionary <WebResourceName, VCardEntry> touchedTypesById = new Dictionary <WebResourceName, VCardEntry>();

            var result = new List <IdWithType <TId> > ();

            var unknownIds = Resolve(allIdsInRepository, result, cachedTypesById, touchedTypesById);

            if (!unknownIds.Any())
            {
                _vcardTypeCache.SetEntries(touchedTypesById);
                return(result);
            }

            s_logger.Info($"Loading {unknownIds.Count} unknown ids, to determine VCard type");

            foreach (var entity in await _cardDavRepository.Get(unknownIds.Select(i => i.Id).ToArray(), NullLoadEntityLogger.Instance, NullCardDavRepositoryLogger.Instance))
            {
                var newEntry = new VCardEntry {
                    Id = entity.Id, Type = entity.Entity.Kind == vCardKindType.Group ? VCardType.Group : VCardType.Contact
                };
                cachedTypesById.Add(entity.Id, newEntry);
            }
            var stillUnknownIds = Resolve(unknownIds, result, cachedTypesById, touchedTypesById);

            _vcardTypeCache.SetEntries(touchedTypesById);

            if (stillUnknownIds.Any())
            {
                throw new Exception("VCard does not exist on server anymore."); // TODO: throw specialized type that causes just a warning
            }
            return(result);
        }
Пример #3
0
 public async Task <IReadOnlyDictionary <TEntityId, T> > GetTransformedEntities <T>(ICollection <TEntityId> ids, ILoadEntityLogger logger, TContext context, Func <EntityWithId <TEntityId, TEntity>, T> transform)
 {
     return(await _chunkedExecutor.ExecuteAsync(
                new Dictionary <TEntityId, T>(_idComparer),
                ids,
                async (chunk, transformedEntities) =>
     {
         var entites = CreateEnumerableWhichCachesOrCleansUp(await _repository.Get(chunk, logger, context));
         foreach (var entity in entites)
         {
             if (!transformedEntities.ContainsKey(entity.Id))
             {
                 transformedEntities.Add(entity.Id, transform(entity));
             }
             else
             {
                 s_logger.WarnFormat("Entitiy '{0}' was contained multiple times in repository response. Ignoring redundant entity", entity.Id);
             }
         }
     }));
 }
Пример #4
0
 public async Task <IEnumerable <EntityWithId <TEntityId, TEntity> > > Get(ICollection <TEntityId> ids, ILoadEntityLogger logger, TContext context)
 {
     return(await Task.Run(() => _decorated.Get(ids, logger, context)));
 }