-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathWmi.cs
47 lines (43 loc) · 1.18 KB
/
Wmi.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Management;
using System.Text;
namespace Ox.BizTalk.TrackedMessageExtractor
{
/// <summary>
/// WMI searcher for BizTalk config
/// </summary>
internal static class BizTalkWmiSearcher
{
private const string MGMT_ROOT = @"root\MicrosoftBizTalkServer";
public static void PopulateWmiSettings(Settings settings)
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher(MGMT_ROOT, "SELECT * FROM MSBTS_GroupSetting");
foreach (ManagementObject group in searcher.Get())
{
if (group != null)
{
group.Get();
settings.BizTalkMgmtDb = group.GetMgmtValueSafe<string>("MgmtDbName");
settings.BizTalkMgmtHost = group.GetMgmtValueSafe<string>("MgmtDbServerName");
settings.BizTalkDTADb = group.GetMgmtValueSafe<string>("TrackingDBName");
settings.BizTalkDTAHost = group.GetMgmtValueSafe<string>("TrackingDBServerName");
}
}
}
private static T GetMgmtValueSafe<T>(this ManagementObject mgmtObj, string key)
{
T result = default(T);
try
{
if (mgmtObj != null)
{
result = (T)mgmtObj[key];
}
}
catch { }
return result;
}
}
}