private async Task LoadRacesAndBloodlines() { UniverseApi api = new UniverseApi(); if (mBloodlines.Count == 0) { List <GetUniverseBloodlines200Ok> bloodlines = await api.GetUniverseBloodlinesAsync( datasource : ESIConfiguration.DataSource); foreach (var i in bloodlines) { mBloodlines.Add(i.BloodlineId.Value, i.Name); } } if (mRaces.Count == 0) { List <GetUniverseRaces200Ok> races = await api.GetUniverseRacesAsync( datasource : ESIConfiguration.DataSource); foreach (var i in races) { mRaces.Add(i.RaceId.Value, i.Name); } } }
private static void LookupByIDAndType(List <EntityInfo> workinglist, List <EntityInfo> createdlist) { RemoveMailingListIds(workinglist); if (workinglist.Count == 0) { return; } UniverseApi api = new UniverseApi(); Queue <List <int?> > queue = new Queue <List <int?> >(); queue.Enqueue(new List <int?>(from x in workinglist where x.EntityType != EntityType.Mailinglist select(int?) x.EntityID)); while (queue.Count > 0) { var idlist = queue.Dequeue(); if (PerformLookup(workinglist, idlist, api, createdlist)) { continue; } if (idlist.Count == 1) { RegisterMailingList(idlist[0].Value); continue; } int halfpoint = idlist.Count / 2; if (halfpoint > 0) { queue.Enqueue(idlist.GetRange(0, halfpoint)); } queue.Enqueue(idlist.GetRange(halfpoint, idlist.Count - halfpoint)); } }
public UniversesController() { _universesApi = new UniverseApi(); }
private static void GetDockableData(long itemID) { if (resolvedDockables.ContainsKey(itemID)) { DockableInstance resolvedDockable = resolvedDockables[itemID]; if (!(DateTime.Now > resolvedDockable.CacheExpires)) { return; } } UniverseApi API = new UniverseApi(); if (API == null) { // TODO - Decide on an error handling strategy; do we warn the user or just log it? return; } ApiResponse <GetUniverseStationsStationIdOk> Station = null; ApiResponse <GetUniverseStructuresStructureIdOk> Structure = null; try { try { //lets try resolving it as a station int stationID = Convert.ToInt32(itemID); Station = API.GetUniverseStationsStationIdWithHttpInfo(stationID); } catch (OverflowException) { string token = Environment.GetEnvironmentVariable("EVEMON_ACCESS_KEY"); if (token == null) { throw new ApplicationException("you need to set the EVEMON_ACCESS_KEY env var or I can't make authed calls :CCCCCCC"); } Configuration.Default.AccessToken = token; //it's too big for an int32, it must be a structure //we need error handling for failed auth here Structure = API.GetUniverseStructuresStructureIdWithHttpInfo(itemID); } } catch (ApiException) { // TODO - Perform relevant logging operations return; } if (Station != null) { //Station.Data.SystemId is not optional, not sure why it's a nullable int in the autogenerated client resolvedDockables[itemID] = new DockableInstance(itemID, Station.Data.Name, Station.Data.SystemId.Value, ExtractCacheExpires(Station.Headers)); } else if (Structure != null) { resolvedDockables[itemID] = new DockableInstance(itemID, Structure.Data.Name, Structure.Data.SolarSystemId.Value, ExtractCacheExpires(Structure.Headers)); } else { // TODO - Perform relevant logging operations return; } }
private static bool PerformLookup(List <EntityInfo> workinglist, List <int?> idlist, UniverseApi api, List <EntityInfo> createdlist) { List <PostUniverseNames200Ok> names; try { names = api.PostUniverseNames(idlist); } catch (Eve.Api.Client.ApiException e) { if (e.ErrorCode == 404) { return(false); } throw; } foreach (var i in names) { var info = workinglist.Find((j) => i.Id.Value == j.EntityID); EntityType type = EntityType.Alliance; switch (i.Category ?? PostUniverseNames200Ok.CategoryEnum.Station) { case PostUniverseNames200Ok.CategoryEnum.Alliance: type = EntityType.Alliance; break; case PostUniverseNames200Ok.CategoryEnum.Corporation: type = EntityType.Corporation; break; case PostUniverseNames200Ok.CategoryEnum.Character: type = EntityType.Character; break; default: continue; } info.Name = i.Name; info.EntityType = type; workinglist.Remove(info); info.OnFinished(true); createdlist.Add(info); } return(true); }
public static void Initialize(EveVoidContext context) { var universeApi = new UniverseApi(); context.Database.Migrate(); //context.Database.EnsureCreated(); var path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"Data/combine.json"); //_logger.Info("Combine Path: " + path); var jsonText = File.ReadAllText(path); //_logger.Info("Combine jsonText: " + jsonText); var json = JsonConvert.DeserializeObject <CombineDump>(jsonText); if (!context.Regions.Any()) { var addList = new List <Region>(); addList.AddRange(json.regions.Select(x => new Region { Id = int.Parse(x.Key), Name = x.Value.name })); var regionIdList = universeApi.GetUniverseRegions(null, null); var jsonRegionIds = json.regions.Select(j => int.Parse(j.Key)).ToHashSet(); foreach (var missingRegion in regionIdList.Where(r => !jsonRegionIds.Contains(r.GetValueOrDefault()))) { if (missingRegion == null) { continue; } var esiRegion = universeApi.GetUniverseRegionsRegionId(missingRegion.Value, "en-us", null, null, "en-us"); addList.Add(new Region { Id = esiRegion.RegionId.Value, Name = esiRegion.Name, }); } context.Regions.AddRange(addList); context.SaveChanges(); } var systemTypes = json.wormholes.Select(x => x.Value.leadsTo).Distinct().ToList(); if (context.SystemTypes.FirstOrDefault(x => x.Name == "Unknown") == null) { context.SystemTypes.AddRange(systemTypes.Select(s => new SystemType { Name = s, Color = SystemTypeColor(s) })); context.SystemTypes.Add(new SystemType { Name = "Unknown", Color = SystemTypeColor("Unknown") }); context.SaveChanges(); } if (context.WormholeTypes.FirstOrDefault(x => x.Name == "????") == null) { context.WormholeTypes.Add(new WormholeType { Name = "????", LeadsTo = context.SystemTypes.FirstOrDefault(s => s.Name == "Unknown"), MaxMass = 2000000000, MaxJump = 300000000, Duration = "24 Hours" }); context.WormholeTypes.Add(new WormholeType { Name = "K162", LeadsTo = context.SystemTypes.FirstOrDefault(s => s.Name == "Unknown"), MaxMass = 2000000000, MaxJump = 300000000, Duration = "24 Hours" }); context.WormholeTypes.AddRange(json.wormholes.Select(x => new WormholeType { Name = x.Key, LeadsTo = context.SystemTypes.FirstOrDefault(s => s.Name == x.Value.leadsTo), MaxMass = x.Value.mass, MaxJump = x.Value.jump, Duration = x.Value.life })); context.SaveChanges(); } if (!context.Constellations.Any()) { var addList = new List <Constellation>(); var constellationIdList = universeApi.GetUniverseConstellations(null, null); foreach (var constellationId in constellationIdList) { if (constellationId == null) { continue; } addList.Add(new Constellation { Id = constellationId.Value, Name = "Temp", RegionId = context.Regions.First().Id, LastUpdate = DateTime.Now.AddDays(-2) }); } context.Constellations.AddRange(addList); context.SaveChanges(); } if (!context.SolarSystems.Any()) { context.SolarSystems.AddRange(json.systems.Select(x => new SolarSystem { Id = int.Parse(x.Key), Name = x.Value.name, Security = x.Value.security == null ? 0 : double.Parse(x.Value.security), Class = x.Value.wClass == null ? 0 : int.Parse(x.Value.wClass), SystemEffect = x.Value.effect, Statics = x.Value.statics?.Select(s => new WormholeStatic { SystemId = int.Parse(x.Key), WormholeTypeId = context.WormholeTypes.FirstOrDefault(e => e.Name == s).Id }).ToList(), SystemTypeId = context.SystemTypes.FirstOrDefault(e => e.Name == getSystemTypeForCombine(x.Value)).Id, ConstellationId = int.Parse(x.Value.constellationID) })); context.SaveChanges(); context.Database.ExecuteSqlRaw(@"update SolarSystems set systemTypeId = (select id from systemTypes where name like 'Trig') where id in (30000021,30000157,30000192,30000206,30001372,30001381,30001413,30001445,30002079,30002225,30002411,30002652,30002702,30002737,30002770,30002797,30003046,30003495, 30003504,30005005,30005029,30010141,30020141,30031392,30040141,30045328,30045329)"); context.Database.ExecuteSqlRaw(@"update SolarSystems set LastUpdate = '2020-01-01' where id in (30000021,30000157,30000192,30000206,30001372,30001381,30001413,30001445,30002079,30002225,30002411,30002652,30002702,30002737,30002770,30002797,30003046,30003495, 30003504,30005005,30005029,30010141,30020141,30031392,30040141,30045328,30045329)"); } if (!context.Stargates.Any()) { context.Stargates.AddRange(json.stargates.Select(x => new Stargate { Id = int.Parse(x.Key), SystemId = x.Value.systemId })); context.SaveChanges(); var stargates = context.Stargates.ToDictionary(x => x.Id, x => x); foreach (var stargate in json.stargates) { stargates[int.Parse(stargate.Key)].DestinationId = stargate.Value.destinationId; } context.SaveChanges(); context.Database.ExecuteSqlRaw(@"delete Stargates where DestinationId in ( select id from Stargates where systemid in (30000021,30000157,30000192,30000206,30001372,30001381,30001413,30001445,30002079,30002225,30002411,30002652,30002702,30002737,30002770,30002797,30003046,30003495, 30003504,30005005,30005029,30010141,30020141,30031392,30040141,30045328,30045329)) or id in (select id from Stargates where systemid in (30000021,30000157,30000192,30000206,30001372,30001381,30001413,30001445,30002079,30002225,30002411,30002652,30002702,30002737,30002770,30002797,30003046,30003495, 30003504,30005005,30005029,30010141,30020141,30031392,30040141,30045328,30045329))"); } if (!context.AdjacencyMatrix.Any()) { var systems = context.SolarSystems.ToList(); var matrix = new Dictionary <int, Dictionary <int, int> >(); foreach (var system in systems) { var maskId = -1; var adjs = system.GetConnections(maskId, true).Select(x => x.SolarSystem); foreach (var adj in adjs) { context.AdjacencyMatrix.Add(new AdjacencyMatrix { RowNumber = system.Id, ColumnNumber = adj.Id, Distance = system.Security < 0.5 || adj.Security < 0.5 ? 100 : 1, MaskId = maskId }); } } context.SaveChanges(); context.Database.ExecuteSqlRaw(@"delete [EveVoid].[dbo].[AdjacencyMatrix] where RowNumber in (30000021,30000157,30000192,30000206,30001372,30001381,30001413,30001445,30002079,30002225,30002411,30002652,30002702,30002737,30002770,30002797,30003046,30003495, 30003504,30005005,30005029,30010141,30020141,30031392,30040141,30045328,30045329) or ColumnNumber in (30000021,30000157,30000192,30000206,30001372,30001381,30001413,30001445,30002079,30002225,30002411,30002652,30002702,30002737,30002770,30002797,30003046,30003495, 30003504,30005005,30005029,30010141,30020141,30031392,30040141,30045328,30045329)"); _logger.Info("Seeded Adjacency"); } //var _universeApi = new UniverseApi(); //var index = 1; //foreach (var systemId in json.systems.Keys) //{ // var didTimeout = true; // while (didTimeout) // { // try { // _logger.Info(index++ + "/" + json.systems.Count); // var esiResult = _universeApi.GetUniverseSystemsSystemId(int.Parse(systemId), "en-us", null, null, "en-us"); // if (esiResult.Stargates != null) // { // foreach (var gateId in esiResult.Stargates) // { // if (gateId.HasValue) // { // var gate = context.Stargates.FirstOrDefault(x => x.Id == gateId); // if (gate == null) // { // var esiResult2 = _universeApi.GetUniverseStargatesStargateId(gateId, null, null); // var desto = new Stargate // { // Id = esiResult2.Destination.StargateId.Value, // SystemId = esiResult2.Destination.SystemId.Value, // }; // context.Stargates.Add(desto); // gate = new Stargate // { // Id = gateId.Value, // SystemId = esiResult2.SystemId.Value, // }; // context.Stargates.Add(gate); // context.SaveChanges(); // desto.DestinationId = gate.Id; // gate.DestinationId = desto.Id; // context.SaveChanges(); // } // } // } // } // didTimeout = false; // } // catch(Exception e) // { // if (!e.Message.Contains("timeout")) // { // didTimeout = false; // } // } // } //} }