Пример #1
0
        private async void TreeUp()
        {
            try
            {
                // Wait Sync work
                await TaskHelper.WaitTask(TaskHelper.STORAGE_EXPLORER_SYNC + Switcher.GetCurrentStorage().GetStorageName());

                // If message is visible, set collapsed.
                if (uiPinFileMessage.Visibility == Visibility.Visible && !uiPinFileMessage.Text.Equals(AppResources.Refreshing))
                {
                    uiPinFileMessage.Visibility = Visibility.Collapsed;
                }

                // Do tree up work and set items to list
                List <FileObject> fileList = StorageExplorer.TreeUp();
                this.CurrentFileObjectList = fileList;
                this.PinFileObjectViewModel.SetItems(this.CurrentFileObjectList, true);
                uiPinFileCurrentPath.Text = StorageExplorer.GetCurrentPath();

                // Clear trees.
                //this.PinFileAppBarButton.IsEnabled = false;
                this.PinSelectedFileList.Clear();
            }
            catch
            {
                return;
            }
        }
Пример #2
0
 private void uiPinFileListUpButton_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
 {
     if (StorageExplorer.GetCurrentTree() != null)
     {
         this.TreeUp();
     }
 }
Пример #3
0
 // 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;
 }
Пример #4
0
 // 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;
 }
        // 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;
        }
        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);
        }
Пример #7
0
        private async void SetPinFileListAsync(IStorageManager iStorageManager, string message, FileObjectViewItem folder)
        {
            // Set Mutex true and Show Process Indicator
            // Clear selected file and set pin button false.
            base.SetProgressRing(uiFileListProgressRing, true);
            await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                uiPinFileListGridView.Visibility = Visibility.Collapsed;
                uiPinFileMessage.Text            = message;
                uiPinFileMessage.Visibility      = Visibility.Visible;
            });

            this.PinSelectedFileList.Clear();

            try
            {
                // Wait Signin and Sync task
                await TaskHelper.WaitSignInTask(iStorageManager.GetStorageName());

                await TaskHelper.WaitTask(TaskHelper.STORAGE_EXPLORER_SYNC + Switcher.GetCurrentStorage().GetStorageName());

                // Get files from current folder in the cloud.
                // If it is not null, set items.
                // Otherwise, show message
                if (folder == null)
                {
                    this.CurrentFileObjectList = StorageExplorer.GetFilesFromRootFolder();
                }
                else
                {
                    this.CurrentFileObjectList = StorageExplorer.GetTreeForFolder(this.GetCloudStorageFileObjectById(folder.Id));
                }
                if (this.CurrentFileObjectList != null)
                {
                    // If didn't change cloud mode while loading, set it to list.
                    // Set file list visible and current path.
                    await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        this.PinFileObjectViewModel.IsDataLoaded = true;
                        uiPinFileListGridView.Visibility         = Visibility.Visible;
                        uiPinFileCurrentPath.Text = StorageExplorer.GetCurrentPath();
                        this.PinFileObjectViewModel.SetItems(this.CurrentFileObjectList, true);
                    });


                    // If there exists file, show it.
                    // Otherwise, show no file message.
                    if (this.CurrentFileObjectList.Count > 0)
                    {
                        await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                        {
                            uiPinFileMessage.Visibility = Visibility.Collapsed;
                        });
                    }
                    else
                    {
                        await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                        {
                            uiPinFileMessage.Text = AppResources.NoFileInFolderMessage;
                        });
                    }
                }
                else
                {
                    await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        uiPinFileListGridView.Visibility = Visibility.Collapsed;
                        uiPinFileMessage.Text            = AppResources.BadLoadingFileMessage;
                        uiPinFileMessage.Visibility      = Visibility.Visible;
                    });
                }
            }
            catch
            {
                uiPinFileListGridView.Visibility = Visibility.Collapsed;
                uiPinFileMessage.Text            = AppResources.BadLoadingFileMessage;
                uiPinFileMessage.Visibility      = Visibility.Visible;
            }
            base.SetProgressRing(uiFileListProgressRing, false);
        }
        private void uiRefreshButton_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            switch (uiExplorerList.SelectedIndex)
            {
            case EventHelper.PICK_PIVOT:
                this.PickFileObjectViewModel.IsDataLoaded = false;
                this.SetPickPivot(AppResources.Refreshing);
                break;


            case EventHelper.PIN_PIVOT:
                this.PinFileObjectViewModel.IsDataLoaded = false;
                TaskHelper.AddTask(TaskHelper.STORAGE_EXPLORER_SYNC + Switcher.GetCurrentStorage().GetStorageName(), StorageExplorer.Refresh());
                this.SetPinPivot(AppResources.Refreshing);
                break;
            }
        }
Пример #9
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);
        }