public FullConfiguration() { DeviceConfiguration = new DeviceConfiguration(); LibraryConfiguration = new LibraryConfiguration(); PlansConfiguration = new PlansConfiguration(); SecurityConfiguration = new SecurityConfiguration(); SystemConfiguration = new SystemConfiguration(); XDeviceConfiguration = new XDeviceConfiguration(); }
surfaces ConvertPlansBack(PlansConfiguration plansConfiguration, DeviceConfiguration deviceConfiguration) { surfaces result = new surfaces(); var innerPlans = new List<surfacesSurface>(); foreach (var plan in plansConfiguration.AllPlans) { var innerPlan = new surfacesSurface(); innerPlans.Add(innerPlan); innerPlan.caption = plan.Caption; innerPlan.height = (plan.Height / 10).ToString(); innerPlan.width = (plan.Width / 10).ToString(); var layers = new List<surfacesSurfaceLayer>(); var layer = new surfacesSurfaceLayer(); layer.name = "Зоны"; layers.Add(layer); innerPlan.layer = layers.ToArray(); var elements = new List<surfacesSurfaceLayerElementsElement>(); foreach (var elementRectangle in plan.ElementRectangles) { var element = new surfacesSurfaceLayerElementsElement(); elements.Add(element); element.@class = "TSCDeRectangle"; element.rect = new surfacesSurfaceLayerElementsElementRect[1]{new surfacesSurfaceLayerElementsElementRect()}; element.rect[0].left = elementRectangle.Left.ToString(); element.rect[0].top = elementRectangle.Top.ToString(); element.rect[0].bottom = (elementRectangle.Top + elementRectangle.Height).ToString(); element.rect[0].right = (elementRectangle.Left + elementRectangle.Width).ToString(); element.rect[0].left = elementRectangle.Top.ToString(); } layer.elements = elements.ToArray(); } result.surface = innerPlans.ToArray(); return result; }
public void LoadFromZipFile(string fileName) { var zipFile = ZipFile.Read(fileName, new ReadOptions { Encoding = Encoding.GetEncoding("cp866") }); var fileInfo = new FileInfo(fileName); var unzipFolderPath = Path.Combine(fileInfo.Directory.FullName, "Unzip"); zipFile.ExtractAll(unzipFolderPath); var zipConfigurationItemsCollectionFileName = Path.Combine(unzipFolderPath, "ZipConfigurationItemsCollection.xml"); if (!File.Exists(zipConfigurationItemsCollectionFileName)) { Logger.Error("FiresecManager.LoadFromZipFile zipConfigurationItemsCollectionFileName file not found"); return; } var zipConfigurationItemsCollection = ZipSerializeHelper.DeSerialize<ZipConfigurationItemsCollection>(zipConfigurationItemsCollectionFileName); if (zipConfigurationItemsCollection == null) { Logger.Error("FiresecManager.LoadFromZipFile zipConfigurationItemsCollection == null"); return; } foreach (var zipConfigurationItem in zipConfigurationItemsCollection.GetWellKnownZipConfigurationItems) { var configurationFileName = Path.Combine(unzipFolderPath, zipConfigurationItem.Name); if (File.Exists(configurationFileName)) { switch (zipConfigurationItem.Name) { case "XDeviceConfiguration.xml": XDeviceConfiguration = ZipSerializeHelper.DeSerialize<XDeviceConfiguration>(configurationFileName); break; case "PlansConfiguration.xml": PlansConfiguration = ZipSerializeHelper.DeSerialize<PlansConfiguration>(configurationFileName); break; } } } var destinationImagesDirectory = AppDataFolderHelper.GetLocalFolder("Administrator/Configuration/Unzip/Content"); var sourceImagesDirectoryInfo = new DirectoryInfo(Path.Combine(unzipFolderPath, "Content")); foreach (var imageFileInfo in sourceImagesDirectoryInfo.GetFiles()) { imageFileInfo.CopyTo(Path.Combine(destinationImagesDirectory, imageFileInfo.Name), true); } zipFile.Dispose(); MergeXDeviceConfiguration(); }
void MergeXDeviceConfiguration() { var errors = new StringBuilder(); var maxZoneNo = 0; if (XManager.Zones.Count > 0) maxZoneNo = XManager.Zones.Max(x=>x.No); var maxDirectionNo = 0; if (XManager.Directions.Count > 0) maxDirectionNo = XManager.Directions.Max(x => x.No); if (XDeviceConfiguration == null) XDeviceConfiguration = new XDeviceConfiguration(); if (PlansConfiguration == null) PlansConfiguration = new PlansConfiguration(); XDeviceConfiguration.Update(); PlansConfiguration.Update(); CreateNewUIDs(); XDeviceConfiguration.Update(); PlansConfiguration.Update(); foreach (var gkDevice in XDeviceConfiguration.RootDevice.Children) { var ipAddress = ""; var ipProperty = gkDevice.Properties.FirstOrDefault(x => x.Name == "IPAddress"); if (ipProperty != null) { ipAddress = ipProperty.StringValue; } var existingGKDevice = XManager.DeviceConfiguration.RootDevice.Children.FirstOrDefault(x => x.Address == ipAddress); if (existingGKDevice != null) { foreach (var device in gkDevice.Children) { var driver = XManager.Drivers.FirstOrDefault(x => x.UID == device.DriverUID); if (driver.DriverType == XDriverType.KAU || driver.DriverType == XDriverType.RSR2_KAU) { var existingKAUDevice = existingGKDevice.Children.FirstOrDefault(x => x.Driver != null && (x.DriverType == XDriverType.KAU || x.DriverType == XDriverType.RSR2_KAU) && x.IntAddress == device.IntAddress); if (existingKAUDevice == null) { existingGKDevice.Children.Add(device); } else { errors.AppendLine("Устройство " + existingKAUDevice.PresentationName + " не было добавленно в конфигурацию из за совпадения адресов"); } } } } else { XManager.DeviceConfiguration.RootDevice.Children.Add(gkDevice); } } foreach (var zone in XDeviceConfiguration.Zones) { zone.No = (ushort)(zone.No + maxZoneNo); XManager.Zones.Add(zone); } foreach (var direction in XDeviceConfiguration.Directions) { direction.No = (ushort)(direction.No + maxDirectionNo); XManager.Directions.Add(direction); } foreach (var plan in PlansConfiguration.Plans) { FiresecManager.PlansConfiguration.Plans.Add(plan); } XManager.UpdateConfiguration(); FiresecManager.UpdateConfiguration(); var errorsString = errors.ToString(); if (!string.IsNullOrEmpty(errorsString)) { MessageBoxService.ShowError(errorsString, "В результате слияния конфигурации возникли ошибки"); } }
surfaces ConvertPlansBack(PlansConfiguration plansConfiguration, DeviceConfiguration deviceConfiguration) { var innerPlansConfiguration = new surfaces(); var innerPlans = new List<surfacesSurface>(); foreach (var plan in plansConfiguration.Plans.OfType<Plan>()) { surfacesSurface innerPlan = new surfacesSurface() { caption = plan.Caption, height = (plan.Height / 10).ToString(), width = (plan.Width / 10).ToString() }; innerPlans.Add(innerPlan); var mainLayer = new surfacesSurfaceLayer() { name = "План" }; var mainLayerElements = new List<surfacesSurfaceLayerElementsElement>(); foreach (var elementRectangle in plan.ElementRectangles) { var innerRectangle = new surfacesSurfaceLayerElementsElement() { @class = "TSCDeRectangle", rect = new surfacesSurfaceLayerElementsElementRect[] { GetRect(elementRectangle) } }; mainLayerElements.Add(innerRectangle); } foreach (var elementEllipse in plan.ElementEllipses) { var innerEllipse = new surfacesSurfaceLayerElementsElement() { @class = "TSCDeEllipse", rect = new surfacesSurfaceLayerElementsElementRect[] { GetRect(elementEllipse) } }; mainLayerElements.Add(innerEllipse); } foreach (var elementTextBlock in plan.ElementTextBlocks) { var innerLable = new surfacesSurfaceLayerElementsElement() { @class = "TSCDeLabel", rect = new surfacesSurfaceLayerElementsElementRect[] { GetRect(elementTextBlock) }, caption = elementTextBlock.Text }; innerLable.pen = new surfacesSurfaceLayerElementsElementPen[1]; innerLable.pen[0] = new surfacesSurfaceLayerElementsElementPen() { color = "cl" + elementTextBlock.ForegroundColor.ToString() }; innerLable.brush = new surfacesSurfaceLayerElementsElementBrush[1]; innerLable.brush[0] = new surfacesSurfaceLayerElementsElementBrush() { color = "cl" + elementTextBlock.BackgroundColor.ToString() }; mainLayerElements.Add(innerLable); } foreach (var elementPolyline in plan.ElementPolylines) { var innerPolyline = new surfacesSurfaceLayerElementsElement() { @class = "TSCDePolyLine", }; var innerPointsCollection = new List<surfacesSurfaceLayerElementsElementPointsPoint>(); foreach (var point in elementPolyline.Points) { innerPointsCollection.Add(new surfacesSurfaceLayerElementsElementPointsPoint() { x = point.X.ToString(), y = point.Y.ToString() }); } innerPolyline.points = innerPointsCollection.ToArray(); mainLayerElements.Add(innerPolyline); } foreach (var elementPolygon in plan.ElementPolygons) { var innerPolyline = new surfacesSurfaceLayerElementsElement() { @class = "TSCDePolygon", }; var innerPointsCollection = new List<surfacesSurfaceLayerElementsElementPointsPoint>(); foreach (var point in elementPolygon.Points) { innerPointsCollection.Add(new surfacesSurfaceLayerElementsElementPointsPoint() { x = point.X.ToString(), y = point.Y.ToString() }); } innerPolyline.points = innerPointsCollection.ToArray(); mainLayerElements.Add(innerPolyline); } mainLayer.elements = mainLayerElements.ToArray(); var devicesLayer = new surfacesSurfaceLayer() { name = "Устройства" }; var innerDeviceElements = new List<surfacesSurfaceLayerElementsElement>(); foreach (var elementDevice in plan.ElementDevices) { var innerDeviceElement = new surfacesSurfaceLayerElementsElement(); var innerRect = new surfacesSurfaceLayerElementsElementRect() { left = elementDevice.Left.ToString(), top = elementDevice.Top.ToString(), bottom = (elementDevice.Top + 10).ToString(), right = (elementDevice.Left + 10).ToString() }; innerDeviceElement.rect = new surfacesSurfaceLayerElementsElementRect[] { innerRect }; var device = deviceConfiguration.Devices.FirstOrDefault(x => x.UID == elementDevice.UID); if (device != null) { innerDeviceElement.id = device.ShapeIds.FirstOrDefault(); } innerDeviceElements.Add(innerDeviceElement); } devicesLayer.elements = innerDeviceElements.ToArray(); var zonesLayer = new surfacesSurfaceLayer() { name = "Зоны" }; var zoneLayerElements = new List<surfacesSurfaceLayerElementsElement>(); foreach (var elementRectangleZone in plan.ElementRectangleZones) { var innerRectangleZone = new surfacesSurfaceLayerElementsElement() { @class = "TFS_ZoneShape", rect = new surfacesSurfaceLayerElementsElementRect[] { GetRect(elementRectangleZone) } }; var zone = deviceConfiguration.Zones.FirstOrDefault(x => x.UID == elementRectangleZone.UID); if (zone != null) { innerRectangleZone.id = zone.ShapeIds.FirstOrDefault(); } zoneLayerElements.Add(innerRectangleZone); } foreach (var elementPolygonZone in plan.ElementPolygonZones) { var innerPolygonZone = new surfacesSurfaceLayerElementsElement() { @class = "TFS_PolyZoneShape", }; var innerPointsCollection = new List<surfacesSurfaceLayerElementsElementPointsPoint>(); foreach (var point in elementPolygonZone.Points) { innerPointsCollection.Add(new surfacesSurfaceLayerElementsElementPointsPoint() { x = point.X.ToString(), y = point.Y.ToString() }); } innerPolygonZone.points = innerPointsCollection.ToArray(); var zone = deviceConfiguration.Zones.FirstOrDefault(x => x.UID == elementPolygonZone.UID); if (zone != null) { innerPolygonZone.id = zone.ShapeIds.FirstOrDefault(); } zoneLayerElements.Add(innerPolygonZone); } zonesLayer.elements = innerDeviceElements.ToArray(); var innerLayers = new List<surfacesSurfaceLayer>(); innerLayers.Add(mainLayer); innerLayers.Add(devicesLayer); innerLayers.Add(zonesLayer); innerPlan.layer = innerLayers.ToArray(); } innerPlansConfiguration.surface = innerPlans.ToArray(); return innerPlansConfiguration; }
public void SetPlansConfiguration(PlansConfiguration plansConfiguration) { ConfigurationFileManager.SetPlansConfiguration(plansConfiguration); ConfigurationCash.PlansConfiguration = plansConfiguration; }
PlansConfiguration ConvertPlans(surfaces innerPlans, DeviceConfiguration deviceConfiguration) { var plansConfiguration = new PlansConfiguration(); if ((innerPlans != null) && (innerPlans.surface != null)) { foreach (var innerPlan in innerPlans.surface) { var plan = new Plan() { Caption = innerPlan.caption, Height = Double.Parse(innerPlan.height) * 10, Width = Double.Parse(innerPlan.width) * 10 }; foreach (var innerLayer in innerPlan.layer) { if (innerLayer.elements == null) continue; switch (innerLayer.name) { case "План": foreach (var innerElement in innerLayer.elements) { switch (innerElement.@class) { case "TSCDePicture": int pictureIndex = 0; AddPictire(plan, innerElement, ref pictureIndex); break; case "TSCDeRectangle": AddRectangle(plan, innerElement); break; case "TSCDeEllipse": AddEllipse(plan, innerElement); break; case "TSCDeLabel": AddLabel(plan, innerElement); break; case "TSCDeText": AddLabel(plan, innerElement, true); break; case "TSCDePolyLine": AddPolyLine(plan, innerElement); break; case "TSCDePolygon": AddPolygon(plan, innerElement); break; default: Logger.Error("ConfigurationConverter.ConvertPlans: Неизвестный элемент " + innerElement.@class); break; } } break; case "Несвязанные зоны": case "Пожарные зоны": case "Охранные зоны": case "Зоны": foreach (var innerElement in innerLayer.elements) { Zone activeZone = null; long longId = long.Parse(innerElement.id); int intId = (int)longId; foreach (var zone in deviceConfiguration.Zones) foreach (var zoneShapeId in zone.ShapeIds) if ((zoneShapeId == longId.ToString()) || (zoneShapeId == intId.ToString())) activeZone = zone; switch (innerElement.@class) { case "TFS_PolyZoneShape": AddPolygonZone(plan, innerElement, activeZone); break; case "TFS_ZoneShape": AddRectangleZone(plan, innerElement, activeZone); break; case "TSCDeRectangle": AddRectangle(plan, innerElement); break; case "TSCDeEllipse": AddEllipse(plan, innerElement); break; case "TSCDeLabel": AddLabel(plan, innerElement); break; case "TSCDeText": AddLabel(plan, innerElement, true); break; case "TSCDePolyLine": AddPolyLine(plan, innerElement); break; case "TSCDePolygon": AddPolygon(plan, innerElement); break; default: Logger.Error("ConfigurationConverter.ConvertPlans: Неизвестный элемент " + innerElement.@class); break; } } break; case "Устройства": foreach (var innerElement in innerLayer.elements) { AddDevice(plan, innerElement, deviceConfiguration); } break; } } plansConfiguration.Plans.Add(plan); } } var picturesDirectory = GetPicturesDirectory(); if (picturesDirectory != null) { DeleteDirectory(Environment.CurrentDirectory + "\\Pictures"); } return plansConfiguration; }
public void SetPlansConfiguration(PlansConfiguration plansConfiguration) { SafeOperationCall(() => { FiresecService.SetPlansConfiguration(plansConfiguration); }); }
public static bool PlanValidator(PlansConfiguration configuration) { //ServiceFactoryBase.ContentService. return true; }