These forums have been archived and are now read-only.

The new forums are live and can be found at https://forums.eveonline.com/

EVE Technology Lab

 
  • Topic is locked indefinitely.
 

[EveLib] A .NET library for EveXML, CREST, EveCentral, and more

First post
Author
Cryten Jones
Advantage Inc
#21 - 2014-05-08 10:47:50 UTC
**Warning Stupid Question""

I have spent a load of time this year teaching myself C# and had been doing ok thus far trying to create my own industry app as a means to lean the language, so in short I have worked a load out but am still a noob.

I have created some code that does a very basic job of pulling info from the API but have decided to use this far superior library for the task so that I can focus on the actual task at hand.

Could some kind person explain to me how I can add Evelib to my project? when I try and add existing project and add in each part of the Evelib solution I get a load of namespace reference errors so I must be doing it wrong.

All I want access to is EveCentral and the ability to fetch from the authenticated API (eg assets, wallets etc)

Thanks in advance.

Icahmura Hasaki
Perkone
Caldari State
#22 - 2014-05-08 11:17:26 UTC
That's a valid question. You will need 3 modules, EveLib.Core, EveLib.EveCentral and EveLib.EveOnline. The reference errors you are seeing, is most likely because you need to add a reference to EveLib.Core in EveCentral and EveOnline.
Assuming you are using VS:
With all 3 projects in your solution, you will see a sub-item under each project called "References". Rightclick this, select "Add reference", select EveLib.Core under "Solution -> Projects". Do this for both EveCentral and EveOnline, and you should be good to go.

Let me know if you're still having issues.

Developer of EveLib and EveAuthUtility

Cryten Jones
Advantage Inc
#23 - 2014-05-08 12:07:08 UTC
Great, thanks! that cleared up the errors... still having issues getting the using eZet.EveLib.Modules to work but again I may be missing somehting
Icahmura Hasaki
Perkone
Caldari State
#24 - 2014-05-08 12:16:53 UTC  |  Edited by: Icahmura Hasaki
You're not entirely clear on what isn't working, could you be more specific? eZet.EveLib.Modules is just a namespace. I do however recognize that the library isn't distributed in a very user-friendly manner at the moment, though I'm not sure what would be the best way to distribute it either.

edit:
Oh, I misread. You need to add EveLib.EveCentral and/or EveLib.EveOnline as a reference in the project you want to use it in, the same way you did with Core.

Developer of EveLib and EveAuthUtility

Cryten Jones
Advantage Inc
#25 - 2014-05-08 12:20:01 UTC
Cryten Jones wrote:
Great, thanks! that cleared up the errors... still having issues getting the using eZet.EveLib.Modules to work but again I may be missing somehting



Never mind, worked it out, thanks
Cryten Jones
Advantage Inc
#26 - 2014-05-08 12:20:47 UTC
Icahmura Hasaki wrote:
You're not entirely clear on what isn't working, could you be more specific? eZet.EveLib.Modules is just a namespace. I do however recognize that the library isn't distributed in a very user-friendly manner at the moment, though I'm not sure what would be the best way to distribute it either.

edit:
Oh, I misread. You need to add EveLib.EveCentral and/or EveLib.EveOnline as a reference in the project you want to use it in, the same way you did with Core.



LOL got there at the same time :-)
Cryten Jones
Advantage Inc
#27 - 2014-05-08 12:26:31 UTC
On a side note:

When I request something from the API, lets say the asset list for a character. What is the return format?

On the project I did myself I processed the API XML into a datatable and returned that.. what is the return format in and what would be the best method for loading that into a table ?

Thanks
Icahmura Hasaki
Perkone
Caldari State
#28 - 2014-05-08 12:40:39 UTC  |  Edited by: Icahmura Hasaki
The API parses the XML and returns an object, depending on the request you make. The EveOnline module returns objects of the type EveApiResponse[T] (cant use html tags) where T is specific to the request, EveCentral uses EveCentralSomeName where SomeName depends on the request.

There are more specific examples in the github readme.

edit:
As a follow up, the best way to insert it in a db would be to convert the API objects into the domain models/data models you use for your database, and then insert those into your database. To convert you can use a simple mapper that reads the data from the API object, and maps it to a new domain object.

Developer of EveLib and EveAuthUtility

Cryten Jones
Advantage Inc
#29 - 2014-05-08 12:53:43 UTC
You are already out of my knowledge here..

I was hoping that I could call character.assetslist(keyData) and get the data back but I can't even work out what the options for T let alone data models etc :-)

Icahmura Hasaki
Perkone
Caldari State
#30 - 2014-05-08 12:56:16 UTC  |  Edited by: Icahmura Hasaki
A specific example for asset list would be:

var key = new CharacterKey(12345, "someVcode");
var character =key.Characters.Single(c => c.CharacterName == "Icahmura Hasaki");
var result = character.GetAssetList(); // or replace var with EveApiResponse[AssetList]

Keep in mind [ ] is a repacement for HTML style pointy brackets if you aren't used to generics. Anyone know if you can get around the forum limitations for showing these?

You can then use intellisense or some other code completion to see the available properties on result, or you can check the source or debug the object to see what's available. In most cases it follows the XML structure, but some properties are slightly renamed for clarity.

Developer of EveLib and EveAuthUtility

Cryten Jones
Advantage Inc
#31 - 2014-05-08 13:22:32 UTC
That's done it! I could not work out the link between the key object and the character object where all the methods live :-)

I am doing most of my data heavy lifting on the SQL side as I know this so your library is all about raw data into database tables where it can be processed with stored procedures.

For multiple accounts should I be creating a new key / char pair for each specifically of is there a neat way to loop though reusing the same objects by just modifying the values?

I was thinking key.vcode = 1234 would allow me to reset the vcode so something new but it seems to be only a get option

Thanks for all the help
Icahmura Hasaki
Perkone
Caldari State
#32 - 2014-05-08 13:31:33 UTC  |  Edited by: Icahmura Hasaki
You need to create a new key object for each API key you want to use, for various design reasons. They are lightweight though and has no impact on anything really :)

You can loop through all characters available for a key by iterating key.Characters, as a normal list. Or you can select a specific one by ID or Name like I showed above.

Developer of EveLib and EveAuthUtility

Cryten Jones
Advantage Inc
#33 - 2014-05-08 13:37:28 UTC
So if I am pulling a list of chars with their key data from the database and then looping though the x number I have .. do you have any advice on how to programatically create x number of new key objects?

Totally understand if you have had enough at this point :-)

Icahmura Hasaki
Perkone
Caldari State
#34 - 2014-05-08 13:44:00 UTC  |  Edited by: Icahmura Hasaki
Place the key data in some enumerable structure, like a List[KeyData] of KeyData objects with a Id and vcode property, or a Dictionary[int, string] with id and vcode respectively.

Then iterate through it like so:
Quote:

var keys = new Dictionary[int, CharacterKey](); // if you want to store it for later
foreach (KeyData data in KeyDataList)
{
var key = new CharacterKey(data.Id, data.vCode);
keys.Add(data.id, key) // if you want to store for later
foreach (Character character in key.Characters)
{
EveApiResponse[AssetList] assets = character.GetAssetList();
// process assets
}
}


Just keep asking questions, I dont mind helping. I'm sure there are others that can use the information aswell :)

edit:
Added example of storing keys for later

Developer of EveLib and EveAuthUtility

Icahmura Hasaki
Perkone
Caldari State
#35 - 2014-05-08 13:57:42 UTC  |  Edited by: Icahmura Hasaki
I should add that you shouldn't hammer the Eve API though. Doing this for a few characters/keys is fine, but don't do it for a 5000 man corporation.

Creating CorporationKey or CharacterKey is lightweight, and you can creates millionsof these. But as soon as you query key.Characters or any other property on the key (besides KeyId or VCode obviously), the API lazily loads all it's properties and available characters. So if you need to query a lot of keys or characters you should follow CCPs guidelines for amount of queries.

Developer of EveLib and EveAuthUtility

Icahmura Hasaki
Perkone
Caldari State
#36 - 2014-05-08 14:10:15 UTC  |  Edited by: Icahmura Hasaki
And another thing, depending on if you check the validity of the keys beforehand or not, you should add checks for that too.

If you have few keys, you can check it by using key.IsValidKey which returns a bool value. Keep in mind though that this DOES query the api endpoint immediately.

If you have many keys, or a few keys that are expected to be correct, you can catch InvalidRequestException instead, and check if the InnerException.Response.StatusCode == HttpStatusCode.Forbidden instead, which means the key is invalid or doesn't have the right permissions.

Developer of EveLib and EveAuthUtility

Cryten Jones
Advantage Inc
#37 - 2014-05-08 14:35:18 UTC  |  Edited by: Cryten Jones
This is for personal use on 4 toons over 4 accounts so it should be light.. I hope...

I am trying to do a foreach(AssetsList.Asset item in assets) where assets is my EveApiResponse[AssetList]

This is saying that your type does not have a getEnumerator so I guess that's a no show.. how else can I loop thought the data ?

edit: eg. I am going to get an asset list for a specific character not looping though for the characters
Icahmura Hasaki
Perkone
Caldari State
#38 - 2014-05-08 14:53:29 UTC  |  Edited by: Icahmura Hasaki
The assets structure is somewhat complicated as assets can contain other assets and so on.

First off, you have to get response.Result to get to the request specific data, for all EveApiResponses objects.

EveApiResponse[AssetList].Result has a a property Assets, which is a collection of Asset objects. Asset objects are a top level object, which is bound to a location in eve. Each Asset object can be a regular item, or a container. It has a property called Items, which is a list of contained Item objects. Each Item object can again have a list of contained Item objects, available in a list called Items.

So basically it's a tree with unknown depth, and you need to navigate it as such.

To find the top level assets you simply iterate response.Result.Assets, where response is the EveApiResponse.

foreach (AssetList.Asset asset in response.Result.Assets) {
// do work
}


edit:
Looking a the code now, it doesn't make sense to make a seperation between Item and Asset, as the only difference is that Asset has a LocationId while Item doesn't. I should probably just set LocationId to 0 for the top level types. Unless there's a reason I did it like this that I cannot remember.

Developer of EveLib and EveAuthUtility

Cryten Jones
Advantage Inc
#39 - 2014-05-08 14:57:17 UTC
So if I don't care about WHERE an item is but only how many I own and other things like singleton status etc will that get me everything or do I HAVE to itterate though

Are you a container > Yes> OK what do you have in you ?

All I am trying to get to is a dataTable that lists all the things that I own across all the characters.
Icahmura Hasaki
Perkone
Caldari State
#40 - 2014-05-08 15:01:17 UTC  |  Edited by: Icahmura Hasaki
All the data is in there, but you do have to iterate through to get it all. You can check if something contains something by checking if Items.Count == 0 or not, on any Item or Asset.

If you have previously done this in your own code, it's basically exactly the same structure, since it reflects the structure of the returned XML.

edit:
There are many ways to create a single flat list of the items. You can use a flatten function, or traverse the tree recursively or iteratively. I'll have to first take a look at the Asset and Item seperation now though, got me curious. If there's no reason to separate, I'll merge them. Hopefully it won't create problems for anyone :)

Developer of EveLib and EveAuthUtility