示例#1
0
        public StateLogicViewModel(DeviceLogicViewModel deviceDetailsViewModel, StateLogic stateLogic)
        {
            AddCommand = new RelayCommand(OnAdd);
            RemoveCommand = new RelayCommand<ClauseViewModel>(OnRemove);
            ChangeJoinOperatorCommand = new RelayCommand(OnChangeJoinOperator);

            StateTypes = new List<XStateType>();
            StateTypes.Add(XStateType.TurnOn);
            StateTypes.Add(XStateType.CancelDelay);
            StateTypes.Add(XStateType.TurnOff);
            StateTypes.Add(XStateType.Stop);
            StateTypes.Add(XStateType.ForbidStart);
            StateTypes.Add(XStateType.TurnOnNow);
            StateTypes.Add(XStateType.TurnOffNow);

            SelectedStateType = stateLogic.StateType;

            _deviceDetailsViewModel = deviceDetailsViewModel;
            Clauses = new ObservableCollection<ClauseViewModel>();
            foreach (var clause in stateLogic.Clauses)
            {
                var clauseViewModel = new ClauseViewModel(this, clause);
                Clauses.Add(clauseViewModel);
            }
        }
示例#2
0
        protected override bool Save()
        {
            var deviceLogic = new XDeviceLogic();
            foreach (var stateLogicViewModel in StateLogics)
            {
                var stateLogic = new StateLogic();
                stateLogic.StateType = stateLogicViewModel.SelectedStateType;
                foreach (var clauseViewModel in stateLogicViewModel.Clauses)
                {
                    var clause = new XClause()
                    {
                        StateType = clauseViewModel.SelectedStateType,
                        Devices = clauseViewModel.Devices.ToList(),
                        Zones = clauseViewModel.Zones.ToList(),
                        ClauseJounOperationType = clauseViewModel.SelectedClauseJounOperationType,
                        ClauseOperationType = clauseViewModel.SelectedClauseOperationType
                    };
                    foreach (var deviceUID in clause.Devices)
                    {
                        var decvice = XManager.DeviceConfiguration.Devices.FirstOrDefault(x=>x.UID == deviceUID);
                        clause.XDevices.Add(decvice);
                    }
                    foreach (var zoneUID in clause.Zones)
                    {
                        var zone = XManager.DeviceConfiguration.Zones.FirstOrDefault(x => x.UID == zoneUID);
                        clause.XZones.Add(zone);
                    }
                    if ((clause.Devices.Count > 0) || (clause.Zones.Count > 0))
                        stateLogic.Clauses.Add(clause);
                }
                if (deviceLogic.StateLogics.Any(x => x.StateType == stateLogic.StateType))
                {
                    MessageBoxService.ShowWarning("Логика для состояние " + stateLogic.StateType.ToDescription() + " дублируется");
                    return false;
                }
                if (stateLogic.Clauses.Count > 0)
                    deviceLogic.StateLogics.Add(stateLogic);

                Device.DeviceLogic = deviceLogic;
            }
            return base.Save();
        }
示例#3
0
        public DeviceLogicViewModel(XDevice device)
        {
            Title = "Настройка логики устройства";
            AddCommand = new RelayCommand(OnAdd);
            RemoveCommand = new RelayCommand<StateLogicViewModel>(OnRemove);

            Device = device;
            if (device.DeviceLogic.StateLogics.Count == 0)
            {
                var stateLogic = new StateLogic();
                var clause = new XClause();
                stateLogic.Clauses.Add(clause);
                device.DeviceLogic.StateLogics.Add(stateLogic);
            }

            StateLogics = new ObservableCollection<StateLogicViewModel>();
            foreach (var stateLogic in device.DeviceLogic.StateLogics)
            {
                var stateLogicViewModel = new StateLogicViewModel(this, stateLogic);
                StateLogics.Add(stateLogicViewModel);
            }
        }
示例#4
0
        void ConvertLogic()
        {
            foreach (var xDevice in XManager.DeviceConfiguration.Devices)
            {
                var device = FiresecManager.Devices.FirstOrDefault(x => x.UID == xDevice.UID);
                if (device != null)
                {
                    if ((device.Driver.IsZoneLogicDevice) && (device.ZoneLogic != null))
                    {
                        var xDeviceLogic = new XDeviceLogic();
                        var stateLogic = new StateLogic()
                        {
                            StateType = XStateType.TurnOn
                        };
                        xDeviceLogic.StateLogics.Add(stateLogic);

                        foreach (var clause in device.ZoneLogic.Clauses)
                        {
                            var xClause = new XClause()
                            {
                                ClauseOperationType = ClauseOperationType.AllZones
                            };
                            if(clause.Operation.HasValue)
                            switch(clause.Operation.Value)
                            {
                                case ZoneLogicOperation.All:
                                    xClause.ClauseOperationType = ClauseOperationType.AllZones;
                                    break;

                                case ZoneLogicOperation.Any:
                                    xClause.ClauseOperationType = ClauseOperationType.AnyZone;
                                    break;
                            }
                            if (clause.Device != null)
                            {
                                ;
                            }
                            if (clause.DeviceUID != Guid.Empty)
                            {
                                ;
                            }
                            switch (clause.State)
                            {
                                case FiresecAPI.Models.ZoneLogicState.Attention:
                                    xClause.StateType = XStateType.Attention;
                                    break;

                                case FiresecAPI.Models.ZoneLogicState.Fire:
                                    xClause.StateType = XStateType.Fire1;
                                    break;

                                case FiresecAPI.Models.ZoneLogicState.Failure:
                                    xClause.StateType = XStateType.Failure;
                                    break;

                                default:
                                    continue;
                            }
                            if ((clause.Zones == null) || (clause.Zones.Count == 0))
                                continue;

                            foreach (var zoneNo in clause.Zones)
                            {
                                var xZone = XManager.DeviceConfiguration.Zones.FirstOrDefault(x=>x.No == zoneNo);
                                xClause.Zones.Add(xZone.UID);
                            }

                            stateLogic.Clauses.Add(xClause);
                        }

                        if (stateLogic.Clauses.Count > 0)
                            xDevice.DeviceLogic = xDeviceLogic;
                    }
                }
            }
        }
示例#5
0
 void OnAdd()
 {
     var stateLogic = new StateLogic();
     var stateLogicViewModel = new StateLogicViewModel(this, stateLogic);
     StateLogics.Add(stateLogicViewModel);
 }