Пример #1
0
        private async void Init()
        {
            // Check if the survey has already been downloaded
            var fileHelper = new FileHelper();

            if (await fileHelper.ExistsAsync(SurveyFileName))
            {
                // Load the survey if it exists
                App.LatestSurvey = await fileHelper.LoadAsync <SurveyModel>(SurveyFileName);
            }

            try
            {
                // Check if an updated survey is available from the service
                var azureSurvey = await SurveyCloudService.GetSurveyAsync(1); // TODO: Replace with actual SurveyID, from GetAvailableSurveysAsync()

                if (azureSurvey != null && (App.LatestSurvey == null || App.LatestSurvey.Version < azureSurvey.Version))
                {
                    App.LatestSurvey = azureSurvey;
                    // Save the survey to the local filesystem
                    await fileHelper.SaveAsync(SurveyFileName, azureSurvey);
                }
            }
            catch (Exception ex)
            {
                DependencyService.Get <IMetricsManagerService>().TrackException("GetSurveyFailed", ex);
            }

            IsBusy = false;
            UpdateSurveyInfo();
        }
Пример #2
0
        /// <summary>
        /// Uploads the survey asynchronously.
        /// </summary>
        /// <param name="response">The survey response.</param>
        /// <returns>A task to await the completion of the upload.</returns>
        public static async Task UploadAsync(this UploadedItem <SurveyResponseModel> response)
        {
            try
            {
                DependencyService.Get <IMetricsManagerService>().TrackEvent("UploadSurveyResponse");
                await SurveyCloudService.SubmitSurveyResponseAsync(response.Item);

                response.Uploaded = DateTime.Now;
                await response.SaveAsync();
            }
            catch (Exception ex)
            {
                DependencyService.Get <IMetricsManagerService>().TrackException("UploadSurveyResponseFailed", ex);
                throw;
            }
        }
Пример #3
0
        private async void UpdateContactInfo()
        {
            try
            {
                var model = await SurveyCloudService.GetContactInfoAsync(1);

                Note        = model.Notes;
                ContactInfo = string.Join("\n", model.Contacts.Select(c => $"{c.Name}: {c.Phone}").ToArray());
            }
            catch (Exception ex)
            {
                DependencyService.Get <IMetricsManagerService>().TrackException("GetContactInfoFailed", ex);
                Note        = "Error";
                ContactInfo = null;
            }

            IsBusy = false;
        }
Пример #4
0
        private async void SaveProfile()
        {
            // Check if any of the required fields are empty or invalid
            if (string.IsNullOrWhiteSpace(FirstName) ||
                string.IsNullOrWhiteSpace(LastName) ||
                string.IsNullOrWhiteSpace(Email) ||
                string.IsNullOrWhiteSpace(MobilePhone) ||
                (string.IsNullOrEmpty(Email) || !_validationHelper.IsValidEmail(Email)) ||
                (string.IsNullOrEmpty(MobilePhone) || !_validationHelper.IsValidPhone(MobilePhone)))
            {
                var @continue = await App.DisplayAlertAsync("Profile Incomplete", "The profile information is not complete - do you want to save anyway, or go back to correct it?", "Continue", "Cancel");

                if (!@continue)
                {
                    return;
                }
            }

            try
            {
                SaveButtonText = "Saving...";
                IsBusy         = true;
                SaveProfileCommand.ChangeCanExecute();
                DependencyService.Get <IMetricsManagerService>().TrackEvent("SaveVolunteer");
                await SurveyCloudService.SaveVolunteerAsync(UserSettings.Volunteer);

                SaveButtonText = "Saved!";
                UpdateCurrentInfo();
                IsBusy = false;
                SaveProfileCommand.ChangeCanExecute();
                await Task.Delay(SaveButtonMessageDelay);
            }
            catch (Exception ex)
            {
                DependencyService.Get <IMetricsManagerService>().TrackException("SaveVolunteerFailed", ex);
                await App.DisplayAlertAsync("Profile Save Error", "Failed to update profile information. Please try again later.", "OK");
            }
            finally
            {
                IsBusy = false;
                SaveProfileCommand.ChangeCanExecute();
                SaveButtonText = DefaultSaveButtonText;
            }
        }
Пример #5
0
        public static async Task RefreshLoginAsync()
        {
            if (!string.IsNullOrEmpty(UserSettings.AuthToken))
            {
                try
                {
                    DependencyService.Get <IMetricsManagerService>().TrackEvent("UserRefresh");
                    Authenticator.User = new MobileServiceUser(UserSettings.UserId)
                    {
                        MobileServiceAuthenticationToken = UserSettings.AuthToken,
                    };

                    var user = await Authenticator.RefreshLoginAsync();

                    Authenticator.User     = user;
                    UserSettings.Volunteer = await SurveyCloudService.GetVolunteerAsync();

                    UserSettings.AuthToken = user?.MobileServiceAuthenticationToken;
                    UserSettings.UserId    = user?.UserId;
                }
                catch (Exception ex)
                {
                    DependencyService.Get <IMetricsManagerService>().TrackException("UserRefreshFailed", ex);
                    Authenticator.User       = null;
                    UserSettings.Volunteer   = new VolunteerModel();
                    UserSettings.VolunteerId = null;
                    UserSettings.AuthToken   = null;
                    UserSettings.UserId      = null;
                }
            }
            else
            {
                try
                {
                    DependencyService.Get <IMetricsManagerService>().TrackEvent("GetAnonymousVolunteer");
                    UserSettings.Volunteer = await SurveyCloudService.GetVolunteerAsync();
                }
                catch (Exception ex)
                {
                    DependencyService.Get <IMetricsManagerService>().TrackException("GetAnonymousVolunteerFailed", ex);
                }
            }
        }
Пример #6
0
        public static async Task LoginAsync(MobileServiceAuthenticationProvider provider)
        {
            try
            {
                DependencyService.Get <IMetricsManagerService>().TrackEvent("UserLogin");
                var properties = provider == MobileServiceAuthenticationProvider.Google
                    ? new Dictionary <string, string>
                {
                    { "access_type", "offline" },
                }
                    : new Dictionary <string, string>(0);

                var user = await Authenticator.LoginAsync(provider, properties);

                UserSettings.Volunteer = await SurveyCloudService.GetVolunteerAsync();

                UserSettings.AuthToken = user?.MobileServiceAuthenticationToken;
                UserSettings.UserId    = user?.UserId;
            }
            catch (Exception ex)
            {
                DependencyService.Get <IMetricsManagerService>().TrackException("UserLoginFailed", ex);
            }
        }