public void UpdateBookmarks(ref List <IData3DSet> _datasets, float widthly, float heightly, Vector3 rotation) { if (_datasets == null) { return; } foreach (IData3DSet dataset in _datasets) { TexturedQuadDataCollection tqdc = dataset as TexturedQuadDataCollection; foreach (TexturedQuadData tqd in tqdc.BaseTextures) { PointData pd; if ((int)tqd.Tag2 == 1) { VisitedSystemsClass vs = (VisitedSystemsClass)tqd.Tag; pd = new PointData((vs.HasTravelCoordinates) ? vs.X : vs.curSystem.x, (vs.HasTravelCoordinates) ? vs.Y : vs.curSystem.y, (vs.HasTravelCoordinates) ? vs.Z : vs.curSystem.z); } else { BookmarkClass bc = (BookmarkClass)tqd.Tag; pd = new PointData(bc.x, bc.y, bc.z); } tqd.UpdateVertices(pd, rotation, widthly, heightly, 0, heightly / 2); } } }
public void Data_age_filter_removes_data_older_than_the_limit_and_keeps_data_more_recent_than_the_limit() { var now = new VisitedSystemsClass { Time = DateTime.Now }; var fourDaysAgo = new VisitedSystemsClass { Time = DateTime.Now.Subtract(TimeSpan.FromDays(4))}; var input = new List<VisitedSystemsClass> { fourDaysAgo, now }; Check.That(TravelHistoryFilter.FromDays(2).Filter(input)).ContainsExactly(now); }
public void Update() { if (this.vs is VisitedSystemsClass) { VisitedSystemsClass vsc = (VisitedSystemsClass)vs; vsc.Update(); } }
public void Last_2_items_filter_returns_the_2_most_recent_items_sorted_by_most_recent_and_removes_the_older_items() { var twentyDaysAgo = new VisitedSystemsClass { Time = DateTime.Now.Subtract(TimeSpan.FromDays(20)) }; var tenDaysAgo = new VisitedSystemsClass { Time = DateTime.Now.Subtract(TimeSpan.FromDays(10)) }; var thirtyDaysAgo = new VisitedSystemsClass { Time = DateTime.Now.Subtract(TimeSpan.FromDays(30)) }; var input = new List<VisitedSystemsClass> { twentyDaysAgo, tenDaysAgo, thirtyDaysAgo }; Check.That(TravelHistoryFilter.Last(2).Filter(input)).ContainsExactly(tenDaysAgo, twentyDaysAgo); }
public IEnumerable <VisitedSystemsClass> ReadSystems(Func <bool> cancelRequested = null) { if (cancelRequested == null) { cancelRequested = () => false; } VisitedSystemsClass last = null; long startpos = filePos; if (TimeZone == null) { if (!ReadHeader()) // may be empty if we read it too fast.. don't worry, monitor will pick it up { System.Diagnostics.Trace.WriteLine("File was empty (for now) " + FileName); yield break; } } VisitedSystemsClass ps; using (Stream stream = File.Open(this.FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { while (!cancelRequested() && ReadNetLogSystem(out ps, cancelRequested, stream)) { if (last == null) { if (systems.Count == 0) { last = VisitedSystemsClass.GetLast(EDDConfig.Instance.CurrentCmdrID, ps.Time); } else { last = systems[systems.Count - 1]; } } if (last != null && ps.Name.Equals(last.Name, StringComparison.InvariantCultureIgnoreCase)) { continue; } if (ps.Time.Subtract(gammastart).TotalMinutes > 0) // Ta bara med efter gamma. { systems.Add(ps); yield return(ps); last = ps; } } } if (startpos != filePos) { Console.WriteLine("Parse ReadData " + FileName + " from " + startpos + " to " + filePos); } }
public void No_filter_does_not_filter_anything() { var veryOldData = new VisitedSystemsClass { Time = DateTime.Now.Subtract(TimeSpan.FromDays(500000)) }; var input = new List <VisitedSystemsClass> { veryOldData }; Check.That(TravelHistoryFilter.NoFilter.Filter(input)).ContainsExactly(veryOldData); }
public NetLogFileReader(TravelLogUnit tlu, List <VisitedSystemsClass> vsclist = null) : base(tlu) { if (vsclist != null) { systems = vsclist; } else { systems = VisitedSystemsClass.GetAll(tlu); } }
private void dEBUGResetAllHistoryToFirstCommandeToolStripMenuItem_Click(object sender, EventArgs e) { List <VisitedSystemsClass> vsall = VisitedSystemsClass.GetAll(); foreach (VisitedSystemsClass vs in vsall) { if (vs.Commander != 0) { vs.Commander = 0; vs.Update(); } } }
public void Data_age_filter_removes_data_older_than_the_limit_and_keeps_data_more_recent_than_the_limit() { var now = new VisitedSystemsClass { Time = DateTime.Now }; var fourDaysAgo = new VisitedSystemsClass { Time = DateTime.Now.Subtract(TimeSpan.FromDays(4)) }; var input = new List <VisitedSystemsClass> { fourDaysAgo, now }; Check.That(TravelHistoryFilter.FromDays(2).Filter(input)).ContainsExactly(now); }
private string DistToStar(VisitedSystemsClass vscentry, Point3D tpos) { string res = ""; if (!double.IsNaN(tpos.X)) { double dist = VisitedSystemsClass.Distance(vscentry, tpos); if (dist >= 0) { res = dist.ToString("0.00"); } } return(res); }
public void Last_2_items_filter_returns_the_2_most_recent_items_sorted_by_most_recent_and_removes_the_older_items() { var twentyDaysAgo = new VisitedSystemsClass { Time = DateTime.Now.Subtract(TimeSpan.FromDays(20)) }; var tenDaysAgo = new VisitedSystemsClass { Time = DateTime.Now.Subtract(TimeSpan.FromDays(10)) }; var thirtyDaysAgo = new VisitedSystemsClass { Time = DateTime.Now.Subtract(TimeSpan.FromDays(30)) }; var input = new List <VisitedSystemsClass> { twentyDaysAgo, tenDaysAgo, thirtyDaysAgo }; Check.That(TravelHistoryFilter.Last(2).Filter(input)).ContainsExactly(tenDaysAgo, twentyDaysAgo); }
public static void FillVisitedSystems(List <VisitedSystemsClass> visitedSystems, bool usedb) { try { using (SQLiteConnectionED cn = new SQLiteConnectionED()) { DbCommand cmd = cn.CreateCommand("SELECT * FROM Distances WHERE(NameA = @NameA and NameB = @NameB) OR(NameA = @NameB and NameB = @NameA) limit 1"); for (int i = 1; i < visitedSystems.Count; i++) // now we filled in current system, fill in previous system (except for last) { VisitedSystemsClass cur = visitedSystems[i]; VisitedSystemsClass prev = visitedSystems[i - 1]; cur.prevSystem = prev.curSystem; double dist = SystemClass.Distance(cur.curSystem, prev.curSystem); // Try the easy way if (dist < 0 && usedb) // failed, and use the db is allowed.. { cmd.Parameters.Clear(); cmd.AddParameterWithValue("@NameA", cur.Name); cmd.AddParameterWithValue("@NameB", prev.Name); using (DbDataReader reader = cmd.ExecuteReader()) { if (reader.Read()) { DistanceClass dst = new DistanceClass(reader); dist = dst.Dist; } } } if (dist > 0) { cur.strDistance = dist.ToString("0.00"); } } } } catch (Exception ex) { System.Diagnostics.Trace.WriteLine("Exception : " + ex.Message); System.Diagnostics.Trace.WriteLine(ex.StackTrace); } }
public void RefreshTarget(DataGridView vsc, List <VisitedSystemsClass> vscl) { SuspendLayout(); string name; double x, y, z; bool targetpresent = TargetClass.GetTargetPosition(out name, out x, out y, out z); if (vsc != null && targetpresent && (config & Configuration.showTargetLine) != 0) { SystemClass cs = VisitedSystemsClass.GetSystemClassFirstPosition(vscl); string dist = (cs != null) ? SystemClass.Distance(cs, x, y, z).ToString("0.00") : "Unknown"; List <ControlEntryProperties> cep = new List <ControlEntryProperties>(); int pos = 4 + (((config & Configuration.showEDSMButton) != 0) ? (int)(40 * tabscalar) : 0); cep.Add(new ControlEntryProperties(FontSel(vsc.Columns[1].DefaultCellStyle.Font, vsc.Font), ref pos, 60 * tabscalar, panel_grip.ForeColor, "Target:")); cep.Add(new ControlEntryProperties(FontSel(vsc.Columns[2].DefaultCellStyle.Font, vsc.Font), ref pos, 150 * tabscalar, panel_grip.ForeColor, name)); cep.Add(new ControlEntryProperties(FontSel(vsc.Columns[3].DefaultCellStyle.Font, vsc.Font), ref pos, 60 * tabscalar, panel_grip.ForeColor, dist)); if (statictoplines == 0) { int row = lt.Add(-1, cep, 0); // insert with rowid -1, at 0 lt.SetFormat(row, cep); statictoplines = 1; UpdateEventsOnControls(this); } else { lt.RefreshTextAtID(-1, cep); // just refresh data, with a row ID of -1 } } else { if (statictoplines == 1) { lt.RemoveAt(0); statictoplines = 0; } } labelExt_NoSystems.Visible = (lt.Count == statictoplines); ResumeLayout(); }
internal static bool SendTravelLog(EDSMClass edsm, VisitedSystemsClass system, EDDiscoveryForm mainform) { string json; if (!system.HasTravelCoordinates) { json = edsm.SetLog(system.Name, system.Time); } else { json = edsm.SetLogWithPos(system.Name, system.Time, system.X, system.Y, system.Z); } if (json != null) { JObject msg = (JObject)JObject.Parse(json); int msgnum = msg["msgnum"].Value <int>(); string msgstr = msg["msg"].Value <string>(); if (msgnum == 100 || msgnum == 401 || msgnum == 402 || msgnum == 403) { system.EDSM_sync = true; system.Update(); return(true); } else { if (mainform != null) { mainform.LogLine("EDSM sync ERROR:" + msgnum.ToString() + ":" + msgstr); } System.Diagnostics.Trace.WriteLine("Error sync:" + msgnum.ToString() + " : " + system.Name); return(false); } } else { return(false); } }
private void AddVisitedSystemsInformation(bool DrawLines, List <VisitedSystemsClass> VisitedSystems) { if (VisitedSystems != null && VisitedSystems.Any() && DrawLines) { VisitedSystemsClass.SetLastKnownSystemPosition(VisitedSystems); IEnumerable <IGrouping <int, VisitedSystemsClass> > colours = from VisitedSystemsClass sysPos in VisitedSystems group sysPos by sysPos.MapColour; if (colours != null) { foreach (IGrouping <int, VisitedSystemsClass> colour in colours) { var datasetl = Data3DSetClass <LineData> .Create("visitedstars" + colour.Key.ToString(), Color.FromArgb(colour.Key), 2.0f); foreach (VisitedSystemsClass sp in colour) { if (sp.curSystem != null && sp.curSystem.HasCoordinate && sp.lastKnownSystem != null && sp.lastKnownSystem.HasCoordinate) { datasetl.Add(new LineData(sp.curSystem.x, sp.curSystem.y, sp.curSystem.z, sp.lastKnownSystem.x, sp.lastKnownSystem.y, sp.lastKnownSystem.z)); } } _datasets.Add(datasetl); var datasetvs = Data3DSetClass <PointData> .Create("visitedstars" + colour.Key.ToString(), Color.Orange, 2.0f); foreach (VisitedSystemsClass sp in colour) { if (sp.curSystem != null && sp.curSystem.HasCoordinate) { datasetvs.Add(new PointData(sp.curSystem.x, sp.curSystem.y, sp.curSystem.z)); } } _datasets.Add(datasetvs); } } } }
public int GetLogs(DateTime starttime, out List <VisitedSystemsClass> log) { log = new List <VisitedSystemsClass>(); string query = "get-logs?startdatetime=" + HttpUtility.UrlEncode(starttime.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture)) + "&apiKey=" + apiKey + "&commanderName=" + HttpUtility.UrlEncode(commanderName); //string query = "get-logs?apiKey=" + apiKey + "&commanderName=" + HttpUtility.UrlEncode(commanderName); var response = RequestGet("api-logs-v1/" + query); var json = response.Body; if (json == null) { return(0); } JObject msg = JObject.Parse(json); int msgnr = msg["msgnum"].Value <int>(); JArray logs = (JArray)msg["logs"]; if (logs != null) { foreach (JObject jo in logs) { VisitedSystemsClass pos = new VisitedSystemsClass(); pos.Name = jo["system"].Value <string>(); string str = jo["date"].Value <string>(); pos.Time = DateTime.ParseExact(str, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal).ToLocalTime(); log.Add(pos); } } return(msgnr); }
public AssignTravelLogSystemForm(TravelHistoryControl travelHistory, VisitedSystemsClass vsc) { InitializeComponent(); this._travelHistory = travelHistory; this._travelLogEntry = vsc; this._linkSystem = vsc.curSystem; this.tbLogSystemName.Text = vsc.Name; this.tbDateVisited.Text = vsc.Time.ToString(); this.tbLogCoordX.Text = vsc.HasTravelCoordinates ? vsc.X.ToString("0.000") : "?"; this.tbLogCoordY.Text = vsc.HasTravelCoordinates ? vsc.Y.ToString("0.000") : "?"; this.tbLogCoordZ.Text = vsc.HasTravelCoordinates ? vsc.Z.ToString("0.000") : "?"; this.tbLogCoordX.TextAlign = vsc.HasTravelCoordinates ? HorizontalAlignment.Right : HorizontalAlignment.Center; this.tbLogCoordY.TextAlign = vsc.HasTravelCoordinates ? HorizontalAlignment.Right : HorizontalAlignment.Center; this.tbLogCoordZ.TextAlign = vsc.HasTravelCoordinates ? HorizontalAlignment.Right : HorizontalAlignment.Center; UpdateLinkedSystemList(vsc.curSystem); tbManualSystemName.AutoCompleteMode = AutoCompleteMode.SuggestAppend; tbManualSystemName.AutoCompleteSource = AutoCompleteSource.CustomSource; AutoCompleteStringCollection autocomplete = new AutoCompleteStringCollection(); SystemClass.GetSystemNames(ref autocomplete); tbManualSystemName.AutoCompleteCustomSource = autocomplete; }
public void Sync() { try { EDSMClass edsm = new EDSMClass(); edsm.apiKey = EDDiscoveryForm.EDDConfig.CurrentCommander.APIKey; edsm.commanderName = EDDiscoveryForm.EDDConfig.CurrentCommander.Name; //string comments = edsm.GetComments(new DateTime(2015, 1, 1)); List <VisitedSystemsClass> log; List <SystemNoteClass> notes; int ret = edsm.GetLogs(new DateTime(2011, 1, 1), out log); int nret = edsm.GetComments(new DateTime(2011, 1, 1), out notes); if (log == null) { log = new List <VisitedSystemsClass>(); } if (_syncTo) { // Send Unsynced system to EDSM. List <VisitedSystemsClass> systems = (from s in mainForm.VisitedSystems where s.EDSM_sync == false && s.Commander == EDDiscoveryForm.EDDConfig.CurrentCommander.Nr select s).ToList <VisitedSystemsClass>(); mainForm.LogLine("EDSM: Sending " + systems.Count.ToString() + " flightlog entries"); foreach (var system in systems) { if (Exit) { running = false; return; } if (system.EDSM_sync == false) { // check if it exist in EDSM VisitedSystemsClass ps2 = (from c in log where c.Name == system.Name && c.Time.Ticks == system.Time.Ticks select c).FirstOrDefault <VisitedSystemsClass>(); if (ps2 != null) { system.EDSM_sync = true; system.Update(); } else { SendTravelLog(edsm, system, mainForm); } } } } TravelLogUnit tlu = null; bool newsystem = false; if (_syncFrom) { // Check for new systems from EDSM foreach (var system in log) { VisitedSystemsClass ps2 = mainForm?.VisitedSystems == null ? null : (from c in mainForm.VisitedSystems where c.Name == system.Name && c.Time.Ticks == system.Time.Ticks select c).FirstOrDefault <VisitedSystemsClass>(); if (ps2 == null) // Add to local DB... { if (tlu == null) // If we dontt have a travellogunit yet then create it. { tlu = new TravelLogUnit(); tlu.type = 2; // EDSM tlu.Path = "https://www.edsm.net/api-logs-v1/get-logs"; tlu.Name = "EDSM-" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture); tlu.Size = 0; tlu.Add(); // Add to Database } VisitedSystemsClass vs = new VisitedSystemsClass(); vs.Source = tlu.id; vs.Unit = tlu.Name; vs.Name = system.Name; vs.Time = system.Time; vs.MapColour = _defmapcolour; vs.EDSM_sync = true; vs.Commander = EDDiscoveryForm.EDDConfig.CurrentCommander.Nr; vs.Add(); // Add to DB; System.Diagnostics.Trace.WriteLine("New from EDSM"); newsystem = true; } } // Sync comments from EDSM foreach (var note in notes) { SystemNoteClass dbnote = SystemNoteClass.GetSystemNoteClass(note.Name.ToLower()); if (dbnote != null) // if there.. { if (note.Time > dbnote.Time) { dbnote.Time = note.Time; dbnote.Note = note.Note; dbnote.Update(); } } else { note.Add(); } } } mainForm.LogLine("EDSM sync Done"); if (newsystem) { OnNewEDSMTravelLog(this); } } catch (Exception ex) { System.Diagnostics.Trace.WriteLine("Exception ex:" + ex.Message); mainForm.LogLineHighlight("EDSM sync Exception " + ex.Message); } }
protected bool ParseVisitedSystem(DateTime time, TimeSpan tzoffset, string line, out VisitedSystemsClass sp) { sp = new VisitedSystemsClass(); try { Regex pattern; /* MKW: Use regular expressions to parse the log; much more readable and robust. * Example log entry: * * From ED 2.1 /1.6 * {19:21:15} System:"Ooscs Fraae JR-L d8-112" StarPos:(-11609.469,639.594,20141.875)ly NormalFlight * string rgexpstr = "{(?<Hour>\\d+):(?<Minute>\\d+):(?<Second>\\d+)} System:\"(?<SystemName>[^\"]+)\" StarPos:\\((?<Pos>.*?)\\)ly( +(?<TravelMode>\\w+))?"; * * new from beta3? * {18:15:14} System:"Pleiades Sector HR-W d1-41" StarPos:(-83.969,-146.156,-334.219)ly Body:0 RelPos:(-1.19887e+07,-9.95573e+06,2.55124e+06)km Supercruise * string rgexpstr = "{(?<Hour>\\d+):(?<Minute>\\d+):(?<Second>\\d+)} System:\"(?<SystemName>[^\"]+)\" StarPos:\\((?<Pos>.*?)\\)ly Body:(?<Body>\d+) StarPos:\\((?<Pos>.*?)\\)ly( +(?<TravelMode>\\w+))?"; * * * Pre ED 2.1/1.6 * {09:36:16} System:0(Thuechea JE-O b11-0) Body:1 Pos:(-6.67432e+009,7.3151e+009,-1.19125e+010) Supercruise * * Also, please note that due to E:D bugs, these entries can be at the end of a line as well, not just on a line of their own. * The RegExp below actually just finds the pattern somewhere in the line, so it caters for rubbish at the end too. */ if (line.Contains("StarPos:")) // new ED 2.1 format { //{(?<Hour>\d+):(?<Minute>\d+):(?<Second>\d+)} System:"(?<SystemName>[^"]+)" StarPos:\((?<Pos>.*?)\)ly( +(?<TravelMode>\w+))? //{(?<Hour>\d+):(?<Minute>\d+):(?<Second>\d+)} System:"(?<SystemName>[^"]+)" StarPos:\((?<Pos>.*?)\)ly( +(?<TravelMode>\w+))? //string rgexpstr = "{(?<Hour>\\d+):(?<Minute>\\d+):(?<Second>\\d+)} System:\"(?<SystemName>[^\"]+)\" StarPos:\\((?<Pos>.*?)\\)ly( +(?<TravelMode>\\w+))?"; string rgexpstr; if (line.Contains("Body:")) { rgexpstr = "System:\"(?<SystemName>[^\"]+)\" StarPos:\\((?<Pos>.*?)\\)ly Body:(?<Body>\\d+) RelPos:\\((?<RelPos>.*?)\\)km( +(?<TravelMode>\\w+))?"; } else { rgexpstr = "System:\"(?<SystemName>[^\"]+)\" StarPos:\\((?<Pos>.*?)\\)ly( +(?<TravelMode>\\w+))?"; } pattern = new Regex(rgexpstr); Match match = pattern.Match(line); if (match != null && match.Success) { //sp.Nr = int.Parse(match.Groups["Body"].Value); sp.Name = match.Groups["SystemName"].Value; string pos = match.Groups["Pos"].Value; try { string[] xyzpos = pos.Split(','); var culture = new System.Globalization.CultureInfo("en-US"); sp.X = double.Parse(xyzpos[0], culture); sp.Y = double.Parse(xyzpos[1], culture); sp.Z = double.Parse(xyzpos[2], culture); } catch { sp.X = double.NaN; sp.Y = double.NaN; sp.Z = double.NaN; } } else { System.Diagnostics.Trace.WriteLine("System parse error 1:" + line); return(false); } } else { pattern = new Regex(@"System:\d+\((?<SystemName>.*?)\) Body:(?<Body>\d+) Pos:\(.*?\)( (?<TravelMode>\w+))?"); Match match = pattern.Match(line); if (match != null && match.Success) { //sp.Nr = int.Parse(match.Groups["Body"].Value); sp.Name = match.Groups["SystemName"].Value; sp.X = Double.NaN; sp.Y = Double.NaN; sp.Z = Double.NaN; } else { System.Diagnostics.Trace.WriteLine("System parse error 2:" + line); return(false); } } sp.Time = time + tzoffset; return(true); } catch { // MKW TODO: should we log bad lines? return(false); } }
public List <SystemPosition> ParseFiles(RichTextBox richTextBox_History, int defaultMapColour) { string datapath; DirectoryInfo dirInfo; datapath = GetNetLogPath(); if (datapath == null) { AppendText(richTextBox_History, "Netlog directory not found!" + Environment.NewLine + "Specify location in settings tab" + Environment.NewLine, Color.Red); return(null); } if (!Directory.Exists(datapath)) // if logfiles directory is not found { if (richTextBox_History != null) { richTextBox_History.Clear(); AppendText(richTextBox_History, "Netlog directory not found!" + Environment.NewLine + "Specify location in settings tab" + Environment.NewLine, Color.Red); //MessageBox.Show("Netlog directory not found!" + Environment.NewLine + "Specify location in settings tab", "EDDiscovery Error", MessageBoxButtons.OK); } return(null); } try { dirInfo = new DirectoryInfo(datapath); } catch (Exception ex) { AppendText(richTextBox_History, "Could not create Directory info: " + ex.Message + Environment.NewLine, Color.Red); return(null); } // Get TravelLogUnits; tlUnits = TravelLogUnit.GetAll(); List <VisitedSystemsClass> vsSystemsList = VisitedSystemsClass.GetAll(ActiveCommander); visitedSystems.Clear(); // Add systems in local DB. if (vsSystemsList != null) { foreach (VisitedSystemsClass vs in vsSystemsList) { if (visitedSystems.Count == 0) { visitedSystems.Add(new SystemPosition(vs)); } else if (!visitedSystems.Last <SystemPosition>().Name.Equals(vs.Name)) // Avoid duplicate if times exist in same system from different files. { visitedSystems.Add(new SystemPosition(vs)); } else { VisitedSystemsClass vs2 = (VisitedSystemsClass)visitedSystems.Last <SystemPosition>().vs; vs.Commander = -2; // Move to dupe user vs.Update(); } } } FileInfo[] allFiles = dirInfo.GetFiles("netLog.*.log", SearchOption.AllDirectories).OrderBy(p => p.Name).ToArray(); NoEvents = true; foreach (FileInfo fi in allFiles) { TravelLogUnit lu = null; bool parsefile = true; if (fi.Name.Equals("netLog.1510280152.01.log")) { parsefile = true; } // Check if we alreade have parse the file and stored in DB. if (tlUnits != null) { lu = (from c in tlUnits where c.Name == fi.Name select c).FirstOrDefault <TravelLogUnit>(); } if (lu != null) { if (lu.Size == fi.Length) // File is already in DB: { parsefile = false; } } else { lu = new TravelLogUnit(); lu.Name = fi.Name; lu.Path = Path.GetDirectoryName(fi.FullName); lu.Size = 0; // Add real size after data is in DB //;(int)fi.Length; lu.type = 1; lu.Add(); } if (parsefile) { int nr = 0; List <SystemPosition> tempVisitedSystems = new List <SystemPosition>(); ParseFile(fi, tempVisitedSystems); foreach (SystemPosition ps in tempVisitedSystems) { SystemPosition ps2; ps2 = (from c in visitedSystems where c.Name == ps.Name && c.time == ps.time select c).FirstOrDefault <SystemPosition>(); if (ps2 == null) { VisitedSystemsClass dbsys = new VisitedSystemsClass(); dbsys.Name = ps.Name; dbsys.Time = ps.time; dbsys.Source = lu.id; dbsys.EDSM_sync = false; dbsys.Unit = fi.Name; dbsys.MapColour = defaultMapColour; dbsys.Commander = ActiveCommander; if (!lu.Beta) // dont store history in DB for beta (YET) { VisitedSystemsClass last = VisitedSystemsClass.GetLast(); if (last == null || !last.Name.Equals(dbsys.Name)) // If same name as last system. Dont Add. otherwise we get a duplet with last from logfile before with different time. { if (!VisitedSystemsClass.Exist(dbsys.Name, dbsys.Time)) { dbsys.Add(); visitedSystems.Add(ps); nr++; } } } } } lu.Size = (int)fi.Length; lu.Update(); AppendText(richTextBox_History, fi.Name + " " + nr.ToString() + " added to local database." + Environment.NewLine, Color.Black); } } NoEvents = false; //var result = visitedSystems.OrderByDescending(a => a.time).ToList<SystemPosition>(); return(visitedSystems); }
private void UpdateRow(DataGridView vsc, DataGridViewRow vscrow, bool addit, int insertat, Point3D tpos) { Debug.Assert(vscrow != null && vsc != null); if (!vscrow.Visible) // may not be visible due to being turned off.. if so, reject. { return; } Color rowc = CSel(vsc.Rows[vscrow.Index].DefaultCellStyle.ForeColor, vsc.ForeColor); if (rowc.GetBrightness() < 0.15) // override if its too dark.. { rowc = Color.White; } int pos = 4; List <ControlEntryProperties> cep = new List <ControlEntryProperties>(); if ((config & Configuration.showEDSMButton) != 0) { cep.Add(new ControlEntryProperties(butfont, ref pos, 40 * tabscalar, panel_grip.ForeColor, "!!<EDSMBUT:" + (string)vscrow.Cells[1].Value)); } if ((config & Configuration.showTime) != 0) { cep.Add(new ControlEntryProperties(FontSel(vsc.Columns[0].DefaultCellStyle.Font, vsc.Font), ref pos, 60 * tabscalar, rowc, ((DateTime)vscrow.Cells[0].Value).ToString("HH:mm.ss"))); } cep.Add(new ControlEntryProperties(FontSel(vsc.Columns[1].DefaultCellStyle.Font, vsc.Font), ref pos, 150 * tabscalar, rowc, (string)vscrow.Cells[1].Value)); if ((config & Configuration.showDistance) != 0) { cep.Add(new ControlEntryProperties(FontSel(vsc.Columns[2].DefaultCellStyle.Font, vsc.Font), ref pos, 50 * tabscalar, rowc, (string)vscrow.Cells[2].Value)); } if (toolStripComboBoxOrder.SelectedIndex == 0 && (config & Configuration.showNotes) != 0) { cep.Add(new ControlEntryProperties(FontSel(vsc.Columns[3].DefaultCellStyle.Font, vsc.Font), ref pos, 150 * tabscalar, rowc, (string)vscrow.Cells[3].Value)); } VisitedSystemsClass vscentry = (VisitedSystemsClass)vscrow.Cells[EDDiscovery.TravelHistoryControl.TravelHistoryColumns.SystemName].Tag; if (toolStripComboBoxOrder.SelectedIndex == 2 && (config & Configuration.showDistancePerStar) != 0) { cep.Add(new ControlEntryProperties(FontSel(vsc.Columns[2].DefaultCellStyle.Font, vsc.Font), ref pos, 60 * tabscalar, rowc, DistToStar(vscentry, tpos))); } if ((config & Configuration.showXYZ) != 0 && vscentry != null) { string xv = (vscentry.curSystem.HasCoordinate) ? vscentry.curSystem.x.ToString("0.00") : "-"; string yv = (vscentry.curSystem.HasCoordinate) ? vscentry.curSystem.y.ToString("0.00") : "-"; string zv = (vscentry.curSystem.HasCoordinate) ? vscentry.curSystem.z.ToString("0.00") : "-"; cep.Add(new ControlEntryProperties(FontSel(vsc.Columns[0].DefaultCellStyle.Font, vsc.Font), ref pos, 60 * tabscalar, rowc, xv)); cep.Add(new ControlEntryProperties(FontSel(vsc.Columns[0].DefaultCellStyle.Font, vsc.Font), ref pos, 50 * tabscalar, rowc, yv)); cep.Add(new ControlEntryProperties(FontSel(vsc.Columns[0].DefaultCellStyle.Font, vsc.Font), ref pos, 60 * tabscalar, rowc, zv)); } if (toolStripComboBoxOrder.SelectedIndex > 0 && (config & Configuration.showNotes) != 0) { cep.Add(new ControlEntryProperties(FontSel(vsc.Columns[3].DefaultCellStyle.Font, vsc.Font), ref pos, 150 * tabscalar, rowc, (string)vscrow.Cells[3].Value)); } if (toolStripComboBoxOrder.SelectedIndex < 2 && (config & Configuration.showDistancePerStar) != 0) { cep.Add(new ControlEntryProperties(FontSel(vsc.Columns[2].DefaultCellStyle.Font, vsc.Font), ref pos, 60 * tabscalar, rowc, DistToStar(vscentry, tpos))); } if (addit) { int row = lt.Add(vscrow.Index, cep, insertat); // row on the summary screen.. remember which row it came from lt.SetFormat(row, cep); } else { lt.RefreshTextAtID(vscrow.Index, cep); // refresh this one with rowid= index } }
public void UpdateHistorySystem(VisitedSystemsClass historysel) { _formMap.UpdateHistorySystem(historysel); }
public bool MoveToSystem(VisitedSystemsClass system) { return(_formMap.SetCenterSystemTo(system)); }
public void Sync(bool pushOnly) { try { SQLiteDBClass db = new SQLiteDBClass(); EDSMClass edsm = new EDSMClass(); edsm.apiKey = EDDiscoveryForm.EDDConfig.CurrentCommander.APIKey; edsm.commanderName = EDDiscoveryForm.EDDConfig.CurrentCommander.Name; //string comments = edsm.GetComments(new DateTime(2015, 1, 1)); List <SystemPosition> log; int ret = edsm.GetLogs(new DateTime(2011, 1, 1), out log); if (log == null) { log = new List <SystemPosition>(); } // Send Unsynced system to EDSM. List <SystemPosition> systems = (from s in mainForm.VisitedSystems where s.vs != null && s.vs.EDSM_sync == false && s.vs.Commander == EDDiscoveryForm.EDDConfig.CurrentCommander.Nr select s).ToList <SystemPosition>(); mainForm.LogLine("EDSM: Sending " + systems.Count.ToString() + " flightlog entries", Color.Black); foreach (var system in systems) { string json = null; if (Exit) { running = false; return; } if (system.vs != null && system.vs.EDSM_sync == false) { // check if it exist in EDSM SystemPosition ps2 = (from c in log where c.Name == system.Name && c.time.Ticks == system.time.Ticks select c).FirstOrDefault <SystemPosition>(); if (ps2 != null) { system.vs.EDSM_sync = true; system.Update(); } else { json = edsm.SetLog(system.Name, system.time); } if (json != null) { JObject msg = (JObject)JObject.Parse(json); int msgnum = msg["msgnum"].Value <int>(); string msgstr = msg["msg"].Value <string>(); if (msgnum == 100 || msgnum == 401 || msgnum == 402 || msgnum == 403) { if (msgnum == 100) { System.Diagnostics.Trace.WriteLine("New"); } system.vs.EDSM_sync = true; system.Update(); } else { mainForm.LogLine("EDSM sync ERROR:" + msgnum.ToString() + ":" + msgstr, Color.Red); System.Diagnostics.Trace.WriteLine("Error sync:" + msgnum.ToString() + " : " + system.Name); break; } } } } TravelLogUnit tlu = null; bool newsystem = false; if (!pushOnly) { // Check for new systems from EDSM int defaultColour = db.GetSettingInt("DefaultMap", Color.Red.ToArgb()); foreach (var system in log) { SystemPosition ps2 = (from c in mainForm.VisitedSystems where c.Name == system.Name && c.time.Ticks == system.time.Ticks select c).FirstOrDefault <SystemPosition>(); if (ps2 == null) // Add to local DB... { if (tlu == null) // If we dontt have a travellogunit yet then create it. { tlu = new TravelLogUnit(); tlu.type = 2; // EDSM tlu.Path = "http://www.edsm.net/api-logs-v1/get-logs"; tlu.Name = "EDSM-" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture); tlu.Size = 0; tlu.Add(); // Add to Database } VisitedSystemsClass vs = new VisitedSystemsClass(); vs.Source = tlu.id; vs.Unit = tlu.Name; vs.Name = system.Name; vs.Time = system.time; vs.MapColour = defaultColour; vs.EDSM_sync = true; vs.Add(); // Add to DB; System.Diagnostics.Trace.WriteLine("New from EDSM"); newsystem = true; } } } mainForm.LogLine("EDSM sync Done", Color.Black); if (newsystem) { OnNewEDSMTravelLog(this); } } catch (Exception ex) { System.Diagnostics.Trace.WriteLine("Exception ex:" + ex.Message); mainForm.LogLine("EDSM sync Exception " + ex.Message, Color.Red); } }
public void Prepare(VisitedSystemsClass historysel, string homesys, ISystem centersys, float zoom, AutoCompleteStringCollection sysname, List <VisitedSystemsClass> visited) { _formMap.Prepare(historysel, homesys, centersys, zoom, sysname, visited); }
private void NetLogMain() { try { m_Watcher = new System.IO.FileSystemWatcher(); if (Directory.Exists(GetNetLogPath())) { m_Watcher.Path = GetNetLogPath() + "\\"; m_Watcher.Filter = "netLog*.log"; m_Watcher.IncludeSubdirectories = true; m_Watcher.NotifyFilter = NotifyFilters.FileName; // | NotifyFilters.Size; m_Watcher.Changed += new FileSystemEventHandler(OnChanged); m_Watcher.Created += new FileSystemEventHandler(OnChanged); m_Watcher.Deleted += new FileSystemEventHandler(OnChanged); m_Watcher.EnableRaisingEvents = true; } } catch (Exception ex) { System.Windows.Forms.MessageBox.Show("Net log watcher exception : " + ex.Message, "EDDiscovery Error"); System.Diagnostics.Trace.WriteLine("NetlogMAin exception : " + ex.Message); System.Diagnostics.Trace.WriteLine(ex.StackTrace); } List <TravelLogUnit> travelogUnits; // Get TravelLogUnits; travelogUnits = null; TravelLogUnit tlUnit = null; SQLiteDBClass db = new SQLiteDBClass(); int ii = 0; while (!Exit) { try { ii++; Thread.Sleep(2000); EliteDangerous.CheckED(); if (NoEvents == false) { if (lastnfi != null) { FileInfo fi = new FileInfo(lastnfi.FileName); if (fi.Length != lastnfi.fileSize || ii % 5 == 0) { if (tlUnit == null || !tlUnit.Name.Equals(Path.GetFileName(lastnfi.FileName))) // Create / find new travellog unit { travelogUnits = TravelLogUnit.GetAll(); // Check if we alreade have parse the file and stored in DB. if (tlUnit == null) { tlUnit = (from c in travelogUnits where c.Name == fi.Name select c).FirstOrDefault <TravelLogUnit>(); } if (tlUnit == null) { tlUnit = new TravelLogUnit(); tlUnit.Name = fi.Name; tlUnit.Path = Path.GetDirectoryName(fi.FullName); tlUnit.Size = 0; // Add real size after data is in DB //;(int)fi.Length; tlUnit.type = 1; tlUnit.Add(); travelogUnits.Add(tlUnit); } } int nrsystems = visitedSystems.Count; ParseFile(fi, visitedSystems); if (nrsystems < visitedSystems.Count) // Om vi har fler system { System.Diagnostics.Trace.WriteLine("New systems " + nrsystems.ToString() + ":" + visitedSystems.Count.ToString()); for (int nr = nrsystems; nr < visitedSystems.Count; nr++) // Lägg till nya i locala databaslogen { VisitedSystemsClass dbsys = new VisitedSystemsClass(); dbsys.Name = visitedSystems[nr].Name; dbsys.Time = visitedSystems[nr].time; dbsys.Source = tlUnit.id; dbsys.EDSM_sync = false; dbsys.Unit = fi.Name; dbsys.MapColour = db.GetSettingInt("DefaultMap", Color.Red.ToArgb()); dbsys.Unit = fi.Name; dbsys.Commander = 0; if (!tlUnit.Beta) // dont store history in DB for beta (YET) { dbsys.Add(); } visitedSystems[nr].vs = dbsys; } } else { //System.Diagnostics.Trace.WriteLine("No change"); } } } } } catch (Exception ex) { System.Diagnostics.Trace.WriteLine("NetlogMAin exception : " + ex.Message); System.Diagnostics.Trace.WriteLine(ex.StackTrace); } } }
public bool ReadNetLogSystem(out VisitedSystemsClass vsc, Func <bool> cancelRequested = null, Stream stream = null, bool ownstream = false) { if (cancelRequested == null) { cancelRequested = () => false; } string line; try { if (stream == null) { stream = File.Open(this.FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); ownstream = true; } while (!cancelRequested() && this.ReadLine(out line, stream)) { ParseLineTime(line); if (line.Contains("[PG]")) { if (line.Contains("[PG] [Notification] Left a playlist lobby")) { this.CQC = false; } if (line.Contains("[PG] Destroying playlist lobby.")) { this.CQC = false; } if (line.Contains("[PG] [Notification] Joined a playlist lobby")) { this.CQC = true; } if (line.Contains("[PG] Created playlist lobby")) { this.CQC = true; } if (line.Contains("[PG] Found matchmaking lobby object")) { this.CQC = true; } } int offset = line.IndexOf("} System:") - 8; if (offset >= 1 && ParseTime(line.Substring(offset, 8)) && this.CQC == false) { //Console.WriteLine(" RD:" + line ); if (line.Contains("ProvingGround")) { continue; } VisitedSystemsClass ps; if (ParseVisitedSystem(this.LastLogTime, this.TimeZoneOffset, line.Substring(offset + 10), out ps)) { // Remove some training systems if (ps.Name.Equals("Training")) { continue; } if (ps.Name.Equals("Destination")) { continue; } if (ps.Name.Equals("Altiris")) { continue; } ps.Source = TravelLogUnit.id; ps.Unit = TravelLogUnit.Name; vsc = ps; return(true); } } } } finally { if (ownstream) { stream.Dispose(); } } vsc = null; return(false); }
public void No_filter_does_not_filter_anything() { var veryOldData = new VisitedSystemsClass { Time = DateTime.Now.Subtract(TimeSpan.FromDays(500000))}; var input = new List<VisitedSystemsClass> { veryOldData }; Check.That(TravelHistoryFilter.NoFilter.Filter(input)).ContainsExactly(veryOldData); }
// called during start up and if refresh history is pressed public List <VisitedSystemsClass> ParseFiles(out string error, int defaultMapColour, Func <bool> cancelRequested, Action <int, string> updateProgress) { error = null; string datapath = GetNetLogPath(); if (datapath == null) { error = "Netlog directory not found!" + Environment.NewLine + "Specify location in settings tab"; return(null); } if (!Directory.Exists(datapath)) // if logfiles directory is not found { error = "Netlog directory is not present!" + Environment.NewLine + "Specify location in settings tab"; return(null); } List <VisitedSystemsClass> vsSystemsList = VisitedSystemsClass.GetAll(EDDConfig.Instance.CurrentCmdrID); List <VisitedSystemsClass> visitedSystems = new List <VisitedSystemsClass>(); Dictionary <string, TravelLogUnit> m_travelogUnits = TravelLogUnit.GetAll().Where(t => t.type == 1).GroupBy(t => t.Name).Select(g => g.First()).ToDictionary(t => t.Name); Dictionary <string, List <VisitedSystemsClass> > vsc_lookup = VisitedSystemsClass.GetAll().GroupBy(v => v.Unit).ToDictionary(g => g.Key, g => g.ToList()); if (vsSystemsList != null) { foreach (VisitedSystemsClass vs in vsSystemsList) { if (visitedSystems.Count == 0) { visitedSystems.Add(vs); } else if (!visitedSystems.Last <VisitedSystemsClass>().Name.Equals(vs.Name)) // Avoid duplicate if times exist in same system from different files. { visitedSystems.Add(vs); } else { VisitedSystemsClass vs2 = (VisitedSystemsClass)visitedSystems.Last <VisitedSystemsClass>(); if (vs2.id != vs.id) { vs.Commander = -2; // Move to dupe user vs.Update(); } } } } // order by file write time so we end up on the last one written FileInfo[] allFiles = Directory.EnumerateFiles(datapath, "netLog.*.log", SearchOption.AllDirectories).Select(f => new FileInfo(f)).OrderBy(p => p.LastWriteTime).ToArray(); List <NetLogFileReader> readersToUpdate = new List <NetLogFileReader>(); for (int i = 0; i < allFiles.Length; i++) { FileInfo fi = allFiles[i]; var reader = OpenFileReader(fi, m_travelogUnits, vsc_lookup); if (!m_travelogUnits.ContainsKey(reader.TravelLogUnit.Name)) { m_travelogUnits[reader.TravelLogUnit.Name] = reader.TravelLogUnit; reader.TravelLogUnit.Add(); } if (!netlogreaders.ContainsKey(reader.TravelLogUnit.Name)) { netlogreaders[reader.TravelLogUnit.Name] = lastnfi; } if (reader.filePos != fi.Length || i == allFiles.Length - 1) // File not already in DB, or is the last one { readersToUpdate.Add(reader); } } using (SQLiteConnectionED cn = new SQLiteConnectionED()) { for (int i = 0; i < readersToUpdate.Count; i++) { NetLogFileReader reader = readersToUpdate[i]; updateProgress(i * 100 / readersToUpdate.Count, reader.TravelLogUnit.Name); using (DbTransaction tn = cn.BeginTransaction()) { foreach (VisitedSystemsClass ps in reader.ReadSystems(cancelRequested)) { ps.EDSM_sync = false; ps.MapColour = defaultMapColour; ps.Commander = EDDConfig.Instance.CurrentCmdrID; ps.Add(cn, tn); visitedSystems.Add(ps); } reader.TravelLogUnit.Update(cn, tn); tn.Commit(); } if (updateProgress != null) { updateProgress((i + 1) * 100 / readersToUpdate.Count, reader.TravelLogUnit.Name); } lastnfi = reader; } } return(visitedSystems); }
private void ScanTickWorker(object sender, System.ComponentModel.DoWorkEventArgs e) { var worker = sender as System.ComponentModel.BackgroundWorker; var entries = new List <VisitedSystemsClass>(); e.Result = entries; int netlogpos = 0; NetLogFileReader nfi = null; try { if (EDDConfig.Instance.NetLogDirAutoMode) { EliteDangerous.CheckED(); } string filename = null; if (m_netLogFileQueue.TryDequeue(out filename)) // if a new one queued, we swap to using it { nfi = OpenFileReader(new FileInfo(filename)); lastnfi = nfi; } else if (!File.Exists(lastnfi.FileName) || lastnfi.filePos >= new FileInfo(lastnfi.FileName).Length) { HashSet <string> tlunames = new HashSet <string>(TravelLogUnit.GetAllNames()); string[] filenames = Directory.EnumerateFiles(GetNetLogPath(), "netLog.*.log", SearchOption.AllDirectories) .Select(s => new { name = Path.GetFileName(s), fullname = s }) .Where(s => !tlunames.Contains(s.name)) .OrderBy(s => s.name) .Select(s => s.fullname) .ToArray(); foreach (var name in filenames) { nfi = OpenFileReader(new FileInfo(name)); lastnfi = nfi; break; } } else { nfi = lastnfi; } if (nfi != null) { if (nfi.TimeZone == null) { nfi.ReadHeader(); if (nfi.TravelLogUnit.id == 0) { nfi.TravelLogUnit.Add(); } } netlogpos = nfi.TravelLogUnit.Size; foreach (VisitedSystemsClass dbsys in nfi.ReadSystems()) { dbsys.EDSM_sync = false; dbsys.MapColour = EDDConfig.Instance.DefaultMapColour; dbsys.Commander = EDDConfig.Instance.CurrentCmdrID; dbsys.Add(); // here we need to make sure the cursystem is set up.. need to do it here because OnNewPosition expects all cursystems to be non null.. VisitedSystemsClass item2 = VisitedSystemsClass.GetLast(dbsys.Commander, dbsys.Time); VisitedSystemsClass.UpdateVisitedSystemsEntries(dbsys, item2, EDDiscoveryForm.EDDConfig.UseDistances); // ensure they have system classes behind them.. entries.Add(dbsys); if (worker.CancellationPending) { break; } } nfi.TravelLogUnit.Update(); } if (worker.CancellationPending) { e.Cancel = true; } } catch (Exception ex) { // Revert and re-read the failed entries if (nfi != null && nfi.TravelLogUnit != null) { nfi.TravelLogUnit.Size = netlogpos; } System.Diagnostics.Trace.WriteLine("Net tick exception : " + ex.Message); System.Diagnostics.Trace.WriteLine(ex.StackTrace); throw; } }