コード例 #1
0
        public async Task <FileObject> GetRootFolderAsync()
        {
            FileObject    rootFile      = new FileObject();
            AboutResource aboutResource = this.Service.About;
            About         about         = await aboutResource.Get().ExecuteAsync();

            rootFile.Id       = about.RootFolderId;
            this.RootFodlerId = about.RootFolderId;
            rootFile.Name     = "";
            return(rootFile);
        }
コード例 #2
0
        public async Task <bool> SignIn()
        {
            this.tcs = new TaskCompletionSource <bool>();
            // Add application settings before work for good UX
            try
            {
                //Uri clientSecretsUri = new Uri("/Utilities/google_secret.json",UriKind.Relative);
                //new ClientSecrets
                //    {
                //        ClientId = GOOGLE_DRIVE_CLIENT_ID,
                //        ClientSecret = GOOGLE_DRIVE_CLIENT_SECRET
                //    }
                this.Credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
                    new Uri("ms-appx:///Assets/client_secret.json"),
                    new[] { DriveService.Scope.Drive },
                    this._GetUserSession(),
                    CancellationToken.None
                    );

                this.Service = new DriveService(new BaseClientService.Initializer()
                {
                    HttpClientInitializer = this.Credential,
                    ApplicationName       = "athere",
                });
                AboutResource aboutResource = this.Service.About;
                About         about         = await aboutResource.Get().ExecuteAsync();

                this.User = about.User;

                string name = this.User.DisplayName;
                string id   = about.PermissionId;

                // Register account
                StorageAccount account = await App.AccountManager.GetStorageAccountAsync(id);

                if (account == null)
                {
                    account = new StorageAccount(id, StorageAccount.StorageAccountType.GOOGLE_DRIVE, name, 0.0);
                    await App.AccountManager.CreateStorageAccountAsync(account);
                }
                this.CurrentAccount = account;

                // Save sign in setting.
                App.ApplicationSettings[GOOGLE_DRIVE_SIGN_IN_KEY] = true;
                App.ApplicationSettings.Save();
                TaskHelper.AddTask(TaskHelper.STORAGE_EXPLORER_SYNC + this.GetStorageName(), StorageExplorer.Synchronize(this.GetStorageName()));
                tcs.SetResult(true);
            }
            catch (Google.GoogleApiException e)
            {
                Debug.WriteLine(e.ToString());
                System.Diagnostics.Debugger.Break();
                tcs.SetResult(false);
            }
            catch (System.Threading.Tasks.TaskCanceledException)
            {
                tcs.SetResult(false);
                System.Diagnostics.Debugger.Break();
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
                tcs.SetResult(false);
                System.Diagnostics.Debugger.Break();
            }

            return(tcs.Task.Result);
        }