-
Notifications
You must be signed in to change notification settings - Fork 2
/
HostStatus.cs
165 lines (150 loc) · 4.95 KB
/
HostStatus.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
namespace Rails
{
/// <summary>
/// Summary description for HostStatus.
/// </summary>
public class HostStatus : System.Windows.Forms.Form
{
private System.Windows.Forms.ListBox listBox1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Timer updateTimer;
private System.ComponentModel.IContainer components;
public HostStatus()
{
InitializeComponent();
}
public Network.Host Host;
HostChannel[] clients;
bool refreshClientList;
Hashtable names = new Hashtable();
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(HostStatus));
this.listBox1 = new System.Windows.Forms.ListBox();
this.button1 = new System.Windows.Forms.Button();
this.updateTimer = new System.Windows.Forms.Timer(this.components);
this.SuspendLayout();
//
// listBox1
//
this.listBox1.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right);
this.listBox1.ItemHeight = 14;
this.listBox1.Location = new System.Drawing.Point(16, 16);
this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(184, 88);
this.listBox1.TabIndex = 0;
this.listBox1.SelectedIndexChanged += new System.EventHandler(this.listBox1_SelectedIndexChanged);
//
// button1
//
this.button1.Anchor = (System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right);
this.button1.Enabled = false;
this.button1.Location = new System.Drawing.Point(16, 112);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(184, 23);
this.button1.TabIndex = 1;
this.button1.Text = "Disconnect selected computer";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// updateTimer
//
this.updateTimer.Enabled = true;
this.updateTimer.Interval = 200;
this.updateTimer.Tick += new System.EventHandler(this.updateTimer_Tick);
//
// HostStatus
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 15);
this.ClientSize = new System.Drawing.Size(216, 150);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.button1,
this.listBox1});
this.Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximumSize = new System.Drawing.Size(99999, 176);
this.MinimumSize = new System.Drawing.Size(224, 176);
this.Name = "HostStatus";
this.Text = "Connected Computers";
this.Closing += new System.ComponentModel.CancelEventHandler(this.HostStatus_Closing);
this.ResumeLayout(false);
}
#endregion
public void Connected(HostChannel client)
{
refreshClientList = true;
}
public void Disconnected(HostChannel client)
{
refreshClientList = true;
}
public void RefreshClientList()
{
if (!refreshClientList)
return;
refreshClientList = false;
listBox1.Items.Clear();
foreach (HostChannel channel in Host.Clients)
{
string name = (string) names[channel.ID];
if (name == null || name.Trim().Length == 0)
name = "Computer #" + channel.ID;
listBox1.Items.Add(name);
}
clients = (HostChannel[]) Host.Clients.ToArray(typeof(HostChannel));
EnableButton();
}
public void SetName(int channelID, string name)
{
names[channelID] = name;
refreshClientList = true;
}
private void HostStatus_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
e.Cancel = true;
}
private void listBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
EnableButton();
}
void EnableButton()
{
button1.Enabled = listBox1.SelectedIndex != -1 && listBox1.Items.Count > 0;
}
private void button1_Click(object sender, System.EventArgs e)
{
HostChannel channel = clients[listBox1.SelectedIndex];
channel.Stop();
}
private void updateTimer_Tick(object sender, System.EventArgs e)
{
RefreshClientList();
}
}
}