当前位置: 首页>>代码示例>>C#>>正文


C# ManagementObjectSearcher.OfType方法代码示例

本文整理汇总了C#中System.Management.ManagementObjectSearcher.OfType方法的典型用法代码示例。如果您正苦于以下问题:C# ManagementObjectSearcher.OfType方法的具体用法?C# ManagementObjectSearcher.OfType怎么用?C# ManagementObjectSearcher.OfType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Management.ManagementObjectSearcher的用法示例。


在下文中一共展示了ManagementObjectSearcher.OfType方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Reload

		/// <summary>Reloads the hardware informations.</summary>
		public void Reload(bool usecache = false)
		{
			if (usecache && _isCollected)
				return;

			try
			{
				var moc = new ManagementObjectSearcher("SELECT * FROM Win32_Printer").Get();

				new ListAssimilator<ManagementObject, PrinterDevice>(moc.OfType<ManagementObject>(), _printerDevices)
				{
					OnPairFound = (o, device) => device.Load(o),
					EqualFunc = (o, device) => device.Name == o.TryGet<string>("Name"),
					CreateFunc = o => PrinterDevice.FromManagementObject(o)
				}.Execute();
			}
			catch (Exception)
			{
			}
			_isCollected = true;
		}
开发者ID:cssack,项目名称:CsGlobals,代码行数:22,代码来源:CsgComputerDevices.cs

示例2: Reload

		/// <summary>Reloads all the items in <see cref="Devices" /> list.</summary>
		/// <param name="usecache">if true the WMI will only be queried if it haven't been done before.</param>
		public void Reload(bool usecache = false)
		{
			if (usecache && _isCollected)
				return;

			try
			{
				var moc = new ManagementObjectSearcher("SELECT * FROM Win32_VideoController").Get();
				new ListAssimilator<ManagementObject, CsgGraphicDevice>(moc.OfType<ManagementObject>(), _devices)
				{
					CreateFunc = o => CsgGraphicDevice.FromManagementObject(o),
					EqualFunc = (o, device) => device.DeviceId == o.TryGet<string>("DeviceID"),
					OnPairFound = (o, device) => device.Load(o)
				}.Execute();
			}
			catch (Exception)
			{
				_devices.Clear();
			}


			_isCollected = true;
		}
开发者ID:cssack,项目名称:CsGlobals,代码行数:25,代码来源:CsgComputerGraphic.cs

示例3: Reload

		/// <summary>Reloads all the items in <see cref="Devices" /> list.</summary>
		/// <param name="usecache">if true the WMI will only be queried if it haven't been done before.</param>
		public void Reload(bool usecache = false)
		{
			if (usecache && _isCollected)
				return;

			try
			{
				var moc = new ManagementObjectSearcher("ROOT\\StandardCimv2", "SELECT * FROM MSFT_NetAdapter WHERE HardwareInterface='True'").Get();

				new ListAssimilator<ManagementObject, CsgNetworkDevice>(moc.OfType<ManagementObject>(), _devices)
				{
					CreateFunc = o => CsgNetworkDevice.FromManagementObject(o),
					EqualFunc = (o, device) => device.DeviceId == o.TryGet<string>("DeviceID"),
					OnPairFound = (o, device) => device.Load(o),
				}.Execute();
			}
			catch (Exception)
			{
				_devices.Clear();
			}


			_isCollected = true;
		}
开发者ID:cssack,项目名称:CsGlobals,代码行数:26,代码来源:CsgComputerNetwork.cs

示例4: CollectDiscDrives

		private void CollectDiscDrives(bool useCache = false)
		{
			if (useCache && _isDiscDrivesCollected)
				return;

			try
			{
				var moc = new ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive").Get();

				new ListAssimilator<ManagementObject, CsgDiskDriveDevice>(moc.OfType<ManagementObject>().ToList(), _devices)
				{
					CreateFunc = mo => CsgDiskDriveDevice.FromManagementObject(mo),
					EqualFunc = (mo, device) => device.DeviceId == mo.TryGet<string>("DeviceID"),
					OnPairFound = (mo, device) => device.Load(mo)
				}.Execute();
			}
			catch (Exception)
			{
				_devices.Clear();
			}


			_isDiscDrivesCollected = true;
		}
开发者ID:cssack,项目名称:CsGlobals,代码行数:24,代码来源:CsgComputerDiskDrive.cs

示例5: CollectDiscPartitions

		internal void CollectDiscPartitions(bool useCache = false)
		{
			if (useCache && _isDiscPartitionsCollected)
				return;

			CollectDiscDrives(true);

			try
			{
				var moc = new ManagementObjectSearcher("SELECT * FROM Win32_DiskPartition").Get();

				var groupedPartitions = moc.OfType<ManagementObject>().GroupBy(x => x.TryGet<UInt32>("DiskIndex")).ToArray();
				foreach (var groupedPartition in groupedPartitions)
				{
					var device = Devices.FirstOrDefault(x => x.Index == groupedPartition.Key);
					if (device == null)
						continue;

					try
					{
						new ListAssimilator<ManagementObject, CsgDiskPartition>(groupedPartition.ToList(), device._partitions)
						{
							CreateFunc = mo => CsgDiskPartition.FromManagementObject(mo),
							EqualFunc = (mo, partition) => partition.DeviceId == mo.TryGet<string>("DeviceID"),
							OnPairFound = (mo, partition) => partition.Load(mo)
						}.Execute();
					}
					catch (Exception)
					{
						device._partitions.Clear();
					}
				}
			}
			catch (Exception)
			{
				foreach (var device in Devices)
				{
					device._partitions.Clear();
				}
			}

			_isDiscPartitionsCollected = true;
		}
开发者ID:cssack,项目名称:CsGlobals,代码行数:43,代码来源:CsgComputerDiskDrive.cs


注:本文中的System.Management.ManagementObjectSearcher.OfType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。