void ConvertDevices(DeviceConfiguration deviceConfiguration, Firesec.Models.CoreConfiguration.config coreConfig) { deviceConfiguration.Devices = new List<Device>(); if (coreConfig == null || coreConfig.dev == null || coreConfig.dev.Count() == 0 || coreConfig.drv == null) { Logger.Error("ConfigurationConverter.ConvertDevices coreConfig.dev = null"); LoadingErrorManager.Add("Пустая коллекция устройств или драйверов при конвертации конфигурации"); return; } var rootInnerDevice = coreConfig.dev[0]; var rootDevice = SetInnerDevice(rootInnerDevice, null, deviceConfiguration, coreConfig); deviceConfiguration.Devices.Add(rootDevice); AddDevice(rootInnerDevice, rootDevice, deviceConfiguration, coreConfig); deviceConfiguration.RootDevice = rootDevice; }
void AddDevice(devType parentInnerDevice, Device parentDevice, DeviceConfiguration deviceConfiguration, Firesec.Models.CoreConfiguration.config coreConfig) { if (parentInnerDevice.dev == null) return; parentDevice.Children = new List<Device>(); foreach (var innerDevice in parentInnerDevice.dev) { var device = SetInnerDevice(innerDevice, parentDevice, deviceConfiguration, coreConfig); if (device != null) { parentDevice.Children.Add(device); deviceConfiguration.Devices.Add(device); AddDevice(innerDevice, device, deviceConfiguration, coreConfig); } } }
public static List<DeviceCustomFunction> Convert(Firesec.Models.Functions.functions functions) { var deviceCustomFunctions = new List<DeviceCustomFunction>(); if (functions != null && functions.Items != null) { foreach (var function in functions.Items) { deviceCustomFunctions.Add(new DeviceCustomFunction() { Code = function.code, Description = function.desc, Name = function.name }); } return deviceCustomFunctions; } return null; }
void ConvertDirections(DeviceConfiguration deviceConfiguration, Firesec.Models.CoreConfiguration.config coreConfig) { deviceConfiguration.Directions = new List<Direction>(); if (coreConfig.part != null) { foreach (var innerDirection in coreConfig.part) { if (innerDirection.type == "direction") { var direction = new Direction() { Id = int.Parse(innerDirection.id), Name = innerDirection.name, Description = innerDirection.desc }; if (innerDirection.PinZ != null) { foreach (var item in innerDirection.PinZ) { if (string.IsNullOrWhiteSpace(item.pidz) == false) { var zoneNo = int.Parse(item.pidz); var zone = deviceConfiguration.Zones.FirstOrDefault(x=>x.No == zoneNo); direction.ZoneUIDs.Add(zone.UID); } } } if (innerDirection.param != null) { var rmParameter = innerDirection.param.FirstOrDefault(x => x.name == "Device_RM"); direction.DeviceRm = GuidHelper.ToGuid(rmParameter.value); var buttonParameter = innerDirection.param.FirstOrDefault(x => x.name == "Device_AM"); direction.DeviceButton = GuidHelper.ToGuid(buttonParameter.value); } deviceConfiguration.Directions.Add(direction); } } } }
public DeviceConfiguration ConvertOnlyDevices(Firesec.Models.CoreConfiguration.config coreConfig) { var deviceConfiguration = new DeviceConfiguration(); ConvertDevices(deviceConfiguration, coreConfig); return deviceConfiguration; }
void SetStates(Firesec.CoreState.config coreState) { if (ConfigurationCash.DeviceConfigurationStates == null) { Logger.Error("Watcher.SetStates FiresecManager.DeviceConfigurationStates = null"); return; } if (ConfigurationCash.DeviceConfigurationStates.DeviceStates == null) { Logger.Error("Watcher.SetStates FiresecManager.DeviceConfigurationStates.DeviceStates = null"); return; } foreach (var deviceState in ConfigurationCash.DeviceConfigurationStates.DeviceStates) { if (deviceState == null) { Logger.Error("Watcher.SetStates deviceState = null"); return; } if (coreState == null) { Logger.Error("Watcher.SetStates coreState = null"); return; } if (coreState.dev == null) { //Logger.Error("Watcher.SetStates coreState.dev = null"); return; } if (deviceState.PlaceInTree == null) { Logger.Error("Watcher.SetStates deviceState.PlaceInTree = null"); return; } bool hasOneChangedState = false; Firesec.CoreState.devType innerDevice = FindDevice(coreState.dev, deviceState.PlaceInTree); if (innerDevice != null) { if (deviceState.Device == null) { Logger.Error("Watcher.SetStates deviceState.Device = null"); return; } if (deviceState.Device.Driver == null) { Logger.Error("Watcher.SetStates deviceState.Device.Driver = null"); return; } if (deviceState.Device.Driver.States == null) { Logger.Error("Watcher.SetStates deviceState.Device.Driver.States = null"); return; } foreach (var driverState in deviceState.Device.Driver.States) { if (innerDevice.state == null) { Logger.Error("Watcher.SetStates innerDevice.state = null"); return; } var innerState = innerDevice.state.FirstOrDefault(a => a.id == driverState.Id); if (deviceState.States == null) { Logger.Error("Watcher.SetStates deviceState.States = null"); return; } var state = deviceState.States.FirstOrDefault(x => x.Code == driverState.Code); if ((state != null) != (innerState != null)) { hasOneChangedState = true; } if (innerState != null) { if (state == null) { state = new DeviceDriverState() { Code = driverState.Code, DriverState = driverState.Copy() }; deviceState.States.Add(state); } if (innerState.time != null) state.Time = JournalConverter.ConvertTime(innerState.time); else state.Time = null; } else { if (state != null) deviceState.States.Remove(state); } } } else { hasOneChangedState = deviceState.States.Count > 0; deviceState.States.Clear(); } if (hasOneChangedState) { ChangedDevices.Add(deviceState); } } }
void ConvertZones(DeviceConfiguration deviceConfiguration, Firesec.Models.CoreConfiguration.config coreConfig) { deviceConfiguration.Zones = new List<Zone>(); if (coreConfig.zone != null) { foreach (var innerZone in coreConfig.zone) { var zone = new Zone() { Name = innerZone.name, No = int.Parse(innerZone.no), Description = innerZone.desc }; if (innerZone.shape != null) { zone.ShapeIds = new List<string>(); foreach (var shape in innerZone.shape) { zone.ShapeIds.Add(shape.id); } } if (innerZone.param != null) { var zoneTypeParam = innerZone.param.FirstOrDefault(x => x.name == "ZoneType"); if (zoneTypeParam != null) { zone.ZoneType = (zoneTypeParam.value == "0") ? ZoneType.Fire : ZoneType.Guard; } var exitTimeParam = innerZone.param.FirstOrDefault(x => x.name == "ExitTime"); if (exitTimeParam != null) { int value; if (int.TryParse(exitTimeParam.value, out value)) zone.EvacuationTime = value; } var fireDeviceCountParam = innerZone.param.FirstOrDefault(x => x.name == "FireDeviceCount"); if (fireDeviceCountParam != null) zone.DetectorCount = int.Parse(fireDeviceCountParam.value); var autoSetParam = innerZone.param.FirstOrDefault(x => x.name == "AutoSet"); if (autoSetParam != null) { int value; if (int.TryParse(autoSetParam.value, out value)) zone.AutoSet = value; } var delayParam = innerZone.param.FirstOrDefault(x => x.name == "Delay"); if (delayParam != null) { int value; if (int.TryParse(delayParam.value, out value)) zone.Delay = value; } var skippedParam = innerZone.param.FirstOrDefault(x => x.name == "Skipped"); if (skippedParam != null) zone.Skipped = skippedParam.value == "1" ? true : false; var enableExitTimeParam = innerZone.param.FirstOrDefault(x => x.name == "EnableExitTime"); if (enableExitTimeParam != null) zone.EnableExitTime = enableExitTimeParam.value == "1" ? true : false; var exitRestoreTypeTypeParam = innerZone.param.FirstOrDefault(x => x.name == "ExitRestoreType"); if (exitRestoreTypeTypeParam != null) { zone.ExitRestoreType = (exitRestoreTypeTypeParam.value == "0") ? ExitRestoreType.SetTimer : ExitRestoreType.RestoreTimer; } var guardZoneTypeParam = innerZone.param.FirstOrDefault(x => x.name == "GuardZoneType"); if (guardZoneTypeParam != null) { zone.GuardZoneType = (GuardZoneType)int.Parse(guardZoneTypeParam.value); } } deviceConfiguration.Zones.Add(zone); } } }
void ConvertZonesBack(DeviceConfiguration deviceConfiguration, Firesec.Models.CoreConfiguration.config coreConfig) { var innerZones = new List<zoneType>(); foreach (var zone in deviceConfiguration.Zones) { var innerZone = new zoneType() { name = zone.Name, idx = zone.No.ToString(), no = zone.No.ToString(), desc = zone.Description }; if (innerZone.name != null) innerZone.name = innerZone.name.Replace('№', 'N'); if (innerZone.desc != null) innerZone.desc = innerZone.desc.Replace('№', 'N'); if (zone.ShapeIds != null && zone.ShapeIds.Count > 0) { var innerShapes = new List<shapeType>(); foreach (var shapeId in zone.ShapeIds) { var innerShape = new shapeType() { id = shapeId }; innerShapes.Add(innerShape); } innerZone.shape = innerShapes.ToArray(); } var zoneParams = new List<paramType>(); zoneParams.Add(new paramType() { name = "ZoneType", type = "Int", value = (zone.ZoneType == ZoneType.Fire) ? "0" : "1" }); zoneParams.Add(new paramType() { name = "Skipped", type = "Bool", value = zone.Skipped ? "1" : "0" }); zoneParams.Add(new paramType() { name = "EnableExitTime", type = "Bool", value = zone.EnableExitTime ? "1" : "0" }); zoneParams.Add(new paramType() { name = "ExitRestoreType", type = "Int", value = (zone.ExitRestoreType == ExitRestoreType.SetTimer) ? "0" : "1" }); zoneParams.Add(new paramType() { name = "GuardZoneType", type = "Int", value = ((int)zone.GuardZoneType).ToString() }); if (zone.DetectorCount > 0) { zoneParams.Add(new paramType() { name = "FireDeviceCount", type = "Int", value = zone.DetectorCount.ToString() }); } zoneParams.Add(new paramType() { name = "ExitTime", type = "SmallInt", value = zone.EvacuationTime.ToString() }); zoneParams.Add(new paramType() { name = "AutoSet", type = "Int", value = zone.AutoSet.ToString() }); zoneParams.Add(new paramType() { name = "Delay", type = "Int", value = zone.Delay.ToString() }); if (zoneParams.Count > 0) innerZone.param = zoneParams.ToArray(); innerZones.Add(innerZone); } if (innerZones.Count > 0) coreConfig.zone = innerZones.ToArray(); else coreConfig.zone = null; }
public DeviceConfiguration ConvertOnlyDevices(Firesec.CoreConfiguration.config firesecConfiguration) { DeviceConfiguration = new DeviceConfiguration(); FiresecConfiguration = firesecConfiguration; ConvertDevices(); return DeviceConfiguration; }
public static Driver Convert(Firesec.Models.Metadata.config coreDriversConfig, drvType innerDriver) { var driver = new Driver() { UID = new Guid(innerDriver.id), StringUID = innerDriver.id, Name = innerDriver.name, ShortName = innerDriver.shortName, HasAddress = innerDriver.ar_no_addr != "1", IsAutoCreate = innerDriver.acr_enabled == "1", MinAutoCreateAddress = int.Parse(innerDriver.acr_from), MaxAutoCreateAddress = int.Parse(innerDriver.acr_to), HasAddressMask = innerDriver.addrMask != null, IsAlternativeUSB = innerDriver.altIntf != null, ChildAddressMask = innerDriver.childAddrMask, IsZoneDevice = ((innerDriver.minZoneCardinality == "0") && (innerDriver.maxZoneCardinality == "0")) == false, IsDeviceOnShleif = innerDriver.addrMask != null && (innerDriver.addrMask == "[8(1)-15(2)];[0(1)-7(255)]" || innerDriver.addrMask == "[0(1)-8(30)]") }; var driverData = DriversHelper.DriverDataList.FirstOrDefault(x => x.DriverId == innerDriver.id && x.IgnoreLevel < 2); if (driverData != null) driver.DriverType = driverData.DriverType; if (innerDriver.options != null) { driver.DisableAutoCreateChildren = innerDriver.options.Contains("DisableAutoCreateChildren"); driver.IsZoneLogicDevice = innerDriver.options.Contains("ExtendedZoneLogic"); driver.CanDisable = innerDriver.options.Contains("Ignorable"); driver.IsPlaceable = innerDriver.options.Contains("Placeable") && driver.DriverType != DriverType.Computer; driver.IsOutDevice = innerDriver.options.Contains("OutDevice"); driver.IgnoreInZoneState = innerDriver.options.Contains("IgnoreInZoneState"); driver.IsNotValidateZoneAndChildren = innerDriver.options.Contains("NotValidateZoneAndChildren"); driver.IsSingleInParent = innerDriver.options.Contains("Single"); driver.IsSingleInZone = innerDriver.options.Contains("SingleInZone"); driver.CanMonitoringDisable = innerDriver.options.Contains("CannotDisable") == false; driver.CanWriteDatabase = innerDriver.options.Contains("DeviceDatabaseWrite"); driver.CanReadDatabase = innerDriver.options.Contains("DeviceDatabaseRead"); driver.CanReadJournal = innerDriver.options.Contains("EventSource") && driver.DriverType != DriverType.MS_1 && driver.DriverType != DriverType.MS_2 && driver.DriverType != DriverType.IndicationBlock && driver.DriverType != DriverType.MS_3 && driver.DriverType != DriverType.MS_4 && driver.DriverType != DriverType.PDU && driver.DriverType != DriverType.PDU_PT && driver.DriverType != DriverType.UOO_TL; driver.CanSynchonize = innerDriver.options.Contains("HasTimer"); driver.CanReboot = innerDriver.options.Contains("RemoteReload"); driver.CanGetDescription = innerDriver.options.Contains("DescriptionString"); driver.CanSetPassword = innerDriver.options.Contains("PasswordManagement"); driver.CanUpdateSoft = innerDriver.options.Contains("SoftUpdates"); driver.CanExecuteCustomAdminFunctions = innerDriver.options.Contains("CustomIOCTLFunctions"); } if (driver.DriverType == DriverType.Exit) driver.IsPlaceable = false; var metadataClass = [email protected](x => x.clsid == innerDriver.clsid); if (metadataClass != null) { driver.DeviceClassName = metadataClass.param.FirstOrDefault(x => x.name == "DeviceClassName").value; } driver.CanEditAddress = true; if (innerDriver.ar_no_addr != null) { if (innerDriver.ar_no_addr == "1") driver.CanEditAddress = false; if (innerDriver.acr_enabled == "1") driver.CanEditAddress = false; } driver.ShleifCount = 0; if (innerDriver.childAddrMask != null) { switch (innerDriver.childAddrMask) { case "[8(1)-15(2)];[0(1)-7(255)]": driver.ShleifCount = 2; break; case "[8(1)-15(4)];[0(1)-7(255)]": driver.ShleifCount = 4; break; case "[8(1)-15(10)];[0(1)-7(255)]": driver.ShleifCount = 10; break; } } if (driver.DriverType == DriverType.BUNS) driver.ShleifCount = 2; if (driver.DriverType == DriverType.USB_BUNS) driver.ShleifCount = 2; driver.HasShleif = driver.ShleifCount == 0 ? false : true; if (innerDriver.name == "Насосная Станция") driver.UseParentAddressSystem = false; else driver.UseParentAddressSystem = innerDriver.options != null && innerDriver.options.Contains("UseParentAddressSystem"); driver.IsChildAddressReservedRange = innerDriver.res_addr != null; driver.ChildAddressReserveRangeCount = driver.IsChildAddressReservedRange ? int.Parse(innerDriver.res_addr) : 0; if (innerDriver.addrMask == "[0(1)-8(8)]") driver.IsRangeEnabled = true; else driver.IsRangeEnabled = innerDriver.ar_enabled == "1"; if (innerDriver.addrMask == "[0(1)-8(8)]") driver.MinAddress = 1; else driver.MinAddress = int.Parse(innerDriver.ar_from); if (innerDriver.addrMask == "[0(1)-8(8)]") driver.MaxAddress = 8; else driver.MaxAddress = int.Parse(innerDriver.ar_to); driver.IsBUtton = false; switch (driver.DriverType) { case DriverType.StopButton: case DriverType.StartButton: case DriverType.AutomaticButton: case DriverType.ShuzOffButton: case DriverType.ShuzOnButton: case DriverType.ShuzUnblockButton: driver.IsBUtton = true; break; } driver.Category = (DeviceCategoryType)int.Parse(innerDriver.cat); driver.CategoryName = driver.Category.ToDescription(); driver.DeviceType = DeviceType.FireSecurity; if (innerDriver.options != null) { if (innerDriver.options.Contains("FireOnly")) driver.DeviceType = DeviceType.Fire; if (innerDriver.options.Contains("SecOnly")) driver.DeviceType = DeviceType.Sequrity; if (innerDriver.options.Contains("TechOnly")) driver.DeviceType = DeviceType.Technoligical; } driver.DeviceTypeName = driver.DeviceType.ToDescription(); var driverdata = DriversHelper.DriverDataList.FirstOrDefault(x => (x.DriverId == innerDriver.id)); if (driverdata != null) { driver.IsIgnore = driverdata.IgnoreLevel > 1; driver.IsAssadIgnore = driverdata.IgnoreLevel > 0; } else { return null; } var allChildren = new List<drvType>(); foreach (var childDriver in coreDriversConfig.drv) { var childClass = [email protected](x => x.clsid == childDriver.clsid); if (childClass != null && childClass.parent != null && childClass.parent.Any(x => x.clsid == innerDriver.clsid)) { if (childDriver.lim_parent != null && childDriver.lim_parent != innerDriver.id) continue; allChildren.Add(childDriver); } } try { driver.Children = new List<Guid>( from drvType childInnerDriver in allChildren where (DriversHelper.DriverDataList.FirstOrDefault(x => x.DriverId == childInnerDriver.id) != null && DriversHelper.DriverDataList.FirstOrDefault(x => x.DriverId == childInnerDriver.id).IgnoreLevel == 0) select new Guid(childInnerDriver.id)); } catch (Exception e) { Logger.Error(e); } driver.AvaliableChildren = new List<Guid>( from drvType childInnerDriver in allChildren where childInnerDriver.acr_enabled != "1" select new Guid(childInnerDriver.id)); if (driver.DisableAutoCreateChildren) { driver.AutoCreateChildren = new List<Guid>(); } else { driver.AutoCreateChildren = new List<Guid>( from drvType childInnerDriver in allChildren where childInnerDriver.acr_enabled == "1" select new Guid(childInnerDriver.id)); } driver.CanAddChildren = driver.AvaliableChildren.Count > 0; if (innerDriver.child_id != null) { driver.AutoChild = new Guid(innerDriver.child_id); driver.AutoChildCount = int.Parse(innerDriver.child_count); } driver.CanAutoDetect = allChildren.Any(x => (x.options != null) && (x.options.Contains("CanAutoDetectInstances"))); driver.Properties = new List<DriverProperty>(); if (innerDriver.propInfo != null && driver.DriverType != DriverType.PumpStation) { foreach (var internalProperty in innerDriver.propInfo) { if ((internalProperty.hidden == "1") && (driver.DriverType != DriverType.UOO_TL)) continue; if (internalProperty.caption == "Заводской номер" || internalProperty.caption == "Версия микропрограммы") continue; if (internalProperty.name.StartsWith("Config$")) continue; if (internalProperty.name == "DeviceCountSecDev") continue; var driverProperty = new DriverProperty() { Name = internalProperty.name, Caption = internalProperty.caption, ToolTip = internalProperty.hint, Default = internalProperty.@default, Visible = internalProperty.hidden == "0" && internalProperty.showOnlyInState == "0", IsHidden = internalProperty.hidden == "1", BlockName = internalProperty.blockName }; if (internalProperty.name.StartsWith("Control$")) { //driverProperty.Name = internalProperty.name.Replace("Control$", ""); driverProperty.IsControl = true; } driverProperty.Parameters = new List<DriverPropertyParameter>(); if (internalProperty.param != null) { foreach (var firesecParameter in internalProperty.param) { driverProperty.Parameters.Add(new DriverPropertyParameter() { Name = firesecParameter.name, Value = firesecParameter.value }); } } if (internalProperty.param != null) { driverProperty.DriverPropertyType = DriverPropertyTypeEnum.EnumType; } else { switch (internalProperty.type) { case "String": driverProperty.DriverPropertyType = DriverPropertyTypeEnum.StringType; break; case "Int": case "Double": driverProperty.DriverPropertyType = DriverPropertyTypeEnum.IntType; break; case "Byte": driverProperty.DriverPropertyType = DriverPropertyTypeEnum.ByteType; break; case "Bool": driverProperty.DriverPropertyType = DriverPropertyTypeEnum.BoolType; break; case "Empty": driverProperty.DriverPropertyType = DriverPropertyTypeEnum.Empty; break; default: continue; } } driver.Properties.Add(driverProperty); } } driver.Parameters = new List<Parameter>(); if (innerDriver.paramInfo != null) { foreach (var innerParameter in innerDriver.paramInfo) { driver.Parameters.Add(new Parameter() { Name = innerParameter.name, Caption = innerParameter.caption, //Visible = innerParameter.hidden == "0" && innerParameter.showOnlyInState == "1" Visible = innerParameter.showOnlyInState == "1" }); } } driver.States = new List<DriverState>(); if (innerDriver.state != null) { var codes = new HashSet<string>(); foreach (var innerState in innerDriver.state) { if (codes.Add(innerState.code) == false) { innerState.code += "_" + Guid.NewGuid().ToString(); } if (innerState.name == null) continue; if (innerState.code == null) continue; driver.States.Add(new DriverState() { Id = innerState.id, Name = innerState.name, AffectChildren = innerState.affectChildren == "1" ? true : false, AffectParent = innerState.AffectedParent == "1" ? true : false, StateType = (StateType)int.Parse(innerState.@class), IsManualReset = innerState.manualReset == "1" ? true : false, CanResetOnPanel = innerState.CanResetOnPanel == "1" ? true : false, //IsAutomatic = innerState.type == "Auto" ? true : false, IsAutomatic = (innerState.code.Contains("AutoOff") || innerState.code.Contains("Auto_Off") || innerState.code.Contains("Auto_off")), Code = innerState.code }); } } return driver; }
void SetStates(Firesec.Models.CoreState.config coreState) { if (coreState == null) coreState = new Models.CoreState.config(); if (coreState.dev == null) coreState.dev = new Models.CoreState.devType[0]; foreach (var device in ConfigurationCash.DeviceConfiguration.Devices) { if (device.PlaceInTree == null) { Logger.Error("Watcher.SetStates deviceState.PlaceInTree = null"); continue; } bool hasOneChangedState = false; Firesec.Models.CoreState.devType innerDevice = FindDevice(coreState.dev, device.PlaceInTree); if (innerDevice != null) { if (device.Driver == null) { Logger.Error("Watcher.SetStates deviceState.Device.Driver = null"); continue; } if (device.Driver.States == null) { Logger.Error("Watcher.SetStates deviceState.Device.Driver.States = null"); continue; } if (innerDevice.state == null) { innerDevice.state = (new List<Firesec.Models.CoreState.stateType>()).ToArray(); } foreach (var driverState in device.Driver.States) { var innerState = innerDevice.state.FirstOrDefault(a => a.id == driverState.Id); var state = device.DeviceState.States.FirstOrDefault(x => x.DriverState.Code == driverState.Code); if ((state != null) != (innerState != null)) { hasOneChangedState = true; } if (innerState != null) { if (state == null) { var cloneddDiverState = driverState.Clone(); if (cloneddDiverState.Name == "Состояние 1") { var property = device.Properties.FirstOrDefault(x => x.Name == "Event1"); if (property != null && !string.IsNullOrEmpty(property.Value)) { cloneddDiverState.Name = property.Value; } } if (cloneddDiverState.Name == "Состояние 2") { var property = device.Properties.FirstOrDefault(x => x.Name == "Event2"); if (property != null && !string.IsNullOrEmpty(property.Value)) { cloneddDiverState.Name = property.Value; } } state = new DeviceDriverState() { DriverState = cloneddDiverState }; device.DeviceState.States.Add(state); } if (innerState.time != null) state.Time = JournalConverter.ConvertTime(innerState.time); else state.Time = null; } else { if (state != null) device.DeviceState.States.Remove(state); } } } else { hasOneChangedState = device.DeviceState.States.Count > 0; device.DeviceState.States.Clear(); } if (hasOneChangedState) { ChangedDevices.Add(device.DeviceState); } } }
void ConvertGuardUsersBack(DeviceConfiguration deviceConfiguration, Firesec.Models.CoreConfiguration.config coreConfig, ref int gid) { var innerGuardUsers = new List<partType>(); int no = 0; foreach (var guardUser in deviceConfiguration.GuardUsers) { var innerGuardUser = new partType() { type = "guarduser", no = no.ToString(), id = guardUser.Id.ToString(), gid = gid++.ToString(), name = guardUser.Name }; ++no; var innerZones = new List<partTypePinZ>(); foreach (var zoneUID in guardUser.ZoneUIDs) { var zone = deviceConfiguration.Zones.FirstOrDefault(x=>x.UID == zoneUID); if (zone != null) { innerZones.Add(new partTypePinZ() { pidz = zone.No.ToString() }); } } innerGuardUser.PinZ = innerZones.ToArray(); var innerGuardUsersParameters = new List<paramType>(); if (guardUser.CanSetZone) { innerGuardUsersParameters.Add(new paramType() { name = "SetZone", type = "Bool", value = "1" }); } if (guardUser.CanUnSetZone) { innerGuardUsersParameters.Add(new paramType() { name = "UnSetZone", type = "Bool", value = "1" }); } if (string.IsNullOrEmpty(guardUser.FIO) == false) { innerGuardUsersParameters.Add(new paramType() { name = "FIO", type = "String", value = guardUser.FIO }); } if (string.IsNullOrEmpty(guardUser.Function) == false) { innerGuardUsersParameters.Add(new paramType() { name = "Function", type = "String", value = guardUser.Function }); } if (string.IsNullOrEmpty(guardUser.Password) == false) { innerGuardUsersParameters.Add(new paramType() { name = "Password", type = "String", value = guardUser.Password }); } if (guardUser.DeviceUID != Guid.Empty) innerGuardUsersParameters.Add(new paramType() { name = "DeviceUID", type = "String", value = guardUser.DeviceUID.ToString() }); if (string.IsNullOrEmpty(guardUser.KeyTM) == false) { innerGuardUsersParameters.Add(new paramType() { name = "KeyTM", type = "String", value = guardUser.KeyTM }); } innerGuardUser.param = innerGuardUsersParameters.ToArray(); innerGuardUsers.Add(innerGuardUser); } var innerDirections = coreConfig.part.ToList(); if (innerDirections != null) { innerGuardUsers.AddRange(innerDirections); } coreConfig.part = innerGuardUsers.ToArray(); }
public void ImitatorStateChanged(Firesec.CoreState.config coreState) { StateChanged(coreState); DatabaseHelper.AddInfoMessage("Имитатор", "Изменение состояния устройства имитатором"); }
internal static void ImitatorStateChanged(Firesec.Models.CoreState.config coreState) { Current.OnStateChanged(coreState); }
devType DeviceToInnerDevice(Device device, DeviceConfiguration deviceConfiguration, Firesec.Models.CoreConfiguration.config coreConfig) { var innerDevice = new devType(); innerDevice.name = device.Description; if (innerDevice.name != null) innerDevice.name = innerDevice.name.Replace('№', 'N'); innerDevice.drv = coreConfig.drv.FirstOrDefault(x => x.id.ToUpper() == device.Driver.StringUID).idx; var intAddress = device.IntAddress; if ((device.Parent != null) && (device.Parent.Driver.IsChildAddressReservedRange)) intAddress -= device.Parent.IntAddress; if (device.Driver.HasAddress) innerDevice.addr = intAddress.ToString(); else innerDevice.addr = "0"; if (device.IsMonitoringDisabled == true) innerDevice.disabled = "1"; else innerDevice.disabled = null; if (device.ZoneUID != Guid.Empty) { var zone = deviceConfiguration.Zones.FirstOrDefault(x => x.UID == device.ZoneUID); if (zone != null) { var zones = new List<inZType>(); zones.Add(new inZType() { idz = zone.No.ToString() }); innerDevice.inZ = zones.ToArray(); } } innerDevice.prop = AddProperties(device).ToArray(); innerDevice.param = AddParameters(device).ToArray(); innerDevice.dev_param = AddDevParameters(device).ToArray(); innerDevice.shape = AddShapes(device).ToArray(); return innerDevice; }
void AddInnerDevice(Device parentDevice, devType parentInnerDevice, DeviceConfiguration deviceConfiguration, Firesec.Models.CoreConfiguration.config coreConfig) { var childInnerDevices = new List<devType>(); foreach (var device in parentDevice.Children) { var childInnerDevice = DeviceToInnerDevice(device, deviceConfiguration, coreConfig); childInnerDevices.Add(childInnerDevice); AddInnerDevice(device, childInnerDevice, deviceConfiguration, coreConfig); } parentInnerDevice.dev = childInnerDevices.ToArray(); }
void ConvertDriversBack(Firesec.Models.CoreConfiguration.config coreConfig) { var drivers = new List<drvType>(); foreach (var driver in ConfigurationCash.DriversConfiguration.Drivers) { var innerDriver = new drvType() { idx = ConfigurationCash.DriversConfiguration.Drivers.IndexOf(driver).ToString(), id = driver.StringUID, name = driver.Name }; drivers.Add(innerDriver); } coreConfig.drv = drivers.ToArray(); }
void ConvertDevicesBack(DeviceConfiguration deviceConfiguration, Firesec.Models.CoreConfiguration.config coreConfig) { ConvertDriversBack(coreConfig); var rootDevice = deviceConfiguration.RootDevice; var rootInnerDevice = DeviceToInnerDevice(rootDevice, deviceConfiguration, coreConfig); AddInnerDevice(rootDevice, rootInnerDevice, deviceConfiguration, coreConfig); coreConfig.dev = new devType[1]; coreConfig.dev[0] = rootInnerDevice; }
void SetZone(Device device, devType innerDevice, DeviceConfiguration deviceConfiguration, Firesec.Models.CoreConfiguration.config coreConfig) { if (innerDevice.inZ != null && innerDevice.inZ.Count() > 0) { string zoneIdx = innerDevice.inZ[0].idz; string zoneNo = coreConfig.zone.FirstOrDefault(x => x.idx == zoneIdx).no; int intZoneNo = int.Parse(zoneNo); var zone = deviceConfiguration.Zones.FirstOrDefault(x => x.No == intZoneNo); if (zone != null) { device.ZoneUID = zone.UID; } } if (innerDevice.prop != null) { var zoneLogicProperty = innerDevice.prop.FirstOrDefault(x => x.name == "ExtendedZoneLogic"); if (zoneLogicProperty != null) { string zoneLogicstring = zoneLogicProperty.value; if (string.IsNullOrEmpty(zoneLogicstring) == false) device.ZoneLogic = ZoneLogicConverter.Convert(deviceConfiguration, SerializerHelper.GetZoneLogic(zoneLogicstring)); } var indicatorLogicProperty = innerDevice.prop.FirstOrDefault(x => x.name == "C4D7C1BE-02A3-4849-9717-7A3C01C23A24"); if (indicatorLogicProperty != null) { string indicatorLogicString = indicatorLogicProperty.value; if (string.IsNullOrEmpty(indicatorLogicString) == false) { var indicatorLogic = SerializerHelper.GetIndicatorLogic(indicatorLogicString); if (indicatorLogic != null) { device.IndicatorLogic = IndicatorLogicConverter.Convert(deviceConfiguration, indicatorLogic); } } } var pDUGroupLogicProperty = innerDevice.prop.FirstOrDefault(x => x.name == "E98669E4-F602-4E15-8A64-DF9B6203AFC5"); if (pDUGroupLogicProperty != null) { string pDUGroupLogicPropertyString = pDUGroupLogicProperty.value; if (string.IsNullOrEmpty(pDUGroupLogicPropertyString) == false) device.PDUGroupLogic = PDUGroupLogicConverter.Convert(SerializerHelper.GetGroupProperties(pDUGroupLogicPropertyString)); } } }
public void OnParametersChanged(Firesec.Models.DeviceParameters.config coreParameters) { ChangedDevices = new HashSet<DeviceState>(); ChangedZones = new HashSet<ZoneState>(); if (coreParameters == null) return; if (coreParameters.dev == null) return; try { foreach (var device in ConfigurationCash.DeviceConfiguration.Devices) { var innerDevice = coreParameters.dev.FirstOrDefault(x => x.name == device.PlaceInTree); if (innerDevice != null) { foreach (var parameter in device.DeviceState.Parameters) { if (innerDevice.dev_param != null && innerDevice.dev_param.Any(x => x.name == parameter.Name)) { var innerParameter = innerDevice.dev_param.FirstOrDefault(x => x.name == parameter.Name); if (innerParameter != null) { if (parameter.Value != innerParameter.value) { ChangedDevices.Add(device.DeviceState); } parameter.Value = innerParameter.value; } } } } } if (ChangedDevices.Count > 0) { OnDevicesParametersChanged(ChangedDevices.ToList()); } } catch (Exception e) { Logger.Error(e, "Исключение при вызове Watcher.OnParametersChanged"); } }
Device SetInnerDevice(devType innerDevice, Device parentDevice, DeviceConfiguration deviceConfiguration, Firesec.Models.CoreConfiguration.config coreConfig) { var device = new Device() { Parent = parentDevice }; var drvType = coreConfig.drv.FirstOrDefault(x => x.idx == innerDevice.drv); if(drvType == null) { Logger.Error("ConfigurationConverter.SetInnerDevice drvType = null " + innerDevice.drv.ToString()); LoadingErrorManager.Add("Ошибка сопоставления при конвертации конфигурации"); return null; } var driverUID = new Guid(drvType.id); device.DriverUID = driverUID; device.Driver = ConfigurationCash.DriversConfiguration.Drivers.FirstOrDefault(x => x.UID == driverUID); if (device.Driver == null) { Logger.Error("ConvertDevices.SetInnerDevice driver = null " + driverUID.ToString()); LoadingErrorManager.Add("Неизвестный драйвер устройства " + driverUID.ToString()); return null; } device.IntAddress = int.Parse(innerDevice.addr); if ((device.Parent != null) && (device.Parent.Driver.IsChildAddressReservedRange)) device.IntAddress += device.Parent.IntAddress; if ((innerDevice.disabled != null) && (innerDevice.disabled == "1")) device.IsMonitoringDisabled = true; if (innerDevice.param != null) { var DatabaseIdParam = innerDevice.param.FirstOrDefault(x => x.name == "DB$IDDevices"); if (DatabaseIdParam != null) device.DatabaseId = DatabaseIdParam.value; var UIDParam = innerDevice.param.FirstOrDefault(x => x.name == "INT$DEV_GUID"); if (UIDParam != null) device.UID = GuidHelper.ToGuid(UIDParam.value); else device.UID = Guid.NewGuid(); } if (innerDevice.dev_param != null) { var AltInterfaceParam = innerDevice.dev_param.FirstOrDefault(x => x.name == "SYS$Alt_Interface"); if (AltInterfaceParam != null) device.IsAltInterface = true; else device.IsAltInterface = false; } device.Properties = new List<Property>(); if (innerDevice.prop != null) { foreach (var innerProperty in innerDevice.prop) { if (innerProperty.name == "IsAlarmDevice") { device.IsRmAlarmDevice = true; continue; } if (innerProperty.name == "NotUsed") { device.IsNotUsed = true; continue; } device.Properties.Add(new Property() { Name = innerProperty.name, Value = innerProperty.value }); } } var description = innerDevice.name; if (description != null) description = description.Replace('¹', '№'); device.Description = description; SetZone(device, innerDevice, deviceConfiguration, coreConfig); device.ShapeIds = new List<string>(); if (innerDevice.shape != null) { foreach (var shape in innerDevice.shape) { device.ShapeIds.Add(shape.id); } } device.PlaceInTree = device.GetPlaceInTree(); return device; }
void OnStateChanged(Firesec.Models.CoreState.config coreState) { try { ChangedDevices = new HashSet<DeviceState>(); ChangedZones = new HashSet<ZoneState>(); SetStates(coreState); PropogateStatesDown(); PropogateStatesUp(); CalculateZones(); if (ChangedDevices.Count > 0) { OnDevicesStateChanged(ChangedDevices.ToList()); } if (ChangedZones.Count > 0) { OnZonesStateChanged(ChangedZones.ToList()); } } catch (Exception e) { Logger.Error(e, "Исключение при вызове Watcher.OnStateChanged"); } }
void ConvertDirectionsBack(DeviceConfiguration deviceConfiguration, Firesec.Models.CoreConfiguration.config coreConfig, ref int gid) { var innerDirections = new List<partType>(); int no = 0; foreach (var direction in deviceConfiguration.Directions) { var innerDirection = new partType() { type = "direction", no = no.ToString(), id = direction.Id.ToString(), gid = gid++.ToString(), name = direction.Name }; ++no; var zonesPartTypePinZ = new List<partTypePinZ>(); foreach (var zoneUID in direction.ZoneUIDs) { var zone = deviceConfiguration.Zones.FirstOrDefault(x => x.UID == zoneUID); if (zone != null) { zonesPartTypePinZ.Add(new partTypePinZ() { pidz = zone.No.ToString() }); } } innerDirection.PinZ = zonesPartTypePinZ.ToArray(); if (direction.DeviceRm != Guid.Empty || direction.DeviceButton != Guid.Empty) { var innerDirectionParameters = new List<paramType>(); innerDirectionParameters.Add(new paramType() { name = "Device_RM", type = "String", value = GuidHelper.ToString(direction.DeviceRm) }); innerDirectionParameters.Add(new paramType() { name = "Device_AM", type = "String", value = GuidHelper.ToString(direction.DeviceRm) }); innerDirection.param = innerDirectionParameters.ToArray(); } if (innerDirection.param != null) { var rmParameter = innerDirection.param.FirstOrDefault(x => x.name == "Device_RM"); direction.DeviceRm = GuidHelper.ToGuid(rmParameter.value); var buttonParameter = innerDirection.param.FirstOrDefault(x => x.name == "Device_AM"); direction.DeviceButton = GuidHelper.ToGuid(buttonParameter.value); } innerDirections.Add(innerDirection); } coreConfig.part = innerDirections.ToArray(); }
Firesec.Models.CoreState.devType FindDevice(Firesec.Models.CoreState.devType[] innerDevices, string PlaceInTree) { return innerDevices != null ? innerDevices.FirstOrDefault(a => a.name == PlaceInTree) : null; }
void ConvertGuardUsers(DeviceConfiguration deviceConfiguration, Firesec.Models.CoreConfiguration.config coreConfig) { deviceConfiguration.GuardUsers = new List<GuardUser>(); if (coreConfig.part != null) { foreach (var innerGuardUser in coreConfig.part) { if (innerGuardUser.type == "guarduser") { var guardUser = new GuardUser() { Id = int.Parse(innerGuardUser.id), Name = innerGuardUser.name }; if (innerGuardUser.PinZ != null) { foreach (var partZone in innerGuardUser.PinZ) { var zoneNo = int.Parse(partZone.pidz); var zone = deviceConfiguration.Zones.FirstOrDefault(x => x.No == zoneNo); guardUser.ZoneUIDs.Add(zone.UID); } } if (innerGuardUser.param != null) { var KeyTMParameter = innerGuardUser.param.FirstOrDefault(x => x.name == "KeyTM"); if (KeyTMParameter != null) { guardUser.KeyTM = KeyTMParameter.value; } var DeviceUIDParameter = innerGuardUser.param.FirstOrDefault(x => x.name == "DeviceUID"); if (DeviceUIDParameter != null) { guardUser.DeviceUID = new Guid(DeviceUIDParameter.value); } var PasswordParameter = innerGuardUser.param.FirstOrDefault(x => x.name == "Password"); if (PasswordParameter != null) { guardUser.Password = PasswordParameter.value; } var FunctionParameter = innerGuardUser.param.FirstOrDefault(x => x.name == "Function"); if (FunctionParameter != null) { guardUser.Function = FunctionParameter.value; } var FIOParameter = innerGuardUser.param.FirstOrDefault(x => x.name == "FIO"); if (FIOParameter != null) { guardUser.FIO = FIOParameter.value; } var CanSetZoneParameter = innerGuardUser.param.FirstOrDefault(x => x.name == "SetZone"); if (CanSetZoneParameter != null) { guardUser.CanSetZone = CanSetZoneParameter.value == "1"; } var CanUnSetZoneParameter = innerGuardUser.param.FirstOrDefault(x => x.name == "UnSetZone"); if (CanUnSetZoneParameter != null) { guardUser.CanUnSetZone = CanUnSetZoneParameter.value == "1"; } } deviceConfiguration.GuardUsers.Add(guardUser); } } } }