Beispiel #1
0
        void HandleAddContactButtonClicked(object sender, EventArgs e)
        {
            MobileCenterHelpers.TrackEvent(MobileCenterConstants.AddContactButtonTapped);

            Device.BeginInvokeOnMainThread(async() =>
                                           await Navigation.PushModalAsync(new BaseNavigationPage(new ContactDetailPage(new ContactModel(), true))));
        }
Beispiel #2
0
        static async Task <HttpResponseMessage> PatchObjectToAPI <T>(string apiUrl, T data)
        {
            var stringPayload = await Task.Run(() => JsonConvert.SerializeObject(data)).ConfigureAwait(false);

            var httpContent = new StringContent(stringPayload, Encoding.UTF8, "application/json");

            var httpRequest = new HttpRequestMessage
            {
                Method     = new HttpMethod("PATCH"),
                RequestUri = new Uri(apiUrl),
                Content    = httpContent
            };

            try
            {
                UpdateActivityIndicatorStatus(true);

                return(await _client.SendAsync(httpRequest).ConfigureAwait(false));
            }
            catch (Exception e)
            {
                MobileCenterHelpers.Log(e);
                return(null);
            }
            finally
            {
                UpdateActivityIndicatorStatus(false);
            }
        }
Beispiel #3
0
        protected override void OnAppearing()
        {
            base.OnAppearing();

            MobileCenterHelpers.TrackEvent(MobileCenterConstants.ContactsListPageAppeared);

            Device.BeginInvokeOnMainThread(_contactsListView.BeginRefresh);
        }
Beispiel #4
0
        static async Task <HttpResponseMessage> DeleteObjectFromAPI(string apiUrl)
        {
            var httpRequest = new HttpRequestMessage(HttpMethod.Delete, new Uri(apiUrl));

            try
            {
                UpdateActivityIndicatorStatus(true);

                return(await _client.SendAsync(httpRequest).ConfigureAwait(false));
            }
            catch (Exception e)
            {
                MobileCenterHelpers.Log(e);
                return(null);
            }
            finally
            {
                UpdateActivityIndicatorStatus(false);
            }
        }
        protected static async Task <HttpResponseMessage> PostObjectToAPI <T>(string apiUrl, T data)
        {
            var stringPayload = await Task.Run(() => JsonConvert.SerializeObject(data)).ConfigureAwait(false);

            var httpContent = new StringContent(stringPayload, Encoding.UTF8, "application/json");

            try
            {
                UpdateActivityIndicatorStatus(true);

                return(await Client.PostAsync(apiUrl, httpContent).ConfigureAwait(false));
            }
            catch (Exception e)
            {
                MobileCenterHelpers.Log(e);
                return(null);
            }
            finally
            {
                UpdateActivityIndicatorStatus(false);
            }
        }
Beispiel #6
0
        static async Task <T> GetDataObjectFromAPI <T, U>(string apiUrl, U data = default(U))
        {
            var stringPayload = string.Empty;

            if (data != null)
            {
                stringPayload = await Task.Run(() => JsonConvert.SerializeObject(data)).ConfigureAwait(false);
            }

            var httpContent = new StringContent(stringPayload, Encoding.UTF8, "application/json");

            try
            {
                UpdateActivityIndicatorStatus(true);

                using (var stream = await _client.GetStreamAsync(apiUrl).ConfigureAwait(false))
                    using (var reader = new StreamReader(stream))
                        using (var json = new JsonTextReader(reader))
                        {
                            if (json == null)
                            {
                                return(default(T));
                            }

                            return(await Task.Run(() => _serializer.Deserialize <T>(json)).ConfigureAwait(false));
                        }
            }
            catch (Exception e)
            {
                MobileCenterHelpers.Log(e);
                return(default(T));
            }
            finally
            {
                UpdateActivityIndicatorStatus(false);
            }
        }
Beispiel #7
0
        protected override void OnAppearing()
        {
            base.OnAppearing();

            MobileCenterHelpers.TrackEvent(MobileCenterConstants.ContactDetailPageAppeared);
        }