Beispiel #1
0
        public void RequestModelTest()
        {
            var status = new ModemStatus
            {
                IsSuccess     = false,
                State         = "Not initialized",
                Manufacturer  = "None",
                ModelName     = string.Empty,
                SerialNumber  = "SN xyz",
                SignalQuality = new SignalQuality {
                    dBmW = 0, Percent = "0.0", IsValid = false
                },
                Imsi         = string.Empty,
                Imei         = string.Empty,
                OperatorName = string.Empty
            };
            var request = new ModemRequestContext
            {
                Response   = status,
                Connection = _configuration
            };
            var handler = new RequestModelHandler();
            var result  = handler.Handle(request, "AT+GMM");

            result.Should().NotBeNull();
            result.Response.ModelName.Should().NotBeEmpty();
            result.Response.IsSuccess.Should().BeTrue();
        }
Beispiel #2
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);
        }
Beispiel #3
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);
                }
            }
        }