private async void GetFoldersAndFilesButton_Click(object sender, RoutedEventArgs e)
        {
            if (!await Tools.CheckInternetConnectionAsync())
            {
                return;
            }

            string txtTop = TopText.Text;
            int    top    = 0;

            if (string.IsNullOrEmpty(txtTop))
            {
                top = 20;
            }
            else
            {
                top = Convert.ToInt32(txtTop);
            }

            SampleController.Current.DisplayWaitRing = true;
            try
            {
                OneDriveItemsList.ItemsSource = await _graphCurrentFolder.GetItemsAsync(top);
            }
            catch (ServiceException ex)
            {
                await OneDriveSampleHelpers.DisplayOneDriveServiceExceptionAsync(ex);
            }
            finally
            {
                SampleController.Current.DisplayWaitRing = false;
                menuButton.Visibility = Visibility.Visible;
                BackButton.Visibility = Visibility.Visible;
            }
        }
        private async Task NavigateBackGraphAsync()
        {
            if (_graphCurrentFolder != null)
            {
                OneDriveStorageFolder currentFolder = null;
                SampleController.Current.DisplayWaitRing = true;
                try
                {
                    if (!string.IsNullOrEmpty(_graphCurrentFolder.Path))
                    {
                        currentFolder = await _graphRootFolder.GetFolderAsync(_graphCurrentFolder.Path);
                    }
                    else
                    {
                        currentFolder = _graphRootFolder;
                    }

                    OneDriveItemsList.ItemsSource = await currentFolder.GetItemsAsync(20);

                    _graphCurrentFolder = currentFolder;
                }
                catch (ServiceException ex)
                {
                    await OneDriveSampleHelpers.DisplayOneDriveServiceExceptionAsync(ex);
                }
                finally
                {
                    SampleController.Current.DisplayWaitRing = false;
                }
            }
        }
        private async Task SigninAsync(int indexProvider, string appClientId)
        {
            if (!await Tools.CheckInternetConnectionAsync())
            {
                return;
            }

            Shell.Current.DisplayWaitRing = true;
            bool succeeded = false;

            try
            {
                // OnlineId
                if (indexProvider == 0)
                {
                    Services.OneDrive.OneDriveService.Instance.Initialize();
                }
                else if (indexProvider == 1)
                {
                    Services.OneDrive.OneDriveService.Instance.Initialize(appClientId, AccountProviderType.Msa, OneDriveScopes.OfflineAccess | OneDriveScopes.ReadWrite);
                }
                else if (indexProvider == 2)
                {
                    Services.OneDrive.OneDriveService.Instance.Initialize(appClientId, AccountProviderType.Adal);
                }
                else if (indexProvider == 3)
                {
                    Services.OneDrive.OneDriveService.GraphInstance.Initialize(appClientId, DelegatedPermissionScopes.Text.Split(' '));
                }

                if (indexProvider == 3)
                {
                    if (!await Services.OneDrive.OneDriveService.GraphInstance.LoginAsync())
                    {
                        throw new Exception("Unable to sign in");
                    }

                    _graphCurrentFolder = _graphRootFolder = await Services.OneDrive.OneDriveService.GraphInstance.RootFolderForMeAsync();

                    OneDriveItemsList.ItemsSource = await _graphRootFolder.GetItemsAsync(20);
                }
                else
                {
                    if (!await Services.OneDrive.OneDriveService.Instance.LoginAsync())
                    {
                        throw new Exception("Unable to sign in");
                    }

                    _currentFolder = _rootFolder = await Services.OneDrive.OneDriveService.Instance.RootFolderAsync();

                    OneDriveItemsList.ItemsSource = _rootFolder.GetItemsAsync();
                }

                succeeded = true;
            }
            catch (ServiceException serviceEx)
            {
                await OneDriveSampleHelpers.DisplayOneDriveServiceExceptionAsync(serviceEx);
            }
            catch (Exception ex)
            {
                await OneDriveSampleHelpers.DisplayMessageAsync(ex.Message);

                TrackingManager.TrackException(ex);
            }
            finally
            {
                Shell.Current.DisplayWaitRing = false;
            }

            if (succeeded)
            {
                FilesBox.Visibility       = Visibility.Visible;
                UserBox.Visibility        = Visibility.Visible;
                ClientIdBox.Visibility    = Visibility.Collapsed;
                ClientIdHelper.Visibility = Visibility.Collapsed;
                LogOutButton.Visibility   = Visibility.Visible;
                ConnectButton.Visibility  = Visibility.Collapsed;
                menuButton.Visibility     = Visibility.Visible;
                BackButton.Visibility     = Visibility.Visible;
            }
            else
            {
                FilesBox.Visibility       = Visibility.Collapsed;
                UserBox.Visibility        = Visibility.Collapsed;
                ClientIdBox.Visibility    = Visibility.Visible;
                ClientIdHelper.Visibility = Visibility.Visible;
                LogOutButton.Visibility   = Visibility.Collapsed;
                ConnectButton.Visibility  = Visibility.Visible;
                menuButton.Visibility     = Visibility.Collapsed;
                BackButton.Visibility     = Visibility.Collapsed;
            }
        }
        private async Task SigninAsync(string appClientId)
        {
            if (!await Tools.CheckInternetConnectionAsync())
            {
                return;
            }

            SampleController.Current.DisplayWaitRing = true;
            bool succeeded = false;

            try
            {
                // Converged app authentication
                // Get the selected Delegated Permissions
                var scopes = DelegatedPermissions.SelectedItems as string[];

                // If the user hasn't selected a scope then set it to FilesReadAll
                if (scopes == null)
                {
                    scopes = new string[] { MicrosoftGraphScope.FilesReadAll };
                }

                OneDriveService.Instance.Initialize(appClientId, scopes, null, null);

                if (!await OneDriveService.Instance.LoginAsync())
                {
                    throw new Exception("Unable to sign in");
                }

                _graphCurrentFolder = _graphRootFolder = await OneDriveService.Instance.RootFolderForMeAsync();

                OneDriveItemsList.ItemsSource = await _graphRootFolder.GetItemsAsync(20);

                OneDriveItemsList.Visibility = Visibility.Visible;

                succeeded = true;
            }
            catch (ServiceException serviceEx)
            {
                await OneDriveSampleHelpers.DisplayOneDriveServiceExceptionAsync(serviceEx);
            }
            catch (Exception ex)
            {
                await OneDriveSampleHelpers.DisplayMessageAsync(ex.Message);

                TrackingManager.TrackException(ex);
            }
            finally
            {
                SampleController.Current.DisplayWaitRing = false;
            }

            if (succeeded)
            {
                FilesBox.Visibility       = Visibility.Visible;
                UserBox.Visibility        = Visibility.Visible;
                ClientIdBox.Visibility    = Visibility.Collapsed;
                ClientIdHelper.Visibility = Visibility.Collapsed;
                LogOutButton.Visibility   = Visibility.Visible;
                ConnectButton.Visibility  = Visibility.Collapsed;
                menuButton.Visibility     = Visibility.Visible;
                BackButton.Visibility     = Visibility.Visible;
            }
            else
            {
                FilesBox.Visibility       = Visibility.Collapsed;
                UserBox.Visibility        = Visibility.Collapsed;
                ClientIdBox.Visibility    = Visibility.Visible;
                ClientIdHelper.Visibility = Visibility.Visible;
                LogOutButton.Visibility   = Visibility.Collapsed;
                ConnectButton.Visibility  = Visibility.Visible;
                menuButton.Visibility     = Visibility.Collapsed;
                BackButton.Visibility     = Visibility.Collapsed;
            }
        }