Пример #1
0
        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);
            }

            Shell.Current.DisplayWaitRing = true;
            try
            {
                OneDriveItemsList.ItemsSource = await _currentFolder.GetItemsAsync(top);
            }
            catch (ServiceException ex)
            {
                await OneDriveSampleHelpers.DisplayOneDriveServiceExceptionAsync(ex);
            }
            finally
            {
                Shell.Current.DisplayWaitRing = false;
                menuButton.Visibility         = Visibility.Visible;
                BackButton.Visibility         = Visibility.Visible;
            }
        }
Пример #2
0
        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)
                {
                    OneDriveService.Instance.Initialize();
                }
                else if (indexProvider == 1)
                {
                    OneDriveService.Instance.Initialize(appClientId, AccountProviderType.Msa, OneDriveScopes.OfflineAccess | OneDriveScopes.ReadWrite);
                }
                else if (indexProvider == 2)
                {
                    OneDriveService.Instance.Initialize(appClientId, AccountProviderType.Adal);
                }
                else if (indexProvider == 3)
                {
                    OneDriveService.Instance.Initialize(appClientId, AccountProviderType.Msal);
                }

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

                _currentFolder = _rootFolder = await 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;
            }
        }