private void PopulateComboBox(List <ComboBoxItemViewModel> groups, DeviceIoType deviceIoType, Guid currentGroup, ComboBox comboBox) { groups = new List <ComboBoxItemViewModel>(); ComboBoxItemViewModel selectedItem = null; groups.Add(new ComboBoxItemViewModel(profile.GetInheritedDeviceGroupName(deviceIoType), new DeviceGroupComboBoxItem() { DeviceIoType = deviceIoType })); foreach (var deviceGroup in context.DeviceGroupsManager.GetDeviceGroupList(deviceIoType)) { var model = new ComboBoxItemViewModel(deviceGroup.Title, new DeviceGroupComboBoxItem() { DeviceGroup = deviceGroup, DeviceIoType = deviceIoType }); groups.Add(model); if (deviceGroup.Guid == currentGroup) { selectedItem = model; } } comboBox.ItemsSource = groups; if (selectedItem != null) { comboBox.SelectedItem = selectedItem; } else { comboBox.SelectedItem = groups[0]; } }
/// <summary> /// Gets a list of available devices from the backend /// </summary> /// <param name="type"></param> public List <Device> GetAvailableDeviceList(DeviceIoType type, bool includeCache = true) { var result = new List <Device>(); var providerList = type == DeviceIoType.Input ? _context.IOController.GetInputList() : _context.IOController.GetOutputList(); foreach (var providerReport in providerList) { foreach (var ioWrapperDevice in providerReport.Value.Devices) { result.Add(new Device(ioWrapperDevice, providerReport.Value, BuildDeviceBindingMenu(ioWrapperDevice.Nodes, type))); } if (includeCache) { var cachedDevices = LoadDeviceCache(providerReport.Value.ProviderDescriptor.ProviderName); foreach (var cachedDevice in cachedDevices) { if (result.Contains(cachedDevice)) { continue; } result.Add(cachedDevice); } } } return(result); }
public DeviceListControlViewModel(Context context, DeviceIoType deviceIoType) : this() { this.context = context; _deviceIoType = deviceIoType; GenerateDeviceList(); GenerateDeviceGroupList(); }
public List <DeviceBindingNode> GetDeviceBindingMenu(Context context, DeviceIoType type) { if (DeviceBindingMenu == null || DeviceBindingMenu.Count == 0) { var ioController = context.IOController; var list = type == DeviceIoType.Input ? ioController.GetInputList() : ioController.GetOutputList(); try { DeviceBindingMenu = GetDeviceBindingMenu(list[ProviderName]?.Devices.Find(d => d.DeviceDescriptor.DeviceHandle == DeviceHandle)?.Nodes, type); } catch (Exception ex) when(ex is KeyNotFoundException || ex is ArgumentNullException) { return(new List <DeviceBindingNode> { new DeviceBindingNode() { Title = "Device not connected", IsBinding = false } }); } } return(DeviceBindingMenu); }
public DeviceBinding(ValueChanged callback, Profile profile, DeviceIoType deviceIoType) { Callback = callback; Profile = profile; DeviceIoType = deviceIoType; Guid = Guid.NewGuid(); IsBound = false; }
public Device(DeviceReport device, ProviderReport providerReport, DeviceIoType type) : this() { Title = device.DeviceName; ProviderName = providerReport.ProviderDescriptor.ProviderName; DeviceHandle = device.DeviceDescriptor.DeviceHandle; DeviceNumber = device.DeviceDescriptor.DeviceInstance; DeviceBindingMenu = GetDeviceBindingMenu(device.Nodes, type); }
public bool RenameDeviceGroup(Guid deviceGroupGuid, DeviceIoType deviceIoType, string title) { var deviceGroups = GetDeviceGroupList(deviceIoType); DeviceGroup.FindDeviceGroup(deviceGroups, deviceGroupGuid).Title = title; Context.ContextChanged(); return(true); }
public Guid AddDeviceGroup(string Title, DeviceIoType deviceIoType) { var deviceGroup = new DeviceGroup(Title); GetDeviceGroupList(deviceIoType).Add(deviceGroup); Context.ContextChanged(); return(deviceGroup.Guid); }
public List <DeviceBindingNode> GetDeviceBindingMenu(Context context, DeviceIoType type) { if (DeviceBindingMenu != null && DeviceBindingMenu.Count != 0) { return(DeviceBindingMenu); } return(context.DevicesManager.GetDeviceBindingMenu(this, type)); }
public void AddDevices(List <Device> devices, DeviceIoType deviceIoType) { devices.ForEach(d => d.Profile = this); var deviceList = deviceIoType == DeviceIoType.Input ? InputDevices : OutputDevices; deviceList.AddRange(devices); OnPropertyChanged(deviceIoType == DeviceIoType.Input ? nameof(InputDevices) : nameof(OutputDevices)); Context.ContextChanged(); }
public ManageDeviceConfigurationViewModel(DeviceConfiguration deviceConfiguration, DeviceIoType deviceIoType) { ViewModel = this; _deviceConfiguration = deviceConfiguration; _deviceIoType = deviceIoType; DeviceConfigurationName = _deviceConfiguration.ConfigurationName; ShadowDevices = new DeviceAddRemoveControlViewModel("Available Devices", "Selected Shadow Devices", GetAllShadowDevices()); _changed = true; }
public DeviceGroup GetDeviceGroup(DeviceIoType deviceIoType) { var deviceGroupGuid = GetDeviceGroupGuid(deviceIoType); if (deviceGroupGuid.Equals(Guid.Empty)) { return(ParentProfile?.GetDeviceGroup(deviceIoType)); } return(Context.DeviceGroupsManager.GetDeviceGroup(deviceIoType, deviceGroupGuid)); }
public bool RemoveDeviceGroup(Guid deviceGroupGuid, DeviceIoType deviceIoType) { var deviceGroups = GetDeviceGroupList(deviceIoType); if (!deviceGroups.Remove(DeviceGroup.FindDeviceGroup(deviceGroups, deviceGroupGuid))) { return(false); } Context.ContextChanged(); return(true); }
private List <IODefinition> GetIODefinitions(DeviceIoType deviceIoType) { var attributes = (PluginIoAttribute[])Attribute.GetCustomAttributes(GetType(), typeof(PluginIoAttribute)); return(attributes.Where(a => a.DeviceIoType == deviceIoType).Select(a => new IODefinition() { Category = a.DeviceBindingCategory, Name = a.Name, GroupName = a.Group }).ToList()); }
public List <Device> GetMissingDeviceList(DeviceIoType deviceIoType) { Context.DevicesManager.RefreshDeviceList(); var availableDeviceList = Context.DevicesManager.GetAvailableDeviceList(deviceIoType); var profileDeviceList = GetDeviceConfigurationList(deviceIoType); foreach (var deviceConfiguration in profileDeviceList) { availableDeviceList.RemoveAll(d => d.Equals(deviceConfiguration.Device)); } return(availableDeviceList); }
public List <DeviceGroup> GetDeviceGroupList(DeviceIoType deviceIoType) { switch (deviceIoType) { case DeviceIoType.Input: return(InputGroups); case DeviceIoType.Output: return(OutputGroups); default: throw new ArgumentOutOfRangeException(nameof(deviceIoType), deviceIoType, null); } }
private Guid GetDeviceGroupGuid(DeviceIoType deviceIoType) { switch (deviceIoType) { case DeviceIoType.Input: return(InputDeviceGroupGuid); case DeviceIoType.Output: return(OutputDeviceGroupGuid); default: throw new ArgumentOutOfRangeException(nameof(deviceIoType), deviceIoType, null); } }
public string GetInheritedDeviceGroupName(DeviceIoType deviceIoType) { var parentDeviceGroupName = "None"; var parentDeviceGroup = ParentProfile?.GetDeviceGroup(deviceIoType); if (parentDeviceGroup != null) { parentDeviceGroupName = parentDeviceGroup.Title; } if (ParentProfile != null) { parentDeviceGroupName += " (Inherited)"; } return(parentDeviceGroupName); }
public List <DeviceConfiguration> GetDeviceConfigurationList(DeviceIoType deviceIoType) { var result = new List <DeviceConfiguration>(); if (ParentProfile != null) { result.AddRange(ParentProfile.GetDeviceConfigurationList(deviceIoType)); } var devices = deviceIoType == DeviceIoType.Input ? InputDeviceConfigurations : OutputDeviceConfigurations; devices.ForEach(d => d.Device.Profile = this); result.AddRange(devices); return(result); }
public void SetDeviceGroup(DeviceIoType ioType, Guid deviceGroupGuid) { switch (ioType) { case DeviceIoType.Input: InputDeviceGroupGuid = deviceGroupGuid; break; case DeviceIoType.Output: OutputDeviceGroupGuid = deviceGroupGuid; break; default: throw new ArgumentOutOfRangeException(nameof(ioType), ioType, null); } Context.ContextChanged(); }
public List <Device> GetMissingDeviceList(DeviceIoType deviceIoType) { var availableDeviceGroupList = Context.DevicesManager.GetAvailableDeviceList(deviceIoType); var availableDeviceList = new List <Device>(); var profileDeviceList = GetDeviceList(deviceIoType); foreach (var deviceGroup in availableDeviceGroupList) { availableDeviceList.AddRange(deviceGroup.Devices); } foreach (var device in profileDeviceList) { availableDeviceList.RemoveAll(d => d.Equals(device)); } return(availableDeviceList); }
/// <summary> /// Gets a list of available devices from the backend /// </summary> /// <param name="type"></param> public List <DeviceGroup> GetAvailableDeviceList(DeviceIoType type) { var deviceGroupList = new List <DeviceGroup>(); var providerList = type == DeviceIoType.Input ? _context.IOController.GetInputList() : _context.IOController.GetOutputList(); foreach (var providerReport in providerList) { var deviceGroup = new DeviceGroup(providerReport.Key); foreach (var ioWrapperDevice in providerReport.Value.Devices) { deviceGroup.Devices.Add(new Device(ioWrapperDevice, providerReport.Value, type)); } deviceGroupList.Add(deviceGroup); } return(deviceGroupList); }
public List <DeviceBindingNode> GetDeviceBindingMenu(Device device, DeviceIoType type, bool includeCache = true) { var availableDeviceList = GetAvailableDeviceList(type, includeCache); try { return(availableDeviceList.Find(d => d.DeviceHandle == device.DeviceHandle).GetDeviceBindingMenu()); } catch (Exception ex) when(ex is KeyNotFoundException || ex is ArgumentNullException || ex is NullReferenceException) { return(new List <DeviceBindingNode> { new DeviceBindingNode() { Title = "Device not connected" } }); } }
public AddDevicesDialogViewModel(List <Device> devices, DeviceIoType deviceIoType) { Devices = new DeviceSelectControlViewModel($"Add {(deviceIoType == DeviceIoType.Input ? "input" : "output")} devices", devices); ViewModel = this; }
public void AddDeviceConfigurations(List <DeviceConfiguration> deviceConfigurations, DeviceIoType deviceIoType) { deviceConfigurations.ForEach(configuration => configuration.Device.Profile = this); var deviceList = deviceIoType == DeviceIoType.Input ? InputDeviceConfigurations : OutputDeviceConfigurations; deviceList.AddRange(deviceConfigurations); OnPropertyChanged(deviceIoType == DeviceIoType.Input ? nameof(InputDeviceConfigurations) : nameof(OutputDeviceConfigurations)); Context.ContextChanged(); }
public AddDevicesDialog(List <Device> devices, DeviceIoType deviceIoType) { DataContext = new AddDevicesDialogViewModel(devices, deviceIoType); InitializeComponent(); }
public ManageDeviceConfigurationDialog(DeviceConfiguration deviceConfiguration, DeviceIoType deviceIoType) { ViewModel = new ManageDeviceConfigurationViewModel(deviceConfiguration, deviceIoType); DataContext = ViewModel; InitializeComponent(); }
private static List <DeviceBindingNode> GetDeviceBindingMenu(List <DeviceReportNode> deviceNodes, DeviceIoType type) { var result = new List <DeviceBindingNode>(); if (deviceNodes == null) { return(result); } foreach (var deviceNode in deviceNodes) { var groupNode = new DeviceBindingNode() { Title = deviceNode.Title, IsBinding = false, ChildrenNodes = GetDeviceBindingMenu(deviceNode.Nodes, type), }; foreach (var bindingInfo in deviceNode.Bindings) { var bindingNode = new DeviceBindingNode() { Title = bindingInfo.Title, IsBinding = true, DeviceBinding = new DeviceBinding(null, null, type) { IsBound = false, KeyType = (int)bindingInfo.BindingDescriptor.Type, KeyValue = bindingInfo.BindingDescriptor.Index, KeySubValue = bindingInfo.BindingDescriptor.SubIndex, DeviceBindingCategory = DeviceBinding.MapCategory(bindingInfo.Category) // TODO Extract to class instead of using DeviceBinding? } }; if (groupNode.ChildrenNodes == null) { groupNode.ChildrenNodes = new List <DeviceBindingNode>(); } groupNode.ChildrenNodes.Add(bindingNode); } result.Add(groupNode); } return(result.Count != 0 ? result : null); }
private static List <DeviceBindingNode> BuildDeviceBindingMenu(List <DeviceReportNode> deviceNodes, DeviceIoType type) { var result = new List <DeviceBindingNode>(); if (deviceNodes == null) { return(result); } foreach (var deviceNode in deviceNodes) { var groupNode = new DeviceBindingNode() { Title = deviceNode.Title, ChildrenNodes = BuildDeviceBindingMenu(deviceNode.Nodes, type), }; if (groupNode.ChildrenNodes == null) { groupNode.ChildrenNodes = new List <DeviceBindingNode>(); } foreach (var bindingInfo in deviceNode.Bindings) { var bindingNode = new DeviceBindingNode() { Title = bindingInfo.Title, DeviceBindingInfo = new DeviceBindingInfo() { KeyType = (int)bindingInfo.BindingDescriptor.Type, KeyValue = bindingInfo.BindingDescriptor.Index, KeySubValue = bindingInfo.BindingDescriptor.SubIndex, DeviceBindingCategory = DeviceBinding.MapCategory(bindingInfo.Category), Blockable = bindingInfo.Blockable } }; groupNode.ChildrenNodes.Add(bindingNode); } result.Add(groupNode); } return(result.Count != 0 ? result : null); }
public List <Device> GetAvailableDevicesListFromSameProvider(DeviceIoType type, Device device) { var availableDeviceList = GetAvailableDeviceList(type); return(availableDeviceList.Where(d => d.ProviderName.Equals(device.ProviderName)).ToList()); }