private void frmSetTogglAPIKey_Load(object sender, EventArgs e) { try { txtKey.Text = Environment.GetEnvironmentVariable("TOGGL_COM_API_KEY", EnvironmentVariableTarget.User); KeyVerification.VerifyKeyAndSaveIt(txtKey.Text); lblSaveFeedback.ForeColor = Color.Green; lblSaveFeedback.Text = "Key is verified."; isThereAKeySaved = true; } catch (Exception exception) { lblSaveFeedback.ForeColor = Color.Red; lblSaveFeedback.Text = "Invalid key or issue saving it."; } }
private void btnSave_Click(object sender, EventArgs e) { try { string key = txtKey.Text.Trim(); KeyVerification.VerifyKeyAndSaveIt(key); lblSaveFeedback.ForeColor = Color.Green; lblSaveFeedback.Text = "Key saved."; isThereAKeySaved = true; } catch (Exception exception) { lblSaveFeedback.ForeColor = Color.Red; lblSaveFeedback.Text = exception.Message; } }
private bool VerifyWeHaveAnAPIKey() { string key = Environment.GetEnvironmentVariable("TOGGL_COM_API_KEY", EnvironmentVariableTarget.User); try { KeyVerification.VerifyKeyAndSaveIt(key); } catch (Exception) { var setKeyForm = new frmSetTogglAPIKey(); var result = setKeyForm.ShowDialog(); if (result == DialogResult.No) { return(false); } } return(true); }