コード例 #1
0
ファイル: ConfigBuilder.cs プロジェクト: JRoughan/Emanate
        public ConfigBuilder WithMapping(Mapping mapping, bool generateDependencies = true)
        {
            config.Mappings.Add(mapping);
            if (generateDependencies)
            {
                if (config.OutputDevices.All(d => d.Id != mapping.OutputDeviceId))
                {
                    var outputDevice = new OutputDeviceBuilder()
                        .WithId(mapping.OutputDeviceId)
                        .Build();
                    WithOutputDevice(outputDevice);
                }

                foreach (var inputGroup in mapping.InputGroups)
                {
                    if (config.InputDevices.All(d => d.Id != inputGroup.InputDeviceId))
                    {
                        var inputDevice = new InputDeviceBuilder()
                            .WithId(inputGroup.InputDeviceId)
                            .Build();
                        WithInputDevice(inputDevice);
                    }
                }
            }
            return this;
        }
コード例 #2
0
        public void should_begin_monitoring_when_started_if_mapping_exists()
        {
            var buildMonitor = Substitute.For<IBuildMonitor>();
            var buildMonitorFactory = Substitute.For<IBuildMonitorFactory>();
            buildMonitorFactory.Create(Arg.Any<IInputDevice>()).Returns(buildMonitor);
            var buildMonitorFactories = Substitute.For<IIndex<string, IBuildMonitorFactory>>();
            buildMonitorFactories["key"].ReturnsForAnyArgs(buildMonitorFactory);

            var outputDevice = new OutputDeviceBuilder().Build();

            var inputDevice = new InputDeviceBuilder().Build();

            var mapping = new Mapping { OutputDeviceId = outputDevice.Id };
            mapping.InputGroups.Add(new InputGroup { InputDeviceId = inputDevice.Id, Inputs = { "Build1", "Build2" } });

            var config = new ConfigBuilder()
                .WithOutputDevice(outputDevice)
                .WithInputDevice(inputDevice)
                .WithMapping(mapping)
                .Build();

            var service = new EmanateService(config, buildMonitorFactories);

            service.Start();

            buildMonitor.Received().BeginMonitoring();
        }
コード例 #3
0
        private void SaveConfiguration()
        {
            globalConfig.Mappings.Clear();
            // TODO: The respective GUIs should take care of keeping this in sync
            foreach (var deviceInfo in ActiveDevices)
            {
                var mapping = new Mapping();
                mapping.OutputDeviceId = deviceInfo.OutputDevice.Id;

                foreach (var inputSelector in deviceInfo.InputSelectors)
                {
                    var inputGroup = new InputGroup();
                    inputGroup.InputDeviceId = inputSelector.Device.Id;
                    foreach (var selectedInput in inputSelector.GetSelectedInputs())
                    {
                        inputGroup.Inputs.Add(selectedInput);
                    }
                    mapping.InputGroups.Add(inputGroup);
                }
                globalConfig.Mappings.Add(mapping);
            }

            try
            {
                configurationCaretaker.Save(globalConfig);
            }
            catch (Exception ex)
            {
                var errorMessage = "Cannot save config file: " + ex.Message;
                Log.Error(errorMessage);
                MessageBox.Show(errorMessage);
            }
        }