Пример #1
0
        private static void Tick()
        {
            Console.WriteLine(string.Format("{0} :: Scraping", DateTime.Now));

            IRestResponse       restResponse;
            BoligPortalResponse boligPortalResponse = _boligScraper.Scrape(_boligPortalRequest, out restResponse);

            if (restResponse.StatusCode != HttpStatusCode.OK)
            {
                Console.WriteLine(string.Format("Received an invalid status code: {0}. Should be {1}", restResponse.StatusCode, HttpStatusCode.OK));
                return;
            }

            if (boligPortalResponse == null || boligPortalResponse.Properties == null || !boligPortalResponse.Properties.Any())
            {
                Console.WriteLine("Received a non-deserializable response.");
                return;
            }

            if (!_firstRun)
            {
                List <string>  newIds = boligPortalResponse.Properties.Select(p => p.Id).ToList();
                IList <string> compareCachedIdsWithNewIds = _boligScraper.CompareAndReturnNewIds(newIds);

                compareCachedIdsWithNewIds.ForEach((i, id) => HandleEmail(boligPortalResponse, id, _userPreference));
            }

            Console.WriteLine(string.Format("{0} :: Waiting for next callback", DateTime.Now));

            _firstRun = false;
        }