private async void connectToDropboxToolStripMenuItem_Click(object sender, EventArgs e) { // create new Dropbox Client Client = new DropboxClient(appId, appSecret); // open authorization webpage Process.Start(Client.GetAuthorizeUrl(ResponseType.Code)); // show input dialog string code = new ConnectWindow().ShowDialog(); EnableUI(false); AuthorizeResponse response = null; // authorize entered code try { response = await Client.AuthorizeCode(code); } catch(InvalidGrantException ex) { MessageBox.Show("Invalid code. Please try again.", "Invalid code", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // save token Properties.Settings.Default.AccessToken = response.AccessToken; Properties.Settings.Default.Save(); // get current account FullAccount currentAccount = await Client.Users.GetCurrentAccount(); // display account name and id connectionStatusLabel.Text = string.Format("Connected as {0} ({1})", currentAccount.Name.DisplayName, currentAccount.AccountId); // refresh tree view await RefreshTreeView(); EnableUI(true); }
private async void connectToDropboxToolStripMenuItem_Click(object sender, EventArgs e) { // create new Dropbox Client Client = new DropboxClient(appId, appSecret); // open authorization webpage Process.Start(Client.GetAuthorizeUrl(ResponseType.Code)); // show input dialog string code = new ConnectWindow().ShowDialog(); EnableUI(false); AuthorizeResponse response = null; // authorize entered code try { response = await Client.AuthorizeCode(code); } catch (InvalidGrantException ex) { MessageBox.Show("Invalid code. Please try again.", "Invalid code", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // save token Properties.Settings.Default.AccessToken = response.AccessToken; Properties.Settings.Default.Save(); // get current account FullAccount currentAccount = await Client.Users.GetCurrentAccount(); // display account name and id connectionStatusLabel.Text = string.Format("Connected as {0} ({1})", currentAccount.Name.DisplayName, currentAccount.AccountId); // refresh tree view await RefreshTreeView(); EnableUI(true); }