Beispiel #1
0
        public CustomerListPage()
        {
            InitializeComponent();

            BindingContext = VM = new CustomerListViewModel();

            // handle auth login/logout

            var tbLoginOut = ToolbarHelper.GenerateToolbarButton("Auth", new Command(async() =>
            {
                if (Settings.AzureADUserInfo != null)
                {
                    // logout
                    new AuthenticationContext(Settings.AzureADAuthority).TokenCache.Clear();

                    DependencyService.Get <IAuthenticator>().ClearCookies();

                    VM.CustomerList.Clear();
                    Settings.AzureADUserInfo = null;

                    await ToastHelper.Success("Logged Out!");
                }
                else
                {
                    // login
                    try
                    {
                        await D365AuthHelper.GetAuthorizationHeader();
                    }
                    catch (Exception ex)
                    {
                        await DisplayAlert("Authentication Error", ex.Message, "Ok");
                        return;
                    }

                    await VM.ExecuteLoadCustomersCommand();

                    await ToastHelper.Success("Customers Loaded!");
                }
            }));

            ToolbarItems.Add(tbLoginOut);
        }
        public SettingsPage()
        {
            InitializeComponent();

            Title = "Settings";

            D365URL.Text          = Settings.D365URL;
            AzureADClientId.Text  = Settings.AzureADClientId;
            AzureADAuthority.Text = Settings.AzureADAuthority;
            AzureADReturnURL.Text = Settings.AzureADReturnURL;

            var tbSave = ToolbarHelper.GenerateToolbarButton("Save", new Command(async() =>
            {
                var isValidUrl = AppUtils.IsValidUrl(D365URL.Text);
                if (!isValidUrl)
                {
                    await DisplayAlert("Error", "Invalid D365 Url.", "Ok");
                    return;
                }

                isValidUrl = AppUtils.IsValidUrl(AzureADAuthority.Text);
                if (!isValidUrl)
                {
                    await DisplayAlert("Error", "Invalid Azure AD Authority Url.", "Ok");
                    return;
                }

                // update settings
                Settings.D365URL          = D365URL.Text;
                Settings.AzureADClientId  = AzureADClientId.Text;
                Settings.AzureADAuthority = AzureADAuthority.Text;
                Settings.AzureADReturnURL = AzureADReturnURL.Text;

                await Navigation.PopModalAsync();
            }));

            ToolbarItems.Add(tbSave);
        }