private void AuthenticateIfNecessary() { if (isAuthenticationRequired && !IsAuthenticationCookieSet()) { var castleSettings = JsonConvert.DeserializeObject <CastleSettings>(MakeGetRequest( string.Format("{0}/about.json", settings.DiagnosticsUrl))); isAuthenticationRequired = castleSettings.IsAuthenticationEnabled; if (isAuthenticationRequired) { MakePostRequest(string.Format("{0}/auth/login", settings.DiagnosticsUrl), string.Format("Login={0}&Password={1}", WebUtility.UrlEncode(settings.UserName), WebUtility.UrlEncode(settings.GetPassword()))); } } }
private void btnCastleConnection_Click(object sender, EventArgs e) { using (var dlg = new DiagnosticsCastleForm()) { dlg.TxtCastleUrl.Text = pluginSettings.DiagnosticsUrl != null ? pluginSettings.DiagnosticsUrl.AbsoluteUri : string.Empty; dlg.TxtCastleUsername.Text = pluginSettings.UserName; dlg.TxtCastlePassword.Text = pluginSettings.GetPassword(); if (dlg.ShowDialog(this) == DialogResult.OK) { pluginSettings.DiagnosticsUrl = new Uri(dlg.TxtCastleUrl.Text); pluginSettings.UserName = dlg.TxtCastleUsername.Text; pluginSettings.SetPassword(dlg.TxtCastlePassword.Text); } } }