コード例 #1
0
        /// <summary>
        /// Updates the characters list with the given CCP data.
        /// </summary>
        /// <param name="tokenInfo">The ESI token info from CCP.</param>
        private void ImportIdentities(EsiAPITokenInfo tokenInfo)
        {
            var  chars  = EveMonClient.CharacterIdentities.Where(id => id.ESIKeys.Contains(this));
            long charID = tokenInfo.CharacterID;

            // Clear the API key on this character
            foreach (CharacterIdentity id in chars)
            {
                id.ESIKeys.Remove(this);
            }

            // Find characters who own this ESI key
            // Can match at most one character
            CharacterIdentity cid = EveMonClient.CharacterIdentities[charID] ??
                                    EveMonClient.CharacterIdentities.Add(charID, tokenInfo.CharacterName);

            // Add the ESI key to the identity
            cid.ESIKeys.Add(this);
            if (cid.CCPCharacter != null)
            {
                // Notify subscribers
                EveMonClient.OnCharacterUpdated(cid.CCPCharacter);
            }

            // Fires the event regarding the character list update
            EveMonClient.OnCharacterListUpdated(this);
            EveMonClient.OnESIKeyCollectionChanged();
        }
コード例 #2
0
ファイル: ESIKey.cs プロジェクト: Slazanger/evemon
        /// <summary>
        /// Updates the token character list, or sets an error flag if it could not be
        /// obtained.
        /// </summary>
        private void OnTokenInfo(JsonResult <EsiAPITokenInfo> result)
        {
            EsiAPITokenInfo tokenInfo = result.Result;

            if (result.HasError)
            {
                HasError = true;
                EveMonClient.Notifications.NotifyCharacterListError(ID, result);
            }
            else
            {
                HasError = false;
                ImportIdentities(tokenInfo);
            }
            EveMonClient.OnESIKeyInfoUpdated(this);
        }
コード例 #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ESIKeyCreationEventArgs"/> class.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="refreshToken">The refresh token.</param>
        /// <param name="charInfo">The ESI key info.</param>
        /// <exception cref="System.ArgumentNullException">charInfo</exception>
        public ESIKeyCreationEventArgs(long id, string refreshToken, JsonResult <EsiAPITokenInfo> charInfo)
        {
            charInfo.ThrowIfNull(nameof(charInfo));

            ID           = id;
            RefreshToken = refreshToken;
            // TODO
            AccessMask = ulong.MaxValue;

            if (charInfo.HasError)
            {
                CCPError = new CCPAPIError()
                {
                    ErrorCode    = charInfo.ResponseCode,
                    ErrorMessage = charInfo.ErrorMessage ??
                                   "No character result retrieved from ESI key"
                }
            }
            ;
            else
            {
                EsiAPITokenInfo result = charInfo.Result;
                CCPError = null;
                long   charId = result.CharacterID;
                string name   = result.CharacterName;

                // Only one character per ESI key
                // Look for an existing character ID and update its name
                CharacterIdentity identity = EveMonClient.CharacterIdentities[charId];
                if (identity != null)
                {
                    identity.CharacterName = name;
                }
                else
                {
                    // Create an identity if necessary
                    identity = EveMonClient.CharacterIdentities.Add(charId, name);
                }
                Identity = identity;
            }
        }