// this function does the history refresh, executes on Background worker or background history refresh thread
        private void DoRefreshHistory(RefreshWorkerArgs args)
        {
            HistoryList hist = null;

            try
            {
                refreshWorkerArgs = args;

                Trace.WriteLine(BaseUtils.AppTicks.TickCountLap() + " Load history for Cmdr " + args.CurrentCommander + " " + EDCommander.Current.Name);

                if (args.RemoveDuplicateFSDEntries)
                {
                    int n = JournalEntry.RemoveDuplicateFSDEntries(EDCommander.CurrentCmdrID);
                    LogLine(string.Format("Removed {0} FSD entries".T(EDTx.EDDiscoveryForm_FSDRem), n));
                }

                if (args.CurrentCommander >= 0)                                              // if we have a real commander
                {
                    journalmonitor.SetupWatchers();                                          // monitors are stopped, set up watchers

                    int forcereloadoflastn = args.ForceJournalReload ? int.MaxValue / 2 : 0; // if forcing a reload, we indicate that by setting the reload count to a very high value, but not enough to cause int wrap

                    journalmonitor.ParseJournalFilesOnWatchers((p, s) => ReportRefreshProgress(p, string.Format("Processing log file {0}".T(EDTx.EDDiscoveryController_PLF), s)),
                                                               forcereloadoflastn);

                    if (args.NetLogPath != null)            // see if net logs need reading for old times sake.
                    {
                        NetLogClass.ParseFiles(args.NetLogPath, out string errstr, EDCommander.Current.MapColour, () => PendingClose, (p, s) => ReportRefreshProgress(p, s),
                                               args.ForceNetLogReload, currentcmdrid: args.CurrentCommander);
                    }
                }

                hist = HistoryList.LoadHistory((s) => ReportRefreshProgress(-1, s),
                                               args.CurrentCommander,
                                               EDDConfig.Instance.FullHistoryLoadDayLimit,
                                               EDDConfig.Instance.EssentialEventTypes
                                               );

                if (args.NetLogPath != null)
                {
                    ReportRefreshProgress(-1, "Netlog Updating System Positions");
                    hist.FillInPositionsFSDJumps(LogLine);                         // if netlog reading, try and resolve systems..
                }

                EDCommander.Current.FID = hist.GetCommanderFID();                   // ensure FID is set.. the other place it gets changed is a read of LoadGame.

                ReportRefreshProgress(-1, "Done");

                Trace.WriteLine(BaseUtils.AppTicks.TickCountLap() + " Load history complete with " + hist.Count + " records");
            }
            catch (Exception ex)
            {
                LogLineHighlight("History Refresh Error: " + ex);
            }

            ReportRefreshProgress(-1, "Refresh Displays".T(EDTx.EDDiscoveryController_RD));

            InvokeAsyncOnUiThread(() => ForegroundHistoryRefreshCompleteonUI(hist));
        }
Пример #2
0
 private void GetVisitedSystems()
 {                                                       // for backwards compatibility, don't store RGB value.
     visitedSystems = netlog.ParseFiles(richTextBox_History, defaultMapColour);
 }
Пример #3
0
 private void GetVisitedSystems(int commander)
 {
     visitedSystems = netlog.ParseFiles(richTextBox_History, defaultColour, commander);
 }
Пример #4
0
        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();
            }
        }