Esempio n. 1
0
        public static async Task<CharactersResponse> GetCharactersAsync(int keyId, string verificationCode)
        {
            using (HttpClient client = new HttpClient())
            {
                string requestUrl = String.Format(CharactersQueryFormat, keyId, verificationCode);
                Uri requestUri = new Uri(requestUrl, UriKind.Relative);

                Uri uri = new Uri(CharactersBaseUri, 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 rowSet = result.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("name")
                            .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);
                    }

                    CharactersResponse response = new CharactersResponse(currentTime, cachedUntil, characters);
                    return response;
                }
            }
        }
Esempio n. 2
0
        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;
                }
            }
        }