Exemplo n.º 1
0
        public async Task SyncRecordRepository <T, TId, TQuery>(IRecordRepository <T, TId, TQuery> source, IRecordRepository <T, TId, TQuery> target, bool full) where TId : class where T : RHasId <TId> where TQuery : QueryRequest, new()
        {
            HashSet <TId> remoteIds = await target.All().ToHashSetAsync();

            await foreach (var item in source.GetAllItems().IgnoreNull())
            {
                Logger.LogInformation($"Loaded {item.Id}");
                if (remoteIds.Contains(item.Id))
                {
                    var result = await target.Update(item);

                    if (result)
                    {
                        Logger.LogInformation($"Updated {item.Id}");
                    }
                    else
                    {
                        Logger.LogError($"Failed to update {item.Id}");
                    }
                }
                else
                {
                    var result = await target.Create(item);

                    if (result is null)
                    {
                        Logger.LogError($"Failed to create {item.Id}");
                    }
                    else
                    {
                        Logger.LogInformation($"Created {item.Id}");
                    }
                }
                remoteIds.Remove(item.Id);
            }
            if (full)
            {
                foreach (var v in remoteIds)
                {
                    var result = await target.Delete(v);

                    if (result)
                    {
                        Logger.LogInformation($"Deleted {v}.");
                    }
                    else
                    {
                        Logger.LogError($"Failed to deleted {v}.");
                    }
                }
            }
        }
Exemplo n.º 2
0
        public static async Task <IEnumerable <TId> > TestAll <T, TId, TQuery>(this IRecordRepository <T, TId, TQuery> repository) where TId : class where T : RHasId <TId> where TQuery : QueryRequest, new()
        {
            var result = repository.All();

            Assert.IsNotNull(result);

            List <TId> res = new List <TId>();

            await foreach (var v in result)
            {
                res.Add(v);
                await repository.TestGet(v);
            }

            return(res);
        }
Exemplo n.º 3
0
 public static IAsyncEnumerable <T?> GetAllItems <T, TId, TQuery>(this IRecordRepository <T, TId, TQuery> repository, CancellationToken cancellationToken = default) where TId : class where T : RHasId <TId> where TQuery : QueryRequest, new()
 {
     return(GetItems(repository, repository.All(cancellationToken), cancellationToken));
 }