public static string GetSegmentList(CoordinatesModel coordinates)
        {
            try
            {
                HttpClient httpClient = GetClient();

                if (httpClient == null)
                {
                    return(null);
                }

                var task = httpClient.SendAsync(GetHttpRequestMessage(coordinates));
                task.Wait();

                if (task.Result.IsSuccessStatusCode)
                {
                    var jsontask = task.Result.Content.ReadAsStringAsync();
                    jsontask.Wait();

                    PulseSegmentListModel segmentList = JsonConvert.DeserializeObject <PulseSegmentListModel>(jsontask.Result);

                    return(string.Join(", ", segmentList.data));
                }
                return("Error while getting segment list. Check API key!");
            } catch (Exception ex) {
                Debug.WriteLine("HttpHelper.QueryPulse(): Error: " + ex.Message);
                return("Error while getting segment list. Check API key!");
            }
        }
Exemple #2
0
        public static void QueryPulse(CoordinatesModel coordinates, HttpSessionStateBase sessionBase, LockingSingleton locker)
        {
            Debug.WriteLine("QueryPulse(): START");

            HttpClient           httpClient = HttpHelper.GetClient();
            HttpSessionStateBase session    = sessionBase;

            if (httpClient == null)
            {
                locker.isLocked = false;
                return;
            }

            httpClient.SendAsync(HttpHelper.GetHttpRequestMessage(coordinates)).ContinueWith((task) =>
            {
                var response = task.Result;
                if (response.StatusCode == HttpStatusCode.OK)
                {
                    Debug.WriteLine("QueryPulse(): Status: " + response.StatusCode);

                    var jsonTask = response.Content.ReadAsStringAsync();
                    jsonTask.Wait();

                    PulseSegmentListModel ps  = JsonConvert.DeserializeObject <PulseSegmentListModel>(jsonTask.Result);
                    session["pulse_segments"] = ps.data;

                    Debug.WriteLine("QueryPulse(): Data: " + string.Join(", ", ps.data));
                }
                else
                {
                    Debug.WriteLine("QueryPulse(): Error: {0}", response);
                }

                locker.isLocked = false;
            });

            Debug.WriteLine("QueryPulse(): END");
            return;
        }