コード例 #1
0
        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];
            }
        }
コード例 #2
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);
        }
コード例 #3
0
 public DeviceListControlViewModel(Context context, DeviceIoType deviceIoType) : this()
 {
     this.context  = context;
     _deviceIoType = deviceIoType;
     GenerateDeviceList();
     GenerateDeviceGroupList();
 }
コード例 #4
0
 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);
 }
コード例 #5
0
ファイル: DeviceBinding.cs プロジェクト: megadrago88/UCR
 public DeviceBinding(ValueChanged callback, Profile profile, DeviceIoType deviceIoType)
 {
     Callback = callback;
     Profile = profile;
     DeviceIoType = deviceIoType;
     Guid = Guid.NewGuid();
     IsBound = false;
 }
コード例 #6
0
 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);
 }
コード例 #7
0
        public bool RenameDeviceGroup(Guid deviceGroupGuid, DeviceIoType deviceIoType, string title)
        {
            var deviceGroups = GetDeviceGroupList(deviceIoType);

            DeviceGroup.FindDeviceGroup(deviceGroups, deviceGroupGuid).Title = title;
            Context.ContextChanged();
            return(true);
        }
コード例 #8
0
        public Guid AddDeviceGroup(string Title, DeviceIoType deviceIoType)
        {
            var deviceGroup = new DeviceGroup(Title);

            GetDeviceGroupList(deviceIoType).Add(deviceGroup);
            Context.ContextChanged();
            return(deviceGroup.Guid);
        }
コード例 #9
0
ファイル: Device.cs プロジェクト: admiralsurf/UCR-DARK
        public List <DeviceBindingNode> GetDeviceBindingMenu(Context context, DeviceIoType type)
        {
            if (DeviceBindingMenu != null && DeviceBindingMenu.Count != 0)
            {
                return(DeviceBindingMenu);
            }

            return(context.DevicesManager.GetDeviceBindingMenu(this, type));
        }
コード例 #10
0
ファイル: Profile.cs プロジェクト: witek86/UCR
        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();
        }
コード例 #11
0
 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;
 }
コード例 #12
0
ファイル: Profile.cs プロジェクト: poutine70/UCR
        public DeviceGroup GetDeviceGroup(DeviceIoType deviceIoType)
        {
            var deviceGroupGuid = GetDeviceGroupGuid(deviceIoType);

            if (deviceGroupGuid.Equals(Guid.Empty))
            {
                return(ParentProfile?.GetDeviceGroup(deviceIoType));
            }
            return(Context.DeviceGroupsManager.GetDeviceGroup(deviceIoType, deviceGroupGuid));
        }
コード例 #13
0
        public bool RemoveDeviceGroup(Guid deviceGroupGuid, DeviceIoType deviceIoType)
        {
            var deviceGroups = GetDeviceGroupList(deviceIoType);

            if (!deviceGroups.Remove(DeviceGroup.FindDeviceGroup(deviceGroups, deviceGroupGuid)))
            {
                return(false);
            }
            Context.ContextChanged();
            return(true);
        }
コード例 #14
0
        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());
        }
コード例 #15
0
ファイル: Profile.cs プロジェクト: admiralsurf/UCR-DARK
        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);
        }
コード例 #16
0
        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);
            }
        }
コード例 #17
0
ファイル: Profile.cs プロジェクト: poutine70/UCR
        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);
            }
        }
コード例 #18
0
ファイル: Profile.cs プロジェクト: poutine70/UCR
        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);
        }
コード例 #19
0
ファイル: Profile.cs プロジェクト: admiralsurf/UCR-DARK
        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);
        }
コード例 #20
0
ファイル: Profile.cs プロジェクト: poutine70/UCR
        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();
        }
コード例 #21
0
ファイル: Profile.cs プロジェクト: witek86/UCR
        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);
        }
コード例 #22
0
        /// <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);
        }
コード例 #23
0
        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"
                    }
                });
            }
        }
コード例 #24
0
 public AddDevicesDialogViewModel(List <Device> devices, DeviceIoType deviceIoType)
 {
     Devices   = new DeviceSelectControlViewModel($"Add {(deviceIoType == DeviceIoType.Input ? "input" : "output")} devices", devices);
     ViewModel = this;
 }
コード例 #25
0
ファイル: Profile.cs プロジェクト: admiralsurf/UCR-DARK
        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();
        }
コード例 #26
0
        public AddDevicesDialog(List <Device> devices, DeviceIoType deviceIoType)
        {
            DataContext = new AddDevicesDialogViewModel(devices, deviceIoType);

            InitializeComponent();
        }
コード例 #27
0
 public ManageDeviceConfigurationDialog(DeviceConfiguration deviceConfiguration, DeviceIoType deviceIoType)
 {
     ViewModel   = new ManageDeviceConfigurationViewModel(deviceConfiguration, deviceIoType);
     DataContext = ViewModel;
     InitializeComponent();
 }
コード例 #28
0
        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);
        }
コード例 #29
0
        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);
        }
コード例 #30
0
        public List <Device> GetAvailableDevicesListFromSameProvider(DeviceIoType type, Device device)
        {
            var availableDeviceList = GetAvailableDeviceList(type);

            return(availableDeviceList.Where(d => d.ProviderName.Equals(device.ProviderName)).ToList());
        }