/// <summary> /// Queries the character's data. Used generically across multiple methods. /// </summary> /// <param name="targetMethod">The ESI method to use.</param> /// <param name="onError">The callback if an error occurs.</param> /// <param name="onSuccess">The callback if the request is successful.</param> private void QueryCharacterData <T>(ESIAPICharacterMethods targetMethod, CharacterQueryMonitor <T> .NotifyErrorCallback onError, Action <T> onSuccess) where T : class { ESIKey apiKey = m_ccpCharacter.Identity.FindAPIKeyWithAccess(targetMethod); // Network available, has access if (NetworkMonitor.IsNetworkAvailable && apiKey != null) { EveMonClient.APIProviders.CurrentProvider.QueryEsiAsync <T>(targetMethod, apiKey.AccessToken, m_ccpCharacter.CharacterID, (result, ignore) => { var target = m_ccpCharacter; // Character may have been deleted or set to not be monitored if (target != null && target.Monitored) { // Notify if an error occured if (target.ShouldNotifyError(result, targetMethod)) { onError.Invoke(target, result); } if (!result.HasError) { onSuccess.Invoke(result.Result); } } }); } }
/// <summary> /// Gets the contract items or bids. /// </summary> private void GetContractData <T, U>(APIProvider.ESIRequestCallback <T> callback, ESIAPICorporationMethods methodCorp, ESIAPICharacterMethods methodPersonal, ResponseParams response) where T : List <U> where U : class { var cid = Character.Identity; ESIKey key; Enum method; long owner; // Special condition to identify corporation contracts in character query if (IssuedFor == IssuedFor.Corporation && ESIAPICorporationMethods. CorporationContracts.Equals(m_method)) { key = cid.FindAPIKeyWithAccess(methodCorp); method = methodCorp; owner = Character.CorporationID; } else { key = cid.FindAPIKeyWithAccess(methodPersonal); method = methodPersonal; owner = Character.CharacterID; } // Only query if the error count has not been exceeded if (key != null && !EsiErrors.IsErrorCountExceeded) { EveMonClient.APIProviders.CurrentProvider.QueryPagedEsi <T, U>(method, callback, new ESIParams(response, key.AccessToken) { ParamOne = owner, ParamTwo = ID }, method); } }
/// <summary> /// Gets the contract items or bids. /// </summary> private void GetContractData <T>(APIProvider.ESIRequestCallback <T> callback, ESIAPICorporationMethods methodCorp, ESIAPICharacterMethods methodPersonal) where T : class { var cid = Character.Identity; ESIKey key; Enum method; long owner; // Special condition to identify corporation contracts in character query if (IssuedFor == IssuedFor.Corporation && ESIAPICorporationMethods. CorporationContracts.Equals(m_method)) { key = cid.FindAPIKeyWithAccess(methodCorp); method = methodCorp; owner = Character.CorporationID; } else { key = cid.FindAPIKeyWithAccess(methodPersonal); method = methodPersonal; owner = Character.CharacterID; } if (key != null) { EveMonClient.APIProviders.CurrentProvider.QueryEsiAsync(method, key.AccessToken, owner, ID, callback, method); } }
/// <summary> /// Adds the icon. /// </summary> /// <param name="method">The method.</param> /// <param name="height">The height.</param> private void AddIcon(Enum method, int height) { Bitmap icon = Resources.KeyGrey16; string iconToolTip = "This is a basic feature query."; if (method is ESIAPICharacterMethods) { ESIAPICharacterMethods apiMethod = (ESIAPICharacterMethods)method; if ((long)apiMethod == ((long)apiMethod & (long)CCPAPIMethodsEnum.AdvancedCharacterFeatures)) { icon = Resources.KeyGold16; iconToolTip = "This is an advanced feature query."; } } PictureBox tempPicture = null; try { tempPicture = new PictureBox(); toolTip.SetToolTip(tempPicture, iconToolTip); tempPicture.Location = new Point(0, height + (RowHeight - icon.Size.Height) / 2); tempPicture.Image = icon; tempPicture.Size = icon.Size; PictureBox picture = tempPicture; tempPicture = null; Controls.Add(picture); } finally { tempPicture?.Dispose(); } }
/// <summary> /// Queries the character's data. /// </summary> private void QueryCharacterData <T>(ESIAPICharacterMethods targetMethod, APIProvider.ESIRequestCallback <T> onUpdated) where T : class { // Quits if no network if (!NetworkMonitor.IsNetworkAvailable) { return; } // Quits if access denied ESIKey apiKey = m_ccpCharacter.Identity.FindAPIKeyWithAccess(targetMethod); if (apiKey == null) { return; } EveMonClient.APIProviders.CurrentProvider.QueryEsiAsync <T>( targetMethod, apiKey.AccessToken, m_ccpCharacter.CharacterID, onUpdated); }
/// <summary> /// Finds the API key with access to the specified API method. /// </summary> /// <param name="method">The method.</param> /// <returns>The API key with access to the specified method or null if non found.</returns> public ESIKey FindAPIKeyWithAccess(ESIAPICharacterMethods method) => ESIKeys.FirstOrDefault(apiKey => apiKey.Monitored && (ulong)method == (apiKey.AccessMask & (ulong)method));