Exemplo n.º 1
0
        async Task <bool> NetworkAvailable()
        {
            var network = DependencyService.Get <Helpers.INetworkState>().getNetworkStatus();

            if (network.Equals(NetworkStatus.NotConnected))
            {
                MessagingCenter.Send(this, "CheckConnection");
                return(false);
            }
            else if (!await DataGit.isSiteReachable("https://api.github.com/"))
            {
                MessagingCenter.Send(this, "SiteUnReachable");
                return(false);
            }
            return(true);
        }
Exemplo n.º 2
0
        async Task ExecuteLoadItemsCommandHttp(bool update)
        {
            if (IsBusy)
            {
                return;
            }
            IsBusy = true;
            if (Repos.Count == 0)
            {
                var databaseObjects = await DataSQLite.GetItemsAsync();

                if (databaseObjects != null && databaseObjects.Any())
                {
                    Repos.ReplaceRange(databaseObjects);
                }
            }
            if (!await NetworkAvailable())
            {
                IsBusy = false;
                return;
            }
            try
            {
                var repos = await DataGit.GetItemsAsync(Repos.Count > 0);

                if (repos != null && repos.Any())
                {
                    await DataSQLite.SaveListAsync(repos);

                    Repos.ReplaceRange(repos);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                MessagingCenter.Send(new MessagingCenterAlert
                {
                    Title   = "Error",
                    Message = "Unable to load items.",
                    Cancel  = "OK"
                }, "message");
            }
            finally
            {
                IsBusy = false;
            }
        }