/// <summary> /// Updates the ESI key. /// </summary> /// <param name="e">The <see cref="ESIKeyCreationEventArgs" /> instance containing the event data.</param> /// <exception cref="System.ArgumentNullException">e</exception> public void Update(ESIKeyCreationEventArgs e) { e.ThrowIfNull(nameof(e)); RefreshToken = e.RefreshToken; AccessMask = e.AccessMask; // Throw out old access token AccessToken = string.Empty; m_keyExpires = DateTime.MinValue; CheckAccessToken(); // Clear the ESI key for the currently associated identities foreach (CharacterIdentity id in EveMonClient.CharacterIdentities.Where(id => id.ESIKeys.Contains(this))) { id.ESIKeys.Remove(this); } // Assign this API key to the new identities and create CCP characters var cid = e.Identity; cid.ESIKeys.Add(this); // Retrieves the ccp character and create one if none if (cid.CCPCharacter != null) { // Notify subscribers EveMonClient.OnCharacterUpdated(cid.CCPCharacter); } else { EveMonClient.Characters.Add(new CCPCharacter(cid)); } }
/// <summary> /// When ESI credentials have been updated. /// </summary> /// <returns></returns> private void OnUpdated(object sender, ESIKeyCreationEventArgs e) { m_creationArgs = e; var error = e.CCPError; CharactersGroupBox.Text = "Characters exposed by ESI key"; // Updates the picture and label for key type if (error != null) { string message = error.ErrorMessage; KeyPicture.Image = Resources.KeyWrong32; KeyLabel.Text = message; CharactersGroupBox.Text = "Error report"; ResultsMultiPanel.SelectedPage = GetErrorPage(e, message); } else { var id = e.Identity; KeyPicture.Image = Resources.DefaultCharacterImage32; KeyLabel.Text = "This is a 'Character' ESI key."; ResultsMultiPanel.SelectedPage = CharactersListPage; // Updates the characters list CharactersListView.Items.Clear(); CharactersListView.Items.Add(new ListViewItem(id.CharacterName) { Tag = id, }); } // Issue a warning if the access of the ESI key is zero if (e.AccessMask == 0UL) { WarningLabel.Text = "Beware! This ESI key does not provide any data!"; WarningLabel.Visible = true; } // Issue a warning if the access of ESI key is less than needed for basic features else if (e.AccessMask < (long)CCPAPIMethodsEnum.BasicCharacterFeatures) { WarningLabel.Text = "Beware! The data this ESI key provides does not suffice for basic features!"; WarningLabel.Visible = true; } else { WarningLabel.Visible = m_updateMode; } // Selects the last page MultiPanel.SelectedPage = ResultPage; }
/// <summary> /// When ESI credentials have been updated. /// </summary> /// <returns></returns> private void OnUpdated(object sender, ESIKeyCreationEventArgs e) { m_creationArgs = e; var error = e.CCPError; CharactersGroupBox.Text = "Characters exposed by ESI key"; // Updates the picture and label for key type if (error != null) { string message = error.ErrorMessage; KeyPicture.Image = Resources.KeyWrong32; KeyLabel.Text = message; CharactersGroupBox.Text = "Error report"; ResultsMultiPanel.SelectedPage = GetErrorPage(e, message); m_keyValid = false; } else { var id = e.Identity; KeyPicture.Image = Resources.DefaultCharacterImage32; KeyLabel.Text = "This is a character ESI key."; ResultsMultiPanel.SelectedPage = CharactersListPage; // Updates the characters list CharactersListView.Items.Clear(); CharactersListView.Items.Add(new ListViewItem(id.CharacterName) { Tag = id, }); m_keyValid = true; } // Issue a warning if the ESI key has no scopes if (e.AccessMask == 0UL) { WarningLabel.Text = Properties.Resources.ErrorNoScopes; WarningLabel.Visible = true; } // Issue a warning if the ESI key does not have the basic scopes else if (e.AccessMask < (long)CCPAPIMethodsEnum.BasicCharacterFeatures) { WarningLabel.Text = Properties.Resources.ErrorFewScopes; WarningLabel.Visible = true; } else { WarningLabel.Visible = m_updateMode; } // Selects the last page MultiPanel.SelectedPage = ResultPage; }
/// <summary> /// Gets the error page. /// </summary> /// <param name="e">The <see cref="ESIKeyCreationEventArgs"/> instance containing the event data.</param> /// <param name="message">The error message.</param> /// <returns>The error page to display.</returns> private MultiPanelPage GetErrorPage(ESIKeyCreationEventArgs e, string message) { if (e.CCPError.IsAuthenticationFailure) { return(AuthenticationErrorPage); } if (e.CCPError.IsLoginDeniedByAccountStatus) { return(LoginDeniedErrorPage); } GeneralErrorLabel.Text = string.Format(CultureConstants.DefaultCulture, GeneralErrorLabel.Text, message); return(GeneralErrorPage); }
/// <summary> /// On the first page, when a textbox is changed, we ensure the previously generated <see cref="ESIKeyCreationEventArgs"/> is destroyed. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void VerificationCodeTextBox_TextChanged(object sender, EventArgs e) { m_creationArgs = null; }
/// <summary> /// On the first page, when a textbox is changed, we ensure the previously generated <see cref="ESIKeyCreationEventArgs"/> is destroyed. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void IDTextBox_TextChanged(object sender, EventArgs e) { m_creationArgs = null; }
/// <summary> /// Cancel. /// Closes the window. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ButtonCancel_Click(object sender, EventArgs e) { m_creationArgs = null; Close(); }