Exemplo n.º 1
0
        public async Task <IEnumerable <PriceHistory> > GetMarketPriceHistoryAsync(long itemTypeId, long regionId)
        {
            var result = await WebServiceConsumer.Consume <DefaultRestClient, JsonDeserializer, OneDayLifetimeDiskCacheAgent, PriceHistoryCollection>(
                $"{this.Server.Crest}market/{regionId}/types/{itemTypeId}/history/"); // TODO

            if (result == null)
            {
                return(new List <PriceHistory>());
            }

            var average = result.Items.Average(x => x.AveragePrice);

            if (_itemprices.ContainsKey(itemTypeId))
            {
                _itemprices[itemTypeId].AveragePrice = average;
            }
            else
            {
                _itemprices.TryAdd(itemTypeId, new ItemPrice
                {
                    ItemId = new ItemId {
                        Id = itemTypeId
                    },
                    AveragePrice  = average,
                    AdjustedPrice = result.Items.Min(x => x.LowPrice)
                });
            }

            return(result.Items);
        }
Exemplo n.º 2
0
        public async Task <IEnumerable <MailBody> > GetMailBodyAsync(CharacterSpecificApiKey apiKey, long messageId)
        {
            var result = await WebServiceConsumer.Consume <DefaultRestClient, XmlDeserializer, EveXmlSpecializedCollectionCacheAgent <MailBodyCollection>, MailBodyCollection>(
                $"{this.Server.XMLApi}char/MailBodies.xml.aspx?keyId={apiKey.KeyId}&vCode={apiKey.VerificationCode}&characterID={apiKey.CharacterId}&IDs={messageId}");

            return(result.Items);
        }
Exemplo n.º 3
0
        public async static Task <string> GetServerVersionAsync()
        {
            var server = Factory.Create <IEveApi>().Server;
            var result = await WebServiceConsumer.Consume <DefaultRestClient, JsonDeserializer, MotdCachingAgent, Motd>(server.Crest);

            return(result.ServerVersion);
        }
Exemplo n.º 4
0
        public async Task <ReadOnlyDictionary <long, AssetItem> > GetAssetsAsync(CharacterSpecificApiKey apiKey)
        {
            var result = await WebServiceConsumer.Consume <DefaultRestClient, XmlDeserializer, EveXmlSpecializedCollectionCacheAgent <AssetItem>, AssetItemCollection>(
                $"{this.Server.XMLApi}char/AssetList.xml.aspx?keyId={apiKey.KeyId}&vCode={apiKey.VerificationCode}&characterID={apiKey.CharacterId}");

            return(result.Items.ToDictionary(x => x.ItemId).AsReadOnly());
        }
Exemplo n.º 5
0
        public async Task <CharacterLocationInfo> GetCharacterLocationAsync(long characterId)
        {
            var token = await this.GetAccessTokenAsync(characterId, CrestAccessScopes.CharacterLocationRead);

            return(await WebServiceConsumer.Consume <DefaultRestClient, JsonDeserializer, CharacterLocationInfo>(
                       $"{this.Server.Crest}characters/{characterId}/location/", token.AccessToken)); // TODO
        }
Exemplo n.º 6
0
        public async Task <IEnumerable <Notification> > GetNotificationsAsync(CharacterSpecificApiKey apiKey)
        {
            var result = await WebServiceConsumer.Consume <DefaultRestClient, XmlDeserializer, NotificationCollection>(
                $"{this.Server.XMLApi}char/Notifications.xml.aspx?keyId={apiKey.KeyId}&vCode={apiKey.VerificationCode}&characterID={apiKey.CharacterId}");

            return(result.Items.Where(x => !x.IsRead));
        }
Exemplo n.º 7
0
        public async Task <IEnumerable <Character> > GetCharactersAsync(ApiKey apiKey)
        {
            var result = await WebServiceConsumer.Consume <DefaultRestClient, XmlDeserializer, EveXmlSpecializedCollectionCacheAgent <Character>, CharacterCollection>(
                $"{this.Server.XMLApi}account/Characters.xml.aspx?keyId={apiKey.KeyId}&vCode={apiKey.VerificationCode}");

            return(result.Items);
        }
Exemplo n.º 8
0
        public async Task <ShipFittingCollection> GetShipFittings(long characterId)
        {
            var token = await this.GetAccessTokenAsync(characterId, CrestAccessScopes.CharacterFittingsRead);

            return(await WebServiceConsumer.Consume <DefaultRestClient, JsonDeserializer, ShipFittingCollection>(
                       $"{this.Server.Crest}characters/{characterId}/fittings/", token.AccessToken)); // TODO
        }
Exemplo n.º 9
0
        private async Task RebuildRefTypeItem()
        {
            var server = Factory.Create <IEveApi>().Server;
            var result = await WebServiceConsumer.Consume <DefaultRestClient, XmlDeserializer, RefTypeItemCollection>($"{server.XMLApi}eve/RefTypes.xml.aspx");

            await EveCache.SetCache(result.Items);
        }
Exemplo n.º 10
0
        public async Task <IEnumerable <MailMessageItem> > GetMailMessagesAsync(CharacterSpecificApiKey apiKey)
        {
            var result = await WebServiceConsumer.Consume <DefaultRestClient, XmlDeserializer, MailMessageCollection>(
                $"{this.Server.XMLApi}char/MailMessages.xml.aspx?keyId={apiKey.KeyId}&vCode={apiKey.VerificationCode}&characterID={apiKey.CharacterId}");

            return(result.Items.Where(x => x.SenderId != apiKey.CharacterId));
        }
Exemplo n.º 11
0
        public async Task <IEnumerable <SkillQueue> > GetSkillQueueAsync(CharacterSpecificApiKey apiKey)
        {
            var result = await WebServiceConsumer.Consume <DefaultRestClient, XmlDeserializer, EveXmlSpecializedCollectionCacheAgent <SkillQueueCollection>, SkillQueueCollection>(
                $"{this.Server.XMLApi}char/SkillQueue.xml.aspx?keyId={apiKey.KeyId}&vCode={apiKey.VerificationCode}&characterID={apiKey.CharacterId}");

            return(result.Items);
        }
Exemplo n.º 12
0
        public async static Task <long> GetOnlinePlayersAsync()
        {
            try
            {
                var server = Factory.Create <IEveApi>().Server;
                var result = await WebServiceConsumer.Consume <DefaultRestClient, XmlDeserializer, ServerStatus>($"{server.XMLApi}server/ServerStatus.xml.aspx");

                return(result.OnlinePlayers);
            }
            catch
            {
                return(0);
            }
        }
Exemplo n.º 13
0
        public async static Task <EveServerStatus> GetServerStatusAsync()
        {
            try
            {
                EveServers   server = Factory.Create <IEveApi>().Server;
                ServerStatus result = await WebServiceConsumer.Consume <DefaultRestClient, XmlDeserializer, ServerStatus>($"{server.XMLApi}server/ServerStatus.xml.aspx");

                return(result.ServerOpen ? EveServerStatus.Online : EveServerStatus.Offline);
            }
            catch
            {
                return(EveServerStatus.Unknown);
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// Tries to authenticate the application using OAuth2 to CREST. The application requires a callback.
        /// Check http://eveonline-third-party-documentation.readthedocs.io/en/latest/sso/nonbrowserapps.html for more information
        /// </summary>
        /// <param name="crest">The information required for the authentification</param>
        /// <exception cref="ArgumentNullException"><paramref name="crest"/> is null</exception>
        /// <exception cref="ArgumentException">No access scope defined</exception>
        public async Task AuthorizeApplicationForCrestAsync(CrestApiKey crest, params string[] accessScopes)
        {
            if (crest == null)
            {
                throw new ArgumentNullException(nameof(crest));
            }

            if (accessScopes.Length == 0)
            {
                throw new ArgumentException("At least one access scope must be defined");
            }

            var url    = $"{this.Server.Login}oauth/authorize/?response_type=code&redirect_uri={WebUtility.HtmlEncode(crest.CallbackUrl)}&client_id={crest.ClientId}&scope={WebUtility.HtmlEncode(accessScopes.Join(" "))}&state={crest.KeyId}";
            var result = await WebAuthenticationBrokerWrapper.AuthenticateAsync(new Uri(url), new Uri(crest.CallbackUrl));

            var parameters = new Uri(result).ParseQueryString();

            var basicAuth = $"{crest.ClientId}:{crest.SecretKey}".ToBase64String();
            var client    = new HttpClient();

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", basicAuth);
            client.DefaultRequestHeaders.Host          = "login.eveonline.com";

            var response = await client.PostAsync(
                $"{this.Server.Login}oauth/token/",
                new FormUrlEncodedContent(new Dictionary <string, string>
            {
                { "grant_type", "authorization_code" },
                { "code", parameters["code"] }
            }));

            var tokenInfo     = JsonConvert.DeserializeObject <CrestTokenInfo>(await response.Content.ReadAsStringAsync());
            var characterInfo = await WebServiceConsumer.Consume <DefaultRestClient, JsonDeserializer, CrestCharacterInfo>($"{this.Server.Login}oauth/verify", tokenInfo.AccessToken, "login.eveonline.com");

            tokenInfo.Authentification = basicAuth;

            if (this.tokenInfos.Any(x => x.CharacterId == characterInfo.CharacterId))
            {
                this.tokenInfos.RemoveAll(x => x.CharacterId == characterInfo.CharacterId);
            }

            this.tokenInfos.Add(new TokenKey
            {
                AccessScope = accessScopes,
                CharacterId = characterInfo.CharacterId,
                TokenInfo   = tokenInfo,
                ServerName  = this.Server.ServerName
            });
        }
Exemplo n.º 15
0
        public async static Task <DateTime> GetEveTimeAsync()
        {
            try
            {
                var eve    = Factory.Create <IEveApi>();
                var result = await WebServiceConsumer.Consume <DefaultRestClient, JsonDeserializer, EveTime>((await eve.GetMotdAsync()).Time.HRef);

                return(result.Time);
            }
            catch
            {
                var info = TimeZoneInfo.FindSystemTimeZoneById("W. Europe Standard Time");
                return(TimeZoneInfo.ConvertTime(DateTimeOffset.Now, info).DateTime);
            }
        }
Exemplo n.º 16
0
        private async Task <List <TResult> > ConsumeUntil <TResult>(string requestUri, Func <TResult, string> nextUri)
        {
            List <TResult> items = new List <TResult>();
            TResult        result;

            do
            {
                result = await WebServiceConsumer.Consume <DefaultRestClient, JsonDeserializer, TResult>(requestUri);

                requestUri = nextUri(result);

                items.Add(result);
            } while (requestUri != null);

            return(items);
        }
Exemplo n.º 17
0
        public async Task CachePriceAsync()
        {
            var priceUrl = (await this.GetMotdAsync()).MarketPrices.HRef;

            try
            {
                if (_itemprices.Count > 0)
                {
                    return;
                }

                var result = await WebServiceConsumer.Consume <DefaultRestClient, JsonDeserializer, EveXmlSpecializedCollectionCacheAgent <ItemPriceCollection>, ItemPriceCollection>(priceUrl);

                result?.Items?.Foreach(x => _itemprices.TryAdd(x.ItemId.Id, x));
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
            }
        }
Exemplo n.º 18
0
        public async Task <IEnumerable <CharacterName> > GetCharacterNamesAsync(long[] characterIds)
        {
            if (characterIds.Length == 0)
            {
                return(new CharacterName[0]);
            }

            // If not loaded... Load it
            try
            {
                if (_characterNames.Count == 0)
                {
                    _characterNames.AddRange(await EveCache.GetCacheCollection <CharacterName>());
                }
            }
            catch
            {
                // Happens... And expected if cache is not available... But too lazy to correctly handle this
            }

            var notFound = characterIds.Where(x => _characterNames.All(y => y.CharacterId != x));

            if (!notFound.Any() && _characterNames.Count > 0)
            {
                return(_characterNames.Where(x => characterIds.Contains(x.CharacterId)));
            }

            var result = await WebServiceConsumer.Consume <DefaultRestClient, XmlDeserializer, CharacterNameCollection>(
                $"{this.Server.XMLApi}eve/CharacterName.xml.aspx?ids={(_characterNames.Count == 0 ? characterIds : notFound).Join(",")}");

            _characterNames.AddRange(result.Items);

            if (result.Items.Any())
            {
                await EveCache.SetCache(_characterNames);
            }

            return(_characterNames.Where(x => characterIds.Contains(x.CharacterId)));
        }
Exemplo n.º 19
0
        public async Task <QuicklookCollection> GetMarketOrdersAsync(long itemTypeId)
        {
            var result = await WebServiceConsumer.Consume <DefaultRestClient, XmlDeserializer, DefaultDiskCacheAgent, QuicklookCollection>(string.Format("http://api.eve-central.com/api/quicklook?typeid={0}", itemTypeId));

            var average = result.SellOrders.Count > 0 ? result.SellOrders.Average(x => x.Price) : 0;

            if (_itemprices.ContainsKey(itemTypeId))
            {
                _itemprices[itemTypeId].AveragePrice = average;
            }
            else
            {
                _itemprices.TryAdd(itemTypeId, new ItemPrice
                {
                    ItemId = new ItemId {
                        Id = itemTypeId
                    },
                    AveragePrice  = average,
                    AdjustedPrice = result.SellOrders.Count > 0 ? result.SellOrders.Min(x => x.Price) : 0
                });
            }

            return(result);
        }
Exemplo n.º 20
0
 public async Task <SolarSystemInfo> GetSolarSystemInfoAsync(long solarSystemId) =>
 await WebServiceConsumer.Consume <DefaultRestClient, JsonDeserializer, SolarSystemInfo>(
     $"{(await this.GetMotdAsync()).SolarSystems.HRef}{solarSystemId}/stats/");
Exemplo n.º 21
0
 public async Task <T> GetCharacterSheetAsync <T>(CharacterSpecificApiKey apiKey)
     where T : CharacterSheetCompact, new()
 {
     return(await WebServiceConsumer.Consume <DefaultRestClient, XmlDeserializer, EveXmlSpecializedCacheAgent <T>, T>(
                $"{this.Server.XMLApi}char/CharacterSheet.xml.aspx?keyId={apiKey.KeyId}&vCode={apiKey.VerificationCode}&characterID={apiKey.CharacterId}"));
 }
Exemplo n.º 22
0
 public async Task <IncursionCollection> GetIncursionsAsync() =>
 await WebServiceConsumer.Consume <DefaultRestClient, JsonDeserializer, FiveMinutesDiskCacheAgent, IncursionCollection>((await this.GetMotdAsync()).Incursions.HRef);
Exemplo n.º 23
0
 public async Task <Motd> GetMotdAsync() => await WebServiceConsumer.Consume <DefaultRestClient, JsonDeserializer, MotdCachingAgent, Motd>(this.Server.Crest);
Exemplo n.º 24
0
 public async Task <SkillInTraining> GetSkillInTrainingAsync(CharacterSpecificApiKey apiKey)
 {
     return(await WebServiceConsumer.Consume <DefaultRestClient, XmlDeserializer, EveXmlSpecializedCacheAgent <SkillInTraining>, SkillInTraining>(
                $"{this.Server.XMLApi}char/SkillInTraining.xml.aspx?keyId={apiKey.KeyId}&vCode={apiKey.VerificationCode}&characterID={apiKey.CharacterId}"));
 }
Exemplo n.º 25
0
        public async Task <IEnumerable <ConquerableStation> > GetConquerableStationAsync()
        {
            var result = await WebServiceConsumer.Consume <DefaultRestClient, XmlDeserializer, EveXmlSpecializedCollectionCacheAgent <ConquerableStation>, ConquerableStationCollection>($"{this.Server.XMLApi}eve/ConquerableStationList.xml.aspx");

            return(result.Items);
        }
Exemplo n.º 26
0
 public async Task <T> GetItemAttributesAsync <T>(long itemTypeId) where T : ItemAttributes, IKeyedModel, new() =>
 await WebServiceConsumer.Consume <DefaultRestClient, JsonDeserializer, EveXmlSpecializedCacheAgent <T>, T>(
     $"{(await this.GetMotdAsync()).InventoryTypes.HRef}{itemTypeId}/");