Exemplo n.º 1
0
        public async Task <string> GetTodayWallpaperUrlAsync()
        {
            string urlResult = string.Empty;

            try
            {
                BingModel  model      = new BingModel();
                var        requestUrl = new Uri(BASE_URL + "HPImageArchive.aspx?format=js&idx=0&n=1&mkt=en-US");
                HttpClient client     = new HttpClient();
                var        response   = await client.GetAsync(requestUrl);

                if (response.IsSuccessStatusCode)
                {
                    var content = await response.Content.ReadAsStringAsync();

                    model = JsonConvert.DeserializeObject <BingModel>(content);
                }

                if (model.Images != null)
                {
                    urlResult = BASE_URL + model.Images.FirstOrDefault().Url;
                }
            }
            catch (Exception ex)
            {
                urlResult = ex.Message;
            }

            return(urlResult);
        }
Exemplo n.º 2
0
        public Image GetTodayWallpaperUrl()
        {
            BingModel model = new BingModel();

            try
            {
                var        requestUrl = new Uri(BASE_URL + "HPImageArchive.aspx?format=js&idx=0&n=1&mkt=en-US");
                HttpClient client     = new HttpClient();
                var        response   = client.GetAsync(requestUrl);
                if (response.Result.IsSuccessStatusCode)
                {
                    var content = response.Result.Content.ReadAsStringAsync();
                    model = JsonConvert.DeserializeObject <BingModel>(content.Result);
                }

                if (model.Images != null)
                {
                    model.Images.FirstOrDefault().Url = BASE_URL + model.Images.FirstOrDefault().Url;
                }
            }
            catch (Exception)
            {
            }

            return(model.Images.FirstOrDefault());
        }
Exemplo n.º 3
0
 public static string ToJson(this BingModel self) => JsonConvert.SerializeObject(self, Converter.Settings);