public void Trace(string source, string msg) { Trace(source + ": " + msg); TraceMessage tm = new TraceMessage(source, msg); Monitor.Enter(_traceTable); if (_traceTable.Contains(source)) { ArrayList l = (ArrayList)_traceTable[source]; while (l.Count > _maxTraces) // remove oldest message until list size is below the limit { l.RemoveAt(0); } l.Add(tm); // add message to the end of the list } else { ArrayList l = new ArrayList(); l.Add(tm); _traceTable.Add(source, l); } // update any visible tracePanels foreach (PanelTrace panel in _panelList) { if (panel.TracesAreVisible(source)) { panel.UpdateTraces(); } } // display the message if a Control has been assigned to this channel Control ctrl = (Control)_traceWindows[source]; if (ctrl != null) { if (ctrl.InvokeRequired) { ctrl.BeginInvoke(new SetControlTextDelegate(SetControlText), new object[] { ctrl, msg }); } else { ctrl.Text = msg; } } Monitor.Exit(_traceTable); }
private void PopulateColumns_TimeView() { bool viewTimeStamp = TimeStampMenuItem.Checked; // add the columns and determine row count for the list (total # of traces) int rowCount = 0; int i = 0; string [] channel = new string[checkedNodesList.Count]; int [] index = new int[checkedNodesList.Count]; foreach (TreeNode node in checkedNodesList) { string header = node.Text; //String.Format("{0}.{1}",node.Parent.Text,node.Text); TraceListView.Columns.Add(header, 150, HorizontalAlignment.Left); if (viewTimeStamp) { TraceListView.Columns.Add("Timestamp", 150, HorizontalAlignment.Left); } index[i] = 0; channel[i] = node.FullPath.Replace('\\', '.'); rowCount += ((ArrayList)ht[channel[i]]).Count; i++; } // now go through each message and put it in the list, oldest message first int x = 0; // the column index for the next message to be added to the listview DateTime dt; TraceMessage tm = new TraceMessage("", ""); for (int row = 0; row < rowCount; row++) { // find the next message to display dt = DateTime.Now; // newer (greater) than all logged TraceMessages for (int col = 0; col < checkedNodesList.Count; col++) { ArrayList l = (ArrayList)ht[channel[col]]; if (index[col] < l.Count) // verify channel has traces left to display { TraceMessage msg = (TraceMessage)l[index[col]]; //if(DateTime.Compare(msg.TimeStamp,dt) < 0) // determine if the message is older if (msg.TimeStamp < dt) // determine if the message is older { dt = msg.TimeStamp; tm = msg; x = col; } } } ++index[x]; // increment the channel index of this message // create the listview items & subitems to display the message string item = ""; int subitemcount = viewTimeStamp ? 2 * checkedNodesList.Count - 1 : checkedNodesList.Count - 1; string [] subitems = new string[subitemcount]; for (int col = 0; col < checkedNodesList.Count; col++) { if (col == 0) // item (message) & subitem (timestamp) { if (col == x) // message { item = tm.Message; if (viewTimeStamp) { subitems[0] = tm.Time; } } else // null { item = ""; if (viewTimeStamp) { subitems[0] = ""; } } } else // subitem (message) & subitem (timestamp) { int z = viewTimeStamp ? 2 * col - 1 : col - 1; if (col == x) // message { subitems[z] = tm.Message; if (viewTimeStamp) { subitems[z + 1] = tm.Time; } } else // null { subitems[z] = ""; if (viewTimeStamp) { subitems[z + 1] = ""; } } } } TraceListView.Items.Add(item); TraceListView.Items[row].SubItems.AddRange(subitems); } }
private void PopulateColumns() { // add the columns and determine max row count for the list int maxRow = 0; bool viewTimeStamp = TimeStampMenuItem.Checked; foreach (TreeNode node in checkedNodesList) { string header = node.Text; //String.Format("{0}.{1}",node.Parent.Text,node.Text); TraceListView.Columns.Add(header, 150, HorizontalAlignment.Left); if (viewTimeStamp) { TraceListView.Columns.Add("Timestamp", 150, HorizontalAlignment.Left); } ArrayList l = (ArrayList)ht[node.FullPath.Replace('\\', '.')]; if (l.Count > maxRow) { maxRow = l.Count; } } // create columns for each channel, don't interleave messages string item; int subitemcount = viewTimeStamp ? 2 * checkedNodesList.Count - 1 : checkedNodesList.Count - 1; string [] subitems = new string[subitemcount]; for (int i = 0; i < maxRow; i++) { // finish the subitem strings item = ""; for (int j = 0; j < checkedNodesList.Count; j++) { ArrayList l = GetTraceList(j); if (j == 0) // item and subitem[0] { if (i < l.Count) { TraceMessage tm = (TraceMessage)l[i]; item = tm.Message; if (viewTimeStamp) { subitems[0] = tm.Time; } } else { item = ""; if (viewTimeStamp) { subitems[0] = ""; } } } else // subitems only { int index = viewTimeStamp ? 2 * j - 1 : j - 1; if (i < l.Count) { TraceMessage tm = (TraceMessage)l[i]; subitems[index] = tm.Message; if (viewTimeStamp) { subitems[index + 1] = tm.Time; } } else { subitems[index] = ""; if (viewTimeStamp) { subitems[index + 1] = ""; } } } } TraceListView.Items.Add(item); TraceListView.Items[i].SubItems.AddRange(subitems); } // scroll to the last item in the list ?? TraceListView.Items[maxRow - 1].EnsureVisible(); }