Example #1
0
        public static SystemPosition Parse(DateTime starttime, string line)
        {
            SystemPosition sp = new SystemPosition();

            try
            {
                if (line.Length < 15)
                    return null;

                if (line.StartsWith("<data>"))
                    return null;

                string str = line.Substring(1, 2);

                int hour = int.Parse(str);
                int min = int.Parse(line.Substring(4, 2));
                int sec = int.Parse(line.Substring(7, 2));

                sp.time = new DateTime(starttime.Year, starttime.Month, starttime.Day, hour, min, sec);

                if (sp.time < starttime)
                    sp.time = sp.time.AddDays(1);

                str = line.Substring(18, line.IndexOf(" Body:")-19);

                sp.Nr = int.Parse(str.Substring(0, str.IndexOf("(")));
                sp.Name = str.Substring(str.IndexOf("(")+1);
                return sp;
            }
            catch
            {
                return null;
            }
        }
        private void starMapColourToolStripMenuItem_Click(object sender, EventArgs e)
        {
            IEnumerable <DataGridViewRow> selectedRows = dataGridViewTravel.SelectedCells.Cast <DataGridViewCell>()
                                                         .Select(cell => cell.OwningRow)
                                                         .Distinct();
            Color colour = selectedRows.First().Cells[4].Style.ForeColor;

            mapColorDialog.Color = colour;
            if (mapColorDialog.ShowDialog(this) == DialogResult.OK)
            {
                this.Cursor = Cursors.WaitCursor;
                string sysName = "";
                foreach (DataGridViewRow r in selectedRows)
                {
                    r.Cells[4].Style.ForeColor = mapColorDialog.Color;
                    sysName = r.Cells[1].Value.ToString();

                    SystemPosition sp = null;
                    sp = (SystemPosition)r.Cells[1].Tag;
                    if (sp == null)
                    {
                        sp = visitedSystems.First(s => s.Name.ToUpperInvariant() == sysName.ToUpperInvariant());
                    }
                    if (sp.vs != null)
                    {
                        sp.vs.MapColour = mapColorDialog.Color.ToArgb();
                        sp.Update();
                    }
                }
                this.Cursor = Cursors.Default;
            }
        }
        private void moveToAnotherCommanderToolStripMenuItem_Click(object sender, EventArgs e)
        {
            IEnumerable <DataGridViewRow> selectedRows = dataGridViewTravel.SelectedCells.Cast <DataGridViewCell>()
                                                         .Select(cell => cell.OwningRow)
                                                         .Distinct();



            List <SystemPosition> listsyspos = new List <SystemPosition>();

            {
                this.Cursor = Cursors.WaitCursor;
                string sysName = "";
                foreach (DataGridViewRow r in selectedRows)
                {
                    sysName = r.Cells[1].Value.ToString();
                    SystemPosition sp = null;

                    sp = (SystemPosition)r.Cells[1].Tag;
                    if (sp != null && sp.vs != null)
                    {
                        listsyspos.Add(sp);
                    }
                }

                MoveToCommander movefrm = new MoveToCommander();

                movefrm.Init(listsyspos.Count > 1);

                DialogResult red = movefrm.ShowDialog();
                if (red == DialogResult.OK)
                {
                    if (movefrm.checkBoxAllInNetlog.Checked == false)   // Movel all in list.
                    {
                        foreach (SystemPosition sp in listsyspos)
                        {
                            sp.vs.Commander = movefrm.selectedCommander.Nr;
                            sp.Update();
                        }
                        this.Cursor = Cursors.Default;
                    }
                    else   // Move all systems from the same session
                    {
                    }
                }



                this.Cursor = Cursors.Default;
            }
        }
Example #4
0
        static public SystemPosition Parse(DateTime lasttime, string line)
        {
            SystemPosition sp = new SystemPosition();

            try
            {
                /* MKW: Use regular expressions to parse the log; much more readable and robust.
                 * Example log entry:
                 * {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.
                 */
                Regex pattern = new Regex(@"{(?<Hour>\d+):(?<Minute>\d+):(?<Second>\d+)} System:\d+\((?<SystemName>.*?)\) Body:(?<Body>\d+) Pos:\(.*?\) (?<TravelMode>\w+)");

                Match match = pattern.Match(line);

                int hour = int.Parse(match.Groups["Hour"].Value);
                int min  = int.Parse(match.Groups["Minute"].Value);
                int sec  = int.Parse(match.Groups["Second"].Value);

                sp.Nr   = int.Parse(match.Groups["Body"].Value);
                sp.Name = match.Groups["SystemName"].Value;

                // Debug
                string travelMode = match.Groups["TravelMode"].Value;

                if (hour >= lasttime.Hour)
                {
                    sp.time = new DateTime(lasttime.Year, lasttime.Month, lasttime.Day, hour, min, sec);
                }
                else
                {
                    DateTime tomorrow = lasttime.AddDays(1);
                    sp.time = new DateTime(tomorrow.Year, tomorrow.Month, tomorrow.Day, hour, min, sec);
                }

                if (sp.time.Subtract(lasttime).TotalHours < -4)
                {
                    sp.time = sp.time.AddDays(1);
                }
                return(sp);
            }
            catch
            {
                // MKW TODO: should we log bad lines?
                return(null);
            }
        }
Example #5
0
        static public SystemPosition Parse(DateTime lasttime, string line)
        {
            SystemPosition sp = new SystemPosition();

            try
            {
                if (line.Length < 15)
                {
                    return(null);
                }

                if (line.StartsWith("<data>"))
                {
                    return(null);
                }

                string str = line.Substring(1, 2);

                int hour = int.Parse(str);
                int min  = int.Parse(line.Substring(4, 2));
                int sec  = int.Parse(line.Substring(7, 2));

                if (hour >= lasttime.Hour)
                {
                    sp.time = new DateTime(lasttime.Year, lasttime.Month, lasttime.Day, hour, min, sec);
                }
                else
                {
                    DateTime tomorrow = lasttime.AddDays(1);
                    sp.time = new DateTime(tomorrow.Year, tomorrow.Month, tomorrow.Day, hour, min, sec);
                }

                if (sp.time.Subtract(lasttime).TotalHours < -4)
                {
                    sp.time = sp.time.AddDays(1);
                }

                str = line.Substring(18, line.IndexOf(" Body:") - 19);

                sp.Nr   = int.Parse(str.Substring(0, str.IndexOf("(")));
                sp.Name = str.Substring(str.IndexOf("(") + 1);
                return(sp);
            }
            catch
            {
                return(null);
            }
        }
Example #6
0
        static public SystemPosition Parse(DateTime starttime, string line)
        {
            SystemPosition sp = new SystemPosition();

            try
            {
                if (line.Length < 15)
                {
                    return(null);
                }

                if (line.StartsWith("<data>"))
                {
                    return(null);
                }

                string str = line.Substring(1, 2);

                int hour = int.Parse(str);
                int min  = int.Parse(line.Substring(4, 2));
                int sec  = int.Parse(line.Substring(7, 2));

                sp.time = new DateTime(starttime.Year, starttime.Month, starttime.Day, hour, min, sec);

                if (sp.time < starttime)
                {
                    sp.time = sp.time.AddDays(1);
                }

                str = line.Substring(18, line.IndexOf(" Body:") - 19);

                sp.Nr   = int.Parse(str.Substring(0, str.IndexOf("(")));
                sp.Name = str.Substring(str.IndexOf("(") + 1);
                return(sp);
            }
            catch
            {
                return(null);
            }
        }
        private void hideSystemToolStripMenuItem_Click(object sender, EventArgs e)
        {
            IEnumerable <DataGridViewRow> selectedRows = dataGridViewTravel.SelectedCells.Cast <DataGridViewCell>()
                                                         .Select(cell => cell.OwningRow)
                                                         .Distinct();



            {
                this.Cursor = Cursors.WaitCursor;
                string sysName = "";
                foreach (DataGridViewRow r in selectedRows)
                {
                    sysName = r.Cells[1].Value.ToString();
                    SystemPosition sp = null;

                    sp = (SystemPosition)r.Cells[1].Tag;



                    if (sp != null && sp.vs != null)
                    {
                        sp.vs.Commander = -1;
                        sp.Update();
                    }
                }
                // Remove rows
                if (selectedRows.Count <DataGridViewRow>() == dataGridViewTravel.Rows.Count)
                {
                    dataGridViewTravel.Rows.Clear();
                }

                foreach (DataGridViewRow row in selectedRows.ToList <DataGridViewRow>())
                {
                    dataGridViewTravel.Rows.Remove(row);
                }
                this.Cursor = Cursors.Default;
            }
        }
        private void buttonMap_Click(object sender, EventArgs e)
        {
            var map          = _discoveryForm.Map;
            var selectedLine = dataGridViewTravel.SelectedCells.Cast <DataGridViewCell>()
                               .Select(cell => cell.OwningRow)
                               .OrderBy(row => row.Index)
                               .Select(r => (int?)r.Index)
                               .FirstOrDefault() ?? -1;
            SystemPosition selectedSys = null;

            if (selectedLine >= 0)
            {
                do
                {
                    selectedSys   = (SystemPosition)dataGridViewTravel.Rows[selectedLine].Cells[1].Tag;
                    selectedLine += 1;
                } while (!selectedSys.curSystem.HasCoordinate && selectedLine < dataGridViewTravel.Rows.Count);
            }
            _discoveryForm.updateMapData();
            map.Instance.Reset();

            map.Instance.HistorySelection = (selectedSys != null && selectedSys.curSystem.HasCoordinate) ? selectedSys.Name : textBoxSystem.Text.Trim();
            map.Show();
        }
        private void ShowSystemInformation(SystemPosition syspos)
        {
            if (syspos == null || syspos.Name==null)
                return;

            currentSysPos = syspos;
            textBoxSystem.Text = syspos.curSystem.name;
            textBoxPrevSystem.Clear();
            textBoxDistance.Text = syspos.strDistance;

            if (syspos.curSystem.HasCoordinate)
            {
                textBoxX.Text = syspos.curSystem.x.ToString("#.#####");
                textBoxY.Text = syspos.curSystem.y.ToString("#.#####");
                textBoxZ.Text = syspos.curSystem.z.ToString("#.#####");
            }
            else
            {
                textBoxX.Text = "?";
                textBoxY.Text = "?";
                textBoxZ.Text = "?";

            }

            int count = GetVisitsCount(syspos.curSystem.name);
            textBoxVisits.Text = count.ToString();

            if (currentSysPos.curSystem.id_eddb > 0)  // Only enable eddb/ross for system that it knows about
            {
                buttonEDDB.Visible = true;
                buttonRoss.Visible = true;
            }
            else
            {
                buttonEDDB.Visible = false;
                buttonRoss.Visible = false;
            }

            textBoxAllegiance.Text = EnumStringFormat(syspos.curSystem.allegiance.ToString());
            textBoxEconomy.Text = EnumStringFormat(syspos.curSystem.primary_economy.ToString());
            textBoxGovernment.Text = EnumStringFormat(syspos.curSystem.government.ToString());
            textBoxState.Text = EnumStringFormat(syspos.curSystem.state.ToString());
            richTextBoxNote.Text = EnumStringFormat(syspos.curSystem.Note);

            bool distedit = false;

            if (syspos.prevSystem != null)
            {
                textBoxPrevSystem.Text = syspos.prevSystem.name;

                if (syspos.curSystem.status == SystemStatusEnum.Unknown || syspos.prevSystem.status == SystemStatusEnum.Unknown)
                    distedit = true;

            }

            textBoxDistance.Enabled = distedit;
            buttonUpdate.Enabled = distedit;
            buttonTrilaterate.Enabled = !syspos.curSystem.HasCoordinate && syspos.curSystem == GetCurrentSystem();
            //buttonTrilaterate.Enabled = true; // FIXME for debugging only

            ShowClosestSystems(syspos.Name);
        }
        private void ShowSystemInformation(SystemPosition syspos)
        {
            if (syspos == null || syspos.Name == null)
            {
                return;
            }

            currentSysPos      = syspos;
            textBoxSystem.Text = syspos.curSystem.name;
            textBoxPrevSystem.Clear();
            textBoxDistance.Text = syspos.strDistance;


            if (syspos.curSystem.HasCoordinate)
            {
                textBoxX.Text = syspos.curSystem.x.ToString("#.#####");
                textBoxY.Text = syspos.curSystem.y.ToString("#.#####");
                textBoxZ.Text = syspos.curSystem.z.ToString("#.#####");

                textBoxSolDist.Text = Math.Sqrt(syspos.curSystem.x * syspos.curSystem.x + syspos.curSystem.y * syspos.curSystem.y + syspos.curSystem.z * syspos.curSystem.z).ToString("0.00");

                //// For test only
                //Stopwatch sw = new Stopwatch();
                //sw.Start();
                //SuggestedReferences refereces = new SuggestedReferences(syspos.curSystem.x, syspos.curSystem.y, syspos.curSystem.z);

                //ReferenceSystem rsys;

                //for (int ii = 0; ii < 16; ii++)
                //{
                //    rsys = refereces.GetCandidate();
                //    refereces.AddReferenceStar(rsys.System);
                //    System.Diagnostics.Trace.WriteLine(rsys.System.name + " Dist: " + rsys.Distance.ToString("0.00") + " x:" + rsys.System.x.ToString() + " y:" + rsys.System.y.ToString() + " z:" + rsys.System.z.ToString() );
                //}
                //sw.Stop();
                //System.Diagnostics.Trace.WriteLine("Reference stars time " + sw.Elapsed.TotalSeconds.ToString("0.000s"));
            }
            else
            {
                textBoxX.Text       = "?";
                textBoxY.Text       = "?";
                textBoxZ.Text       = "?";
                textBoxSolDist.Text = "";
            }

            int count = GetVisitsCount(syspos.curSystem.name);

            textBoxVisits.Text = count.ToString();

            if (currentSysPos.curSystem.id_eddb > 0)  // Only enable eddb/ross for system that it knows about
            {
                buttonEDDB.Visible = true;
                buttonRoss.Visible = true;
            }
            else
            {
                buttonEDDB.Visible = false;
                buttonRoss.Visible = false;
            }


            textBoxAllegiance.Text = EnumStringFormat(syspos.curSystem.allegiance.ToString());
            textBoxEconomy.Text    = EnumStringFormat(syspos.curSystem.primary_economy.ToString());
            textBoxGovernment.Text = EnumStringFormat(syspos.curSystem.government.ToString());
            textBoxState.Text      = EnumStringFormat(syspos.curSystem.state.ToString());
            richTextBoxNote.Text   = EnumStringFormat(syspos.curSystem.Note);

            bool distedit = false;

            if (syspos.prevSystem != null)
            {
                textBoxPrevSystem.Text = syspos.prevSystem.name;

                if (syspos.curSystem.status == SystemStatusEnum.Unknown || syspos.prevSystem.status == SystemStatusEnum.Unknown)
                {
                    distedit = true;
                }
            }

            textBoxDistance.Enabled   = distedit;
            buttonUpdate.Enabled      = distedit;
            buttonTrilaterate.Enabled = !syspos.curSystem.HasCoordinate && syspos.curSystem == GetCurrentSystem();
            //buttonTrilaterate.Enabled = true; // FIXME for debugging only


            ShowClosestSystems(syspos.Name);
        }
        private void ShowClosestSystems(string name)
        {
            sysDist = new List <SystemDist>();
            SystemClass LastSystem = null;
            float       dx, dy, dz;
            double      dist;

            try
            {
                if (name == null)
                {
                    var result = visitedSystems.OrderByDescending(a => a.time).ToList <SystemPosition>();


                    for (int ii = 0; ii < result.Count; ii++) //foreach (var item in result)
                    {
                        SystemPosition item = result[ii];

                        LastSystem = SystemData.GetSystem(item.Name);
                        name       = item.Name;
                        if (LastSystem != null)
                        {
                            break;
                        }
                    }
                }
                else
                {
                    LastSystem = SystemData.GetSystem(name);
                }

                if (name != null)
                {
                    label3.Text = "Closest systems from " + name.ToString();
                }

                dataGridViewNearest.Rows.Clear();

                if (LastSystem == null)
                {
                    return;
                }

                foreach (SystemClass pos in SystemData.SystemList)
                {
                    dx   = (float)(pos.x - LastSystem.x);
                    dy   = (float)(pos.y - LastSystem.y);
                    dz   = (float)(pos.z - LastSystem.z);
                    dist = dx * dx + dy * dy + dz * dz;

                    //distance = (float)((system.x - arcsystem.x) * (system.x - arcsystem.x) + (system.y - arcsystem.y) * (system.y - arcsystem.y) + (system.z - arcsystem.z) * (system.z - arcsystem.z));

                    if (dist > 0)
                    {
                        SystemDist sdist = new SystemDist();
                        sdist.name = pos.name;
                        sdist.dist = Math.Sqrt(dist);
                        sysDist.Add(sdist);
                    }
                }

                var list = (from t in sysDist orderby t.dist select t).Take(50);

                foreach (SystemDist sdist in list)
                {
                    object[] rowobj = { sdist.name, sdist.dist.ToString("0.00") };
                    dataGridViewNearest.Rows.Add(rowobj);
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine("Exception : " + ex.Message);
                System.Diagnostics.Trace.WriteLine(ex.StackTrace);
            }
        }
        public void RefreshHistory()
        {
            Stopwatch sw1 = new Stopwatch();

            //richTextBox_History.Clear();


            sw1.Start();


            TimeSpan maxDataAge = TimeSpan.Zero;
            int      atMost     = 0;

            switch (comboBoxHistoryWindow.SelectedIndex)
            {
            case 0:
                maxDataAge = new TimeSpan(6, 0, 0);     // 6 hours
                break;

            case 1:
                maxDataAge = new TimeSpan(12, 0, 0);     // 12 hours
                break;

            case 2:
                maxDataAge = new TimeSpan(24, 0, 0);     // 24 hours
                break;

            case 3:
                maxDataAge = new TimeSpan(3 * 24, 0, 0);     // 3 days
                break;

            case 4:
                maxDataAge = new TimeSpan(7 * 24, 0, 0);     // 1 week
                break;

            case 5:
                maxDataAge = new TimeSpan(14 * 24, 0, 0);     // 2 weeks
                break;

            case 6:
                maxDataAge = new TimeSpan(30, 0, 0, 0);     // 30 days (month)
                break;

            case 7:
                atMost = 20;     // Last 20
                break;

            case 8:
                maxDataAge = new TimeSpan(100000, 24, 0, 0);     // all
                break;

            default:
                maxDataAge = new TimeSpan(7 * 24, 0, 0);     // 1 week (default)
                break;
            }


            if (visitedSystems == null || visitedSystems.Count == 0)
            {
                GetVisitedSystems();
            }

            if (visitedSystems == null)
            {
                return;
            }

            List <SystemPosition> result;

            if (atMost > 0)
            {
                result = visitedSystems.OrderByDescending(s => s.time).Take(atMost).ToList();
            }
            else
            {
                var oldestData = DateTime.Now.Subtract(maxDataAge);
                result = (from systems in visitedSystems where systems.time > oldestData orderby systems.time descending select systems).ToList();
            }

            dataGridViewTravel.Rows.Clear();

            System.Diagnostics.Trace.WriteLine("SW1: " + (sw1.ElapsedMilliseconds / 1000.0).ToString("0.000"));

            for (int ii = 0; ii < result.Count; ii++) //foreach (var item in result)
            {
                SystemPosition item = result[ii];
                SystemPosition item2;

                if (ii < result.Count - 1)
                {
                    item2 = result[ii + 1];
                }
                else
                {
                    item2 = null;
                }

                AddHistoryRow(false, item, item2);
            }


            if (result.Count != visitedSystems.Count)
            {
                // we didn't put all the systems in the history grid
                // make sure that the LastKnown system is properly loaded if it's not visible so trilateration can find it...
                var lastKnown = (from systems
                                 in visitedSystems
                                 where systems.curSystem != null && systems.curSystem.HasCoordinate
                                 orderby systems.time descending
                                 select systems.curSystem).FirstOrDefault();
                if (lastKnown == null)
                {
                    for (int ii = visitedSystems.Count - 1; ii > 0; ii--)
                    {
                        SystemClass sys = SystemData.GetSystem(visitedSystems[ii].Name);
                        if (visitedSystems[ii].curSystem == null && sys != null)
                        {
                            visitedSystems[ii].curSystem = sys;
                            if (sys.HasCoordinate)
                            {
                                break;
                            }
                        }
                    }
                }
            }

            System.Diagnostics.Trace.WriteLine("SW2: " + (sw1.ElapsedMilliseconds / 1000.0).ToString("0.000"));

            if (dataGridViewTravel.Rows.Count > 0)
            {
                ShowSystemInformation((SystemPosition)(dataGridViewTravel.Rows[0].Cells[1].Tag));
            }
            System.Diagnostics.Trace.WriteLine("SW3: " + (sw1.ElapsedMilliseconds / 1000.0).ToString("0.000"));
            sw1.Stop();

            if (textBoxFilter.TextLength > 0)
            {
                FilterGridView();
            }
        }
        private void AddHistoryRow(bool insert, SystemPosition item, SystemPosition item2)
        {
            SystemClass sys1 = null, sys2;
            double      dist;


            sys1 = SystemData.GetSystem(item.Name);
            if (sys1 == null)
            {
                sys1 = new SystemClass(item.Name);
                if (SQLiteDBClass.globalSystemNotes.ContainsKey(sys1.SearchName))
                {
                    sys1.Note = SQLiteDBClass.globalSystemNotes[sys1.SearchName].Note;
                }
            }
            if (item2 != null)
            {
                sys2 = SystemData.GetSystem(item2.Name);
                if (sys2 == null)
                {
                    sys2 = new SystemClass(item2.Name);
                }
            }
            else
            {
                sys2 = null;
            }

            item.curSystem  = sys1;
            item.prevSystem = sys2;
            if (!insert)
            {
                if (item.vs == null)
                {
                    SystemPosition known = visitedSystems.First(x => x.Name == item.Name);
                    if (known != null)
                    {
                        item.vs = known.vs;
                    }
                }
            }

            string diststr = "";

            dist = 0;
            if (sys2 != null)
            {
                if (sys1.HasCoordinate && sys2.HasCoordinate)
                {
                    dist = SystemData.Distance(sys1, sys2);
                }
                else
                {
                    dist = DistanceClass.Distance(sys1, sys2);
                }

                if (dist > 0)
                {
                    diststr = dist.ToString("0.00");
                }
            }

            item.strDistance = diststr;

            //richTextBox_History.AppendText(item.time + " " + item.Name + Environment.NewLine);

            object[] rowobj = { item.time, item.Name, diststr, item.curSystem.Note, "█" };
            int      rownr;

            if (insert)
            {
                dataGridViewTravel.Rows.Insert(0, rowobj);
                rownr = 0;
            }
            else
            {
                dataGridViewTravel.Rows.Add(rowobj);
                rownr = dataGridViewTravel.Rows.Count - 1;
            }

            var cell = dataGridViewTravel.Rows[rownr].Cells[1];

            cell.Tag = item;

            dataGridViewTravel.Rows[rownr].DefaultCellStyle.ForeColor = (sys1.HasCoordinate) ? _discoveryForm.theme.VisitedSystemColor : _discoveryForm.theme.NonVisitedSystemColor;

            cell = dataGridViewTravel.Rows[rownr].Cells[4];
            cell.Style.ForeColor = (item.vs == null) ? Color.FromArgb(defaultMapColour) : Color.FromArgb(item.vs.MapColour);
        }
        public void RefreshHistory()
        {
            Stopwatch sw1 = new Stopwatch();

            //richTextBox_History.Clear();


            sw1.Start();


            TimeSpan maxDataAge = TimeSpan.Zero;
            int      atMost     = 0;

            switch (comboBoxHistoryWindow.SelectedIndex)
            {
            case 0:
                maxDataAge = new TimeSpan(6, 0, 0);     // 6 hours
                break;

            case 1:
                maxDataAge = new TimeSpan(12, 0, 0);     // 12 hours
                break;

            case 2:
                maxDataAge = new TimeSpan(24, 0, 0);     // 24 hours
                break;

            case 3:
                maxDataAge = new TimeSpan(3 * 24, 0, 0);     // 3 days
                break;

            case 4:
                maxDataAge = new TimeSpan(7 * 24, 0, 0);     // 1 week
                break;

            case 5:
                maxDataAge = new TimeSpan(14 * 24, 0, 0);     // 2 weeks
                break;

            case 6:
                maxDataAge = new TimeSpan(30, 0, 0, 0);     // 30 days (month)
                break;

            case 7:
                atMost = 20;     // Last 20
                break;

            case 8:
                maxDataAge = new TimeSpan(100000, 24, 0, 0);     // all
                break;

            default:
                maxDataAge = new TimeSpan(7 * 24, 0, 0);     // 1 week (default)
                break;
            }


            if (visitedSystems == null || visitedSystems.Count == 0)
            {
                visitedSystems = netlog.ParseFiles(richTextBox_History);
            }


            if (visitedSystems == null)
            {
                return;
            }

            //var result = visitedSystems.OrderByDescending(a => a.time).ToList<SystemPosition>();

            List <SystemPosition> result;

            if (atMost > 0)
            {
                result = visitedSystems.OrderByDescending(s => s.time).Take(atMost).ToList();
            }
            else
            {
                var oldestData = DateTime.Now.Subtract(maxDataAge);
                result = (from systems in visitedSystems where systems.time > oldestData orderby systems.time descending select systems).ToList();
            }

            //DataTable dt = new DataTable();
            //dataGridView1.Columns.Clear();
            //dt.Columns.Add("Time");
            //dt.Columns.Add("System");
            //dt.Columns.Add("Distance");


            dataGridView1.Rows.Clear();

            //dataGridView1.DataSource = dt;

            System.Diagnostics.Trace.WriteLine("SW1: " + (sw1.ElapsedMilliseconds / 1000.0).ToString("0.000"));


            for (int ii = 0; ii < result.Count; ii++) //foreach (var item in result)
            {
                SystemPosition item = result[ii];
                SystemPosition item2;

                if (ii < result.Count - 1)
                {
                    item2 = result[ii + 1];
                }
                else
                {
                    item2 = null;
                }

                AddHistoryRow(false, item, item2);
            }

            System.Diagnostics.Trace.WriteLine("SW2: " + (sw1.ElapsedMilliseconds / 1000.0).ToString("0.000"));

            //setRowNumber(dataGridView1);

            if (dataGridView1.Rows.Count > 0)
            {
                lastRowIndex = 0;
                ShowSystemInformation((SystemPosition)(dataGridView1.Rows[0].Cells[1].Tag));
            }
            System.Diagnostics.Trace.WriteLine("SW3: " + (sw1.ElapsedMilliseconds / 1000.0).ToString("0.000"));
            sw1.Stop();

            if (textBoxFilter.TextLength > 0)
            {
                FilterGridView();
            }
        }
Example #15
0
        public int GetLogs(DateTime starttime, out List<SystemPosition> log)
        {
            log = new List<SystemPosition>();

            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)
                {
                    SystemPosition pos = new SystemPosition();

                    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;
        }
        private void AddHistoryRow(bool insert, SystemPosition item, SystemPosition item2)
        {
            SystemClass sys1 = null, sys2;
            double      dist;

            sys1 = SystemData.GetSystem(item.Name);
            if (sys1 == null)
            {
                sys1 = new SystemClass(item.Name);
                if (SQLiteDBClass.globalSystemNotes.ContainsKey(sys1.SearchName))
                {
                    sys1.Note = SQLiteDBClass.globalSystemNotes[sys1.SearchName].Note;
                }
            }
            if (item2 != null)
            {
                sys2 = SystemData.GetSystem(item2.Name);
                if (sys2 == null)
                {
                    sys2 = new SystemClass(item2.Name);
                }
            }
            else
            {
                sys2 = null;
            }

            item.curSystem  = sys1;
            item.prevSystem = sys2;


            string diststr = "";

            dist = 0;
            if (sys2 != null)
            {
                if (sys1.HasCoordinate && sys2.HasCoordinate)
                {
                    dist = SystemData.Distance(sys1, sys2);
                }
                else
                {
                    dist = DistanceClass.Distance(sys1, sys2);
                }

                if (dist > 0)
                {
                    diststr = dist.ToString("0.00");
                }
            }

            item.strDistance = diststr;

            //richTextBox_History.AppendText(item.time + " " + item.Name + Environment.NewLine);

            object[] rowobj = { item.time, item.Name, diststr, item.curSystem.Note };
            int      rownr;

            if (insert)
            {
                dataGridView1.Rows.Insert(0, rowobj);
                rownr = 0;
            }
            else
            {
                dataGridView1.Rows.Add(rowobj);
                rownr = dataGridView1.Rows.Count - 1;
            }

            var cell = dataGridView1.Rows[rownr].Cells[1];

            cell.Tag = item;

            if (!sys1.HasCoordinate)      // Mark all systems without coordinates
            {
                cell.Style.ForeColor = Color.Blue;
            }
        }
        private void AddHistoryRow(bool insert, SystemPosition item, SystemPosition item2)
        {
            SystemClass sys1 = null, sys2;
            double dist;
            

            sys1 = SystemData.GetSystem(item.Name);
            if (sys1 == null)
            {
                sys1 = new SystemClass(item.Name);
                if (SQLiteDBClass.globalSystemNotes.ContainsKey(sys1.SearchName))
                {
                    sys1.Note = SQLiteDBClass.globalSystemNotes[sys1.SearchName].Note;
                }
            }
            if (item2 != null)
            {
                sys2 = SystemData.GetSystem(item2.Name);
                if (sys2 == null)
                    sys2 = new SystemClass(item2.Name);

            }
            else
                sys2 = null;

            item.curSystem = sys1;
            item.prevSystem = sys2;
            if (!insert)
            {
                SystemPosition known = visitedSystems.First(x => x.Name == item.Name);
                if (known != null) item.vs = known.vs;
            }

            string diststr = "";
            dist = 0;
            if (sys2 != null)
            {

                if (sys1.HasCoordinate && sys2.HasCoordinate)
                    dist = SystemData.Distance(sys1, sys2);
                else
                {

                    dist = DistanceClass.Distance(sys1, sys2);
                }

                if (dist > 0)
                    diststr = dist.ToString("0.00");
            }

            item.strDistance = diststr;

            //richTextBox_History.AppendText(item.time + " " + item.Name + Environment.NewLine);

                object[] rowobj = { item.time, item.Name, diststr, item.curSystem.Note, "█" };
                int rownr;

                if (insert)
                {
                    dataGridView1.Rows.Insert(0, rowobj);
                    rownr = 0;
                }
                else
                {
                    dataGridView1.Rows.Add(rowobj);
                    rownr = dataGridView1.Rows.Count - 1;
                }

                var cell = dataGridView1.Rows[rownr].Cells[1];

                cell.Tag = item;

                if (!sys1.HasCoordinate)  // Mark all systems without coordinates
                    cell.Style.ForeColor = Color.Blue;

                cell = dataGridView1.Rows[rownr].Cells[4];
                cell.Style.ForeColor = Color.FromArgb(item.vs == null ? defaultColour : item.vs.MapColour);
            }
        internal void NewPosition(object source)
        {
            try
            {
                string name = netlog.visitedSystems.Last().Name;
                Invoke((MethodInvoker) delegate
                {
                    LogText("Arrived to system: ");
                    SystemClass sys1 = SystemData.GetSystem(name);
                    if (sys1 == null || sys1.HasCoordinate == false)
                    {
                        LogTextHighlight(name);
                    }
                    else
                    {
                        LogText(name);
                    }


                    int count = GetVisitsCount(name);

                    LogText("  : Vist nr " + count.ToString() + Environment.NewLine);
                    System.Diagnostics.Trace.WriteLine("Arrived to system: " + name + " " + count.ToString() + ":th visit.");

                    var result = visitedSystems.OrderByDescending(a => a.time).ToList <SystemPosition>();

                    //if (TrilaterationControl.Visible)
                    //{
                    //    CloseTrilateration();
                    //    MessageBox.Show("You have arrived to another system while trilaterating."
                    //                    + " As a pre-caution to prevent any mistakes with submitting wrong systems or distances"
                    //                    + ", your trilateration was aborted.");
                    //}


                    SystemPosition item = result[0];
                    SystemPosition item2;

                    if (result.Count > 1)
                    {
                        item2 = result[1];
                    }
                    else
                    {
                        item2 = null;
                    }

                    // grab distance to next (this) system
                    textBoxDistanceToNextSystem.Enabled = false;
                    if (textBoxDistanceToNextSystem.Text.Length > 0 && item2 != null)
                    {
                        SystemClass currentSystem = null, previousSystem = null;
                        SystemData.SystemList.ForEach(s =>
                        {
                            if (s.name == item.Name)
                            {
                                currentSystem = s;
                            }
                            if (s.name == item2.Name)
                            {
                                previousSystem = s;
                            }
                        });

                        if (currentSystem == null || previousSystem == null || !currentSystem.HasCoordinate || !previousSystem.HasCoordinate)
                        {
                            var presetDistance = DistanceAsDouble(textBoxDistanceToNextSystem.Text.Trim(), 45);
                            if (presetDistance.HasValue)
                            {
                                var distance = new DistanceClass
                                {
                                    Dist            = presetDistance.Value,
                                    CreateTime      = DateTime.UtcNow,
                                    CommanderCreate = EDDiscoveryForm.EDDConfig.CurrentCommander.Name,
                                    NameA           = item.Name,
                                    NameB           = item2.Name,
                                    Status          = DistancsEnum.EDDiscovery
                                };
                                Console.Write("Pre-set distance " + distance.NameA + " -> " + distance.NameB + " = " + distance.Dist);
                                distance.Store();
                                SQLiteDBClass.AddDistanceToCache(distance);
                            }
                        }
                    }
                    textBoxDistanceToNextSystem.Clear();
                    textBoxDistanceToNextSystem.Enabled = true;

                    AddHistoryRow(true, item, item2);
                    StoreSystemNote();
                });
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine("Exception NewPosition: " + ex.Message);
                System.Diagnostics.Trace.WriteLine("Trace: " + ex.StackTrace);
            }
        }
        private void AddHistoryRow(DateTime oldestData, SystemPosition item, SystemPosition item2)
        {
            SystemClass sys1 = null, sys2;
            double dist;

            sys1 = SystemData.GetSystem(item.Name);
            if (sys1 == null)
            {
                sys1 = new SystemClass(item.Name);
                if (SQLiteDBClass.globalSystemNotes.ContainsKey(sys1.SearchName))
                {
                    sys1.Note = SQLiteDBClass.globalSystemNotes[sys1.SearchName].Note;
                }
            }
            if (item2 != null)
            {
                sys2 = SystemData.GetSystem(item2.Name);
                if (sys2 == null)
                    sys2 = new SystemClass(item2.Name);

            }
            else
                sys2 = null;

            item.curSystem = sys1;
            item.prevSystem = sys2;

            string diststr = "";
            dist = 0;
            if (sys2 != null)
            {

                if (sys1.HasCoordinate && sys2.HasCoordinate)
                    dist = SystemData.Distance(sys1, sys2);
                else
                {

                    dist = DistanceClass.Distance(sys1, sys2);
                }

                if (dist > 0)
                    diststr = dist.ToString("0.00");
            }

            item.strDistance = diststr;

            //richTextBox_History.AppendText(item.time + " " + item.Name + Environment.NewLine);

            if (item.time.Subtract(oldestData).TotalDays > 0)
            {
                object[] rowobj = new object[] { item.time, item.Name, diststr, item.curSystem.Note };
                int rownr;

                if (oldestData.Year == 1990)
                {
                    dataGridView1.Rows.Insert(0, rowobj);
                    rownr = 0;
                }
                else
                {
                    dataGridView1.Rows.Add(rowobj);
                    rownr = dataGridView1.Rows.Count - 1;
                }

                var cell = dataGridView1.Rows[rownr].Cells[1];

                cell.Tag = item;

                if (!sys1.HasCoordinate)  // Mark all systems without coordinates
                    cell.Style.ForeColor = Color.Blue;
            }
        }
        private void ShowSystemInformation(SystemPosition syspos)
        {
            if (syspos == null || syspos.Name==null)
                return;

            currentSysPos = syspos;
            textBoxSystem.Text = syspos.curSystem.name;
            textBoxPrevSystem.Clear();
            textBoxDistance.Text = syspos.strDistance;
          

            if (syspos.curSystem.HasCoordinate)
            {
                textBoxX.Text = syspos.curSystem.x.ToString("#.#####");
                textBoxY.Text = syspos.curSystem.y.ToString("#.#####");
                textBoxZ.Text = syspos.curSystem.z.ToString("#.#####");

                textBoxSolDist.Text = Math.Sqrt(syspos.curSystem.x * syspos.curSystem.x + syspos.curSystem.y * syspos.curSystem.y + syspos.curSystem.z * syspos.curSystem.z).ToString("0.00");

                //// For test only
                //Stopwatch sw = new Stopwatch();
                //sw.Start();
                //SuggestedReferences refereces = new SuggestedReferences(syspos.curSystem.x, syspos.curSystem.y, syspos.curSystem.z);

                //ReferenceSystem rsys;

                //for (int ii = 0; ii < 16; ii++)
                //{
                //    rsys = refereces.GetCandidate();
                //    refereces.AddReferenceStar(rsys.System);
                //    System.Diagnostics.Trace.WriteLine(rsys.System.name + " Dist: " + rsys.Distance.ToString("0.00") + " x:" + rsys.System.x.ToString() + " y:" + rsys.System.y.ToString() + " z:" + rsys.System.z.ToString() );
                //}
                //sw.Stop();
                //System.Diagnostics.Trace.WriteLine("Reference stars time " + sw.Elapsed.TotalSeconds.ToString("0.000s"));


            }
            else
            {
                textBoxX.Text = "?";
                textBoxY.Text = "?";
                textBoxZ.Text = "?";
                textBoxSolDist.Text = "";

            }

            int count = GetVisitsCount(syspos.curSystem.name);
            textBoxVisits.Text = count.ToString();

            if (currentSysPos.curSystem.id_eddb > 0)  // Only enable eddb/ross for system that it knows about
            {
                buttonEDDB.Visible = true;
                buttonRoss.Visible = true;
            }
            else
            {
                buttonEDDB.Visible = false;
                buttonRoss.Visible = false;
            }


            textBoxAllegiance.Text = EnumStringFormat(syspos.curSystem.allegiance.ToString());
            textBoxEconomy.Text = EnumStringFormat(syspos.curSystem.primary_economy.ToString());
            textBoxGovernment.Text = EnumStringFormat(syspos.curSystem.government.ToString());
            textBoxState.Text = EnumStringFormat(syspos.curSystem.state.ToString());
            richTextBoxNote.Text = EnumStringFormat(syspos.curSystem.Note);

            bool distedit = false;

            if (syspos.prevSystem != null)
            {
                textBoxPrevSystem.Text = syspos.prevSystem.name;

                if (syspos.curSystem.status == SystemStatusEnum.Unknown || syspos.prevSystem.status == SystemStatusEnum.Unknown)
                    distedit = true;

            }

            textBoxDistance.Enabled = distedit;
            buttonUpdate.Enabled = distedit;
            buttonTrilaterate.Enabled = !syspos.curSystem.HasCoordinate && syspos.curSystem == GetCurrentSystem();
            //buttonTrilaterate.Enabled = true; // FIXME for debugging only


            ShowClosestSystems(syspos.Name);
        }
Example #21
0
        private int ReadData(FileInfo fi, List <SystemPosition> visitedSystems, int count, StreamReader sr)
        {
            DateTime gammastart = new DateTime(2014, 11, 22, 13, 00, 00);

            DateTime       filetime = DateTime.Now.AddDays(-500);
            string         FirstLine = sr.ReadLine();
            string         line, str;
            NetLogFileInfo nfi = null;

            str = "20" + FirstLine.Substring(0, 8) + " " + FirstLine.Substring(9, 5);

            filetime = DateTime.Parse(str);

            if (netlogfiles.ContainsKey(fi.FullName))
            {
                nfi = netlogfiles[fi.FullName];
                sr.BaseStream.Position = nfi.filePos;
                sr.DiscardBufferedData();
            }

            while ((line = sr.ReadLine()) != null)
            {
                if (line.Contains(" System:"))
                {
                    SystemPosition ps = SystemPosition.Parse(filetime, line);
                    if (ps != null)
                    {
                        if (ps.Name.Equals("Training"))
                        {
                            continue;
                        }
                        if (ps.Name.Equals("Destination"))
                        {
                            continue;
                        }


                        if (visitedSystems.Count > 0)
                        {
                            if (visitedSystems[visitedSystems.Count - 1].Name.Equals(ps.Name))
                            {
                                continue;
                            }
                        }

                        if (ps.time.Subtract(gammastart).TotalMinutes > 0)  // Ta bara med efter gamma.
                        {
                            visitedSystems.Add(ps);
                            count++;

                            //System.Diagnostics.Trace.WriteLine("Added system: " + ps.Name);
                        }

                        //Console.WriteLine(line);
                    }
                }
            }


            if (nfi == null)
            {
                nfi = new NetLogFileInfo();
            }

            nfi.FileName    = fi.FullName;
            nfi.lastchanged = File.GetLastWriteTimeUtc(nfi.FileName);
            nfi.filePos     = sr.BaseStream.Position;
            nfi.fileSize    = fi.Length;

            netlogfiles[nfi.FileName] = nfi;
            lastnfi = nfi;

            return(count);
        }
Example #22
0
        private int ReadData(FileInfo fi, List <SystemPosition> visitedSystems, int count, StreamReader sr)
        {
            DateTime gammastart = new DateTime(2014, 11, 22, 13, 00, 00);

            DateTime       filetime = DateTime.Now.AddDays(-500);
            string         FirstLine = sr.ReadLine();
            string         line, str;
            NetLogFileInfo nfi = null;
            bool           CQC = false;

            str = "20" + FirstLine.Substring(0, 8) + " " + FirstLine.Substring(9, 5);

            filetime = DateTime.Parse(str);

            if (netlogfiles.ContainsKey(fi.FullName))
            {
                nfi = netlogfiles[fi.FullName];
                sr.BaseStream.Position = nfi.filePos;
                sr.DiscardBufferedData();
                CQC = nfi.CQC;
            }

            while ((line = sr.ReadLine()) != null)
            {
                if (line.Contains("[PG] [Notification] Left a playlist lobby"))
                {
                    CQC = false;
                }

                if (line.Contains("[PG] Destroying playlist lobby."))
                {
                    CQC = false;
                }

                if (line.Contains("[PG] [Notification] Joined a playlist lobby"))
                {
                    CQC = true;
                }
                if (line.Contains("[PG] Created playlist lobby"))
                {
                    CQC = true;
                }
                if (line.Contains("[PG] Found matchmaking lobby object"))
                {
                    CQC = true;
                }

                if (line.Contains(" System:") && CQC == false)
                {
                    if (line.Contains("ProvingGround"))
                    {
                        continue;
                    }

                    SystemPosition ps = SystemPosition.Parse(filetime, line);
                    if (ps != null)
                    {   // Remove some training systems
                        if (ps.Name.Equals("Training"))
                        {
                            continue;
                        }
                        if (ps.Name.Equals("Destination"))
                        {
                            continue;
                        }
                        if (ps.Name.Equals("Altiris"))
                        {
                            continue;
                        }
                        filetime = ps.time;

                        if (visitedSystems.Count > 0)
                        {
                            if (visitedSystems[visitedSystems.Count - 1].Name.Equals(ps.Name))
                            {
                                continue;
                            }
                        }

                        if (ps.time.Subtract(gammastart).TotalMinutes > 0)  // Ta bara med efter gamma.
                        {
                            visitedSystems.Add(ps);
                            count++;

                            //System.Diagnostics.Trace.WriteLine("Added system: " + ps.Name);
                        }

                        //Console.WriteLine(line);
                    }
                }
            }


            if (nfi == null)
            {
                nfi = new NetLogFileInfo();
            }

            nfi.FileName    = fi.FullName;
            nfi.lastchanged = File.GetLastWriteTimeUtc(nfi.FileName);
            nfi.filePos     = sr.BaseStream.Position;
            nfi.fileSize    = fi.Length;
            nfi.CQC         = CQC;

            netlogfiles[nfi.FileName] = nfi;
            lastnfi = nfi;

            return(count);
        }