public void TestMgmtObjectCollectData() { MgmtObjectConfiguration conf = new MgmtObjectConfiguration() { Namespace = @"root\cimv2", From = @"WIN32_PerfRawData_HvStats_HyperVHypervisorLogicalProcessor", Where = @"Name='_Total'", PerfCounters = new PerfCounterConfigurationList() }; conf.PerfCounters.Add(new PerfCounterConfiguration() { As = "PercentHypervisorRuntime", Select = "PercentHypervisorRuntime" }); var mgmtObj = MgmtObject.CreateInstance(conf); var data = mgmtObj.CollectData(new Dictionary <String, Object>()); var list = (List <Object>)data; Assert.IsNotNull(list); var jsonObj = (IDictionary <String, Object>)list.FirstOrDefault(); Assert.IsNotNull(jsonObj["PercentHypervisorRuntime"]); //Prevent PropertyData object is returned //The value in PropertyData should be returned not the container Assert.IsFalse(jsonObj["PercentHypervisorRuntime"] is PropertyData); }
public MgmtObject TestDynamicMemoryMgmtObject() { MgmtObjectConfiguration conf = new MgmtObjectConfiguration() { Type = MgmtObjectType.DynamicMemory, }; var mgmtObj = MgmtObject.CreateInstance(conf); Assert.IsNotNull(mgmtObj); Assert.IsTrue(mgmtObj is DynamicMemoryMgmtObject); return mgmtObj; }
internal QueryMgmtObject(MgmtObjectConfiguration conf) : base(conf) { //If specific perf count is given, instead of "*", which means select all, // we should construct an array of selected properties and parse it through WQL query to improve performance if (this.conf.PerfCounters != null && this.conf.PerfCounters.Count != 0 && !this.conf.PerfCounters.Any(counter => !String.IsNullOrEmpty(counter.Select) && counter.Select.Equals("*"))) { //The properties start with "_" needs to be handled specially. //Like "_Path", it is not in Properties set, which is by the design of .net's WMI libary. this.selectedProperties = this.conf.PerfCounters .Select(counter => counter.Select).Where(p => !String.IsNullOrEmpty(p) && !p.StartsWith("_")).ToArray(); } }
public MgmtObject TestDynamicMemoryMgmtObject() { MgmtObjectConfiguration conf = new MgmtObjectConfiguration() { Type = MgmtObjectType.DynamicMemory, }; var mgmtObj = MgmtObject.CreateInstance(conf); Assert.IsNotNull(mgmtObj); Assert.IsTrue(mgmtObj is DynamicMemoryMgmtObject); return(mgmtObj); }
public static MgmtObject CreateInstance(MgmtObjectConfiguration conf) { if(conf == null) { throw new ArgumentNullException("conf"); } if(conf.Type == MgmtObjectType.DynamicMemory) { return new DynamicMemoryMgmtObject(conf); } return new QueryMgmtObject(conf); }
public static MgmtObject CreateInstance(MgmtObjectConfiguration conf) { if (conf == null) { throw new ArgumentNullException("conf"); } if (conf.Type == MgmtObjectType.DynamicMemory) { return(new DynamicMemoryMgmtObject(conf)); } return(new QueryMgmtObject(conf)); }
public void TestMgmtObjectSelectPath() { MgmtObjectConfiguration conf = new MgmtObjectConfiguration() { Namespace = @"root\cimv2", From = @"WIN32_PerfRawData_HvStats_HyperVHypervisorLogicalProcessor", Where = @"Name='_Total'", PerfCounters = new PerfCounterConfigurationList() }; conf.PerfCounters.Add(new PerfCounterConfiguration() { Select = "*" }); var mgmtObj = MgmtObject.CreateInstance(conf); var data = mgmtObj.CollectData(new Dictionary <String, Object>()) as IList <Object>; Assert.IsNotNull(data); }
public void TestMgmtObjectErrorHandling() { //Test namespace wrong try { MgmtObjectConfiguration conf = new MgmtObjectConfiguration() { Namespace = @"root\FALSE_NAMESPACE", From = "WIN32_PerfRawData_HvStats_HyperVHypervisorLogicalProcessor", PerfCounters = new PerfCounterConfigurationList() { new PerfCounterConfiguration() } }; var mgmtObj = MgmtObject.CreateInstance(conf); var data = mgmtObj.CollectData(new Dictionary <String, Object>()); Assert.Fail("ManagementException expected"); } catch (ManagementException e) { Console.WriteLine(e); Console.WriteLine(); } //Test class name wrong try { MgmtObjectConfiguration conf = new MgmtObjectConfiguration() { Namespace = @"root\cimv2", From = @"FALSE_CLASS", PerfCounters = new PerfCounterConfigurationList() { new PerfCounterConfiguration() } }; var mgmtObj = MgmtObject.CreateInstance(conf); var data = mgmtObj.CollectData(new Dictionary <String, Object>()); Assert.Fail("ManagementException expected"); } catch (ManagementException e) { Console.WriteLine(e); Console.WriteLine(); } //Test no instance found try { MgmtObjectConfiguration conf = new MgmtObjectConfiguration() { Namespace = @"root\cimv2", From = @"WIN32_PerfRawData_HvStats_HyperVHypervisorLogicalProcessor", Where = @"Name='FALSE_NAME'", PerfCounters = new PerfCounterConfigurationList() { new PerfCounterConfiguration() } }; var mgmtObj = MgmtObject.CreateInstance(conf); var data = mgmtObj.CollectData(new Dictionary <String, Object>()); Assert.Fail("ManagementException expected"); } catch (NotImplementedException e) { Console.WriteLine(e); Console.WriteLine(); } //Test null perf count { MgmtObjectConfiguration conf = new MgmtObjectConfiguration() { Namespace = @"root\cimv2", From = @"WIN32_PerfRawData_HvStats_HyperVHypervisorLogicalProcessor", Where = @"Name='_Total'", }; var mgmtObj = MgmtObject.CreateInstance(conf); var data = mgmtObj.CollectData(new Dictionary <String, Object>()); Assert.IsNull(data); } }
public DynamicMemoryMgmtObject(MgmtObjectConfiguration conf) : base(conf) { }
protected MgmtObject(MgmtObjectConfiguration conf) { this.conf = conf; }