private async void UploadFile() { // if user is not logged in if (GAuthenticator.Service == null) { return; } IsActionRunning = true; var dialog = new OpenFileDialog(); DialogResult result = dialog.ShowDialog(); if (result == DialogResult.OK) { if ((DateTime.UtcNow - GAuthenticator.WhenTokenReceived).Minutes >= 5) { await GAuthenticator.RefreshToken(); } await UploadFileASync(dialog.FileName); Files = UIItemsCreator.NewFileItemsList(); } else { CurrentState = ResourceStrings.DefaultErrorState; } IsActionRunning = false; }
private async void OnStartup() { IsActionRunning = true; CurrentState = ResourceStrings.LoginState; await Task.Run(() => GAuthenticator.Authenticate("Drive downloader")); CurrentState = ResourceStrings.UpdateFilesState; var filesResult = await Task.Run(() => UIItemsCreator.NewFileItemsList()); Files = (filesResult == null) ? null : filesResult; CurrentState = ResourceStrings.DefaultActionState; IsActionRunning = false; }
private async void DeleteFile() { if (Files == null) { return; } IsActionRunning = true; //refresh token if it's expired if ((DateTime.UtcNow - GAuthenticator.WhenTokenReceived).Minutes >= 5) { await GAuthenticator.RefreshToken(); } foreach (var file in Files) { if (file.IsSelected) { try { GAuthenticator.Service.Files.Delete(file.Id).Execute(); } catch { CurrentState = ResourceStrings.DefaultErrorState; } } } Files = UIItemsCreator.NewFileItemsList(); IsActionRunning = false; }