Exemplo n.º 1
0
        private async Task <MonitoredPageViewModel.TimeInfo> GetRemoteTimeInfoAsync()
        {
            string responseContent;

            using (var http = new HttpClient())
            {
                using (HttpResponseMessage response = await http.GetAsync("http://worldtimeapi.org/api/ip"))
                {
                    response.EnsureSuccessStatusCode();
                    responseContent = await response.Content.ReadAsStringAsync();
                }
            }

            dynamic timeInfo = JObject.Parse(responseContent);

            var timeInfoObj = new MonitoredPageViewModel.TimeInfo()
            {
                UtcTime       = timeInfo.utc_datetime,
                LocalTime     = timeInfo.datetime,
                LocalTimeZone = $"{timeInfo.timezone} ({timeInfo.abbreviation})",
                LocationInfo  = "worldtimeapi.org"
            };

            // Is this really a bug in Newtonsoft that caused the time to be deserialized to local??
            timeInfoObj.UtcTime   = timeInfoObj.UtcTime.ToUniversalTime();
            timeInfoObj.LocalTime = timeInfoObj.LocalTime.ToLocalTime();

            return(timeInfoObj);
        }
Exemplo n.º 2
0
        private async Task <MonitoredPageViewModel.TimeInfo> GetFunctionTimeInfoAsync()
        {
            string responseContent;

            using (var http = new HttpClient())
            {
                using (HttpResponseMessage response = await http.GetAsync("https://availabilitymonitoring-extension-monitoredfuncsample.azurewebsites.net/api/TimeServer"))
                {
                    response.EnsureSuccessStatusCode();
                    responseContent = await response.Content.ReadAsStringAsync();
                }
            }

            MonitoredPageViewModel.TimeInfo timeInfo = JsonConvert.DeserializeObject <MonitoredPageViewModel.TimeInfo>(responseContent);
            return(timeInfo);
        }