Exemple #1
0
        async Task <bool> ExecuteLoadMiniHacksAsync(bool force = false)
        {
            if (IsBusy)
            {
                return(false);
            }

            try
            {
                IsBusy       = true;
                NoHacksFound = false;

                #if DEBUG
                await Task.Delay(1000);
                #endif

                var hacks = await StoreManager.MiniHacksStore.GetItemsAsync(force);

                var finalHacks = hacks.ToList();
                foreach (var hack in finalHacks)
                {
                    try
                    {
                        if (Device.OS != TargetPlatform.WinPhone && Device.OS != TargetPlatform.Windows && FeatureFlags.AppLinksEnabled)
                        {
                            Application.Current.AppLinks.RegisterLink(hack.GetAppLink());
                        }
                    }
                    catch (Exception applinkException)
                    {
                        // don't crash the app
                        Logger.Report(applinkException, "AppLinks.RegisterLink", hack.Id);
                    }

                    hack.IsCompleted = Settings.Current.IsHackFinished(hack.Id);
                }

                MiniHacks.ReplaceRange(finalHacks);

                NoHacksFound = MiniHacks.Count == 0;
            }
            catch (Exception ex)
            {
                Logger.Report(ex, "Method", "ExecuteLoadMiniHacksAsync");
                MessagingService.Current.SendMessage(MessageKeys.Error, ex);
            }
            finally
            {
                IsBusy = false;
            }

            return(true);
        }
        async Task <bool> ExecuteLoadMiniHacksAsync(bool force = false)
        {
            if (IsBusy)
            {
                return(false);
            }

            try
            {
                IsBusy       = true;
                NoHacksFound = false;


                var json = Settings.JsonFile;

                if (force || string.IsNullOrWhiteSpace(json))
                {
                    using (var client = new HttpClient())
                    {
                        json = await client.GetStringAsync("https://techdays-2016.azurewebsites.net/tables/minihack?ZUMO-API-VERSION=2.0.0").ConfigureAwait(false);
                    }
                }

                var finalHacks = JsonConvert.DeserializeObject <List <MiniHack> >(json);

                Device.BeginInvokeOnMainThread(() =>
                {
                    MiniHacks.ReplaceRange(finalHacks);

                    NoHacksFound = MiniHacks.Count == 0;
                });
            }
            catch (Exception ex)
            {
                var inner = ex;
                while (inner != null)
                {
                    System.Diagnostics.Debug.WriteLine(inner.ToString());
                    inner = inner.InnerException;
                }
                await page.DisplayAlert("Error", "Unable to load hacks, please check internet. Error: " + ex.Message, "OK");
            }
            finally
            {
                Device.BeginInvokeOnMainThread(() => IsBusy = false);
            }

            return(true);
        }
Exemple #3
0
        async Task <bool> ExecuteLoadMiniHacksAsync(bool force = false)
        {
            if (IsBusy)
            {
                return(false);
            }

            try
            {
                IsBusy       = true;
                NoHacksFound = false;

                #if DEBUG
                await Task.Delay(1000);
                #endif

                var hacks = await StoreManager.MiniHacksStore.GetItemsAsync(force);

                var finalHacks = hacks.ToList();
                foreach (var hack in finalHacks)
                {
                    hack.IsCompleted = Settings.Current.IsHackFinished(hack.Id);
                }


                MiniHacks.ReplaceRange(finalHacks);

                NoHacksFound = MiniHacks.Count == 0;
            }
            catch (Exception ex)
            {
                Logger.Report(ex, "Method", "ExecuteLoadMiniHacksAsync");
                MessagingService.Current.SendMessage(MessageKeys.Error, ex);
            }
            finally
            {
                IsBusy = false;
            }

            return(true);
        }