Esempio n. 1
0
        private void OnNavigateToCitywideCommands(bool isCommandOnSelectedDevices)
        {
            IEnumerable <IRuntimeDeviceViewModel> devicesToOperate;

            if (isCommandOnSelectedDevices)
            {
                devicesToOperate = SelectedDeviceViewModels;
            }
            else
            {
                devicesToOperate = Devices;
            }
            if (!devicesToOperate.Any())
            {
                return;
            }
            _cityWideCommandsLogger.SetIsCommandOnSelectedDevices(isCommandOnSelectedDevices);
            CitywideCommandResult result = CitywideCommandResult.Cancel;

            this._interactionService.Interact(ApplicationInteractionProviders.CitywideCommandsInteractionProvider,
                                              viewModel => { },
                                              viewModel =>
            {
                result = viewModel.Result;
                if (result != CitywideCommandResult.Cancel)
                {
                    AcceptCitywideCommand(result, devicesToOperate);
                }
            });
        }
Esempio n. 2
0
        private void AcceptCitywideCommand(CitywideCommandResult result, IEnumerable <IRuntimeDeviceViewModel> devicesToOperate)
        {
            this._interactionService.Interact(ApplicationInteractionProviders.QuestionMessageBoxInteractionProvider,
                                              viewModel =>
            {
                viewModel.Title = "Вы уверены?";
                if (result == CitywideCommandResult.OnNighlight)
                {
                    viewModel.Message = "Включить ночное освещение?";
                }
                else if (result == CitywideCommandResult.OffNighlight)
                {
                    viewModel.Message = "Выключить ночное освещение?";
                }
                else if (result == CitywideCommandResult.AutoAll)
                {
                    viewModel.Message = "Включить авторежим?";
                }
                else if (result == CitywideCommandResult.ManualModeAll)
                {
                    viewModel.Message = "Включить ручной режим?";
                }
                else if (result == CitywideCommandResult.OnEvening)
                {
                    viewModel.Message = "Включить вечернее освещение?";
                }
                else if (result == CitywideCommandResult.OffEvening)
                {
                    viewModel.Message = "Выключить вечернее освещение?";
                }
                else if (result == CitywideCommandResult.OnFull)
                {
                    viewModel.Message = "Включить полное освещение?";
                }
                else if (result == CitywideCommandResult.OffFull)
                {
                    viewModel.Message = "Выключить полное освещение?";
                }
                else if (result == CitywideCommandResult.OnBacklight)
                {
                    viewModel.Message = "Включить подсветку?";
                }
                else if (result == CitywideCommandResult.OffBacklight)
                {
                    viewModel.Message = "Выключить подсветку?";
                }
                else if (result == CitywideCommandResult.OnIllumination)
                {
                    viewModel.Message = "Включить иллюминацию?";
                }
                else if (result == CitywideCommandResult.OffIllumination)
                {
                    viewModel.Message = "Выключить иллюминацию?";
                }
                else if (result == CitywideCommandResult.OnStoregEnergy)
                {
                    viewModel.Message = "Включить энергосбережение?";
                }
                else if (result == CitywideCommandResult.OffStoregEnergy)
                {
                    viewModel.Message = "Выключить энергосбережение?";
                }
            },
                                              viewModel =>
            {
                if (viewModel.Result == MessageBoxResult.YES)
                {
                    if (result == CitywideCommandResult.Cancel)
                    {
                        return;
                    }
                    else if (result == CitywideCommandResult.OnNighlight)
                    {
                        _cityWideCommandsLogger.NightLightingOn(_logger);
                        foreach (var runtimeLogicalDevice in devicesToOperate)
                        {
                            _deviceCommandService.AddDeviceCommandCreator(
                                () => _deviceCommandFactory.CreateRunNightlightingCommand(
                                    runtimeLogicalDevice.Model as IRuntimeDevice), runtimeLogicalDevice);
                        }
                    }
                    else if (result == CitywideCommandResult.OffNighlight)
                    {
                        _cityWideCommandsLogger.NightLightingOff(_logger);
                        foreach (var runtimeLogicalDevice in devicesToOperate)
                        {
                            _deviceCommandService.AddDeviceCommandCreator(
                                () => _deviceCommandFactory.CreateStopNightlightingCommand(
                                    runtimeLogicalDevice.Model as IRuntimeDevice), runtimeLogicalDevice);
                        }
                    }
                    else if (result == CitywideCommandResult.AutoAll)
                    {
                        _cityWideCommandsLogger.AutoModeAllStarters(_logger);
                        foreach (var runtimeLogicalDevice in devicesToOperate)
                        {
                            _deviceCommandService.AddDeviceCommandCreator(
                                () => _deviceCommandFactory.CreateRunAutoModeCommand(
                                    runtimeLogicalDevice.Model as IRuntimeDevice), runtimeLogicalDevice);
                        }
                    }
                    else if (result == CitywideCommandResult.ManualModeAll)
                    {
                        _cityWideCommandsLogger.ManualModeAllStarters(_logger);

                        foreach (var runtimeLogicalDevice in devicesToOperate)
                        {
                            _deviceCommandService.AddDeviceCommandCreator(
                                () => _deviceCommandFactory.CreateStopAutoModeCommand(
                                    runtimeLogicalDevice.Model as IRuntimeDevice), runtimeLogicalDevice);
                        }
                    }
                    else if (result == CitywideCommandResult.OnEvening)
                    {
                        _cityWideCommandsLogger.EveninglightingLightingOn(_logger);

                        foreach (var runtimeLogicalDevice in devicesToOperate)
                        {
                            _deviceCommandService.AddDeviceCommandCreator(
                                () => _deviceCommandFactory.CreateRunEveninglightingCommand(
                                    runtimeLogicalDevice.Model as IRuntimeDevice), runtimeLogicalDevice);
                        }
                    }
                    else if (result == CitywideCommandResult.OffEvening)
                    {
                        _cityWideCommandsLogger.EveninglightingLightingOff(_logger);

                        foreach (var runtimeLogicalDevice in devicesToOperate)
                        {
                            _deviceCommandService.AddDeviceCommandCreator(
                                () => _deviceCommandFactory.CreateStopEveninglightingCommand(
                                    runtimeLogicalDevice.Model as IRuntimeDevice), runtimeLogicalDevice);
                        }
                    }
                    else if (result == CitywideCommandResult.OnFull)
                    {
                        _cityWideCommandsLogger.FulllightingLightingOn(_logger);

                        foreach (var runtimeLogicalDevice in devicesToOperate)
                        {
                            _deviceCommandService.AddDeviceCommandCreator(
                                () => _deviceCommandFactory.CreateRunFullLightingCommand(
                                    runtimeLogicalDevice.Model as IRuntimeDevice), runtimeLogicalDevice);
                        }
                    }
                    else if (result == CitywideCommandResult.OffFull)
                    {
                        _cityWideCommandsLogger.FulllightingLightingOff(_logger);

                        foreach (var runtimeLogicalDevice in devicesToOperate)
                        {
                            _deviceCommandService.AddDeviceCommandCreator(
                                () => _deviceCommandFactory.CreateStopFullLightingCommand(
                                    runtimeLogicalDevice.Model as IRuntimeDevice), runtimeLogicalDevice);
                        }
                    }
                    else if (result == CitywideCommandResult.OnBacklight)
                    {
                        _cityWideCommandsLogger.BackLightOn(_logger);

                        foreach (var runtimeLogicalDevice in devicesToOperate)
                        {
                            _deviceCommandService.AddDeviceCommandCreator(
                                () => _deviceCommandFactory.CreateRunBackLightLightingCommand(
                                    runtimeLogicalDevice.Model as IRuntimeDevice), runtimeLogicalDevice);
                        }
                    }
                    else if (result == CitywideCommandResult.OffBacklight)
                    {
                        _cityWideCommandsLogger.BackLightOff(_logger);

                        foreach (var runtimeLogicalDevice in devicesToOperate)
                        {
                            _deviceCommandService.AddDeviceCommandCreator(
                                () => _deviceCommandFactory.CreateStopBackLightLightingCommand(
                                    runtimeLogicalDevice.Model as IRuntimeDevice), runtimeLogicalDevice);
                        }
                    }
                    else if (result == CitywideCommandResult.OnIllumination)
                    {
                        _cityWideCommandsLogger.IlluminationOn(_logger);

                        foreach (var runtimeLogicalDevice in devicesToOperate)
                        {
                            _deviceCommandService.AddDeviceCommandCreator(
                                () => _deviceCommandFactory.CreateRunIlluminationCommand(
                                    runtimeLogicalDevice.Model as IRuntimeDevice), runtimeLogicalDevice);
                        }
                    }
                    else if (result == CitywideCommandResult.OffIllumination)
                    {
                        _cityWideCommandsLogger.IlluminationOff(_logger);

                        foreach (var runtimeLogicalDevice in devicesToOperate)
                        {
                            _deviceCommandService.AddDeviceCommandCreator(
                                () => _deviceCommandFactory.CreateStopIlluminationCommand(
                                    runtimeLogicalDevice.Model as IRuntimeDevice), runtimeLogicalDevice);
                        }
                    }
                    else if (result == CitywideCommandResult.OnStoregEnergy)
                    {
                        _cityWideCommandsLogger.EnergySavingOn(_logger);
                        foreach (var runtimeLogicalDevice in devicesToOperate)
                        {
                            _deviceCommandService.AddDeviceCommandCreator(
                                () => _deviceCommandFactory.CreateStartEnergySavingCommand(
                                    runtimeLogicalDevice.Model as IRuntimeDevice), runtimeLogicalDevice);
                        }
                    }
                    else if (result == CitywideCommandResult.OffStoregEnergy)
                    {
                        _cityWideCommandsLogger.EnergySavingOff(_logger);
                        foreach (var runtimeLogicalDevice in devicesToOperate)
                        {
                            _deviceCommandService.AddDeviceCommandCreator(
                                () => _deviceCommandFactory.CreateStopEnergySavingCommand(
                                    runtimeLogicalDevice.Model as IRuntimeDevice), runtimeLogicalDevice);
                        }
                    }
                    else
                    {
                        throw new ArgumentException("Citywide result exeption");
                    }
                }
            });
        }