コード例 #1
0
 internal ApiKeyInformationResponse(DateTime currentTime, DateTime cachedUntil, ApiKey key, IEnumerable<Character> characters)
     : base(currentTime, cachedUntil)
 {
     this.Key = key;
     this.Characters = characters;
 }
コード例 #2
0
ファイル: ApiCore.cs プロジェクト: EmitCode/EVEComm
        public static async Task<ApiKeyInformationResponse> GetApiKeyInformationAsync(int keyId, string verificationCode)
        {
            using (HttpClient client = new HttpClient())
            {
                string requestUrl = String.Format(ApiKeyInformationQueryFormat, keyId, verificationCode);
                Uri requestUri = new Uri(requestUrl, UriKind.Relative);

                Uri uri = new Uri(ApiKeyInformationBaseUri, requestUri);

                using (Stream stream = await client.GetStreamAsync(uri))
                {
                    XDocument document = XDocument.Load(stream);

                    XElement eveApi = document.Element("eveapi");

                    string currentTimeValue = eveApi
                        .Element("currentTime")
                        .Value;

                    DateTime currentTime = DateTime.Parse(currentTimeValue);

                    string cachedUntilValue = eveApi
                        .Element("cachedUntil")
                        .Value;

                    DateTime cachedUntil = DateTime.Parse(cachedUntilValue);

                    XElement result = eveApi.Element("result");
                    XElement key = result.Element("key");

                    string accessMaskValue = key
                        .Attribute("accessMask")
                        .Value;

                    int accessMask = Int32.Parse(accessMaskValue);

                    string typeValue = key
                        .Attribute("type")
                        .Value;

                    ApiKeyType type;
                    switch (typeValue)
                    {
                        case "Account":
                            type = ApiKeyType.Account;
                            break;

                        case "Character":
                            type = ApiKeyType.Character;
                            break;

                        case "Corporation":
                            type = ApiKeyType.Corporation;
                            break;

                        default:
                            type = ApiKeyType.Unknown;
                            break;
                    }

                    string expiresValue = key
                        .Attribute("expires")
                        .Value;

                    DateTime expires;
                    if (String.IsNullOrWhiteSpace(expiresValue))
                    {
                        expires = DateTime.MaxValue;
                    }
                    else
                    {
                        expires = DateTime.Parse(expiresValue);
                    }

                    ApiKey apiKey = new ApiKey(keyId, verificationCode, type, accessMask, expires);

                    XElement rowSet = key.Element("rowset");

                    List<Character> characters = new List<Character>();
                    foreach (XElement row in rowSet.Elements("row"))
                    {
                        string characterIdValue = row
                            .Attribute("characterID")
                            .Value;

                        long characterId = Int64.Parse(characterIdValue);

                        string characterName = row
                            .Attribute("characterName")
                            .Value;

                        string corporationIdValue = row
                            .Attribute("corporationID")
                            .Value;

                        long corporationId = Int64.Parse(corporationIdValue);

                        string corporationName = row
                            .Attribute("corporationName")
                            .Value;

                        Corporation corporation = new Corporation(corporationId, corporationName);

                        Character character = new Character(characterId, characterName, corporation);
                        characters.Add(character);
                    }

                    ApiKeyInformationResponse response = new ApiKeyInformationResponse(currentTime, cachedUntil, apiKey, characters);
                    return response;
                }
            }
        }