예제 #1
0
        public static async Task <List <GuardianSectionArticle> > FindNews()
        {
            var guardianItems = new List <GuardianSectionArticle>();

            GuardianSectionEnumerationResponse categories = await NewsFinder.GetSections();

            GuardianSectionEnumerationResponseField sectionResponse = categories.Response;

            var queries = 0;

            foreach (GuardianSection section in sectionResponse.Results)
            {
                long start = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;

                guardianItems = guardianItems.Concat(await NewsFinder.GetSectionResponse(section)).ToList();

                ++queries;

                if (queries == 12)
                {
                    long end       = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
                    var  totalTime = (int)(end - start);

                    if (totalTime < 1000)
                    {
                        Thread.Sleep(1000 - totalTime + 100);
                    }

                    queries = 0;
                }
            }

            return(guardianItems);
        }
예제 #2
0
        private async Task RunAsync(CancellationToken cancellationToken)
        {
            // TODO: Replace the following with your own logic.
            while (!cancellationToken.IsCancellationRequested)
            {
                Trace.TraceInformation("Working");

                List <GuardianSectionArticle> articles = await NewsFinder.FindNews();

                await this.newsPusher.PushNews(articles);

                await Task.Delay(new TimeSpan(1, 0, 0, 0));
            }
        }