Esempio n. 1
0
        private async Task ProcessAll(JArray items)
        {
            this.CancellationToken.ThrowIfCancellationRequested();

            var deletedIds = new List <string>();
            var upsertList = new List <JObject>();

            foreach (var token in items)
            {
                var item = token as JObject;
                if (item == null)
                {
                    continue;
                }

                if (!this.cursor.OnNext())
                {
                    break;
                }

                string id = this.Reader.GetId(item);
                if (id == null)
                {
                    continue;
                }

                var pendingOperation = await this.OperationQueue.GetOperationByItemIdAsync(this.Table.TableName, id);

                if (pendingOperation != null)
                {
                    continue;
                }

                DateTimeOffset updatedAt = this.Reader.GetUpdatedAt(item).GetValueOrDefault(Epoch).ToUniversalTime();
                strategy.SetUpdateAt(updatedAt);

                if (this.Reader.IsDeleted(item))
                {
                    deletedIds.Add(id);
                }
                else
                {
                    upsertList.Add(item);
                }
            }

            if (upsertList.Any())
            {
                await this.Store.UpsertAsync(this.Table.TableName, upsertList, ignoreMissingColumns : true);
            }

            if (deletedIds.Any())
            {
                await this.Store.DeleteAsync(this.Table.TableName, deletedIds);
            }

            await this.strategy.OnResultsProcessedAsync();
        }
Esempio n. 2
0
        private async Task ProcessAll(JArray items)
        {
            if (items is null)
            {
                return;
            }

            this.CancellationToken.ThrowIfCancellationRequested();

            var deletedIds = new List <string>();
            var upsertList = new List <JObject>();

            foreach (var token in items)
            {
                if (!(token is JObject item))
                {
                    continue;
                }

                if (!this.cursor.OnNext())
                {
                    break;
                }

                string id = this.Reader.GetId(item);
                if (id == null)
                {
                    Serilog.Log.Warning("PullAction.ProcessAll : WARNING: THE FOLLOWING ODATA ENTRY DOES NOT HAVE A VALID 'id' FIELD ========================");
                    Serilog.Log.Warning(item.ToString());
                    Serilog.Log.Warning("PullAction.ProcessAll : ============================================================================================");
                    continue;
                }

                var pendingOperation = await this.OperationQueue.GetOperationByItemIdAsync(this.Table.TableName, id);

                if (pendingOperation != null)
                {
                    continue;
                }

                DateTimeOffset updatedAt = this.Reader.GetUpdatedAt(item).GetValueOrDefault(Epoch).ToUniversalTime();
                strategy.SetUpdateAt(updatedAt);

                if (this.Reader.IsDeleted(item))
                {
                    deletedIds.Add(id);
                }
                else
                {
                    upsertList.Add(item);
                }
            }

            if (upsertList.Any())
            {
                await this.Store.UpsertAsync(this.Table.TableName, upsertList, ignoreMissingColumns : true);
            }

            if (deletedIds.Any())
            {
                await this.Store.DeleteAsync(this.Table.TableName, deletedIds);
            }

            await this.strategy.OnResultsProcessedAsync();
        }