DirectOutputR1
DirectOutput framework R1 for virtual pinball cabinets.
Go to:
Overview 
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events Macros Pages
SystemMonitor.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Linq;
7 using System.Text;
8 using System.Windows.Forms;
9 using DirectOutput.General;
10 using DirectOutput.General.Statistics;
11 
12 namespace DirectOutput.Frontend
13 {
14  public partial class SystemMonitor : Form
15  {
16  private Pinball Pinball;
18  {
19  this.Pinball = Pinball;
20  InitializeComponent();
21  RefreshData();
22  }
23 
24 
25 
26  public void RefreshData()
27  {
28  RefreshThreads();
29  RefreshDurationStatistics();
30  }
31 
32  private void RefreshDurationStatistics()
33  {
35 
36  DurationStatistics.Rows.Clear();
38  {
39  int RowIndex = DurationStatistics.Rows.Add();
40  DurationStatistics.Rows[RowIndex].Tag = Item;
41  DurationStatistics[StatGroup.Name, RowIndex].Value = (Item.GroupName.IsNullOrWhiteSpace()?"":Item.GroupName);
42  DurationStatistics[StatName.Name, RowIndex].Value = Item.Name;
43  DurationStatistics[StatCallsCount.Name, RowIndex].Value = "{0} calls".Build(Item.ValuesCount);
44  if (Item.ValuesCount > 0)
45  {
46  DurationStatistics[StatTotalDuration.Name, RowIndex].Value = Item.TotalDuration.Format();
47  DurationStatistics[StatAvgDuration.Name, RowIndex].Value = Item.AverageDuration.Format();
48  DurationStatistics[StatMinDuration.Name, RowIndex].Value = Item.MinDuration.Format();
49  DurationStatistics[StatMaxDuration.Name, RowIndex].Value = Item.MaxDuration.Format();
50  }
51  }
52  }
53 
54 
55  private void RefreshThreads() {
56 
57  ThreadDisplay.Rows.Clear();
58 
59  foreach (ThreadInfo TI in Pinball.ThreadInfoList)
60  {
61  int RowIndex = ThreadDisplay.Rows.Add();
62  ThreadDisplay[ThreadName.Name, RowIndex].Value = TI.ThreadName;
63  ThreadDisplay[ThreadHostObject.Name, RowIndex].Value = (!TI.HostName.IsNullOrEmpty() ? TI.HostName : "");
64  ThreadDisplay[ThreadIsAlive.Name, RowIndex].Value = TI.IsAlive;
65  ThreadDisplay[ThreadLastHeartBeat.Name, RowIndex].Value = TI.LastHeartBeat.ToString("HH:mm:ss");
66  int Ms=(int)(DateTime.Now-TI.LastHeartBeat).TotalMilliseconds;
67  if(Ms>TI.HeartBeatTimeOutMs) {
68  ThreadDisplay[ThreadLastHeartBeat.Name, RowIndex].Style.BackColor = System.Drawing.Color.FromArgb(255, 0, 0);
69  }
70  else if (Ms > TI.HeartBeatTimeOutMs / 2)
71  {
72  int Red = ((65536 / (TI.HeartBeatTimeOutMs / 2) * (Ms - (TI.HeartBeatTimeOutMs / 2))) / 256).Limit(0, 255);
73  int Green = 255 - Red;
74  ThreadDisplay[ThreadLastHeartBeat.Name, RowIndex].Style.BackColor = System.Drawing.Color.FromArgb(Red, Green, 0);
75  }
76  else
77  {
78  ThreadDisplay[ThreadLastHeartBeat.Name, RowIndex].Style.BackColor = System.Drawing.Color.FromArgb(0, 255, 0);
79  }
80  ThreadDisplay[ThreadExceptions.Name, RowIndex].Value = TI.Exceptions.Count;
81  ThreadDisplay[ThreadProcessorNumber.Name, RowIndex].Value = TI.ProcessorNumber;
82  }
83 
84 
85  ThreadDisplay.ClearSelection();
86  ThreadDisplay.Refresh();
87 
88  }
89 
90  private void RefreshButton_Click(object sender, EventArgs e)
91  {
92  RefreshData();
93  }
94 
95  private void DurationStatistics_CellClick(object sender, DataGridViewCellEventArgs e)
96  {
97  if (e.RowIndex >= 0 && e.RowIndex < DurationStatistics.Rows.Count)
98  {
99  new TimeSpanStatisticsDetails((TimeSpanStatisticsItem)DurationStatistics.Rows[e.RowIndex].Tag).ShowDialog(this);
100  }
101  }
102 
103 
104 
105  }
106 }