コード例 #1
0
        /// <summary>
        /// Called when character's skill in training gets updated.
        /// </summary>
        /// <param name="result">The result.</param>
        /// <param name="character">The character's name.</param>
        private void OnSkillInTrainingUpdated(APIResult <SerializableAPISkillInTraining> result, string characterName)
        {
            CCPCharacter ccpCharacter = EveClient.Characters.FirstOrDefault(x => x.Name == characterName) as CCPCharacter;

            // Return on error
            if (result.HasError)
            {
                // Checks if EVE Backend Database is temporarily disabled
                if (result.EVEBackendDatabaseDisabled)
                {
                    return;
                }

                if (ccpCharacter != null)
                {
                    EveClient.Notifications.NotifySkillInTrainingError(ccpCharacter, result);
                }

                m_skillInTrainingCache[characterName].State = ResponseState.InError;
                return;
            }

            if (ccpCharacter != null)
            {
                EveClient.Notifications.InvalidateCharacterAPIError(ccpCharacter);
            }

            m_skillInTrainingCache[characterName].State = result.Result.SkillInTraining == 1
                                                     ? ResponseState.Training
                                                     : ResponseState.NotTraining;

            // In the event this becomes a very long running process because of latency
            // and characters have been removed from the account since they were queried
            // remove those characters from the cache
            IEnumerable <KeyValuePair <string, SkillInTrainingResponse> > toRemove =
                m_skillInTrainingCache.Where(x => !CharacterIdentities.Any(y => y.Name == x.Key));

            foreach (var charToRemove in toRemove)
            {
                m_skillInTrainingCache.Remove(charToRemove.Key);
            }

            // If we did not get response from a character in account yet
            // or there was an error in any responce,
            // we are not sure so wait until next time
            if (m_skillInTrainingCache.Any(x => x.Value.State == ResponseState.Unknown ||
                                           x.Value.State == ResponseState.InError))
            {
                return;
            }

            // We have successful responces from all characters in account,
            // so we notify the user and fire the event
            NotifyAccountNotInTraining();

            // Fires the event regarding the account characters skill in training update
            EveClient.OnAccountCharactersSkillInTrainingUpdated(this);

            // Reset update pending flag
            m_updatePending = false;
        }