/// <summary> /// Constructor. /// </summary> /// <param name="character">The character to monitor.</param> /// <param name="method">The method to use.</param> /// <param name="onSuccess">An action to call on success.</param> /// <param name="onFailure">The callback to use upon failure.</param> internal CharacterQueryMonitor(CCPCharacter character, Enum method, Action <T> onSuccess, NotifyErrorCallback onFailure) : base(method, (result) => { // Character may have been set to not be monitored if (character.Monitored) { if (character.ShouldNotifyError(result, method)) { onFailure.Invoke(character, result); } if (!result.HasError) { onSuccess.Invoke(result.Result); } } foreach (var monitor in character.QueryMonitors.Where(monitor => monitor.Method. HasParent(method))) { character.QueryMonitors.Query(monitor.Method); } }) { m_character = character; }
/// <summary> /// Constructor. /// </summary> /// <param name="character"></param> /// <param name="method"></param> /// <param name="onUpdated"></param> internal CorporationQueryMonitor(CCPCharacter character, Enum method, Action <T> onSuccess, NotifyErrorCallback onFailure) : base(method, (result) => { if (character.Monitored) { // "No corp role(s)" = 403 if (result.HasError) { int rolesError = result.ErrorMessage?.IndexOf("role", StringComparison.InvariantCultureIgnoreCase) ?? -1; // Do not invoke onFailure on corp roles error since we cannot actually // determine whether the key had the roles until we try if ((result.ErrorCode != 403 || rolesError <= 0) && character. ShouldNotifyError(result, method)) { onFailure.Invoke(character, result); } } else { onSuccess.Invoke(result.Result); } } }) { m_character = character; }
/// <summary> /// Constructor. /// </summary> /// <param name="character"></param> /// <param name="method"></param> /// <param name="onUpdated"></param> internal CorporationQueryMonitor(CCPCharacter character, Enum method, Action <T> onSuccess, NotifyErrorCallback onFailure) : base(method, (result) => { // Character may have been set to not be monitored if (character.Monitored) { if (character.ShouldNotifyError(result, method)) { onFailure.Invoke(character, result); } if (!result.HasError) { onSuccess.Invoke(result.Result); } } }) { m_character = character; }
/// <summary> /// Constructor. /// </summary> /// <param name="character">The character to monitor.</param> /// <param name="method">The method to use.</param> /// <param name="onSuccess">An action to call on success.</param> /// <param name="onFailure">The callback to use upon failure.</param> internal CorporationQueryMonitor(CCPCharacter character, Enum method, Action <T> onSuccess, NotifyErrorCallback onFailure) : base(character, method, (result) => { if (character.Monitored) { // "No corp role(s)" = 403 if (result.HasError) { // Do not invoke onFailure on corp roles error since we cannot actually // determine whether the key had the roles until we try if (result.ErrorCode != 403 && character.ShouldNotifyError(result, method)) { onFailure.Invoke(character, result); } } else if (result.HasData) { onSuccess.Invoke(result.Result); } } }) { }
/// <summary> /// Handles the response from an ESI query. /// </summary> /// <param name="character">The character to monitor.</param> /// <param name="method">The method to use.</param> /// <param name="ifNoData">Whether to invoke the success callback on a "No Data" /// response.</param> /// <param name="result">The result of the query.</param> /// <param name="onSuccess">An action to call on success.</param> /// <param name="onFailure">The callback to use upon failure.</param> private static void HandleQuery(CCPCharacter character, Enum method, bool ifNoData, EsiResult <T> result, Action <T> onSuccess, NotifyErrorCallback onFailure) { // Character may have been set to not be monitored if (character.Monitored) { bool hasData = result.HasData; if (character.ShouldNotifyError(result, method)) { onFailure.Invoke(character, result); } if (!result.HasError && (ifNoData || hasData)) { onSuccess.Invoke(hasData ? result.Result : null); } } foreach (var monitor in character.QueryMonitors) { if (monitor.Method.HasParent(method)) { character.QueryMonitors.Query(monitor.Method); } } }