Exemplo n.º 1
0
        public async void CameraBtn_Tapped(object sender, EventArgs e)
        {
            try
            {
                using (var scope = new ActivityIndicatorScope(activityIndicator, activityIndicatorPanel, true))
                {
                    if (!CrossMedia.Current.IsPickPhotoSupported)
                    {
                        await DisplayAlert("Photos Not Supported", ":( Permission not granted to photos.", "OK");

                        return;
                    }

                    MediaFile file = await CrossMedia.Current.PickPhotoAsync(new PickMediaOptions
                    {
                        PhotoSize = PhotoSize.Medium
                    });

                    if (file == null)
                    {
                        return;
                    }

                    _mediaFile = file;

                    foreach (var child in cameraImageGrid.Children.Reverse())
                    {
                        cameraImageGrid.Children.Remove(child);
                    }
                    cameraImageGrid.RowDefinitions.Clear();
                    cameraImageGrid.ColumnDefinitions.Clear();
                    cameraImageGrid.RowDefinitions.Add(new RowDefinition {
                        Height = GridLength.Star
                    });
                    cameraImageGrid.ColumnDefinitions.Add(new ColumnDefinition {
                        Width = GridLength.Star
                    });
                    var claimImage = new Image
                    {
                        Aspect            = Aspect.AspectFit,
                        VerticalOptions   = LayoutOptions.FillAndExpand,
                        HorizontalOptions = LayoutOptions.FillAndExpand
                    };
                    claimImage.Source = ImageSource.FromFile(file.Path);
                    cameraImageGrid.Children.Add(claimImage, 0, 0);
                }
            }
            catch (Exception ex)
            {
                Utils.TraceException("CameraBtn_Tapped ", ex);
                await DisplayAlert("Image upload failed", "Image upload failed. Please try again later", "Ok");
            }
        }
Exemplo n.º 2
0
        private async void OnLogoutButtonClicked(object sender, EventArgs e)
        {
            using (var scope = new ActivityIndicatorScope(activityIndicator, activityIndicatorPanel, true))
            {
                HttpResponseMessage response = await HttpUtil.DeleteAsync(Settings.HubTagUrl + MobileServiceHelper.msInstance.Client.InstallationId, authenticationResult.Token);

                if (!response.IsSuccessStatusCode)
                {
                    Utils.TraceStatus("InitMobileService Post Failure " + response.StatusCode);
                }
            }
            App.PCApplication.UserTokenCache.Clear(Settings.ClientID);
            await Navigation.PopAsync();
        }
Exemplo n.º 3
0
        async void OnLoginButtonClicked(object sender, EventArgs e)
        {
            if (!Settings.CheckAllConfigure())
            {
                await DisplayAlert("Configuration", "Please go to settings page and configure, then Sigin In again.", "OK");

                return;
            }
            try
            {
                using (var scope = new ActivityIndicatorScope(activityIndicator, activityIndicatorPanel, true))
                {
                    App.PCApplication = new PublicClientApplication(Settings.Authority, Settings.ClientID);
                    App.PCApplication.PlatformParameters = App.PlatformParameters;

                    MobileServiceHelper.msInstance = new MobileServiceHelper();

                    var result = await App.PCApplication.AcquireTokenAsync(
                        new string[] { Settings.ClientID },
                        string.Empty,
                        UiOptions.SelectAccount,
                        string.Empty,
                        null,
                        Settings.Authority,
                        Settings.SignUpSignInpolicy);

                    await MobileServiceHelper.msInstance.InitMobileService(result);

                    await Navigation.PushAsync(new MainPage(result));
                }
            }
            catch (MsalException ex)
            {
                if (ex.Message != null && ex.Message.Contains("AADB2C90118"))
                {
                    //await OnForgotPassword();
                    Utils.TraceStatus("Login Failure, ForgotPassword?");
                }
                if (ex.ErrorCode != "authentication_canceled")
                {
                    await DisplayAlert("An error has occurred", "Exception message: " + ex.Message, "Dismiss");
                }
            }
        }
Exemplo n.º 4
0
        private async void OnSubmitClaimButtonClicked(object sender, EventArgs e)
        {
            try
            {
                if (_mediaFile != null)
                {
                    using (var scope = new ActivityIndicatorScope(activityIndicator, activityIndicatorPanel, true))
                    {
                        HttpResponseMessage response = await HttpUtil.PostImageAsync(_mediaFile, Settings.UploadImageUrl, _authenticationResult.Token);

                        if (response.IsSuccessStatusCode)
                        {
                            string responseURL = await response.Content.ReadAsStringAsync();

                            char[] charsToTrim = { '\"' };
                            responseURL = responseURL.Trim(charsToTrim);

                            Random     rnd       = new Random();
                            string     claimName = rnd.Next(15000, 16000).ToString();
                            ClaimModel claim     = new ClaimModel
                            {
                                Id               = Guid.NewGuid().ToString(),
                                Name             = claimName,
                                Status           = "Submitted",
                                ClaimDateTime    = this.datePicker.Date,
                                ClaimDescription = this.claimDescriptionEditor.Text,
                                ImageUrl         = responseURL,
                                Tag              = ""
                            };

                            SubmitCaseRsp ret = await CallQueue(claim);

                            if (ret != null && ret.result)
                            {
                                _parentPage.AddNewClaim(claim);
                                await DisplayAlert("Thank you", "Your claim is being processed.", "Ok");

                                await Navigation.PopAsync();
                            }
                            else
                            {
                                await DisplayAlert("Please resubmit", "Photo doesn't appear to match the claim.", "Ok");
                            }
                        }
                        else
                        {
                            // If the call failed with access denied, show the user an error indicating they might need to sign-in again.
                            if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized)
                            {
                                await DisplayAlert("Unauthorized", "Please login again, then new claim works well again", "Ok");

                                await Navigation.PopToRootAsync();
                            }
                            else
                            {
                                await DisplayAlert("Error", response.StatusCode.ToString(), "Ok");
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Utils.TraceException("Image upload failed", ex);
                await DisplayAlert("Image upload failed", "Image upload failed. Please try again later", "Ok");
            }
        }