protected override void OnLookup() { var instanceId = 0; while (Devcon.Find(FireShockDevice.ClassGuid, out var path, out var instance, instanceId++)) { if (ChildDevices.Any(h => h.DevicePath.Equals(path))) { continue; } Log.Information("Found FireShock device {Path} ({Instance})", path, instance); var device = FireShockDevice.CreateDevice(path, ChildDevices.Count); device.DeviceDisconnected += (sender, args) => { var dev = (FireShockDevice)sender; Log.Information("Device {Device} disconnected", dev); ChildDevices.Remove(dev); dev.Dispose(); }; ChildDevices.Add(device); device.InputReportReceived += (sender, args) => OnInputReportReceived((IDualShockDevice)sender, args.Report); } }
protected override void OnLookup() { var instanceId = 0; while (Devcon.Find(AirBenderHost.ClassGuid, out var path, out var instance, instanceId++)) { if (_hosts.Any(h => h.DevicePath.Equals(path))) { continue; } Log.Information("Found AirBender device {Path} ({Instance})", path, instance); var host = new AirBenderHost(path); host.HostDeviceDisconnected += (sender, args) => { var device = (AirBenderHost)sender; _hosts.Remove(device); device.Dispose(); }; host.ChildDeviceAttached += (sender, args) => ChildDevices.Add((DualShockDevice)args.Device); host.ChildDeviceRemoved += (sender, args) => ChildDevices.Remove((DualShockDevice)args.Device); host.InputReportReceived += (sender, args) => OnInputReportReceived((DualShockDevice)args.Device, args.Report); _hosts.Add(host); } }
public Boolean InsertDevice(ChildDevices childDevices) { // define defaults blocked classes if (childDevices.BlockedURLs == null) { childDevices.BlockedURLs = ConfigurationManager.AppSettings["DefaultBlockedURLs"]; } var device = new Device { LicenseId = childDevices.LicenseId, TbpId = childDevices.Tbpid, Name = childDevices.Name, Avatar = childDevices.Avatar, OnlineTimeFrames = childDevices.OnlineTimeFrames, OnlineWebTimeFrames = childDevices.OnlineWebTimeFrames, BlockedUrls = childDevices.BlockedURLs, Obs = "", Created = DateTime.UtcNow, Updated = DateTime.UtcNow, Version = "1.0", Type = childDevices.Type, ChildDevices = new Collection <ChildDevice> { new ChildDevice { ChildId = childDevices.ChildId } } }; using (var context = new CustomerInfoRepository()) { context.Devices.Add(device); try { context.SaveChanges(); } catch (Exception) { return(false); } } var repository = new CustomerRepository(); repository.InsertBlocker(childDevices.LicenseId, childDevices.ChildId, device.Id, childDevices.BlockedURLs); repository.InsertOnlineTime(childDevices.LicenseId, childDevices.ChildId, device.Id, childDevices.OnlineTimeFrames, childDevices.OnlineWebTimeFrames); return(true); }
public void InsertDeviceTest() { var repository = new CustomerRepositoryHelper(); var device = new ChildDevices { LicenseId = "123", Tbpid = "432", ChildId = 2, Name = "Name", Avatar = "avatar", OnlineTimeFrames = "otf", OnlineWebTimeFrames = "owtf" }; Console.WriteLine(repository.InsertDevice(device)); }
protected override void OnLookup() { var instanceId = 0; while (Devcon.Find(FireShockDevice.ClassGuid, out var path, out var instance, instanceId++)) { if (ChildDevices.Any(h => h.DevicePath.Equals(path))) { continue; } Log.Information("Found FireShock device {Path} ({Instance})", path, instance); // // Find the lowest controller index that is currently unused // var newIndex = ChildDevices.Count; if (reclaimedDeviceIndices.Count > 0) { reclaimedDeviceIndices.Sort(); newIndex = reclaimedDeviceIndices[0]; reclaimedDeviceIndices.RemoveAt(0); } var device = FireShockDevice.CreateDevice(path, newIndex); device.DeviceDisconnected += (sender, args) => { var dev = (FireShockDevice)sender; Log.Information("Device {Device} disconnected", dev); ChildDevices.Remove(dev); reclaimedDeviceIndices.Add(dev.DeviceIndex); dev.Dispose(); }; ChildDevices.Add(device); device.InputReportReceived += (sender, args) => OnInputReportReceived((IDualShockDevice)sender, args.Report); } }
/// <summary> /// Update New Device /// </summary> public Device UpdateDevice(ChildDevices childDevices) { using (var context = new CustomerInfoRepository()) { var updating = context.Devices.SingleOrDefault(x => x.Id == childDevices.Id); if (updating != null) { updating.Updated = DateTime.UtcNow; foreach (var childDevice in updating.ChildDevices.ToArray()) { context.ChildDevices.Remove(childDevice); } var newChildDevice = new ChildDevice { DeviceId = updating.Id, ChildId = childDevices.ChildId }; context.ChildDevices.Add(newChildDevice); updating.ChildDevices.Add(newChildDevice); if (childDevices.Name != null) { updating.Name = childDevices.Name; } if (childDevices.Avatar != null) { updating.Avatar = childDevices.Avatar; } if (childDevices.OnlineTimeFrames != null) { updating.OnlineTimeFrames = childDevices.OnlineTimeFrames; } if (childDevices.OnlineWebTimeFrames != null) { updating.OnlineWebTimeFrames = childDevices.OnlineWebTimeFrames; } if (childDevices.BlockedURLs != null) { updating.BlockedUrls = childDevices.BlockedURLs; } if (childDevices.Obs != null) { updating.Obs = childDevices.Obs; } if (childDevices.Type != null) { updating.Type = childDevices.Type; } try { context.SaveChanges(); } catch (Exception) { return(null); } var repository = new CustomerRepository(); repository.UpdateBlocker(childDevices.LicenseId, childDevices.ChildId, childDevices.Id, childDevices.BlockedURLs); repository.UpdateOnlineTime(childDevices.LicenseId, childDevices.ChildId, childDevices.Id, childDevices.OnlineTimeFrames, childDevices.OnlineWebTimeFrames); return(updating); } else { return(null); } } }
protected override void OnLookup() { var instanceId = 0; // // Enumerate GUID_DEVINTERFACE_BTHPS3_SIXAXIS // while (Devcon.Find( BthPS3Device.GUID_DEVINTERFACE_BTHPS3_SIXAXIS, out var path, out var instance, instanceId++ )) { if (ChildDevices.Any(h => h.DevicePath.Equals(path))) { continue; } Log.Information("Found SIXAXIS device {Path} ({Instance})", path, instance); // // Find the lowest controller index that is currently unused // var newIndex = ChildDevices.Count; if (reclaimedDeviceIndices.Count > 0) { reclaimedDeviceIndices.Sort(); newIndex = reclaimedDeviceIndices[0]; reclaimedDeviceIndices.RemoveAt(0); } var device = BthPS3Device.CreateSixaxisDevice(path, newIndex); // // Subscribe to device removal event // device.DeviceDisconnected += (sender, args) => { var dev = (BthPS3Device)sender; Log.Information("Device {Device} disconnected", dev); ChildDevices.Remove(dev); reclaimedDeviceIndices.Add(dev.DeviceIndex); dev.Dispose(); }; ChildDevices.Add(device); // // Route incoming input reports through to master hub // device.InputReportReceived += (sender, args) => OnInputReportReceived((IDualShockDevice)sender, args.Report); } instanceId = 0; // // Enumerate GUID_DEVINTERFACE_BTHPS3_NAVIGATION // while (Devcon.Find( BthPS3Device.GUID_DEVINTERFACE_BTHPS3_NAVIGATION, out var path, out var instance, instanceId++ )) { if (ChildDevices.Any(h => h.DevicePath.Equals(path))) { continue; } Log.Information("Found Navigation device {Path} ({Instance})", path, instance); // // Find the lowest controller index that is currently unused // var newIndex = ChildDevices.Count; if (reclaimedDeviceIndices.Count > 0) { reclaimedDeviceIndices.Sort(); newIndex = reclaimedDeviceIndices[0]; reclaimedDeviceIndices.RemoveAt(0); } var device = BthPS3Device.CreateNavigationDevice(path, newIndex); // // Subscribe to device removal event // device.DeviceDisconnected += (sender, args) => { var dev = (BthPS3Device)sender; Log.Information("Device {Device} disconnected", dev); ChildDevices.Remove(dev); reclaimedDeviceIndices.Add(dev.DeviceIndex); dev.Dispose(); }; ChildDevices.Add(device); // // Route incoming input reports through to master hub // device.InputReportReceived += (sender, args) => OnInputReportReceived((IDualShockDevice)sender, args.Report); } }