public async Task Run() { if (mHttpServerTask != null) { throw new InvalidOperationException("Browser already running"); } mCancelHttpServer = new CancellationTokenSource(); TaskCompletionSource <int> setport = new TaskCompletionSource <int>(); mHttpServerTask = RunHttpServer(mCancelHttpServer.Token, setport); mPort = await setport.Task; mLog.Info($"Running Local server at: http://localhost:{mPort}"); Success = false; string url = SSOAuth.GetUrl(AccessFlags, mPort, PrivateData, out mChallengeCode).ToString(); StartSystemBrowser(url); var task = mHttpServerTask; await task; mHttpServerTask = null; }
private async Task Authorize(string authcode, string challenge_code) { try { mCancel = new CancellationTokenSource(); cActionText.Text = "Authorizing account."; mLog.Info(cActionText.Text); TokenInfo tinfo = await SSOAuth.GetTokenInfoAsync(authcode, challenge_code, mCancel.Token); cActionText.Text = "Retrieving Character information."; mLog.Info(cActionText.Text); CharacterInfo cinfo = await SSOAuth.GetCharacterInfoAsync(tinfo.AccessToken, mCancel.Token); if (await GetClient().UpdateAccountAuthAsync(tinfo, cinfo, mOptions.Flags)) { mLog.Info($"Updated Account:{cinfo.CharacterName}({cinfo.CharacterId})"); } else { await GetClient().AddAccountAsync(tinfo, cinfo, mOptions.Flags); mLog.Info($"Added Account:{cinfo.CharacterName}({cinfo.CharacterId})"); } } catch (TaskCanceledException) { } catch (Exception e) { mLog.Error(e, "Authorize Failed"); MessageBox.Show(e.Message, "Unable to add account"); mIsCancelling = false; mCancel = null; cCreationPage.Visibility = Visibility.Visible; cActionPage.Visibility = Visibility.Hidden; return; } mIsCancelling = false; mCancel = null; Close(); }