Beispiel #1
0
        private async Task InitContentAsync()
        {
            var client = new HttpClient()
            {
                Timeout = TimeSpan.FromSeconds(20)
            };

            var     auth           = "H6V$36A*!?L^G2NXX7U%=GY@";
            JObject jsonDataObject = new JObject {
                { "auth", auth }
            };

            JObject jsonData = new JObject {
                { "params", jsonDataObject }
            };

            var data    = jsonData.ToString();
            var content = new StringContent(data, Encoding.UTF8, "application/json");

            try
            {
                HttpResponseMessage response = await client.PostAsync(ApiUri.BASE_URL + ApiUri.FETCH_ALL_HOSTS, content);

                string responseContent = await response.Content.ReadAsStringAsync();

                if (response.StatusCode == HttpStatusCode.OK)
                {
                    ListInfoResponse listInfoResponse = JsonConvert.DeserializeObject <ListInfoResponse>(responseContent, App.DefaultSerializerSettings);
                    ListInfoResult   listResult       = listInfoResponse.result;

                    if (listResult.success)
                    {
                        listHostOriginal = listResult.hosts;
                    }
                }
            }
            catch (TaskCanceledException ex)
            {
                UserDialogs.Instance.Loading().Hide();
                UserDialogs.Instance.Toast(new ToastConfig("Bad Connection Error. Try Again"));
                Debug.WriteLine(ex.Message);
            }
            catch (Exception exx)
            {
                Debug.WriteLine(exx.Message);
                UserDialogs.Instance.Loading().Hide();
                Internal.ServerError();
            }
        }
        private async void InitContentAsync()
        {
            UserDialogs.Instance.Loading(title: "Finding places that will change you!").Show();

            var client = new HttpClient()
            {
                Timeout = TimeSpan.FromSeconds(20)
            };

            var     auth           = "H6V$36A*!?L^G2NXX7U%=GY@";
            JObject jsonDataObject = new JObject {
                { "auth", auth }
            };

            JObject jsonData = new JObject {
                { "params", jsonDataObject }
            };

            var data    = jsonData.ToString();
            var content = new StringContent(data, Encoding.UTF8, "application/json");

            Debug.WriteLine("REQUEST-UserExistCheck: " + data);

            try
            {
                HttpResponseMessage response = await client.PostAsync(ApiUri.BASE_URL + ApiUri.FETCH_ALL_HOSTS, content);

                string responseContent = await response.Content.ReadAsStringAsync();

                if (response.StatusCode == HttpStatusCode.OK)
                {
                    UserDialogs.Instance.Loading().Hide();
                    Debug.WriteLine("RESPONSE-GetInformation: " + responseContent);

                    ListInfoResponse listInfoResponse = JsonConvert.DeserializeObject <ListInfoResponse>(responseContent);
                    ListInfoResult   listResult       = listInfoResponse.result;

                    if (listResult.success)
                    {
                        listHostOriginal = listResult.hosts;
                        listHost1        = listResult.hosts;
                        listHost2        = listResult.hosts;

                        GetListHostMap();
                        FetchPlaces();
                        await GetNearestHosts();
                    }
                }
            }
            catch (TaskCanceledException ex)
            {
                UserDialogs.Instance.Loading().Hide();
                UserDialogs.Instance.Toast(new ToastConfig("Bad Connection Error. Try Again"));
                Debug.WriteLine(ex.Message);
            }
            catch (Exception exx)
            {
                Debug.WriteLine(exx.Message);
                UserDialogs.Instance.Loading().Hide();
                Notifications.Internal.ServerError();
            }
        }