public static StarSystem StarSystemFromEDDP(dynamic json, decimal? x, decimal? y, decimal? z) { StarSystem StarSystem = new StarSystem(); StarSystem.name = (string)json["name"]; StarSystem.x = json["x"] == null ? x : (decimal?)json["x"]; StarSystem.y = json["y"] == null ? y : (decimal?)json["y"]; StarSystem.z = json["z"] == null ? y : (decimal?)json["z"]; if (json["is_populated"] != null) { // We have real data so populate the rest of the data StarSystem.EDDBID = (long)json["id"]; StarSystem.population = (long?)json["population"] == null ? 0 : (long?)json["population"]; StarSystem.allegiance = (string)json["allegiance"]; StarSystem.government = (string)json["government"]; StarSystem.faction = (string)json["faction"]; StarSystem.primaryeconomy = (string)json["primary_economy"]; StarSystem.state = (string)json["state"] == "None" ? null : (string)json["state"]; StarSystem.security = (string)json["security"]; StarSystem.power = (string)json["power"] == "None" ? null : (string)json["power"]; StarSystem.powerstate = (string)json["power_state"]; StarSystem.stations = StationsFromEDDP(StarSystem.name, json); } StarSystem.lastupdated = DateTime.Now; return StarSystem; }
public StarSystem GetOrCreateStarSystem(string name, bool fetchIfMissing = true) { StarSystem system = GetStarSystem(name, fetchIfMissing); if (system == null) { if (fetchIfMissing) { system = DataProviderService.GetSystemData(name, null, null, null); } if (system == null) { system = new StarSystem(); system.name = name; } if (system.lastvisit == null) { system.lastvisit = DateTime.Now; } insertStarSystem(system); } return system; }
private void setSystemDistanceFromHome(StarSystem system) { Logging.Info("HomeStarSystem is " + (HomeStarSystem == null ? null : HomeStarSystem.name)); if (HomeStarSystem != null && HomeStarSystem.x != null && system.x != null) { system.distancefromhome = (decimal)Math.Round(Math.Sqrt(Math.Pow((double)(system.x - HomeStarSystem.x), 2) + Math.Pow((double)(system.y - HomeStarSystem.y), 2) + Math.Pow((double)(system.z - HomeStarSystem.z), 2)), 2); Logging.Info("Distance from home is " + system.distancefromhome); } }
private void updateCurrentSystem(string name) { if (name == null) { return; } if (CurrentStarSystem == null || CurrentStarSystem.name != name) { LastStarSystem = CurrentStarSystem; CurrentStarSystem = StarSystemSqLiteRepository.Instance.GetOrCreateStarSystem(name); setSystemDistanceFromHome(CurrentStarSystem); } }
private void updateStarSystem(StarSystem system) { using (var con = SimpleDbConnection()) { con.Open(); using (var cmd = new SQLiteCommand(con)) { cmd.CommandText = UPDATE_SQL; cmd.Prepare(); cmd.Parameters.AddWithValue("@totalvisits", system.visits); cmd.Parameters.AddWithValue("@lastvisit", system.lastvisit); cmd.Parameters.AddWithValue("@starsystem", JsonConvert.SerializeObject(system)); cmd.Parameters.AddWithValue("@starsystemlastupdated", system.lastupdated); cmd.Parameters.AddWithValue("@name", system.name); cmd.ExecuteNonQuery(); } con.Close(); } }
public void SaveStarSystem(StarSystem starSystem) { if (GetStarSystem(starSystem.name) == null) { insertStarSystem(starSystem); } else { updateStarSystem(starSystem); } }
private static void setStarSystemValues(StarSystem system, string prefix, ref dynamic vaProxy) { Logging.Debug("Setting system information (" + prefix + ")"); try { vaProxy.SetText(prefix + " name", system == null ? null : system.name); vaProxy.SetText(prefix + " name (spoken)", system == null ? null : Translations.StarSystem(system.name)); vaProxy.SetDecimal(prefix + " population", system == null ? null : (decimal?)system.population); vaProxy.SetText(prefix + " population (spoken)", system == null ? null : Translations.Humanize(system.population)); vaProxy.SetText(prefix + " allegiance", system == null ? null : system.allegiance); vaProxy.SetText(prefix + " government", system == null ? null : system.government); vaProxy.SetText(prefix + " faction", system == null ? null : system.faction); vaProxy.SetText(prefix + " primary economy", system == null ? null : system.primaryeconomy); vaProxy.SetText(prefix + " state", system == null ? null : system.state); vaProxy.SetText(prefix + " security", system == null ? null : system.security); vaProxy.SetText(prefix + " power", system == null ? null : system.power); vaProxy.SetText(prefix + " power (spoken)", EDDI.Instance.CurrentStarSystem == null ? null : Translations.Power(EDDI.Instance.CurrentStarSystem.power)); vaProxy.SetText(prefix + " power state", system == null ? null : system.powerstate); vaProxy.SetDecimal(prefix + " X", system == null ? null : system.x); vaProxy.SetDecimal(prefix + " Y", system == null ? null : system.y); vaProxy.SetDecimal(prefix + " Z", system == null ? null : system.z); vaProxy.SetInt(prefix + " visits", system == null ? (int?)null : system.visits); vaProxy.SetText(prefix + " comment", system == null ? null : system.comment); vaProxy.SetDecimal(prefix + " distance from home", system == null ? null : system.distancefromhome); if (system != null) { foreach (Station Station in system.stations) { vaProxy.SetText(prefix + " station name", Station.name); } vaProxy.SetInt(prefix + " stations", system.stations.Count); vaProxy.SetInt(prefix + " orbital stations", system.stations.Count(s => !s.IsPlanetary())); vaProxy.SetInt(prefix + " starports", system.stations.Count(s => s.IsStarport())); vaProxy.SetInt(prefix + " outposts", system.stations.Count(s => s.IsOutpost())); vaProxy.SetInt(prefix + " planetary stations", system.stations.Count(s => s.IsPlanetary())); vaProxy.SetInt(prefix + " planetary outposts", system.stations.Count(s => s.IsPlanetaryOutpost())); vaProxy.SetInt(prefix + " planetary ports", system.stations.Count(s => s.IsPlanetaryPort())); } setStatus(ref vaProxy, "Operational"); } catch (Exception e) { setStatus(ref vaProxy, "Failed to set system information", e); } Logging.Debug("Set system information (" + prefix + ")"); }