Exemple #1
0
        public async Task <NewsPost> GetResponse(string url)
        {
            try
            {
                var rmh = RequestModelHandler.GetInstance();
                if (rmh.UrlDateDictionary.ContainsKey(new Uri(url)))
                {
                    if (!rmh.AddUriElement(new Uri(url), rmh.UrlDateDictionary))
                    {
                        return(await _dmrs.GetDtoFromBaseAsync(url));
                    }
                }
                else
                {
                    rmh.AddUriElement(new Uri(url), rmh.UrlDateDictionary);
                    HttpSpecialFactory http = new HttpSpecialFactory();
                    var client   = http.CreateWithUrl(url);
                    var response = await GetApiResponseAsync(client);

                    await Task.Run(() => _dmrs.ApiResponseToDtoAsync(response));

                    var result = await Task.Run(() => _dmrs.GetDtoFromBaseAsync(url));

                    return(result);
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            return(null);
        }
Exemple #2
0
        public async Task CacheDictionary()
        {
            var rmh  = RequestModelHandler.GetInstance();
            var ras  = new RssApiService();
            var http = new HttpSpecialFactory();

            using (var unitOfWork = new UnitOfWork(new RssContext()))
            {
                HttpClient client;
                var        query = unitOfWork.FeedList.Select(rss => rss.Url).Distinct();
                foreach (var item in query)
                {
                    rmh.UrlDateDictionary.Add(new Uri(item), DateTime.Now);
                    client = http.CreateWithUrl(item);
                    var response = await ras.GetApiResponseAsync(client);

                    await _dmrsInstance.ApiResponseToDtoAsync(response);
                }
            }
        }