public ISystem FindSystem(string name, EDSM.GalacticMapping glist = null) // in system or name { ISystem ds1 = SystemCache.FindSystem(name); // now go thru the cache.. if (ds1 == null) { HistoryEntry vs = FindByName(name); if (vs != null) { ds1 = vs.System; } else if (glist != null) { EDSM.GalacticMapObject gmo = glist.Find(name, true, true); if (gmo != null && gmo.points.Count > 0) { ds1 = SystemClassDB.GetSystem(gmo.galMapSearch); if (ds1 != null) { return(new EDSM.GalacticMapSystem(ds1, gmo)); } else { return(new EDSM.GalacticMapSystem(gmo)); } } } } return(ds1); }
// Runs as a thread. private void ViewPushedSystems() { try { pushed = edsm.GetPushedSystems(); foreach (String system in pushed) { SystemClassDB star = SystemClassDB.GetSystem(system); if (star == null) { star = new SystemClassDB(system); } this.BeginInvoke(new MethodInvoker(() => { var index = dataGridViewClosestSystems.Rows.Add("EDSM"); dataGridViewClosestSystems[1, index].Value = system; dataGridViewClosestSystems[1, index].Tag = star; })); } } catch (Exception ex) { this.BeginInvoke(new MethodInvoker(() => { LogTextHighlight("ViewPushedSystems Exception:" + ex.Message); LogText(ex.StackTrace); })); } }
public ISystem PosAlongRoute(double percentage) // go along route and give me a co-ord along it.. { double dist = CumulativeDistance() * percentage / 100.0; ISystem last = null; for (int i = 0; i < Systems.Count; i++) { ISystem s = SystemClassDB.GetSystem(Systems[i]); if (s != null) { if (last != null) { double d = s.Distance(last); if (dist < d) { d = dist / d; return(new SystemClass("WP" + (i).ToString() + "-" + "WP" + (i + 1).ToString() + "-" + d.ToString("#.00"), last.X + (s.X - last.X) * d, last.Y + (s.Y - last.Y) * d, last.Z + (s.Z - last.Z) * d)); } dist -= d; } last = s; } } return(last); }
private void editBookmarkToolStripMenuItem_Click(object sender, EventArgs e) { int[] selectedRows = dataGridViewExplore.SelectedCells.OfType <DataGridViewCell>().Where(c => c.RowIndex != dataGridViewExplore.NewRowIndex).Select(c => c.RowIndex).OrderBy(v => v).Distinct().ToArray(); if (selectedRows.Length == 0) { return; } var obj = dataGridViewExplore[0, selectedRows[0]].Value; if (obj == null) { return; } ISystem sc = SystemClassDB.GetSystem((string)obj); if (sc == null) { ExtendedControls.MessageBoxTheme.Show(FindForm(), "Unknown system, system is without co-ordinates", "Edit bookmark", MessageBoxButtons.OK); } else { TargetHelpers.showBookmarkForm(this, discoveryform, sc, null, false); } }
public void InitSettingsTab() { checkBoxEDSMLog.Checked = EDDiscoveryForm.EDDConfig.EDSMLog; checkBoxOrderRowsInverted.Checked = EDDiscoveryForm.EDDConfig.OrderRowsInverted; checkBoxMinimizeToNotifyIcon.Checked = EDDiscoveryForm.EDDConfig.MinimizeToNotifyIcon; checkBoxKeepOnTop.Checked = EDDiscoveryForm.EDDConfig.KeepOnTop; checkBoxUseNotifyIcon.Checked = EDDiscoveryForm.EDDConfig.UseNotifyIcon; checkBoxUTC.Checked = EDDiscoveryForm.EDDConfig.DisplayUTC; checkBoxAutoLoad.Checked = EDDiscoveryForm.EDDConfig.AutoLoadPopOuts; checkBoxAutoSave.Checked = EDDiscoveryForm.EDDConfig.AutoSavePopOuts; checkBoxMinimizeToNotifyIcon.Enabled = EDDiscoveryForm.EDDConfig.UseNotifyIcon; HomeSystem = SystemClassDB.GetSystem(SQLiteDBClass.GetSettingString("DefaultMapCenter", "Sol")); textBoxDefaultZoom.Text = SQLiteDBClass.GetSettingDouble("DefaultMapZoom", 1.0).ToString(); bool selectionCentre = SQLiteDBClass.GetSettingBool("CentreMapOnSelection", true); radioButtonHistorySelection.Checked = selectionCentre; radioButtonCentreHome.Checked = !selectionCentre; dataGridViewCommanders.AutoGenerateColumns = false; // BEFORE assigned to list.. dataGridViewCommanders.DataSource = EDCommander.GetList(); panel_defaultmapcolor.BackColor = Color.FromArgb(EDDConfig.Instance.DefaultMapColour); this.comboBoxTheme.SelectedIndexChanged += this.comboBoxTheme_SelectedIndexChanged; // now turn on the handler.. }
private void textBoxHomeSystem_Validated(object sender, EventArgs e) { if (!string.IsNullOrWhiteSpace(textBoxHomeSystem.Text)) { HomeSystem = SystemClassDB.GetSystem(textBoxHomeSystem.Text); } }
private void textBoxName_Validated(object sender, EventArgs e) { if (!freeSystemEntry) { return; } string t = textBoxName.Text.Trim(); ISystem s = SystemClassDB.GetSystem(t); if (s != null) { var edsm = new EDSMClass(); edsmurl = edsm.GetUrlToEDSMSystem(t); userControlSurfaceBookmarks1.NewForSystem(t); SystemNoteClass sn = SystemNoteClass.GetNoteOnSystem(t); textBoxNotes.Text = (sn != null) ? sn.Note : ""; InitialisePos(s); buttonOK.Enabled = true; labelBadSystem.Text = ""; } else { buttonOK.Enabled = false; textBoxName.SelectAll(); labelBadSystem.Text = "System name not recognised"; } }
public void AddWantedSystem(string sysName) { if (wanted == null) { PopulateLocalWantedSystems(); } WantedSystemClass entry = wanted.Where(x => x.system == sysName).FirstOrDefault(); //duplicate? if (entry == null) { WantedSystemClass toAdd = new WantedSystemClass(sysName); // make one.. toAdd.Add(); // add to db. wanted.Add(toAdd); SystemClassDB star = SystemClassDB.GetSystem(sysName); if (star == null) { star = new SystemClassDB(sysName); } var index = dataGridViewClosestSystems.Rows.Add("Local"); dataGridViewClosestSystems[1, index].Value = sysName; dataGridViewClosestSystems[1, index].Tag = star; } }
private void dataGridViewDistances_CellValidating(object sender, DataGridViewCellValidatingEventArgs e) { try { if (e.ColumnIndex == 0) { var value = e.FormattedValue.ToString(); var cell = dataGridViewDistances[e.ColumnIndex, e.RowIndex]; if (value == "" && (cell.Value == null || cell.Value.ToString() == "")) { return; } var system = SystemClassDB.GetSystem(value); var enteredSystems = GetEnteredSystems(); if (cell.Value != null) { enteredSystems.RemoveAll(s => s.name == cell.Value.ToString()); } if (system == null || (enteredSystems.Contains(system))) { return; } } if (e.ColumnIndex == 1) { var value = e.FormattedValue.ToString().Trim(); if (value == "") { dataGridViewDistances.Rows[e.RowIndex].ErrorText = null; return; } var parsed = DistanceParser.ParseInterstellarDistance(value); if (parsed.HasValue) { dataGridViewDistances.Rows[e.RowIndex].ErrorText = null; } else { e.Cancel = true; dataGridViewDistances.Rows[e.RowIndex].ErrorText = "Invalid number"; } } } catch (Exception ex) { this.BeginInvoke(new MethodInvoker(() => { LogTextHighlight("Exception:" + ex.Message); LogText(ex.StackTrace); })); } }
public void Update(BookmarkClass bk) // from multiple places, update this bookmark, region or system.. { string note = ""; string name; long? edsmid = null; if (!bk.isRegion) { ISystem s = SystemClassDB.GetSystem(bk.StarName); if (s != null) // paranoia { InitialisePos(s); edsmid = s.EDSMID; } else { InitialisePos(bk.x, bk.y, bk.z); } SystemNoteClass sn = SystemNoteClass.GetNoteOnSystem(bk.StarName); note = (sn != null) ? sn.Note : ""; name = bk.StarName; } else { // region, set position, set name InitialisePos(bk.x, bk.y, bk.z); name = bk.Heading; } this.Text = "Update Bookmark".Tx(this, "UB"); buttonOK.Text = "Update".Tx(this); textBoxName.Text = name; textBoxName.ReadOnly = !bk.isRegion; textBoxBookmarkNotes.Text = bk.Note; textBoxBookmarkNotes.CursorToEnd(); textBoxBookmarkNotes.ScrollToCaret(); textBoxTravelNote.Text = note; textBoxTime.Text = bk.Time.ToString(); checkBoxTarget.Checked = bk.id == TargetClass.GetTargetBookmark(); // who is the target of a bookmark (0=none) if (bk.isRegion) { HideEDSM(); HideTravelNote(); HideSurfaceBookmarks(); } else { var edsm = new EDSMClass(); edsmurl = edsm.GetUrlToEDSMSystem(name, edsmid); SurfaceBookmarks.Init(bk.StarName, bk.PlanetaryMarks); } buttonOK.Enabled = true; }
private ISystem GetSystem(string sysname) { ISystem sys = SystemClassDB.GetSystem(sysname); if (sys == null) { //if (edsm.IsKnownSystem(sysname)) //{ // sys = new SystemClass(sysname); //} } return(sys); }
private void deleteAllWithKnownPositionToolStripMenuItem_Click(object sender, EventArgs e) { List <string> edsmCheckNames = new List <string>(); List <string> removeNames = new List <string>(); string sysName = ""; for (int i = dataGridViewClosestSystems.RowCount - 1; i >= 0; i--) { DataGridViewRow r = dataGridViewClosestSystems.Rows[i]; sysName = r.Cells[1].Value.ToString(); if (r.Cells[0].Value.ToString() == "Local") { var sys = SystemClassDB.GetSystem(sysName); if (sys == null) { edsmCheckNames.Add(sysName); } else if (sys.HasCoordinate) { removeNames.Add(sysName); } } } if (edsmCheckNames.Count() > 0) { EDSMClass edsm = new EDSMClass(); List <string> nowKnown = edsm.CheckForNewCoordinates(edsmCheckNames); foreach (string s in nowKnown) { removeNames.Add(s); } } for (int i = dataGridViewClosestSystems.RowCount - 1; i >= 0; i--) { DataGridViewRow r = dataGridViewClosestSystems.Rows[i]; sysName = r.Cells[1].Value.ToString(); if (removeNames.Contains(sysName)) { WantedSystemClass entry = wanted.Where(x => x.system == sysName).FirstOrDefault(); if (entry != null) { entry.Delete(); dataGridViewClosestSystems.Rows.Remove(r); wanted.Remove(entry); } } } }
public override bool ExecuteAction(ActionProgramRun ap) { string res; if (ap.functions.ExpandString(UserData, out res) != Conditions.ConditionFunctions.ExpandResult.Failed) { StringParser sp = new StringParser(res); string prefix = "ST_"; string cmdname = sp.NextQuotedWord(); if (cmdname != null && cmdname.Equals("PREFIX", StringComparison.InvariantCultureIgnoreCase)) { prefix = sp.NextWord(); if (prefix == null) { ap.ReportError("Missing name after Prefix in Star"); return(true); } cmdname = sp.NextQuotedWord(); } if (cmdname != null) { ISystem sc = SystemClassDB.GetSystem(cmdname); ap[prefix + "Found"] = sc != null ? "1" : "0"; if (sc != null) { Conditions.ConditionVariables vars = new Conditions.ConditionVariables(); ActionVars.SystemVars(vars, sc, prefix); ap.Add(vars); ActionVars.SystemVarsFurtherInfo(ap, (ap.actioncontroller as ActionController).HistoryList, sc, prefix); } } else { ap.ReportError("Missing starname in Star"); } } else { ap.ReportError(res); } return(true); }
private void ValidateAndSaveHomeSystem() { string t = textBoxHomeSystem.Text.Trim(); ISystem s = SystemClassDB.GetSystem(t); if (s != null) { textBoxHomeSystem.Text = s.Name; EDDConfig.Instance.HomeSystem = s; } else { textBoxHomeSystem.Text = EDDConfig.Instance.HomeSystem.Name; } }
private void textBoxHomeSystem_Validated(object sender, EventArgs e) { string t = textBoxHomeSystem.Text.Trim(); ISystem s = SystemClassDB.GetSystem(t); if (s != null) { textBoxHomeSystem.Text = s.Name; EDDConfig.Instance.HomeSystem = s; } else { textBoxHomeSystem.Text = EDDConfig.Instance.HomeSystem.Name; } }
/* Tries to load the system data for the given name. If no system data is available, but the system is known, * it creates a new System entity, otherwise logs it and returns null. */ private SystemClassDB getSystemForTrilateration(string systemName) { var system = SystemClassDB.GetSystem(systemName); if (system == null) { if (!edsm.IsKnownSystem(systemName)) { LogTextHighlight("Only systems with coordinates or already known to EDSM can be added" + Environment.NewLine); } else { system = new SystemClassDB(systemName); } } return(system); }
public void NotedSystem(string name, string note, bool istarget) // from target, a system with notes { this.Text = "System Information".Tx(this, "SI"); ISystem s = SystemClassDB.GetSystem(name); textBoxName.Text = name; textBoxTravelNote.Text = (note != null) ? note : ""; checkBoxTarget.Checked = istarget; HideTime(); HideBookmarkNotes(); HideSurfaceBookmarks(); var edsm = new EDSMClass(); edsmurl = edsm.GetUrlToEDSMSystem(s?.Name ?? name, s?.EDSMID); }
/* Tries to load the system data for the given name. If no system data is available, but the system is known, * it creates a new System entity, otherwise logs it and returns null. */ private ISystem getSystemForTrilateration(string systemName, bool fromEDSM) { var system = SystemClassDB.GetSystem(systemName); if (system == null) { EDSMClass edsm = new EDSMClass(); if (fromEDSM || edsm.IsKnownSystem(systemName)) { system = new SystemClass(systemName); } else { LogTextHighlight("Only systems with coordinates or already known to EDSM can be added".Tx(this, "Co") + Environment.NewLine); } } return(system); }
private void checkForUnknownSystemsNowKnown() { for (int i = 0, count = dataGridViewDistances.Rows.Count - 1; i < count; i++) { var systemCell = dataGridViewDistances[0, i]; var oldSystem = (SystemClassDB)systemCell.Tag; if (!oldSystem.HasCoordinate) { var value = systemCell.Value as string; var newSystem = SystemClassDB.GetSystem(value); if (newSystem != null && newSystem.HasCoordinate) { systemCell.Tag = newSystem; dataGridViewDistances[3, i].Style.ForeColor = _discoveryForm.theme.VisitedSystemColor; dataGridViewDistances[3, i].Value = "Position found"; } } } }
private void dataGridViewRouteSystems_CellValidating(object sender, DataGridViewCellValidatingEventArgs e) { if (e.ColumnIndex == 0) { string sysname = e.FormattedValue.ToString(); var row = dataGridViewExplore.Rows[e.RowIndex]; var cell = dataGridViewExplore[e.ColumnIndex, e.RowIndex]; ISystem sys = SystemClassDB.GetSystem(sysname); if (sysname != "" && sys == null && !edsm.IsKnownSystem(sysname)) { row.ErrorText = "System not known to EDSM"; } else { row.ErrorText = ""; } } }
public double CumulativeDistance() { ISystem last = null; double distance = 0; for (int i = 0; i < Systems.Count; i++) { ISystem s = SystemClassDB.GetSystem(Systems[i]); if (s != null) { if (last != null) { distance += s.Distance(last); } last = s; } } return(distance); }
public void Update(BookmarkClass bk) { string note = ""; string name; if (!bk.isRegion) { SystemNoteClass sn = SystemNoteClass.GetNoteOnSystem(bk.StarName); ISystem s = SystemClassDB.GetSystem(bk.StarName); InitialisePos(s); note = (sn != null) ? sn.Note : ""; name = bk.StarName; } else { name = bk.Heading; } Update(name, note, bk.Note, bk.Time.ToString(), bk.isRegion, false, bk.PlanetaryMarks); userControlSurfaceBookmarks1.DisplayPlanetMarks(bk); buttonOK.Enabled = true; }
private void PopulateLocalWantedSystems() { wanted = WantedSystemClass.GetAllWantedSystems(); if (wanted != null && wanted.Any()) { foreach (WantedSystemClass sys in wanted) { SystemClass star = SystemClassDB.GetSystem(sys.system); if (star == null) { star = new SystemClassDB(sys.system); } var index = dataGridViewClosestSystems.Rows.Add("Local"); dataGridViewClosestSystems[1, index].Value = sys.system; dataGridViewClosestSystems[1, index].Tag = star; } } else { wanted = new List <WantedSystemClass>(); } }
public void AddWantedSystem(string sysName) { if (wanted == null) { PopulateLocalWantedSystems(); } else { // there can be multiple instances tied to the history form so this might already exist... List <WantedSystemClass> dbCheck = WantedSystemClass.GetAllWantedSystems(); if (dbCheck != null && dbCheck.Where(s => s.system == sysName).Any()) // if we have wanted systems in the DB... and its there.. { return; } } WantedSystemClass entry = wanted.Where(x => x.system == sysName).FirstOrDefault(); //duplicate? if (entry == null) { WantedSystemClass toAdd = new WantedSystemClass(sysName); // make one.. toAdd.Add(); // add to db. wanted.Add(toAdd); ISystem star = SystemClassDB.GetSystem(sysName); if (star == null) { star = new SystemClass(sysName); } var index = dataGridViewClosestSystems.Rows.Add("Local"); dataGridViewClosestSystems[1, index].Value = sysName; dataGridViewClosestSystems[1, index].Tag = star; } }
// given the system list, which is the next waypoint to go to. return the system (or null if not available or past end) and the waypoint.. (0 based) public Tuple <ISystem, int> ClosestTo(ISystem sys) { double dist = Double.MaxValue; ISystem found = null; int closest = -1; List <ISystem> list = new List <ISystem>(); for (int i = 0; i < Systems.Count; i++) { ISystem s = SystemClassDB.GetSystem(Systems[i]); if (s != null) { double sd = s.Distance(sys); if (sd < dist) { dist = sd; closest = i; found = s; } } list.Add(s); } if (found != null) { //System.Diagnostics.Debug.WriteLine("Found at " + closest + " System " + found.name + " " + found.x + " " + found.y + " " + found.z + " dist " + dist); if (closest > 0) { int lastentry = closest - 1; while (lastentry >= 0 && list[lastentry] == null) // go and find the last one which had a position.. { lastentry--; } if (lastentry >= 0 && list[lastentry] != null) // found it, so work out using distance if we are closest to last or past it { double distlasttoclosest = list[closest].Distance(list[lastentry]); // last->closest vs double distlasttocur = sys.Distance(list[lastentry]); // last->cur position if (distlasttocur > distlasttoclosest - 0.1) // past current because the distance last->cur > last->closest waypoint { return(new Tuple <ISystem, int>(closest < Systems.Count - 1 ? list[closest + 1] : null, closest + 1)); // en-route to this. may be null } else { return(new Tuple <ISystem, int>(found, closest)); // en-route to this } } } return(new Tuple <ISystem, int>(found, closest)); } else { return(null); } }
public override bool ExecuteAction(ActionProgramRun ap) { string res; if (ap.functions.ExpandString(UserData, out res) != Conditions.ConditionFunctions.ExpandResult.Failed) { StringParser sp = new StringParser(res); string prefix = "S_"; string cmdname = sp.NextQuotedWord(); if (cmdname != null && cmdname.Equals("PREFIX", StringComparison.InvariantCultureIgnoreCase)) { prefix = sp.NextWord(); if (prefix == null) { ap.ReportError("Missing name after Prefix in Scan"); return(true); } cmdname = sp.NextQuotedWord(); } bool edsm = false; if (cmdname != null && cmdname.Equals("EDSM", StringComparison.InvariantCultureIgnoreCase)) { edsm = true; cmdname = sp.NextQuotedWord(); } if (cmdname != null) { StarScan scan = (ap.actioncontroller as ActionController).HistoryList.starscan; ISystem sc = SystemClassDB.GetSystem(cmdname); if (sc == null) { sc = new SystemClass(cmdname); sc.EDSMID = 0; } StarScan.SystemNode sn = scan.FindSystem(sc, edsm); System.Globalization.CultureInfo ct = System.Globalization.CultureInfo.InvariantCulture; if (sn != null) { int starno = 1; ap[prefix + "Stars"] = sn.starnodes.Count.ToString(ct); foreach (KeyValuePair <string, StarScan.ScanNode> scannode in sn.starnodes) { DumpInfo(ap, scannode, prefix + "Star_" + starno.ToString(ct), "_Planets"); int pcount = 1; if (scannode.Value.children != null) { foreach (KeyValuePair <string, StarScan.ScanNode> planetnodes in scannode.Value.children) { DumpInfo(ap, planetnodes, prefix + "Planet_" + starno.ToString(ct) + "_" + pcount.ToString(ct), "_Moons"); if (planetnodes.Value.children != null) { int mcount = 1; foreach (KeyValuePair <string, StarScan.ScanNode> moonnodes in planetnodes.Value.children) { DumpInfo(ap, moonnodes, prefix + "Moon_" + starno.ToString(ct) + "_" + pcount.ToString(ct) + "_" + mcount.ToString(ct), "_Submoons"); if (moonnodes.Value.children != null) { int smcount = 1; foreach (KeyValuePair <string, StarScan.ScanNode> submoonnodes in moonnodes.Value.children) { DumpInfo(ap, submoonnodes, prefix + "SubMoon_" + starno.ToString(ct) + "_" + pcount.ToString(ct) + "_" + mcount.ToString(ct) + "_" + smcount.ToString(ct), null); smcount++; } } mcount++; } } pcount++; } } starno++; } } else { ap[prefix + "Stars"] = "0"; } } else { ap.ReportError("Missing starname in Scan"); } } else { ap.ReportError(res); } return(true); }
public int GetLogs(DateTime?starttimeutc, DateTime?endtimeutc, out List <HistoryEntry> log, out DateTime logstarttime, out DateTime logendtime) { log = new List <HistoryEntry>(); logstarttime = DateTime.MaxValue; logendtime = DateTime.MinValue; if (!IsApiKeySet) { return(0); } string query = "get-logs?showId=1&apiKey=" + apiKey + "&commanderName=" + HttpUtility.UrlEncode(commanderName); if (starttimeutc != null) { query += "&startDateTime=" + HttpUtility.UrlEncode(starttimeutc.Value.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture)); } if (endtimeutc != null) { query += "&endDateTime=" + HttpUtility.UrlEncode(endtimeutc.Value.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture)); } var response = RequestGet("api-logs-v1/" + query, handleException: true); if (response.Error) { return(0); } var json = response.Body; if (json == null) { return(0); } JObject msg = JObject.Parse(json); int msgnr = msg["msgnum"].Int(0); JArray logs = (JArray)msg["logs"]; if (logs != null) { string startdatestr = msg["startDateTime"].Value <string>(); string enddatestr = msg["endDateTime"].Value <string>(); if (startdatestr == null || !DateTime.TryParseExact(startdatestr, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal, out logstarttime)) { logstarttime = DateTime.MaxValue; } if (enddatestr == null || !DateTime.TryParseExact(enddatestr, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal, out logendtime)) { logendtime = DateTime.MinValue; } using (SQLiteConnectionSystem cn = new SQLiteConnectionSystem()) { foreach (JObject jo in logs) { string name = jo["system"].Value <string>(); string ts = jo["date"].Value <string>(); long id = jo["systemId"].Value <long>(); bool firstdiscover = jo["firstDiscover"].Value <bool>(); DateTime etutc = DateTime.ParseExact(ts, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal | DateTimeStyles.AssumeUniversal); // UTC time SystemClass sc = SystemClassDB.GetSystem(id, cn, SystemClassDB.SystemIDType.EdsmId); if (sc == null) { sc = new SystemClassDB(name) { id_edsm = id } } ; HistoryEntry he = HistoryEntry.MakeVSEntry(sc, etutc, EliteConfigInstance.InstanceConfig.DefaultMapColour, "", "", firstdiscover: firstdiscover); // FSD jump entry log.Add(he); } } } return(msgnr); }
private void updateScreen() { if (currentSystem == null) { return; } if (_currentRoute == null) { DisplayText("Please set a route, by right clicking", ""); return; } if (_currentRoute.Systems.Count == 0) { DisplayText(_currentRoute.Name, "Route contains no waypoints"); return; } string topline = ""; string bottomLine = ""; string firstSystemName = _currentRoute.Systems[0]; SystemClassDB firstSystem = SystemClassDB.GetSystem(firstSystemName); SystemClassDB finalSystem = SystemClassDB.GetSystem(_currentRoute.Systems[_currentRoute.Systems.Count - 1]); if (finalSystem != null) { string mesg = "remain"; double distX = SystemClassDB.Distance(currentSystem.System, finalSystem); //Small hack to pull the jump range from TripPanel1 var jumpRange = SQLiteDBClass.GetSettingDouble("TripPanel1" + "JumpRange", -1.0); if (jumpRange > 0) { int jumps = (int)Math.Ceiling(distX / jumpRange); if (jumps > 0) { mesg = "@ " + jumps.ToString() + ((jumps == 1) ? " jump" : " jumps"); } } topline = String.Format("{0} {1} WPs {2:N2}ly {3}", _currentRoute.Name, _currentRoute.Systems.Count, distX, mesg); } else { topline = String.Format("{0} {1} WPs remain", _currentRoute.Name, _currentRoute.Systems.Count); } SystemClassDB nearestSystem = null; double minDist = double.MaxValue; int nearestidx = -1; for (int i = 0; i < _currentRoute.Systems.Count; i++) { String sys = _currentRoute.Systems[i]; SystemClassDB sc = SystemClassDB.GetSystem(sys); if (sc == null) { continue; } double dist = SystemClassDB.Distance(currentSystem.System, sc); if (dist <= minDist) { if (nearestSystem == null || !nearestSystem.name.Equals(sc.name)) { minDist = dist; nearestidx = i; nearestSystem = sc; } } } string name = null; if (nearestSystem != null && firstSystem != null) { double first2Neasest = SystemClassDB.Distance(firstSystem, nearestSystem); double first2Me = SystemClassDB.Distance(firstSystem, currentSystem.System); string nextName = null; int wp = nearestidx + 1; if (nearestidx < _currentRoute.Systems.Count - 1) { nextName = _currentRoute.Systems[nearestidx + 1]; } if (first2Me >= first2Neasest && !String.IsNullOrWhiteSpace(nextName)) { name = nextName; wp++; } else { name = nearestSystem.name; } SystemClassDB nextSystem = SystemClassDB.GetSystem(name); if (nextSystem == null) { bottomLine = String.Format("WP{0}: {1} {2}", wp, nextName, autoCopyWPToolStripMenuItem.Checked ? " (AUTO)" : ""); } else { double distance = SystemClassDB.Distance(currentSystem.System, nextSystem); bottomLine = String.Format("{0:N2}ly to WP{1}: {2} {3}", distance, wp, name, autoCopyWPToolStripMenuItem.Checked ? " (AUTO)" : ""); } } else { bottomLine = String.Format("WP{0}: {1} {2}", 1, firstSystemName, autoCopyWPToolStripMenuItem.Checked ? " (AUTO)" : ""); name = firstSystemName; } if (name != null && name.CompareTo(lastsystem) != 0) { if (autoCopyWPToolStripMenuItem.Checked) { Clipboard.SetText(name); } if (autoSetTargetToolStripMenuItem.Checked) { string targetName; double x, y, z; TargetClass.GetTargetPosition(out targetName, out x, out y, out z); if (name.CompareTo(targetName) != 0) { RoutingUtils.setTargetSystem(discoveryform, name, false); } } } lastsystem = name; DisplayText(topline, bottomLine); }
// Protected against bad JSON public int GetLogs(DateTime?starttimeutc, DateTime?endtimeutc, out List <JournalFSDJump> log, out DateTime logstarttime, out DateTime logendtime) { log = new List <JournalFSDJump>(); logstarttime = DateTime.MaxValue; logendtime = DateTime.MinValue; if (!ValidCredentials) { return(0); } string query = "get-logs?showId=1&apiKey=" + apiKey + "&commanderName=" + HttpUtility.UrlEncode(commanderName); if (starttimeutc != null) { query += "&startDateTime=" + HttpUtility.UrlEncode(starttimeutc.Value.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture)); } if (endtimeutc != null) { query += "&endDateTime=" + HttpUtility.UrlEncode(endtimeutc.Value.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture)); } var response = RequestGet("api-logs-v1/" + query, handleException: true); if (response.Error) { return(0); } var json = response.Body; if (json == null) { return(0); } try { JObject msg = JObject.Parse(json); int msgnr = msg["msgnum"].Int(0); JArray logs = (JArray)msg["logs"]; if (logs != null) { string startdatestr = msg["startDateTime"].Value <string>(); string enddatestr = msg["endDateTime"].Value <string>(); if (startdatestr == null || !DateTime.TryParseExact(startdatestr, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal, out logstarttime)) { logstarttime = DateTime.MaxValue; } if (enddatestr == null || !DateTime.TryParseExact(enddatestr, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal, out logendtime)) { logendtime = DateTime.MinValue; } using (SQLiteConnectionSystem cn = new SQLiteConnectionSystem()) { foreach (JObject jo in logs) { string name = jo["system"].Value <string>(); string ts = jo["date"].Value <string>(); long id = jo["systemId"].Value <long>(); bool firstdiscover = jo["firstDiscover"].Value <bool>(); DateTime etutc = DateTime.ParseExact(ts, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal | DateTimeStyles.AssumeUniversal); // UTC time ISystem sc = SystemClassDB.GetSystem(id, cn, SystemClassDB.SystemIDType.EdsmId, name: name); if (sc == null) { if (DateTime.UtcNow.Subtract(etutc).TotalHours < 6) // Avoid running into the rate limit { sc = GetSystemsByName(name)?.FirstOrDefault(s => s.EDSMID == id); } if (sc == null) { sc = new SystemClass(name) { EDSMID = id }; } } JournalFSDJump fsd = new JournalFSDJump(etutc, sc, EliteConfigInstance.InstanceConfig.DefaultMapColour, firstdiscover, (int)SyncFlags.EDSM); log.Add(fsd); } } } return(msgnr); } catch (Exception e) { System.Diagnostics.Debug.WriteLine("Failed due to " + e.ToString()); return(499); // BAD JSON } }
// double percent = 0; Timer t = new Timer();// play thru harness private void Display(ISystem cursys) { if (currentRoute == null) { DisplayText("Please set a route, by right clicking", ""); return; } if (currentRoute.Systems.Count == 0) { DisplayText(currentRoute.Name, "Route contains no waypoints"); return; } string topline = ""; ISystem finalSystem = SystemClassDB.GetSystem(currentRoute.Systems[currentRoute.Systems.Count - 1]); if (finalSystem != null && cursys.HasCoordinate) { string mesg = "remain"; double distX = cursys.Distance(finalSystem); //Small hack to pull the jump range from TripPanel1 var jumpRange = SQLiteDBClass.GetSettingDouble("TripPanel1" + "JumpRange", -1.0); //TBD Not a good idea. if (jumpRange > 0) { int jumps = (int)Math.Ceiling(distX / jumpRange); if (jumps > 0) { mesg = "@ " + jumps.ToString() + ((jumps == 1) ? " jump" : " jumps"); } } topline = String.Format("{0} {1} WPs, {2:N2}ly {3}", currentRoute.Name, currentRoute.Systems.Count, distX, mesg); } else { topline = String.Format("{0} {1} WPs remain", currentRoute.Name, currentRoute.Systems.Count); } string bottomline = ""; Tuple <ISystem, int> closest = cursys.HasCoordinate ? currentRoute.ClosestTo(cursys) : null; if (closest != null) { if (closest.Item2 >= currentRoute.Systems.Count) // if past end.. { bottomline = String.Format("Past Last WP{0} {1}", closest.Item2, currentRoute.LastSystem); } else { string name = null; if (closest.Item1 != null) // if have a closest system { double distance = cursys.Distance(closest.Item1); bottomline = String.Format("{0:N2}ly to WP{1} {2} @ {3},{4},{5}", distance, closest.Item2 + 1, closest.Item1.Name, closest.Item1.X.ToString("0.#"), closest.Item1.Y.ToString("0.#"), closest.Item1.Z.ToString("0.#")); name = closest.Item1.Name; } else { // just know waypoint.. bottomline = String.Format("To WP{0} {1}", closest.Item2 + 1, currentRoute.Systems[closest.Item2]); name = currentRoute.Systems[closest.Item2]; } if (lastsystem == null || name.CompareTo(lastsystem) != 0) { if (autoCopyWPToolStripMenuItem.Checked) { Clipboard.SetText(name); } if (autoSetTargetToolStripMenuItem.Checked) { string targetName; double x, y, z; TargetClass.GetTargetPosition(out targetName, out x, out y, out z); if (name.CompareTo(targetName) != 0) { TargetHelpers.setTargetSystem(this, discoveryform, name, false); } } lastsystem = name; } } } else { bottomline = "No current position/no systems found in database"; } DisplayText(topline, bottomline); }