/// <summary> /// Get a working provider (so, an access token) from Dropbox. /// </summary> /// <param name="savedState"></param> /// <param name="silent"></param> public async Task <string> Register(string savedState = null, bool silent = false) { var result = new TaskCompletionSource <string>(); // Check if the saved token is still usable if (await ClientFactory(savedState)) { result.SetResult(savedState); return(await result.Task); } // If the saved token was not usable and silent is true, return with failure if (silent) { result.SetResult(null); return(await result.Task); } // If it is not, try to get a new one var url = DropboxOAuth2Helper.GetAuthorizeUri( OAuthResponseType.Code, Obscure.CaesarDecode(Config.AppKey), (string)null); var form = new CodeForm(url.ToString(), 43); var success = false; form.OnResult += async code => { success = true; form.Close(); var response = await DropboxOAuth2Helper.ProcessCodeFlowAsync( code, Obscure.CaesarDecode(Config.AppKey), Obscure.CaesarDecode(Config.AppSecret)); if (response?.AccessToken != null && await ClientFactory(response.AccessToken)) { result.SetResult(response.AccessToken); } else { result.SetResult(null); } }; form.FormClosed += (sender, args) => { if (!success) { result.SetResult(null); } }; Process.Start(url.ToString()); form.Show(); return(await result.Task); }
/// <summary> /// Get an access token from OneDrive - or try to use an existing one. /// </summary> /// <param name="savedState">Previous serialized TokenResponse from OneDrive.</param> /// <param name="showForm"></param> /// <returns></returns> public async Task <string> Register(string savedState = null, bool showForm = true) { var result = new TaskCompletionSource <string>(); var provider = new AuthProvider(); // Check if there is a saved token and try to use it if (!string.IsNullOrEmpty(savedState)) { provider.Session = JsonConvert.DeserializeObject <TokenResponse>(Obscure.Base64Decode(savedState)); if (await ClientFactory(provider)) { result.SetResult(savedState); return(await result.Task); } } // If the saved token was not usable and showForm is false, return with failure if (!showForm) { result.SetResult(null); return(await result.Task); } // Create a CodeForm and open OneDrive token request link to obtain a new token var form = new CodeForm(provider.Url, 37); var success = false; form.OnResult += async code => { success = true; form.Close(); provider.ProcessCode(code); if (await ClientFactory(provider)) { result.SetResult(Obscure.Base64Encode(JsonConvert.SerializeObject(provider.Session))); } else { result.SetResult(null); } }; form.FormClosed += (sender, e) => { if (!success) { result.SetResult(null); } }; System.Diagnostics.Process.Start(provider.Url); form.Show(); return(await result.Task); }
/// <summary> /// 查看文档窗体按钮点击事件 /// </summary> private void CodeButton_Click(object sender, RoutedEventArgs e) { //显示了查看文档窗体,或是点击了设置项就不执行后面操作。 if (IsDocFormShow || CheckedItemName == "Setting0") { return; } CodeForm codeForm = new CodeForm(); DoubleAnimation animation = new DoubleAnimation(0, 1, new Duration(TimeSpan.FromSeconds(0.4)));//设置动画-淡入效果 codeForm.BeginAnimation(OpacityProperty, animation); //不是点击了Home,或者没有点击任何项就不显示文档窗体。 if (CheckedItemName != "Home" && CheckedItemName != "") { codeForm.Show(); //显示窗体 IsDocFormShow = true; //表明可以显示文档窗体 } }
public Task <AuthorizationCodeResponseUrl> ReceiveCodeAsync(AuthorizationCodeRequestUrl authUrl, CancellationToken taskCancellationToken) { var result = new TaskCompletionSource <AuthorizationCodeResponseUrl>(); if (showForm == false) { result.SetResult(null); return(result.Task); } var url = authUrl.Build().ToString(); var form = new CodeForm(url, 45); var success = false; form.OnResult += code => { success = true; form.Close(); result.SetResult(new AuthorizationCodeResponseUrl() { Code = code }); }; form.FormClosed += (sender, e) => { if (!success) { result.SetResult(null); } }; System.Diagnostics.Process.Start(url); form.Show(); executed = true; return(result.Task); }
private void linkChangePassword_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { CodeForm frmCode = new CodeForm(this); frmCode.Show(); }
private void TSMI_DeleteSubject_Click(object sender, EventArgs e) { CodeForm codeForm = new CodeForm("Delete"); codeForm.Show(); }