public MPTDeviceViewModel(GKMPTDevice mptDevice) { MPTDevice = mptDevice; Device = mptDevice.Device; MPTDevicePropertiesViewModel = new MPTDevicePropertiesViewModel(Device, false); ShowPropertiesCommand = new RelayCommand(OnShowProperties, CanShowProperties); }
public MPTDeviceSelectationViewModel(GKMPTDevice mptDevice = null) { AvailableMPTDeviceTypes = new ObservableCollection<MPTDeviceTypeViewModel>(); AvailableMPTDeviceTypes.Add(new MPTDeviceTypeViewModel(GKMPTDeviceType.DoNotEnterBoard)); AvailableMPTDeviceTypes.Add(new MPTDeviceTypeViewModel(GKMPTDeviceType.ExitBoard)); AvailableMPTDeviceTypes.Add(new MPTDeviceTypeViewModel(GKMPTDeviceType.AutomaticOffBoard)); AvailableMPTDeviceTypes.Add(new MPTDeviceTypeViewModel(GKMPTDeviceType.Speaker)); AvailableMPTDeviceTypes.Add(new MPTDeviceTypeViewModel(GKMPTDeviceType.HandStart)); AvailableMPTDeviceTypes.Add(new MPTDeviceTypeViewModel(GKMPTDeviceType.HandStop)); AvailableMPTDeviceTypes.Add(new MPTDeviceTypeViewModel(GKMPTDeviceType.HandAutomaticOn)); AvailableMPTDeviceTypes.Add(new MPTDeviceTypeViewModel(GKMPTDeviceType.HandAutomaticOff)); AvailableMPTDeviceTypes.Add(new MPTDeviceTypeViewModel(GKMPTDeviceType.Bomb)); if (mptDevice == null) { Title = "Создание устройства МПТ"; MptDevice = new GKMPTDevice { MPTDeviceType = AvailableMPTDeviceTypes.First().MPTDeviceType }; } else { Title = "Настройка устройства МПТ"; MptDevice = mptDevice; } CopyProperties(); }
public void RemoveDeviceTestLogicForMptNsDoor() { var device = AddDevice(kauDevice11, GKDriverType.RSR2_AM_1); var device2 = AddDevice(kauDevice11, GKDriverType.RSR2_AM_1); GKManager.UpdateConfiguration(); var clause = new GKClause { ClauseOperationType = ClauseOperationType.AllDevices, DeviceUIDs = { device.UID } }; var gkLogic = new GKLogic(); gkLogic.OnClausesGroup.Clauses.Add(clause); var mpt = new GKMPT(); var gkMptDevice = new GKMPTDevice { Device = device, DeviceUID = device.UID }; GKManager.AddMPT(mpt); GKManager.SetMPTLogic(mpt, gkLogic); mpt.MPTDevices.Add(gkMptDevice); Assert.IsTrue(mpt.MptLogic.OnClausesGroup.Clauses.Any(x => x.DeviceUIDs.Contains(device.UID))); Assert.IsTrue(mpt.MPTDevices.Any(x => x.DeviceUID == device.UID)); Assert.IsTrue(mpt.InputDependentElements.Contains(device)); Assert.IsTrue(device.OutputDependentElements.Contains(mpt)); var pump = new GKPumpStation(); GKManager.AddPumpStation(pump); GKManager.SetPumpStationStartLogic(pump, gkLogic); GKManager.ChangePumpDevices(pump, new List<GKDevice>() {device}); Assert.IsTrue(pump.StartLogic.OnClausesGroup.Clauses.Any(x => x.DeviceUIDs.Contains(device.UID))); Assert.IsTrue(pump.NSDevices.Contains(device)); Assert.IsTrue(pump.InputDependentElements.Contains(device)); Assert.IsTrue(device.OutputDependentElements.Contains(pump)); var door = new GKDoor(); GKManager.AddDoor(door); GKManager.SetDoorOpenRegimeLogic(door, gkLogic); GKManager.SetDoorCloseRegimeLogic(door, gkLogic); GKManager.ChangeEnterButtonDevice(door, device); Assert.IsTrue(door.EnterButton == device); Assert.IsTrue(door.EnterButtonUID == device.UID); Assert.IsTrue(device.Door == door); Assert.IsTrue(device.OutputDependentElements.Contains(door)); Assert.IsTrue(door.InputDependentElements.Contains(device)); door.EnterButton = null; door.EnterButtonUID = Guid.Empty; GKManager.ChangeExitButtonDevice(door, device); Assert.IsTrue(door.ExitButton == device); Assert.IsTrue(door.ExitButtonUID == device.UID); Assert.IsTrue(device.Door == door); door.ExitButton = null; door.ExitButtonUID = Guid.Empty; GKManager.ChangeLockControlDevice(door, device); Assert.IsTrue(door.LockControlDevice == device); Assert.IsTrue(door.LockControlDeviceUID == device.UID); Assert.IsTrue(device.Door == door); door.LockDevice = null; door.LockControlDeviceUID = Guid.Empty; GKManager.ChangeLockControlDeviceExit(door, device); Assert.IsTrue(door.LockControlDeviceExitUID == device.UID); Assert.IsTrue(door.LockControlDeviceExit == device); Assert.IsTrue(device.Door == door); door.LockDeviceExit = null; door.LockControlDeviceExitUID = Guid.Empty; GKManager.ChangeLockDevice(door, device); Assert.IsTrue(door.LockDevice == device); Assert.IsTrue(door.LockDeviceUID == device.UID); Assert.IsTrue(device.Door == door); door.LockDeviceUID = Guid.Empty; door.LockDevice = null; GKManager.ChangeLockDeviceExit(door, device); Assert.IsTrue(door.LockDeviceExit == device); Assert.IsTrue(door.LockDeviceExitUID == device.UID); Assert.IsTrue(device.Door == door); Assert.IsTrue(door.OpenRegimeLogic.OnClausesGroup.Clauses.Any(x => x.DeviceUIDs.Contains( device.UID))); Assert.IsTrue(door.CloseRegimeLogic.OnClausesGroup.Clauses.Any(x => x.DeviceUIDs.Contains(device.UID))); GKManager.RemoveDevice(device); Assert.IsFalse(mpt.MptLogic.OnClausesGroup.Clauses.Any(x => x.DeviceUIDs.Contains(device.UID))); Assert.IsFalse(mpt.InputDependentElements.Any(x => x.UID == device.UID)); Assert.IsFalse(pump.StartLogic.OnClausesGroup.Clauses.Any(x => x.DeviceUIDs.Contains(device.UID))); Assert.IsFalse(pump.InputDependentElements.Any(x => x.UID == device.UID)); Assert.IsFalse(mpt.MPTDevices.Any(x => x.DeviceUID == device.UID)); Assert.IsFalse(pump.NSDevices.Contains(device)); Assert.IsFalse(door.InputDependentElements.Any(x => x.UID == device.UID)); }
public void TestMPTInMultiGk() { var device1 = AddDevice(kauDevice11, GKDriverType.RSR2_GuardDetector); var device2 = AddDevice(kauDevice21, GKDriverType.RSR2_GuardDetector); var mpt = new GKMPT(); GKManager.MPTs.Add(mpt); var clause = new GKClause { ClauseOperationType = ClauseOperationType.AllDevices, StateType = GKStateBit.Failure, DeviceUIDs = {device1.UID, device2.UID} }; mpt.MptLogic.OnClausesGroup.Clauses.Add(clause); var validator = new Validator(); var errors = validator.Validate(); Assert.IsTrue(errors.Any(x => x.ErrorLevel == ValidationErrorLevel.CannotWrite && x.Error == "Содержится в нескольких ГК")); mpt.MptLogic = new GKLogic(); clause = new GKClause { ClauseOperationType = ClauseOperationType.AllDevices, StateType = GKStateBit.Failure, DeviceUIDs = { device1.UID } }; mpt.MptLogic.OnClausesGroup.Clauses.Add(clause); foreach (var deviceType in new List<GKMPTDeviceType>(Enum.GetValues(typeof(GKMPTDeviceType)).Cast<GKMPTDeviceType>())) { mpt.MPTDevices = new List<GKMPTDevice>(); var mptDevice = new GKMPTDevice { Device = device2, DeviceUID = device2.UID, MPTDeviceType = deviceType }; mpt.MPTDevices.Add(mptDevice); validator = new Validator(); errors = validator.Validate(); Assert.IsTrue(errors.Any(x => x.ErrorLevel == ValidationErrorLevel.CannotWrite && x.Error == "Содержится в нескольких ГК")); } }
public void ChangeDriverDeviceTest() { var mpt = new GKMPT(); var am1Device = CreateDevice(GKDriverType.RSR2_AM_1); var mptDevice = new GKMPTDevice { Device = am1Device, DeviceUID = am1Device.UID, MPTDeviceType = GKMPTDeviceType.HandStart }; mpt.MPTDevices.Add(mptDevice); GKManager.DeviceConfiguration.MPTs.Add(mpt); CreateGroupControllerModule(); ClientManager.PlansConfiguration = new RubezhAPI.Models.PlansConfiguration(); var devicesViewModel = new DevicesViewModel(); devicesViewModel.Initialize(); var deviceViewModel = devicesViewModel.AllDevices.FirstOrDefault(x => x.Device == am1Device); var mptViewModel = GroupControllerModule.MPTsViewModel.MPTs[0]; Assert.IsTrue(mpt.MPTDevices.Count == 1); Assert.IsTrue(mpt.InputDependentElements.Count == 1 && mpt.InputDependentElements[0] == am1Device); Assert.IsTrue(mptViewModel.Devices.Count == 1 && mptViewModel.Devices[0].MPTDevice.Device.DriverType == GKDriverType.RSR2_AM_1); var cardReaderDriver = GKManager.Drivers.FirstOrDefault(x => x.DriverType == GKDriverType.RSR2_CardReader); deviceViewModel.Driver = cardReaderDriver; Assert.IsTrue(mpt.MPTDevices.Count == 0); Assert.IsTrue(mpt.InputDependentElements.Count == 0); Assert.IsTrue(mptViewModel.Devices.Count == 1); GroupControllerModule.MPTsViewModel.OnShow(); Assert.IsTrue(mptViewModel.Devices.Count == 0); }
public void RemoveDeviceTest() { var mpt = new GKMPT(); var am1Device = CreateDevice(GKDriverType.RSR2_AM_1); var mptDevice = new GKMPTDevice { Device = am1Device, DeviceUID = am1Device.UID, MPTDeviceType = GKMPTDeviceType.HandStart }; mpt.MPTDevices.Add(mptDevice); GKManager.DeviceConfiguration.MPTs.Add(mpt); CreateGroupControllerModule(); var devicesViewModel = GroupControllerModule.DevicesViewModel; var deviceViewModel = devicesViewModel.AllDevices.FirstOrDefault(x => x.Device == am1Device); var mptViewModel = GroupControllerModule.MPTsViewModel.MPTs[0]; Assert.IsTrue(mpt.MPTDevices.Count == 1); Assert.IsTrue(mpt.InputDependentElements.Count == 1 && mpt.InputDependentElements[0] == am1Device); Assert.IsTrue(mptViewModel.Devices.Count == 1 && mptViewModel.Devices[0].MPTDevice == mptDevice); deviceViewModel.RemoveCommand.Execute(); Assert.IsTrue(mpt.MPTDevices.Count == 0); Assert.IsTrue(mpt.InputDependentElements.Count == 0); Assert.IsTrue(mptViewModel.Devices.Count == 1); GroupControllerModule.MPTsViewModel.OnShow(); Assert.IsTrue(mptViewModel.Devices.Count == 0); }
public void RemoveMptTest() { MockMessageBoxService.ShowConfirmationResult = true; var mpt = new GKMPT(); var am1Device = CreateDevice(GKDriverType.RSR2_AM_1); var mptDevice = new GKMPTDevice { Device = am1Device, DeviceUID = am1Device.UID, MPTDeviceType = GKMPTDeviceType.HandStart }; mpt.MPTDevices.Add(mptDevice); GKManager.DeviceConfiguration.MPTs.Add(mpt); CreateGroupControllerModule(); Assert.IsTrue(mpt.MPTDevices.Any(x => x.Device == am1Device && x.MPTDeviceType == GKMPTDeviceType.HandStart)); Assert.IsTrue(am1Device.IsInMPT); Assert.IsTrue(mpt.InputDependentElements.Count == 1); Assert.IsTrue(am1Device.OutputDependentElements.Count == 1); var mptsViewModel = GroupControllerModule.MPTsViewModel; mptsViewModel.SelectedMPT = mptsViewModel.MPTs.FirstOrDefault(x => x.MPT == mpt); mptsViewModel.DeleteCommand.Execute(); Assert.IsTrue(GKManager.DeviceConfiguration.MPTs.Count == 0); Assert.IsFalse(am1Device.IsInMPT); Assert.IsTrue(am1Device.OutputDependentElements.Count == 0); }
public void EditMptDeviceFewMptsTest() { var am1Device1 = CreateDevice(GKDriverType.RSR2_AM_1); var am1Device2 = CreateDevice(GKDriverType.RSR2_AM_1); var am1Device3 = CreateDevice(GKDriverType.RSR2_AM_1); var mpt1 = new GKMPT(); var mpt2 = new GKMPT(); var mptDevice1 = new GKMPTDevice { Device = am1Device1, DeviceUID = am1Device1.UID, MPTDeviceType = GKMPTDeviceType.HandStart }; var mptDevice2 = new GKMPTDevice { Device = am1Device2, DeviceUID = am1Device2.UID, MPTDeviceType = GKMPTDeviceType.HandStart }; mpt1.MPTDevices.Add(mptDevice1); mpt2.MPTDevices.Add(mptDevice2); GKManager.DeviceConfiguration.MPTs.Add(mpt1); GKManager.DeviceConfiguration.MPTs.Add(mpt2); CreateGroupControllerModule(); var mptViewModel1 = GroupControllerModule.MPTsViewModel.MPTs[0]; var mptViewModel2 = GroupControllerModule.MPTsViewModel.MPTs[1]; MockDialogService.OnShowModal += x => { var mptDeviceSelectationViewModel = x as MPTDeviceSelectationViewModel; mptDeviceSelectationViewModel.SelectedMPTDeviceType = mptDeviceSelectationViewModel.AvailableMPTDeviceTypes.FirstOrDefault(type => type.MPTDeviceType == GKMPTDeviceType.HandStart); Assert.IsTrue(mptDeviceSelectationViewModel.Devices.Count == 2 && mptDeviceSelectationViewModel.Devices[0] == am1Device1 && mptDeviceSelectationViewModel.Devices[1] == am1Device3); Assert.IsTrue(mptViewModel1.Devices.Count == 1 && mptViewModel1.Devices[0].MPTDevice.Device.DriverType == GKDriverType.RSR2_AM_1); }; mptViewModel1.EditCommand.Execute(); }
public void EditMptDeviceTest() { var mpt = new GKMPT(); var am1Device = CreateDevice(GKDriverType.RSR2_AM_1); var rm1Device = CreateDevice(GKDriverType.RSR2_RM_1); var mptDevice = new GKMPTDevice { Device = am1Device, DeviceUID = am1Device.UID, MPTDeviceType = GKMPTDeviceType.HandStart }; mpt.MPTDevices.Add(mptDevice); GKManager.DeviceConfiguration.MPTs.Add(mpt); CreateGroupControllerModule(); var mptViewModel = GroupControllerModule.MPTsViewModel.MPTs[0]; mptViewModel.SelectedDevice = mptViewModel.Devices.FirstOrDefault(x => x.MPTDevice == mptDevice); MockDialogService.OnShowModal += x => { var mptDeviceSelectationViewModel = x as MPTDeviceSelectationViewModel; mptDeviceSelectationViewModel.SelectedMPTDeviceType = mptDeviceSelectationViewModel.AvailableMPTDeviceTypes.FirstOrDefault(type => type.MPTDeviceType == GKMPTDeviceType.DoNotEnterBoard); mptDeviceSelectationViewModel.SelectedDevice = mptDeviceSelectationViewModel.Devices.FirstOrDefault(device => device.UID == rm1Device.UID); mptDeviceSelectationViewModel.SaveCommand.Execute(); }; mptViewModel.EditCommand.Execute(); Assert.IsTrue(mpt.MPTDevices.Any(x => x.Device == rm1Device && x.MPTDeviceType == GKMPTDeviceType.DoNotEnterBoard)); Assert.IsFalse(am1Device.IsInMPT); Assert.IsTrue(rm1Device.IsInMPT); Assert.IsFalse(mpt.InputDependentElements.Contains(am1Device)); Assert.IsTrue(mpt.InputDependentElements.Contains(rm1Device)); Assert.IsTrue(am1Device.OutputDependentElements.Count == 0); Assert.IsTrue(rm1Device.OutputDependentElements.Count == 1 && rm1Device.OutputDependentElements[0] == mpt); Assert.IsTrue(mptViewModel.Devices.Count == 1 && mptViewModel.Devices[0].MPTDevice.Device.DriverType == GKDriverType.RSR2_RM_1); }
public void DeleteMptDeviceTest() { var mpt = new GKMPT(); var am1Device = CreateDevice(GKDriverType.RSR2_AM_1); var mptDevice = new GKMPTDevice { Device = am1Device, DeviceUID = am1Device.UID, MPTDeviceType = GKMPTDeviceType.HandStart }; mpt.MPTDevices.Add(mptDevice); GKManager.DeviceConfiguration.MPTs.Add(mpt); CreateGroupControllerModule(); var mptViewModel = GroupControllerModule.MPTsViewModel.MPTs[0]; Assert.IsTrue(mpt.MPTDevices.Any(x => x.Device == am1Device && x.MPTDeviceType == GKMPTDeviceType.HandStart)); Assert.IsTrue(am1Device.IsInMPT); Assert.IsTrue(mpt.InputDependentElements.Count == 1); Assert.IsTrue(am1Device.OutputDependentElements.Count == 1); mptViewModel.DeleteCommand.Execute(); Assert.IsFalse(mpt.MPTDevices.Any(x => x.Device == am1Device && x.MPTDeviceType == GKMPTDeviceType.HandStart)); Assert.IsFalse(am1Device.IsInMPT); Assert.IsTrue(mpt.InputDependentElements.Count == 0); Assert.IsTrue(am1Device.OutputDependentElements.Count == 0); }
public void SetIsMPT(GKMPTDevice mptDevice) { if (mptDevice.Device != null) { mptDevice.Device.IsInMPT = true; GKManager.SetDeviceLogic(mptDevice.Device, new GKLogic()); mptDevice.Device.ZoneUIDs = new List<Guid>(); mptDevice.Device.Zones.Clear(); } }
GKMPTDevice CreateMptDevice(GKDevice device, GKMPTDeviceType mptDeviceType = GKMPTDeviceType.Speaker) { var mptDevice = new GKMPTDevice(); mptDevice.MPTDeviceType = mptDeviceType; mptDevice.Device = device; mptDevice.DeviceUID = device.UID; return mptDevice; }
void UpdateMptDevice(GKMPTDevice mptDevice) { var device = mptDevice.Device; GKManager.DeviceConfiguration.SetMPTDefaultProperty(device, mptDevice.MPTDeviceType); GKManager.DeviceConfiguration.SetIsMPT(mptDevice); ChangeIsInMPT(mptDevice.Device, true); MPT.ChangedLogic(); Update(); ServiceFactory.SaveService.GKChanged = true; }