protected override async Task<bool> Fetch(CollectorHttpClient client, ReadWriteCursor front, ReadCursor back, CancellationToken cancellationToken)
        {
            await front.Load(cancellationToken);

            DateTime frontDateTime = front.Value;

            JObject root = await client.GetJObjectAsync(Index, cancellationToken);

            List<Task<JObject>> tasks = new List<Task<JObject>>();

            foreach (JObject rootItem in root["items"])
            {
                DateTime pageTimeStamp = rootItem["commitTimeStamp"].ToObject<DateTime>();

                if (pageTimeStamp > frontDateTime)
                {
                    int count = int.Parse(rootItem["count"].ToString());

                    Total += count;

                    front.Value = pageTimeStamp;
                    await front.Save(cancellationToken);
                }
            }

            return true;
        }
        protected override async Task <bool> Fetch(CollectorHttpClient client, ReadWriteCursor front, ReadCursor back)
        {
            await front.Load();

            DateTime frontDateTime = front.Value;

            JObject root = await client.GetJObjectAsync(Index);

            List <Task <JObject> > tasks = new List <Task <JObject> >();

            foreach (JObject rootItem in root["items"])
            {
                DateTime pageTimeStamp = rootItem["commitTimeStamp"].ToObject <DateTime>();

                if (pageTimeStamp > frontDateTime)
                {
                    int count = int.Parse(rootItem["count"].ToString());

                    Total += count;

                    front.Value = pageTimeStamp;
                    await front.Save();
                }
            }

            return(true);
        }
예제 #3
0
        public async Task <bool> ProcessAsync(CancellationToken token)
        {
            var advisories = await _queryService.GetAdvisoriesSinceAsync(_cursor, token);

            var hasAdvisories = advisories != null && advisories.Any();

            _logger.LogInformation("Found {AdvisoryCount} new advisories to process", advisories?.Count() ?? 0);
            if (hasAdvisories)
            {
                var lastUpdatedAt = advisories.Max(i => i.UpdatedAt);
                await _ingestor.IngestAsync(advisories.Select(v => v).ToList());

                _cursor.Value = lastUpdatedAt;
                await _cursor.Save(token);
            }

            return(hasAdvisories);
        }