本文整理汇总了C#中Device.SetConnected方法的典型用法代码示例。如果您正苦于以下问题:C# Device.SetConnected方法的具体用法?C# Device.SetConnected怎么用?C# Device.SetConnected使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Device
的用法示例。
在下文中一共展示了Device.SetConnected方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RefreshDevices
public void RefreshDevices()
{
// Mark all devices as disconnected. We will check which of those
// are connected below.
foreach (var device in Devices)
{
device.SetConnected(false);
}
// Discover joystick devices
int xinput_device_count = 0;
foreach (RawInputDeviceList dev in WinRawInput.GetDeviceList())
{
// Skip non-joystick devices
if (dev.Type != RawInputDeviceType.HID)
continue;
// We use the device handle as the hardware id.
// This works, but the handle will change whenever the
// device is unplugged/replugged. We compensate for this
// by checking device GUIDs, below.
// Note: we cannot use the GUID as the hardware id,
// because it is costly to query (and we need to query
// that every time we process a device event.)
IntPtr handle = dev.Device;
bool is_xinput = IsXInput(handle);
Guid guid = GetDeviceGuid(handle);
long hardware_id = handle.ToInt64();
Device device = Devices.FromHardwareId(hardware_id);
if (device != null)
{
// We have already opened this device, mark it as connected
device.SetConnected(true);
}
else
{
device = new Device(handle, guid, is_xinput,
is_xinput ? xinput_device_count++ : 0);
// This is a new device, query its capabilities and add it
// to the device list
if (!QueryDeviceCaps(device))
{
continue;
}
device.SetConnected(true);
// Check if a disconnected device with identical GUID already exists.
// If so, replace that device with this instance.
Device match = null;
foreach (Device candidate in Devices)
{
if (candidate.GetGuid() == guid && !candidate.GetCapabilities().IsConnected)
{
match = candidate;
}
}
if (match != null)
{
Devices.Remove(match.Handle.ToInt64());
}
Devices.Add(hardware_id, device);
Debug.Print("[{0}] Connected joystick {1} ({2})",
GetType().Name, device.GetGuid(), device.GetCapabilities());
}
}
}
示例2: FetchDevicesAsync
private async Task<IEnumerable<Device>> FetchDevicesAsync(Config config, CancellationToken cancellationToken)
{
var connections = await this.apiClient.Value.FetchConnectionsAsync(cancellationToken);
// We can potentially see duplicate devices (if the user set their config file that way). Ignore them.
var devices = config.Devices.DistinctBy(x => x.DeviceID).Select(device =>
{
var deviceObj = new Device(device.DeviceID, device.Name);
ItemConnectionData connectionData;
if (connections.DeviceConnections.TryGetValue(device.DeviceID, out connectionData))
{
if (connectionData.Connected && connectionData.Address != null)
deviceObj.SetConnected(SyncthingAddressParser.Parse(connectionData.Address));
if (connectionData.Paused)
deviceObj.SetPaused();
}
return deviceObj;
});
cancellationToken.ThrowIfCancellationRequested();
return devices;
}