Esempio n. 1
0
        private static async Task <List <RssItem> > SyncCoreAsync(LocalDbContext ctx, ISyncSource syncSource, SyncSourceInfo syncInfo,
                                                                  CancellationToken cancellationToken)
        {
            if (syncInfo is null)
            {
                syncInfo = new SyncSourceInfo {
                    SyncSourceId = syncSource.SyncSourceId
                };
                ctx.Add(syncInfo);
            }

            var page = await syncSource.TryGetItemsAsync(syncInfo.LastSyncId, cancellationToken)
                       .ConfigureAwait(false);

            if (page.LastId is int lastId)
            {
                syncInfo.LastSyncId = lastId;
            }

            var newItems = page.GetItems().Select(z =>
            {
                var r = new RssItem();
                r.UpdateFrom(z);
                return(r);
            }).ToList();

            return(ctx.AddOrIgnoreRange(newItems));
        }