public async Task<bool> SignIn()
        {
            this.tcs = new TaskCompletionSource<bool>();
            try
            {
                // If it haven't registerd live client, register
                LiveConnectClient liveClient = await this.GetLiveConnectClientAsync();
                this.LiveClient = liveClient;

                // Get id and name.
                LiveOperationResult operationResult = await this.LiveClient.GetAsync("me");
                string accountId = (string)operationResult.Result["id"];
                string accountUserName = (string)operationResult.Result["name"];

                // Register account
                await TaskHelper.WaitTask(App.AccountManager.GetPtcId());
                StorageAccount storageAccount = await App.AccountManager.GetStorageAccountAsync(accountId);
                if (storageAccount == null)
                {
                    storageAccount = new StorageAccount();
                    storageAccount.Id = accountId;
                    storageAccount.StorageName = this.GetStorageName();
                    storageAccount.UserName = accountUserName;
                    storageAccount.UsedSize = 0.0;
                    await App.AccountManager.CreateStorageAccountAsync(storageAccount);
                }
                this.CurrentAccount = storageAccount;

                // Save sign in setting.
                App.ApplicationSettings[ONE_DRIVE_SIGN_IN_KEY] = true;
                App.ApplicationSettings.Save();
                TaskHelper.AddTask(TaskHelper.STORAGE_EXPLORER_SYNC + this.GetStorageName(), StorageExplorer.Synchronize(this.GetStorageName()));
                tcs.SetResult(true);
            }
            catch
            {
                tcs.SetResult(false);
            }

            return tcs.Task.Result;
        }
 public async Task<bool> CreateStorageAccountAsync(StorageAccount sa)
 {
     MSStorageAccount mssa = StorageAccount.ConvertToMSStorageAccount(sa);
     mssa.ptc_account_id = this.GetPtcId();
     await App.MobileService.GetTable<MSStorageAccount>().InsertAsync(mssa);
     return true;
 }
 // Remove user and record
 public void SignOut()
 {
     LiveAuthClient liveAuthClient = new LiveAuthClient(LIVE_CLIENT_ID);
     liveAuthClient.Logout();
     App.ApplicationSettings.Remove(ONE_DRIVE_SIGN_IN_KEY);
     StorageExplorer.RemoveKey(this.GetStorageName());
     this.LiveClient = null;
     this.CurrentAccount = null;
 }
 // Remove user and record
 public void SignOut()
 {
     App.ApplicationSettings.Remove(GOOGLE_DRIVE_USER_KEY);
     App.ApplicationSettings.Remove(GOOGLE_DRIVE_SIGN_IN_KEY);
     StorageExplorer.RemoveKey(this.GetStorageName());
     this.CurrentAccount = null;
 }
        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;
        }
 public static StorageAccount ConvertToStorageAccount(MSStorageAccount mssa)
 {
     StorageAccount sa = new StorageAccount();
     sa.Id = mssa.account_platform_id;
     sa.StorageName = mssa.account_platform_id_type;
     sa.UserName = mssa.account_name;
     sa.UsedSize = mssa.account_used_size;
     return sa;
 }
 public static MSStorageAccount ConvertToMSStorageAccount(StorageAccount sa)
 {
     MSStorageAccount mssa = new MSStorageAccount(sa.Id, sa.StorageName, sa.UserName, sa.UsedSize);
     return mssa;
 }
 public StorageAccount(string id, StorageAccount.StorageAccountType type, string userName, double usedSize)
 {
     this.Id = id;
     this.StorageName = type.ToString();
     this.UserName = userName;
     this.UsedSize = usedSize;
 }
 // Remove user and record
 public void SignOut()
 {
     App.ApplicationSettings.Remove(DROPBOX_USER_KEY);
     App.ApplicationSettings.Remove(DROPBOX_SIGN_IN_KEY);
     StorageExplorer.RemoveKey(this.GetStorageName());
     //this._client = null;
     this.CurrentAccount = null;
 }
Esempio n. 10
0
        public static MSStorageAccount ConvertToMSStorageAccount(StorageAccount sa)
        {
            MSStorageAccount mssa = new MSStorageAccount(sa.Id, sa.StorageName, sa.UserName, sa.UsedSize);

            return(mssa);
        }