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;
		}
		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;
		}
		static PointCollection GetPointCollection(surfacesSurfaceLayerElementsElement innerElementLayer)
		{
			var pointCollection = new PointCollection();
			try
			{
				foreach (var innerPoint in innerElementLayer.points)
				{
					var point = new System.Windows.Point()
					{
						X = Parse(innerPoint.x),
						Y = Parse(innerPoint.y)
					};

					pointCollection.Add(point);
				}
			}
			catch (Exception e)
			{
				Logger.Error(e, "ConfigurationConverter.GetPointCollection");
			}
			return pointCollection;
		}
		void AddRectangleZone(Plan plan, surfacesSurfaceLayerElementsElement innerElement, Zone zone)
		{
			try
			{
				var elementRectangleZone = new ElementRectangleZone()
				{
					ZoneUID = zone == null ? Guid.Empty : zone.UID,
					Left = Math.Min(Parse(innerElement.rect[0].left), Parse(innerElement.rect[0].right)),
					Top = Math.Min(Parse(innerElement.rect[0].top), Parse(innerElement.rect[0].bottom)),
					Width = Math.Abs(Parse(innerElement.rect[0].right) - Parse(innerElement.rect[0].left)),
					Height = Math.Abs(Parse(innerElement.rect[0].bottom) - Parse(innerElement.rect[0].top))
				};
				plan.ElementRectangleZones.Add(elementRectangleZone);
				if (zone != null)
				{
					if (zone.PlanElementUIDs == null)
						zone.PlanElementUIDs = new List<Guid>();
					zone.PlanElementUIDs.Add(elementRectangleZone.UID);
				}
			}
			catch (Exception e)
			{
				Logger.Error(e, "ConfigurationConverter.AddRectangleZone");
			}
		}
		void AddPictire(Plan plan, surfacesSurfaceLayerElementsElement innerElement, ref int pictureIndex)
		{
			try
			{
				if (innerElement.picture == null)
					return;

				foreach (var innerPicture in innerElement.picture)
				{
					if (string.IsNullOrEmpty(innerPicture.idx))
						innerPicture.idx = pictureIndex++.ToString();

					var picturesDirectory = GetPicturesDirectory();
					if (picturesDirectory == null)
						continue;
					var directoryInfo = new DirectoryInfo(picturesDirectory + "\\Sample" + innerPicture.idx + "." + innerPicture.ext);
					if (File.Exists(directoryInfo.FullName) == false)
						continue;

					if (innerPicture.ext == "emf")
					{
						var metafile = new Metafile(directoryInfo.FullName);
						innerPicture.ext = "bmp";
						directoryInfo = new DirectoryInfo(picturesDirectory + "\\Sample" + innerPicture.idx + "." + innerPicture.ext);
						metafile.Save(directoryInfo.FullName, ImageFormat.Bmp);
						metafile.Dispose();
					}

					var guid = ServiceFactoryBase.ContentService.AddContent(directoryInfo.FullName);
					var elementRectanglePicture = new ElementRectangle()
					{
						Left = Parse(innerElement.rect[0].left),
						Top = Parse(innerElement.rect[0].top),
						Height = Parse(innerElement.rect[0].bottom) - Parse(innerElement.rect[0].top),
						Width = Parse(innerElement.rect[0].right) - Parse(innerElement.rect[0].left),
					};

					if ((elementRectanglePicture.Left == 0) && (elementRectanglePicture.Top == 0) && (elementRectanglePicture.Width == plan.Width) && (elementRectanglePicture.Height == plan.Height))
					{
						plan.BackgroundImageSource = guid;
						plan.BackgroundSourceName = directoryInfo.FullName;
					}
					else
					{
						elementRectanglePicture.BackgroundImageSource = guid;
						elementRectanglePicture.BackgroundSourceName = directoryInfo.FullName;
						plan.ElementRectangles.Add(elementRectanglePicture);
					}
				}
			}
			catch (Exception e)
			{
				Logger.Error(e, "ConfigurationConverter.AddPictire");
			}
		}
		void AddPolygonZone(Plan plan, surfacesSurfaceLayerElementsElement innerElement, Zone zone)
		{
			try
			{
				if (innerElement.points != null)
				{
					var elementPolygonZone = new ElementPolygonZone()
					{
						ZoneUID = zone == null ? Guid.Empty : zone.UID,
					};
					elementPolygonZone.Points = GetPointCollection(innerElement);
					//elementPolygonZone.Normalize();
					plan.ElementPolygonZones.Add(elementPolygonZone);
					if (zone != null)
					{
						if (zone.PlanElementUIDs == null)
							zone.PlanElementUIDs = new List<Guid>();
						zone.PlanElementUIDs.Add(elementPolygonZone.UID);
					}
				};
			}
			catch (Exception e)
			{
				Logger.Error(e, "ConfigurationConverter.AddPolygonZone");
			}
		}
		void AddDevice(Plan plan, surfacesSurfaceLayerElementsElement innerElement, DeviceConfiguration deviceConfiguration)
		{
			try
			{
				if (innerElement.rect != null)
				{
					var innerRect = innerElement.rect[0];

					long longId = long.Parse(innerElement.id);
					int intId = (int)longId;

					var height = Parse(innerRect.bottom) - Parse(innerRect.top);
					var width = Parse(innerRect.right) - Parse(innerRect.left);
					var elementDevice = new ElementDevice()
					{
						Left = Parse(innerRect.left) + height / 2,
						Top = Parse(innerRect.top) + width / 2
					};
					plan.ElementDevices.Add(elementDevice);

					foreach (var device in deviceConfiguration.Devices)
					{
						foreach (var deviceShapeId in device.ShapeIds)
						{
							if ((deviceShapeId == longId.ToString()) || (deviceShapeId == intId.ToString()))
							{
								elementDevice.DeviceUID = device.UID;
								device.PlanElementUIDs.Add(elementDevice.UID);
							}
						}
					}
				}
			}
			catch (Exception e)
			{
				Logger.Error(e, "ConfigurationConverter.AddPolygonZone");
			}
		}
		void AddPolygon(Plan plan, surfacesSurfaceLayerElementsElement innerElement)
		{
			try
			{
				var elementPolygon = new ElementPolygon();
				elementPolygon.Points = GetPointCollection(innerElement);
				//elementPolygon.Normalize();
				plan.ElementPolygons.Add(elementPolygon);
			}
			catch (Exception e)
			{
				Logger.Error(e, "ConfigurationConverter.AddPolygon");
			}
		}
		void AddLabel(Plan plan, surfacesSurfaceLayerElementsElement innerElement, bool stretch = false)
		{
			try
			{
				var elementTextBlock = new ElementTextBlock()
				{
					Text = innerElement.caption,
					Left = Parse(innerElement.rect[0].left),
					Top = Parse(innerElement.rect[0].top),
					Height = Parse(innerElement.rect[0].bottom) - Parse(innerElement.rect[0].top),
					Width = Parse(innerElement.rect[0].right) - Parse(innerElement.rect[0].left),
					Stretch = true,
					FontBold = false,
					FontItalic = false,
				};

				FontFamily fontFamily = new FontFamily("Arial");
				double fontDpiSize = elementTextBlock.Height / 2;
				double fontHeight = Math.Ceiling(fontDpiSize * fontFamily.LineSpacing);
				elementTextBlock.FontSize = fontHeight;

				if (innerElement.brush != null)
					try
					{
						elementTextBlock.BackgroundColor = ConvertColor(innerElement.brush[0].color);
					}
					catch (Exception e)
					{
						Logger.Error(e, "Исключение при вызове ConfigurationConverter.ConvertPlans");
					}

				if (innerElement.pen != null)
					try
					{
						elementTextBlock.ForegroundColor = ConvertColor(innerElement.pen[0].color);
					}
					catch (Exception e)
					{
						Logger.Error(e, "Исключение при вызове ConfigurationConverter.ConvertPlans innerElementLayer.pen");
					}

				plan.ElementTextBlocks.Add(elementTextBlock);
			}
			catch (Exception e)
			{
				Logger.Error(e, "ConfigurationConverter.AddLabel");
			}
		}
		void AddEllipse(Plan plan, surfacesSurfaceLayerElementsElement innerElement)
		{
			try
			{
				var elementEllipse = new ElementEllipse()
				{
					Left = Parse(innerElement.rect[0].left),
					Top = Parse(innerElement.rect[0].top),
					Height = Parse(innerElement.rect[0].bottom) - Parse(innerElement.rect[0].top),
					Width = Parse(innerElement.rect[0].right) - Parse(innerElement.rect[0].left)
				};
				plan.ElementEllipses.Add(elementEllipse);
			}
			catch (Exception e)
			{
				Logger.Error(e, "ConfigurationConverter.AddEllipse");
			}
		}