Beispiel #1
0
        protected 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)
            {
                DebugHelpers.PrintException(e);
                return(null);
            }
            finally
            {
                UpdateActivityIndicatorStatus(false);
            }
        }
Beispiel #2
0
 public static void BeginInvokeOnMainThread(Action method)
 {
     Device.BeginInvokeOnMainThread(() =>
     {
         try
         {
             method?.Invoke();
         }
         catch (Exception e)
         {
             DebugHelpers.PrintException(e);
         }
     });
 }
 public static void BeginInvokeOnMainThread(Action a)
 {
     lock (_locker)
     {
         Device.BeginInvokeOnMainThread(() =>
         {
             try
             {
                 a?.Invoke();
             }
             catch (Exception ex)
             {
                 DebugHelpers.PrintException(ex);
             }
         });
     }
 }
Beispiel #4
0
        public static Task <T> BeginInvokeOnMainThreadAsync <T>(Func <Task <T> > method)
        {
            var tcs = new TaskCompletionSource <T>();

            Device.BeginInvokeOnMainThread(async() =>
            {
                try
                {
                    var task = method?.Invoke();
                    tcs?.SetResult(await task);
                }
                catch (Exception e)
                {
                    DebugHelpers.PrintException(e);
                    tcs?.SetException(e);
                }
            });

            return(tcs?.Task);
        }
Beispiel #5
0
        public static async Task <ODataResponseListReport> GetReports()
        {
            UpdateActivityIndicatorStatus(true);

            try
            {
                var client = await GetPowerBIClient();

                return(await client.Reports.GetReportsAsync());
            }
            catch (Exception e)
            {
                DebugHelpers.PrintException(e);
                return(null);
            }
            finally
            {
                UpdateActivityIndicatorStatus(false);
            }
        }
        public static async Task <Reports> GetReports()
        {
            await UpdateActivityIndicatorStatus(true).ConfigureAwait(false);

            try
            {
                var client = await GetPowerBIClient().ConfigureAwait(false);

                return(client.Reports.GetReports());
            }
            catch (Exception e)
            {
                DebugHelpers.PrintException(e);
                return(new Reports());
            }
            finally
            {
                await UpdateActivityIndicatorStatus(false).ConfigureAwait(false);
            }
        }
Beispiel #7
0
        protected static Task <HttpResponseMessage> DeleteObjectFromAPI(string apiUrl)
        {
            var httpRequest = new HttpRequestMessage(HttpMethod.Delete, new Uri(apiUrl));

            try
            {
                UpdateActivityIndicatorStatus(true);

                return(Client.SendAsync(httpRequest));
            }
            catch (Exception e)
            {
                DebugHelpers.PrintException(e);
                return(null);
            }
            finally
            {
                UpdateActivityIndicatorStatus(false);
            }
        }
        public static Task <T> BeginInvokeOnMainThreadAsync <T>(Func <T> a)
        {
            lock (_locker)
            {
                var tcs = new TaskCompletionSource <T>();

                Device.BeginInvokeOnMainThread(() =>
                {
                    try
                    {
                        var result = a();
                        tcs?.SetResult(result);
                    }
                    catch (Exception ex)
                    {
                        tcs?.SetException(ex);
                        DebugHelpers.PrintException(ex);
                    }
                });
                return(tcs?.Task);
            }
        }
Beispiel #9
0
        protected static async Task <TDataObject> GetDataObjectFromAPI <TDataObject, TPayloadData>(string apiUrl, TPayloadData data = default(TPayloadData))
        {
            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(TDataObject));
                            }

                            return(await Task.Run(() => Serializer.Deserialize <TDataObject>(json)).ConfigureAwait(false));
                        }
            }
            catch (Exception e)
            {
                DebugHelpers.PrintException(e);
                return(default(TDataObject));
            }
            finally
            {
                UpdateActivityIndicatorStatus(false);
            }
        }