示例#1
0
        /// <summary>
        /// Attempts to get page from server, if there are 10 failures then the user is alerted
        /// </summary>
        /// <param name="pagename">name of page to retrieve</param>
        private async Task AttemptGetPage(string pagename)
        {
            //subscribe to connection issues
            var errorCount = 0;

            MessagingCenter.Subscribe <ServerAccess>(this, "httprequestexception", sender =>
            {
                //display error after 10 attempts
                if (errorCount < 10)
                {
                    errorCount++;
                }
                else if (errorCount == 10)
                {
                    errorCount++;
                    //alert user that there was a connection issue
                    DisplayAlert("Warning", "No connection to the server could be established, make sure you are connected to the internet", "ok");
                }
            });

            //gets home page from database
            await _viewModel.GetPageAsync(pagename);

            //unsubscribe to connection issues
            MessagingCenter.Unsubscribe <PageViewModel>(this, "httprequestexception");
        }