-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathHyperVStatus.xaml.cs
More file actions
96 lines (86 loc) · 2.76 KB
/
HyperVStatus.xaml.cs
File metadata and controls
96 lines (86 loc) · 2.76 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Management;
using System.Windows;
using TheFlightSims.HyperVDDA.DefaultUI;
using TheFlightSims.HyperVDDA.WMIProperties;
/*
* Primary namespace for HyperV-DDA application
* It contains the main window and all related methods for the core application
*/
namespace TheFlightSims.HyperVDDA
{
/*
* Hyper-V Services Status Window
*/
public partial class HyperVStatus : Window
{
////////////////////////////////////////////////////////////////
/// Global Properties and Constructors Region
/// This region contains global properties and constructors
/// for the MachineMethods class.
////////////////////////////////////////////////////////////////
protected MachineMethods machine;
public static readonly HashSet<string> serviceNames = new HashSet<string>()
{
"HvHost",
"vmickvpexchange",
"gcs",
"vmicguestinterface",
"vmicshutdown",
"vmicheartbeat",
"vmcompute",
"vmicvmsession",
"vmicrdv",
"vmictimesync",
"vmms",
"vmicvss"
};
public HyperVStatus(MachineMethods machine)
{
InitializeComponent();
this.machine = machine;
RefreshServices();
}
/*
* Button and UI methods behaviour....
*/
private void Refresh_Click(object sender, RoutedEventArgs e)
{
ListHVSrv.Items.Clear();
RefreshServices();
}
/*
* Non-button methods
*/
private void RefreshServices()
{
try
{
machine.Connect("root\\cimv2");
using (ManagementObjectCollection srvList = machine.GetObjects("Win32_Service", "Name, Caption, State"))
{
foreach (ManagementObject srv in srvList.Cast<ManagementObject>())
{
if (srv["Name"] == null || !serviceNames.Contains(srv["Name"].ToString()))
{
srv.Dispose();
continue;
}
_ = ListHVSrv.Items.Add(new
{
ServiceName = srv["Caption"]?.ToString() ?? "Unknown",
ServiceStatus = srv["State"]?.ToString() ?? "Unknown"
});
srv.Dispose();
}
}
}
catch (Exception ex)
{
(new ExceptionView()).HandleException(ex);
}
}
}
}