public ConfigurationCompareViewModel(GKDeviceConfiguration localConfiguration, GKDeviceConfiguration remoteConfiguration, GKDevice device, string configFileName = "")
		{
			Title = "Сравнение конфигураций " + device.PresentationName;
			ChangeCurrentGkCommand = new RelayCommand(OnChangeCurrentGk);
			LoadConfigurationFromFileCommand = new RelayCommand(OnLoadConfigurationFromFile);
			NextDifferenceCommand = new RelayCommand(OnNextDifference, CanNextDifference);
			PreviousDifferenceCommand = new RelayCommand(OnPreviousDifference, CanPreviousDifference);

			ConfigFileName = configFileName;
			ConfigFromFile = CanChangeOrOpenConfiguration = !string.IsNullOrEmpty(configFileName);

			var remoteConfig = new ZipFile(ConfigFileName);
			OnlyGKDeviceConfiguration = remoteConfig.Entries.Count == 1;

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

			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();
		}
Beispiel #2
0
		public static List<byte> CreateHash1(GKDeviceConfiguration deviceConfiguration, GKDevice gkControllerDevice)
		{
			deviceConfiguration.UpdateConfiguration();
			deviceConfiguration.PrepareDescriptors();
			var stringBuilder = new StringBuilder();
			stringBuilder.Append("devices:");
			foreach (var device in deviceConfiguration.Devices)
			{
				if (device.IsRealDevice && device.GKParent == gkControllerDevice)
					stringBuilder.Append(device.PresentationName).Append("@");
			}
			stringBuilder.Append("zones:");
			foreach (var zone in deviceConfiguration.Zones)
			{
				if (zone.GkDatabaseParent == gkControllerDevice)
					stringBuilder.Append(zone.PresentationName).Append("@");
			}
			stringBuilder.Append("directions:");
			foreach (var direction in deviceConfiguration.Directions)
			{
				if (direction.GkDatabaseParent == gkControllerDevice)
					stringBuilder.Append(direction.PresentationName).Append("@");
			}
			stringBuilder.Append("pumpStations:");
			foreach (var pumpStation in deviceConfiguration.PumpStations)
			{
				if (pumpStation.GkDatabaseParent == gkControllerDevice)
				{
					stringBuilder.Append(pumpStation.PresentationName).Append("@");
					if (pumpStation.NSDevices != null)
					{
						stringBuilder.Append("nsDevices:");
						foreach (var nsDevice in pumpStation.NSDevices)
						{
							if (nsDevice.GKParent == gkControllerDevice)
								stringBuilder.Append(nsDevice.PresentationName).Append("@");
						}
					}
				}
			}
			stringBuilder.Append("mpts:");
			foreach (var mpt in deviceConfiguration.MPTs)
			{
				if (mpt.GkDatabaseParent == gkControllerDevice)
				{
					stringBuilder.Append(mpt.PresentationName).Append("@");
					if (mpt.MPTDevices != null)
					{
						stringBuilder.Append("nsDevices:");
						foreach (var mptDevice in mpt.MPTDevices)
						{
							if (mptDevice.Device.GKParent == gkControllerDevice)
								stringBuilder.Append(mptDevice.Device.PresentationName).Append("@");
						}
					}
				}
			}
			stringBuilder.Append("delays:");
			foreach (var delay in deviceConfiguration.Delays)
			{
				if (delay.GkDatabaseParent == gkControllerDevice)
				{
					stringBuilder.Append(delay.PresentationName).Append("@");
				}
			}
			stringBuilder.Append("guardZones:");
			foreach (var guardZone in deviceConfiguration.GuardZones)
			{
				if (guardZone.GkDatabaseParent == gkControllerDevice)
					stringBuilder.Append(guardZone.PresentationName).Append("@");
			}
			stringBuilder.Append("codes:");
			foreach (var code in deviceConfiguration.Codes)
			{
				if (code.GkDatabaseParent == gkControllerDevice)
					stringBuilder.Append(code.PresentationName).Append("@");
			}
			stringBuilder.Append("door:");
			foreach (var door in deviceConfiguration.Doors)
			{
				if (door.GkDatabaseParent == gkControllerDevice)
					stringBuilder.Append(door.PresentationName).Append("@");
			}
			return SHA256.Create().ComputeHash(Encoding.GetEncoding(1251).GetBytes(stringBuilder.ToString())).ToList();
		}
		GKDeviceConfiguration CreateConfiguration()
		{
			var newConfiguration = new GKDeviceConfiguration();
			var drivers = GKManager.Drivers;
			var systemDriver = drivers.FirstOrDefault(x => x.DriverType == GKDriverType.System);
			var gkDriver = drivers.FirstOrDefault(x => x.DriverType == GKDriverType.GK);
			var kauDriver = drivers.FirstOrDefault(x => x.DriverType == GKDriverType.RSR2_KAU);
			var alsDriver = drivers.FirstOrDefault(x => x.DriverType == GKDriverType.RSR2_KAU_Shleif);

			var alsDevice = new GKDevice { DriverUID = alsDriver.UID };

			var kauDevice = new GKDevice { DriverUID = kauDriver.UID };
			kauDevice.Children.Add(alsDevice);

			var gkDevice = new GKDevice { DriverUID = gkDriver.UID };
			gkDevice.Children.Add(kauDevice);

			newConfiguration.RootDevice = new GKDevice { DriverUID = systemDriver.UID };
			newConfiguration.RootDevice.Children.Add(gkDevice);
			newConfiguration.UpdateConfiguration();
			return newConfiguration;
		}
		public ObjectsListViewModel (GKDevice device, GKDeviceConfiguration deviceConfiguration)
		{
			deviceConfiguration.Update();
			deviceConfiguration.UpdateConfiguration();
			deviceConfiguration.PrepareDescriptors();
			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);
					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);
					Objects.Add(objectViewModel);
				}
			if (deviceConfiguration.MPTs != null)
				foreach (var mpt in deviceConfiguration.MPTs.Where(x => x.GkDatabaseParent != null && x.GkDatabaseParent.Address == device.Address))
				{
					var objectViewModel = new ObjectViewModel(mpt);
					Objects.Add(objectViewModel);
				}
			if (deviceConfiguration.Delays != null)
				foreach (var delay in deviceConfiguration.Delays.Where(x => x.GkDatabaseParent != null && x.GkDatabaseParent.Address == device.Address))
				{
					var objectViewModel = new ObjectViewModel(delay);
					Objects.Add(objectViewModel);
				}
			if (deviceConfiguration.GuardZones != null)
				foreach (var guardZone in deviceConfiguration.GuardZones.Where(x => x.GkDatabaseParent != null && x.GkDatabaseParent.Address == device.Address))
				{
					var objectViewModel = new ObjectViewModel(guardZone);
					Objects.Add(objectViewModel);
				}
			if (deviceConfiguration.Codes != null)
				foreach (var code in deviceConfiguration.Codes.Where(x => x.GkDatabaseParent != null && x.GkDatabaseParent.Address == device.Address))
				{
					var objectViewModel = new ObjectViewModel(code);
					Objects.Add(objectViewModel);
				}
			if (deviceConfiguration.Doors != null)
				foreach (var door in deviceConfiguration.Doors.Where(x => x.GkDatabaseParent != null && x.GkDatabaseParent.Address == device.Address))
				{
					var objectViewModel = new ObjectViewModel(door);
					Objects.Add(objectViewModel);
				}
		}