public ConfigurationCompareViewModel(XDeviceConfiguration localConfiguration, XDeviceConfiguration remoteConfiguration, XDevice device, bool configFromFile)
		{
			Title = "Сравнение конфигураций " + device.PresentationName;
			ConfigFromFile = configFromFile;
			ChangeCommand = new RelayCommand(OnChange);
			NextDifferenceCommand = new RelayCommand(OnNextDifference, CanNextDifference);
			PreviousDifferenceCommand = new RelayCommand(OnPreviousDifference, CanPreviousDifference);

			LocalConfiguration = localConfiguration;
			RemoteConfiguration = remoteConfiguration;
			RemoteConfiguration.Update();
			UpdateConfigurationHelper.Update(RemoteConfiguration);

			LocalDevice = localConfiguration.Devices.FirstOrDefault(x => x.DriverType == device.DriverType && x.Address == device.Address);
			RemoteDevice = remoteConfiguration.Devices.FirstOrDefault(x => x.DriverType == device.DriverType && x.Address == device.Address);
		    if (RemoteDevice == null)
		    {
		        Error = "ГК в удаленной конфигурации имеет невалидный IP адрес";
                return;
		    }
		    LocalObjectsViewModel = new ObjectsListViewModel(LocalDevice, localConfiguration);
			RemoteObjectsViewModel = new ObjectsListViewModel(RemoteDevice, remoteConfiguration);
			CompareObjectLists();
			InitializeMismatchedIndexes();
		}
		public ObjectsListViewModel (XDevice device, XDeviceConfiguration deviceConfiguration)
		{
			deviceConfiguration.Update();
			Objects = new List<ObjectViewModel>();

			foreach (var childDevice in deviceConfiguration.Devices)
			{
				var objectViewModel = new ObjectViewModel(childDevice);
				var parent = childDevice.AllParents.FirstOrDefault(x => x.ShortName == device.ShortName && x.Address == device.Address);
				if (parent != null && childDevice.IsRealDevice)
					Objects.Add(objectViewModel);
			}
			if (deviceConfiguration.Zones != null)
				foreach (var zone in deviceConfiguration.Zones.Where(x => x.GkDatabaseParent != null && x.GkDatabaseParent.Address == device.Address))
				{
					var objectViewModel = new ObjectViewModel(zone);
					Objects.Add(objectViewModel);
				}
			if (deviceConfiguration.Directions != null)
				foreach (var direction in deviceConfiguration.Directions.Where(x => x.GkDatabaseParent != null && x.GkDatabaseParent.Address == device.Address))
				{
					var objectViewModel = new ObjectViewModel(direction) { ObjectType = ObjectType.Direction };
					Objects.Add(objectViewModel);
				}
			if (deviceConfiguration.PumpStations != null)
				foreach (var pumpStation in deviceConfiguration.PumpStations.Where(x => x.GkDatabaseParent != null && x.GkDatabaseParent.Address == device.Address))
				{
					var objectViewModel = new ObjectViewModel(pumpStation) { ObjectType = ObjectType.PumpStation };
					Objects.Add(objectViewModel);
				}
		}
		override public bool ReadConfiguration(XDevice gkDevice)
		{
			var progressCallback = GKProcessorManager.StartProgress("Чтение конфигурации " + gkDevice.PresentationName, "Проверка связи", 2, true, GKProgressClientType.Administrator);
			var result = DeviceBytesHelper.Ping(gkDevice);
			if (!result)
			{
				Error = "Устройство " + gkDevice.PresentationName + " недоступно";
				return false;
			}
			IpAddress = gkDevice.GetGKIpAddress();
			ControllerDevices = new Dictionary<ushort, XDevice>();
			DeviceConfiguration = new XDeviceConfiguration();
			var rootDriver = XManager.Drivers.FirstOrDefault(x => x.DriverType == XDriverType.System);
			DeviceConfiguration.RootDevice = new XDevice
			{
				Driver = rootDriver,
				DriverUID = rootDriver.UID
			};
			GKProcessorManager.DoProgress("Перевод ГК в технологический режим", progressCallback);
			if (!DeviceBytesHelper.GoToTechnologicalRegime(gkDevice, progressCallback))
			{
				Error = "Не удалось перевести " + gkDevice.PresentationName + " в технологический режим\n" +
				        "Устройство не доступно, либо вашего " +
				        "IP адреса нет в списке разрешенного адреса ГК";
				GKProcessorManager.StopProgress(progressCallback);
				return false;
			}
			var gkFileReaderWriter = new GKFileReaderWriter();
			var gkFileInfo = gkFileReaderWriter.ReadInfoBlock(gkDevice);
			if (gkFileReaderWriter.Error != null)
			{
				Error = gkFileReaderWriter.Error;
				GKProcessorManager.StopProgress(progressCallback);
				return false;
			}
			progressCallback = GKProcessorManager.StartProgress("Чтение конфигурации " + gkDevice.PresentationName, "", gkFileInfo.DescriptorsCount, true, GKProgressClientType.Administrator);
			ushort descriptorNo = 0;
#if SETCONFIGTOFILE
			var allBytes = new List<List<byte>>();
#endif
			while (true)
			{
				if (progressCallback.IsCanceled)
				{
					Error = "Операция отменена";
					break;
				}
				descriptorNo++;
				GKProcessorManager.DoProgress("Чтение базы данных объектов ГК " + descriptorNo, progressCallback);
				const byte packNo = 1;
				var data = new List<byte>(BitConverter.GetBytes(descriptorNo)) {packNo};
				var sendResult = SendManager.Send(gkDevice, 3, 19, ushort.MaxValue, data);
				var bytes = sendResult.Bytes;
#if SETCONFIGTOFILE
				allBytes.Add(bytes);
#endif
				if (sendResult.HasError || bytes.Count < 5)
				{
					Error = "Возникла ошибка при чтении объекта " + descriptorNo;
					break;
				}

				if (bytes[3] == 0xff && bytes[4] == 0xff)
					break;
				
				if (!Parse(bytes.Skip(3).ToList(), descriptorNo))
					break;
			}
#if SETCONFIGTOFILE
			/* Опция включения записи конфигурации в файл */
			BytesHelper.BytesToFile("GKConfiguration.txt", allBytes);
#endif
			GKProcessorManager.DoProgress("Перевод ГК в рабочий режим", progressCallback);
			if (!DeviceBytesHelper.GoToWorkingRegime(gkDevice, progressCallback))
			{
				Error = "Не удалось перевести устройство в рабочий режим в заданное время";
			}
			GKProcessorManager.StopProgress(progressCallback);
			if(Error != null)
				return false;
			DeviceConfiguration.Update();
			return true;
		}
		override public bool ReadConfiguration(XDevice device)
		{
			IpAddress = device.GetGKIpAddress();
			var allbytes = BytesHelper.BytesFromFile("GKConfiguration.txt");
			ControllerDevices = new Dictionary<ushort, XDevice>();
			DeviceConfiguration = new XDeviceConfiguration();
			var rootDriver = XManager.Drivers.FirstOrDefault(x => x.DriverType == XDriverType.System);
			var rootDevice = new XDevice()
			{
				Driver = rootDriver,
				DriverUID = rootDriver.UID
			};
			DeviceConfiguration.RootDevice = rootDevice;
			ushort descriptorNo = 0;
			int count = 0;
			GKProcessorManager.OnStartProgress("Чтение конфигурации " + device.PresentationName);
			while (true)
			{
				descriptorNo++;
				byte packNo = 1;
				var descriptorNoBytes = new List<byte>(BitConverter.GetBytes(descriptorNo));
				var data = new List<byte>(descriptorNoBytes);
				data.Add(packNo);
				var bytes = allbytes[count];
				count++;
				if (bytes.Count < 5)
					break;
				if (bytes[3] == 0xff && bytes[4] == 0xff)
					break;
				if (!Parse(bytes.Skip(3).ToList(), descriptorNo))
					break;
			}
			GKProcessorManager.OnStopProgress();
			if (Error != null)
			{
				return false;
			}
			DeviceConfiguration.Update();
			XManager.UpdateGKPredefinedName(GkDevice);
			return true;
		}