private DataGridViewRow CreateHistoryRow(HistoryEntry he, BaseUtils.StringSearchTerms search)
        {
            DateTime time = EDDConfig.Instance.ConvertTimeToSelectedFromUTC(he.EventTimeUTC);

            he.FillInformation(out string EventDescription, out string EventDetailedInfo);
            string detail = EventDescription;

            detail = detail.AppendPrePad(EventDetailedInfo.LineLimit(15, Environment.NewLine + "..."), Environment.NewLine);

            if (search.Enabled)
            {
                bool matched = false;

                if (search.Terms[0] != null)
                {
                    string timestr  = time.ToString();
                    int    rown     = EDDConfig.Instance.OrderRowsInverted ? he.EntryNumber : (discoveryform.history.Count - he.EntryNumber + 1);
                    string entryrow = rown.ToStringInvariant();
                    matched = timestr.IndexOf(search.Terms[0], StringComparison.InvariantCultureIgnoreCase) >= 0 ||
                              he.EventSummary.IndexOf(search.Terms[0], StringComparison.InvariantCultureIgnoreCase) >= 0 ||
                              detail.IndexOf(search.Terms[0], StringComparison.InvariantCultureIgnoreCase) >= 0 ||
                              entryrow.IndexOf(search.Terms[0], StringComparison.InvariantCultureIgnoreCase) >= 0;
                }

                if (!matched && search.Terms[1] != null)       // system
                {
                    matched = he.System.Name.WildCardMatch(search.Terms[1], true);
                }
                if (!matched && search.Terms[2] != null)       // body
                {
                    matched = he.Status.BodyName?.WildCardMatch(search.Terms[2], true) ?? false;
                }
                if (!matched && search.Terms[3] != null)       // station
                {
                    matched = he.Status.StationName?.WildCardMatch(search.Terms[3], true) ?? false;
                }
                if (!matched && search.Terms[4] != null)       // stationfaction
                {
                    matched = he.Status.StationFaction?.WildCardMatch(search.Terms[4], true) ?? false;
                }

                if (!matched)
                {
                    return(null);
                }
            }

            var rw = dataGridViewJournal.RowTemplate.Clone() as DataGridViewRow;

            rw.CreateCells(dataGridViewJournal, time, "", he.EventSummary, detail);

            rw.Tag = he;

            rowsbyjournalid[he.Journalid] = rw;
            return(rw);
        }
        private void AddEntry(HistoryEntry he)
        {
            bool add = he.IsJournalEventInEventFilter(GetSetting(dbFilter, "All"));

            if (!add)
            {
                ftotalevents++;
                UpdateToolTipsForFilter();
            }

            if (add && !HistoryFilterHelpers.FilterHistory(he, fieldfilter, discoveryform.Globals))
            {
                add = false;
                ftotalfilters++;
                UpdateToolTipsForFilter();
            }

            if (add)
            {
                var sst = new BaseUtils.StringSearchTerms(textBoxSearch.Text, searchterms);
                var row = CreateHistoryRow(he, sst);     // we might be filtered out by search
                if (row != null)
                {
                    dataGridViewJournal.Rows.Insert(0, row);
                }
                else
                {
                    add = false;
                }
            }

            if (add)                                // its been added, we have at least 1 row visible, at row 0
            {
                var filter = (TravelHistoryFilter)comboBoxTime.SelectedItem ?? TravelHistoryFilter.NoFilter;

                if (filter.MaximumNumberOfItems != null)        // this one won't remove the latest one
                {
                    for (int r = dataGridViewJournal.Rows.Count - 1; r >= filter.MaximumNumberOfItems; r--)
                    {
                        dataGridViewJournal.Rows.RemoveAt(r);
                    }
                }

                if (checkBoxCursorToTop.Checked) // Move focus to first row
                {
                    dataGridViewJournal.ClearSelection();
                    dataGridViewJournal.SetCurrentAndSelectAllCellsOnRow(0);       // its the current cell which needs to be set, moves the row marker as well
                    FireChangeSelection();
                }
            }
        }
        private void Display(HistoryList hl, bool disablesorting)
        {
            todo.Clear();           // ensure in a quiet state
            queuedadds.Clear();
            todotimer.Stop();

            if (hl == null)     // just for safety
            {
                return;
            }

            this.dataGridViewJournal.Cursor = Cursors.WaitCursor;
            buttonExtExcel.Enabled          = buttonFilter.Enabled = buttonField.Enabled = false;

            current_historylist = hl;

            Tuple <long, int> pos = CurrentGridPosByJID();

            SortOrder sortorder = dataGridViewJournal.SortOrder;
            int       sortcol   = dataGridViewJournal.SortedColumn?.Index ?? -1;

            if (sortcol >= 0 && disablesorting)
            {
                dataGridViewJournal.Columns[sortcol].HeaderCell.SortGlyphDirection = SortOrder.None;
                sortcol = -1;
            }

            var filter = (TravelHistoryFilter)comboBoxTime.SelectedItem ?? TravelHistoryFilter.NoFilter;

            List <HistoryEntry> result = filter.Filter(hl.EntryOrder());

            fdropdown = hl.Count - result.Count();

            result = HistoryList.FilterByJournalEvent(result, GetSetting(dbFilter, "All"), out ftotalevents);
            result = HistoryFilterHelpers.FilterHistory(result, fieldfilter, discoveryform.Globals, out ftotalfilters);

            dataGridViewJournal.Rows.Clear();
            rowsbyjournalid.Clear();

            dataGridViewJournal.Columns[0].HeaderText = EDDConfig.Instance.GetTimeTitle();

            List <HistoryEntry[]> chunks = new List <HistoryEntry[]>();

            int chunksize = 500;

            for (int i = 0; i < result.Count; i += chunksize, chunksize = 2000)
            {
                HistoryEntry[] chunk = new HistoryEntry[i + chunksize > result.Count ? result.Count - i : chunksize];

                result.CopyTo(i, chunk, 0, chunk.Length);
                chunks.Add(chunk);
            }

            var sst = new BaseUtils.StringSearchTerms(textBoxSearch.Text, searchterms);

            System.Diagnostics.Stopwatch swtotal = new System.Diagnostics.Stopwatch(); swtotal.Start();

            //int lrowno = 0;

            foreach (var chunk in chunks)
            {
                todo.Enqueue(() =>
                {
                    //System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); sw.Start();

                    List <DataGridViewRow> rowstoadd = new List <DataGridViewRow>();

                    foreach (var item in chunk)
                    {
                        var row = CreateHistoryRow(item, sst);
                        if (row != null)
                        {
                            //row.Cells[2].Value = (lrowno++).ToString() + " " + item.Journalid + " " + (string)row.Cells[2].Value;
                            rowstoadd.Add(row);
                        }
                    }

                    dataGridViewJournal.Rows.AddRange(rowstoadd.ToArray()); // much faster to send in one chunk

                    // System.Diagnostics.Debug.WriteLine("J Chunk Load in " + sw.ElapsedMilliseconds);

                    if (dataGridViewJournal.MoveToSelection(rowsbyjournalid, ref pos, false))
                    {
                        FireChangeSelection();
                    }
                });
            }

            todo.Enqueue(() =>
            {
                System.Diagnostics.Debug.WriteLine(BaseUtils.AppTicks.TickCount + " JG TOTAL TIME " + swtotal.ElapsedMilliseconds);

                UpdateToolTipsForFilter();

                if (dataGridViewJournal.MoveToSelection(rowsbyjournalid, ref pos, true))
                {
                    FireChangeSelection();
                }

                if (sortcol >= 0)
                {
                    dataGridViewJournal.Sort(dataGridViewJournal.Columns[sortcol], (sortorder == SortOrder.Descending) ? ListSortDirection.Descending : ListSortDirection.Ascending);
                    dataGridViewJournal.Columns[sortcol].HeaderCell.SortGlyphDirection = sortorder;
                }

                this.dataGridViewJournal.Cursor = Cursors.Default;
                buttonExtExcel.Enabled          = buttonFilter.Enabled = buttonField.Enabled = true;

                while (queuedadds.Count > 0)              // finally, dequeue any adds added
                {
                    System.Diagnostics.Debug.WriteLine("JG Dequeue paused adds");
                    AddEntry(queuedadds.Dequeue());
                }
            });

            todotimer.Start();
        }
Beispiel #4
0
        private DataGridViewRow CreateHistoryRow(HistoryEntry he, BaseUtils.StringSearchTerms search)
        {
            //string debugt = item.Journalid + "  " + item.System.id_edsm + " " + item.System.GetHashCode() + " "; // add on for debug purposes to a field below

            DateTime time = EDDConfig.Instance.ConvertTimeToSelectedFromUTC(he.EventTimeUTC);
            var      node = discoveryform.history.StarScan?.FindSystemSynchronous(he.System, false); // may be null

            string visits = discoveryform.history.Visits(he.System.Name).ToString();
            string info   = Infoline(he.System, node); // lookup node, using star name, no EDSM lookup.

            if (search.Enabled)
            {
                bool matched = false;

                if (search.Terms[0] != null)
                {
                    string timestr = time.ToString();
                    matched = timestr.IndexOf(search.Terms[0], StringComparison.InvariantCultureIgnoreCase) >= 0 ||
                              he.System.Name.IndexOf(search.Terms[0], StringComparison.InvariantCultureIgnoreCase) >= 0 ||
                              visits.IndexOf(search.Terms[0], StringComparison.InvariantCultureIgnoreCase) >= 0 ||
                              info.IndexOf(search.Terms[0], StringComparison.InvariantCultureIgnoreCase) >= 0;
                }

                if (!matched && search.Terms[1] != null)       // system
                {
                    matched = he.System.Name.WildCardMatch(search.Terms[1], true);
                }
                if (!matched && search.Terms[2] != null)       // body
                {
                    matched = he.Status.BodyName?.WildCardMatch(search.Terms[2], true) ?? false;
                }
                if (!matched && search.Terms[3] != null)       // station
                {
                    matched = he.Status.StationName?.WildCardMatch(search.Terms[3], true) ?? false;
                }
                if (!matched && search.Terms[4] != null)       // stationfaction
                {
                    matched = he.Status.StationFaction?.WildCardMatch(search.Terms[4], true) ?? false;
                }

                if (!matched)
                {
                    return(null);
                }
            }

            var rw = dataGridViewStarList.RowTemplate.Clone() as DataGridViewRow;

            rw.CreateCells(dataGridViewStarList, time, he.System.Name, visits, info, node?.ScanValue(true).ToString("N0") ?? "0");

            rowsbyjournalid[he.Journalid] = rw;
            rw.Tag = he;

            rw.Cells[1].Style.ForeColor = (he.System.HasCoordinate) ? Color.Empty : ExtendedControls.Theme.Current.UnknownSystemColor;

            he.FillInformation(out string EventDescription, out string EventDetailedInfo);

            string tip = String.Join(Environment.NewLine, he.EventSummary, EventDescription, EventDetailedInfo);

            rw.Cells[1].ToolTipText = tip;
            rw.Cells[3].ToolTipText = tip;

            return(rw);
        }
Beispiel #5
0
        public void Display(bool disablesorting)
        {
            todo.Clear();               // clear queues and stop timer
            queuedadds.Clear();
            todotimer.Stop();

            this.dataGridViewStarList.Cursor = Cursors.WaitCursor;

            var pos = CurrentGridPosByIndex();

            SortOrder sortorder = dataGridViewStarList.SortOrder;
            int       sortcol   = dataGridViewStarList.SortedColumn?.Index ?? -1;

            if (sortcol >= 0 && disablesorting)
            {
                dataGridViewStarList.Columns[sortcol].HeaderCell.SortGlyphDirection = SortOrder.None;
                sortcol = -1;
            }

            rowsbyjournalid.Clear();
            dataGridViewStarList.Rows.Clear();

            dataGridViewStarList.Columns[0].HeaderText = EDDConfig.Instance.GetTimeTitle();

            var visitlist = discoveryform.history.Visited.Values.ToList();

            // sort is latest first
            visitlist.Sort(delegate(HistoryEntry left, HistoryEntry right) { return(right.EventTimeUTC.CompareTo(left.EventTimeUTC)); });

            var filter = (TravelHistoryFilter)comboBoxTime.SelectedItem ?? TravelHistoryFilter.NoFilter;

            visitlist = filter.FilterLatestFirst(visitlist);      // and filter

            //foreach (var v in visitlist) System.Diagnostics.Debug.WriteLine("Visit {0} {1} {2}", v.EventTimeUTC, v.System.Name, v.Visits);

            List <HistoryEntry[]> syslistchunks = new List <HistoryEntry[]>();

            int chunksize = 500;

            for (int i = 0; i < visitlist.Count; i += chunksize, chunksize = 2000)
            {
                int            totake       = Math.Min(chunksize, visitlist.Count - i);
                HistoryEntry[] syslistchunk = new HistoryEntry[totake];
                visitlist.CopyTo(i, syslistchunk, 0, totake);
                syslistchunks.Add(syslistchunk);
            }

            var sst = new BaseUtils.StringSearchTerms(textBoxSearch.Text, searchterms);

            //System.Diagnostics.Stopwatch swtotal = new System.Diagnostics.Stopwatch(); swtotal.Start();

            foreach (var syslistchunk in syslistchunks)
            {
                todo.Enqueue(() =>
                {
                    List <DataGridViewRow> rowstoadd = new List <DataGridViewRow>();

                    foreach (var he in syslistchunk)
                    {
                        var row = CreateHistoryRow(he, sst);
                        if (row != null)
                        {
                            rowstoadd.Add(row);
                        }
                    }

                    dataGridViewStarList.Rows.AddRange(rowstoadd.ToArray());
                });

                if (dataGridViewStarList.MoveToSelection(rowsbyjournalid, ref pos, false))
                {
                    FireChangeSelection();
                }
            }

            todo.Enqueue(() =>
            {
                if (dataGridViewStarList.MoveToSelection(rowsbyjournalid, ref pos, true))
                {
                    FireChangeSelection();
                }

                if (sortcol >= 0)
                {
                    dataGridViewStarList.Sort(dataGridViewStarList.Columns[sortcol], (sortorder == SortOrder.Descending) ? ListSortDirection.Descending : ListSortDirection.Ascending);
                    dataGridViewStarList.Columns[sortcol].HeaderCell.SortGlyphDirection = sortorder;
                }

                autoupdaterowoffset = autoupdaterowstart = 0;
                autoupdateedsm.Start();

                this.dataGridViewStarList.Cursor = Cursors.Arrow;

                while (queuedadds.Count > 0)              // finally, dequeue any adds added
                {
                    System.Diagnostics.Debug.WriteLine("SL Dequeue paused adds");
                    AddEntry(queuedadds.Dequeue());
                }
            });

            todotimer.Start();
        }
Beispiel #6
0
        private void AddEntry(HistoryEntry he)
        {
            bool scan = he.journalEntry is IStarScan;                           // is this a scan node

            if (he.IsFSDCarrierJump || scan)                                    // jumped or scan
            {
                DataGridViewRow rowpresent = null;
                HistoryEntry    rowhe      = null;

                foreach (DataGridViewRow rowf in dataGridViewStarList.Rows)
                {
                    var her = rowf.Tag as HistoryEntry;
                    if (her != null && her.System.Name.Equals(he.System.Name))
                    {
                        rowpresent = rowf;
                        rowhe      = rowpresent.Tag as HistoryEntry;
                        break;
                    }
                }

                if (he.IsFSDCarrierJump)                                      // jumped
                {
                    bool added = false;                                       // this means row 0 is visible and added

                    if (rowpresent != null)                                   // if its in the list, move to top and set visit count
                    {
                        dataGridViewStarList.Rows.Remove(rowpresent);
                        rowpresent.Cells[2].Value = discoveryform.history.Visits(he.System.Name); // update count
                        dataGridViewStarList.Rows.Insert(0, rowpresent);                          // move to top..
                        added = true;
                    }
                    else
                    {                                                           // not in the list, add it
                        var visitlist = discoveryform.history.Visited.Values.ToList();
                        visitlist.Sort(delegate(HistoryEntry left, HistoryEntry right) { return(right.EventTimeUTC.CompareTo(left.EventTimeUTC)); });
                        var filter = (TravelHistoryFilter)comboBoxTime.SelectedItem ?? TravelHistoryFilter.NoFilter;
                        visitlist = filter.FilterLatestFirst(visitlist);                       // and filter

                        if (visitlist.Count > 0 && visitlist[0].System.Name == he.System.Name) // if the filtered result has our system in (which must be the first, since its newest), its inside the filter, add
                        {
                            var sst = new BaseUtils.StringSearchTerms(textBoxSearch.Text, searchterms);
                            var row = CreateHistoryRow(visitlist[0], sst);
                            if (row != null)    // text may have filtered it out
                            {
                                dataGridViewStarList.Rows.Insert(0, row);
                                added = true;
                            }
                        }
                    }

                    if (added && checkBoxCursorToTop.Checked)           // if we have a row 0
                    {
                        //System.Diagnostics.Debug.WriteLine("Auto Sel");
                        dataGridViewStarList.ClearSelection();
                        dataGridViewStarList.SetCurrentAndSelectAllCellsOnRow(0);       // its the current cell which needs to be set, moves the row marker as well
                        FireChangeSelection();
                    }
                }
                else if (scan)                                                                                    // these can affect the display, so update
                {
                    if (rowpresent != null)                                                                       // only need to do something if its displayed
                    {
                        var    node = discoveryform.history.StarScan?.FindSystemSynchronous(rowhe.System, false); // may be null
                        string info = Infoline(rowhe.System, node);                                               // lookup node, using star name, no EDSM lookup.
                        rowpresent.Cells[3].Value = info;                                                         // update info
                        rowpresent.Cells[4].Value = node?.ScanValue(true).ToString("N0") ?? "0";                  // update scan value
                    }
                }
            }
        }