public static EDSMResponse <Ranks> Convert(this JSONRanks c, int?htmlStatus, string htmlStatusMessage) { var wrapper = new EDSMResponse <Ranks> { HTMLStatus = htmlStatus ?? -1, HTMLStatusResponse = htmlStatusMessage }; if (c == null) { wrapper.MessageNumber = 1; wrapper.Message = "API returned an empty object. This is unusual."; return(wrapper); } Ranks ranks = ParseRanks(); if (ranks != null) { wrapper.Message = c.msg; wrapper.MessageNumber = c.msgnum ?? -1; wrapper.Data = ranks; return(wrapper); } // Workaround for a bug in the EDSM Api. Refer to https://github.com/EDSM-NET/FrontEnd/issues/322 wrapper.MessageNumber = (c.msgnum == 201 || c.msgnum == 203) ? c.msgnum ?? -1 : 207; wrapper.Message = (c.msgnum == 201 || c.msgnum == 203) ? htmlStatusMessage : "Commander name not found. CMDR might not exist or has their profile set to private"; return(wrapper); Ranks ParseRanks() { if (c == null) { return(null); } if (c.ranks == null) { return(null); } return(new Ranks { Combat = (Combat)c.ranks.Combat, Trade = (Trade)c.ranks.Trade, Explore = (Explore)c.ranks.Explore, Federation = (Federation)c.ranks.Federation, Imperial = (Empire)c.ranks.Empire, Progress = c.progress }); } }
public static EDSMResponse <InProximity> Convert(this InProximityJSONEntry[] json, int?HTMLStatus, string HTMLStatusMessage) { var wrapper = new EDSMResponse <InProximity> { HTMLStatus = HTMLStatus ?? -1, HTMLStatusResponse = HTMLStatusMessage }; if (json == null) { wrapper.Message = "API responded with an empty object. This probably means that the system does not exist"; wrapper.MessageNumber = 1; wrapper.Data = null; return(wrapper); } if (json.Length == 0) { wrapper.Message = "API responded with an empty array. This probably means that there are no known systems in the vicinity or said system does not exist."; wrapper.MessageNumber = 3; return(wrapper); } var data = new InProximity { entries = GenerateEntries() }; wrapper.Data = data; wrapper.Message = null; wrapper.MessageNumber = -1; return(wrapper); InProximityEntry[] GenerateEntries() { var entries = new InProximityEntry[json.Length]; for (int i = 0; i < json.Length; i++) { var entry = json[i]; var converted = new InProximityEntry { Distance = entry.distance ?? -1, Name = entry.name, PermitName = entry.permitName, NeedsPermit = entry.requirePermit }; entries[i] = converted; } return(entries); } }
public static EDSMResponse <StarSystem> Convert(this SystemJSON json, int?HTMLStatus, string HTMLStatusMessage) { var wrapper = new EDSMResponse <StarSystem> { HTMLStatus = HTMLStatus ?? -1, HTMLStatusResponse = HTMLStatusMessage }; if (json == null) { wrapper.Message = "Empty response. This probably means that EDSM could not find said System."; wrapper.MessageNumber = 1; return(wrapper); } var returnObj = new StarSystem { Id = (uint?)json.id ?? 0, Name = json.name, PermitName = json.permitName }; if (json.coords != null) { returnObj.Coordinate = new Orcabot.Types.Coordinate { X = json.coords.x, Y = json.coords.y, Z = json.coords.z }; } if (json.primaryStar != null) { returnObj.IsScoopable = json.primaryStar.isScoopable; } if (json.information != null) { var info = json.information; returnObj.ControllingFactionName = info.faction; returnObj.ControllingFactionState = info.factionState; returnObj.Population = (ulong?)info.population ?? 0; returnObj.Security = GetSecurityFromEDSMString(info.security); returnObj.Economy = GetEconomyFromEDSMString(info.economy); } wrapper.Data = returnObj; return(wrapper); }
public static EDSMResponse <Position> Convert(this JSONPosition position, int?HttpResponse, string HttpResponseMessage) { var wrapper = new EDSMResponse <Position> { HTMLStatus = HttpResponse ?? -1, HTMLStatusResponse = HttpResponseMessage }; if (position == null) { // Workaround for a bug in the EDSM Api. Refer to https://github.com/EDSM-NET/FrontEnd/issues/322 wrapper.Data = null; wrapper.MessageNumber = HttpResponse ?? 203; wrapper.Message = HttpResponseMessage ?? "Commander name not found. CMDR might not exist or has their profile set to private"; return(wrapper); } if (position.coordinates == null) { // Workaround for a bug in the EDSM Api. Refer to https://github.com/EDSM-NET/FrontEnd/issues/322 wrapper.MessageNumber = (position.msgnum == 201)? 201 : 203; wrapper.Message = (position.msgnum == 201) ? HttpResponseMessage : "Commander name not found. CMDR might not exist or has their profile set to private"; wrapper.Data = null; return(wrapper); } Position data = new Position { Coordinates = position.coordinates, Time = DateTime.ParseExact(position.date, "yyyy-MM-dd HH:mm:ss", null), SystemName = position.system }; wrapper.Message = position.msg; wrapper.MessageNumber = position.msgnum ?? -1; wrapper.Data = data; return(wrapper); }