-
Notifications
You must be signed in to change notification settings - Fork 0
/
ServiceView.cs
209 lines (195 loc) · 6.51 KB
/
ServiceView.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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
// Copyright © 2011 Parttimenerd, licenced under the GPL Version 3
using System;
using System.Collections.Generic;
using System.Drawing;
using System.ServiceProcess;
using System.Windows.Forms;
using Microsoft.VisualBasic.Devices;
namespace TinyTaskkill
{
/// <summary>
/// Description of ServiceView.
/// </summary>
public partial class ServiceView : Form
{
private int lauf_variable = 0;
Dictionary<string,string> keydata = new Dictionary<string, string>();
public ServiceView()
{
InitializeComponent();
UpdateTable();
keydata.Add("F1", GUITexts.get("Help"));
keydata.Add("F2", GUITexts.get("Log out"));
keydata.Add("F4", GUITexts.get("Close ServiceView"));
keydata.Add("F5", GUITexts.get("Update data"));
keydata.Add("F6", GUITexts.get("Copy data"));
keydata.Add("F7", GUITexts.get("Show/Hide advanced functions"));
keydata.Add("F8", GUITexts.get("Fontdialog"));
this.MinimizeBox = true;
this.ShowDialog();
}
public ServiceView(Font font)
{
InitializeComponent();
UpdateTable();
this.Font = font;
keydata.Add("F1", GUITexts.get("Help"));
keydata.Add("F2", GUITexts.get("Log out"));
keydata.Add("F4", GUITexts.get("Close ServiceView"));
keydata.Add("F5", GUITexts.get("Update data"));
keydata.Add("F6", GUITexts.get("Copy data"));
keydata.Add("F7", GUITexts.get("Show/Hide advanced functions"));
keydata.Add("F8", GUITexts.get("Fontdialog"));
this.MinimizeBox = true;
this.Size = dataGridView.PreferredSize;
this.ShowDialog();
}
void UpdateTable(){
dataGridView.Rows.Clear();
DataGridViewRow row;
DataGridViewButtonCell button;
string text;
foreach(ServiceController controller in ServiceController.GetServices()){
row = null;
//try {
foreach (DataGridViewRow _row in dataGridView.Rows){
if ((string)_row.Tag == controller.ServiceName)
_row.HeaderCell.Value = lauf_variable+"";
}
//} catch (Exception) {}
if (row != null){
row.HeaderCell.Value = lauf_variable+"";
row.HeaderCell.Tag = lauf_variable;
try {
addCell(row, 2, controller.Status.ToString(), "", true);
} catch (Exception) {}
}
else {
row = dataGridView.Rows[dataGridView.Rows.Add()];
row.HeaderCell.Tag = lauf_variable;
row.Tag = controller.ServiceName;
try {
addCell(row, 0, controller.ServiceName+"", "", true);
} catch (Exception) {}
try {
addCell(row, 1, controller.DisplayName, "", true);
} catch (Exception) {}
try {
addCell(row, 2, controller.Status.ToString(), "", true);
} catch (Exception) {}
if (Pausieren.Visible) {
try {
if (controller.CanPauseAndContinue){
button = new DataGridViewButtonCell();
if (controller.Status.ToString() == "Running")
button.Value = GUITexts.get("Pause");
else
button.Value = GUITexts.get("Fortsetzen");
button.Tag = controller.ServiceName;
button.ToolTipText = GUITexts.get("Pause the service")+" " + controller.ServiceName;
row.Cells[3] = button;
}else
addCell(row, 3, " ", GUITexts.get("Unable to pause the service"), true);
if (controller.CanStop){
button = new DataGridViewButtonCell();
button.Value = GUITexts.get("Stop");
button.Tag = controller.ServiceName;
button.ToolTipText = GUITexts.get("Stop the service")+" " + controller.ServiceName;
row.Cells[4] = button;
}
else
addCell(row, 4, " ", GUITexts.get("Unable to stop the service"), true);
if (controller.CanShutdown){
button = new DataGridViewButtonCell();
button.Value = GUITexts.get("Abort");
button.Tag = controller.ServiceName;
button.ToolTipText = GUITexts.get("Abort the service")+" " + controller.ServiceName;
row.Cells[5] = button;
}
else
addCell(row, 5, " ", GUITexts.get("Unable to abort the service"), true);
} catch (Exception) {}
}
text = "";
try {
foreach(ServiceController contr in controller.DependentServices)
text += " " + contr.ServiceName + ";";
addCell(row, dataGridView.Rows.Count - 1, text, "", true);
}
catch (Exception) {}
text = "";
try {
foreach(ServiceController contr in controller.ServicesDependedOn)
text += " " + contr.ServiceName + ";";
addCell(row, dataGridView.Rows.Count - 1, text, "", true);
}
catch (Exception) {}
}
}
foreach (DataGridViewRow _row in dataGridView.Rows){
if((int)_row.HeaderCell.Tag == lauf_variable-1)
_row.HeaderCell.Value = lauf_variable+"";
//dataGridView.Rows.Remove(_row);
}
lauf_variable++;
}
void addCell(DataGridViewRow row, int stelle, string text, string tag, bool read_only){
DataGridViewCell cell = row.Cells[stelle];
cell.Value = text;
cell.Tag = tag;
cell.ReadOnly = read_only;
}
public static void Main(string[] args){
new ServiceView();
}
void DataGridView1CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
ServiceController SearchController(string name){
foreach(ServiceController controller in ServiceController.GetServices()){
if (controller.ServiceName == name)
return controller;
}
return new ServiceController();
}
void ServiceViewResize(object sender, EventArgs e)
{
}
void DataGridViewKeyUp(object sender, KeyEventArgs e)
{
if(e.KeyCode == Keys.F5)
UpdateTable();
if(e.KeyCode == Keys.F1)
new KeyCombinationHelp(keydata, this.Font);
if(e.KeyCode == Keys.F6){
string str = "";
foreach (DataGridViewColumn col in dataGridView.Columns)
str += string.Format("\"{0}\",", col.HeaderText);
foreach (DataGridViewRow row in dataGridView.Rows){
str += "\n";
foreach (DataGridViewCell cell in row.Cells){
try {
str += string.Format("\"{0}\",", cell.Value.ToString());
} catch (Exception) {}
}
}
(new Computer()).Clipboard.SetText(str);
}
if(e.KeyCode == Keys.F6){
Pausieren.Visible = !Pausieren.Visible;
Stoppen.Visible = !Stoppen.Visible;
Schließen.Visible = !Schließen.Visible;
UpdateTable();
}
if(e.KeyCode == Keys.F2)
Taskmethods.logOut();
if(e.KeyCode == Keys.F4)
this.Close();
if (e.KeyCode == Keys.F8){
fontDialog.Font = this.Font;
fontDialog.ShowDialog();
this.Font = fontDialog.Font;
}
}
}
}