public void ComparePumpStationNsDevices()
		{
			Initialize();
			var localPs = CreatePumpStation(LocalConfiguration);
			var remotePs = CreatePumpStation(RemoteConfiguration);
			var remoteNsDevice = CreateBushDrenazhDevice(RemoteAlsDevice);
			remotePs.NSDevices.Add(remoteNsDevice);
			remotePs.NSDeviceUIDs.Add(remoteNsDevice.UID);
			var viewModel = new ConfigurationCompareViewModel(LocalConfiguration, RemoteConfiguration, LocalGkDevice);
			Assert.IsTrue(viewModel.LocalObjectsViewModel.Objects.FirstOrDefault(x => x.PumpStation != null && x.PumpStation.No == localPs.No).DifferenceDiscription == "Не совпадают насосы");
			Assert.IsTrue(viewModel.RemoteObjectsViewModel.Objects.FirstOrDefault(x => x.PumpStation != null && x.PumpStation.No == remotePs.No).DifferenceDiscription == "Не совпадают насосы");

			remotePs.NSDevices.Remove(remoteNsDevice);
			remotePs.NSDeviceUIDs.Remove(remoteNsDevice.UID);
			remotePs.Invalidate(RemoteConfiguration);
			var localNsDevice = CreateBushDrenazhDevice(LocalAlsDevice);
			localPs.NSDevices.Add(localNsDevice);
			localPs.NSDeviceUIDs.Add(localNsDevice.UID);
			viewModel = new ConfigurationCompareViewModel(LocalConfiguration, RemoteConfiguration, LocalGkDevice);
			Assert.IsTrue(viewModel.LocalObjectsViewModel.Objects.FirstOrDefault(x => x.PumpStation != null && x.PumpStation.No == localPs.No).DifferenceDiscription == "Не совпадают насосы");
			Assert.IsTrue(viewModel.RemoteObjectsViewModel.Objects.FirstOrDefault(x => x.PumpStation != null && x.PumpStation.No == remotePs.No).DifferenceDiscription == "Не совпадают насосы");
		}
		public void ComparePumpStations()
		{
			Initialize();
			CreatePumpStation(LocalConfiguration);
			CreatePumpStation(RemoteConfiguration);
			var viewModel = new ConfigurationCompareViewModel(LocalConfiguration, RemoteConfiguration, LocalGkDevice);
			var localHasDifferences = viewModel.LocalObjectsViewModel.Objects.Any(x => x.HasDifferences);
			var remoteHasDifferences = viewModel.RemoteObjectsViewModel.Objects.Any(x => x.HasDifferences);
			Assert.IsFalse(localHasDifferences);
			Assert.IsFalse(remoteHasDifferences);

			LocalConfiguration.PumpStations.Clear();
			viewModel = new ConfigurationCompareViewModel(LocalConfiguration, RemoteConfiguration, LocalGkDevice);
			localHasDifferences = viewModel.LocalObjectsViewModel.Objects.Any(x => x.HasDifferences);
			remoteHasDifferences = viewModel.RemoteObjectsViewModel.Objects.Any(x => x.HasDifferences);
			Assert.IsTrue(localHasDifferences);
			Assert.IsTrue(remoteHasDifferences);
			var localPumpStation = viewModel.LocalObjectsViewModel.Objects.FirstOrDefault(x => x.ObjectType == ObjectType.PumpStation);
			var remotePumpStation = viewModel.RemoteObjectsViewModel.Objects.FirstOrDefault(x => x.ObjectType == ObjectType.PumpStation);
			Assert.IsTrue(localPumpStation.DifferenceDiscription == "Отсутствует в локальной конфигурации");
			Assert.IsTrue(localPumpStation.IsAbsent && !localPumpStation.IsPresent);
			Assert.IsTrue(remotePumpStation.DifferenceDiscription == "Отсутствует в локальной конфигурации");
			Assert.IsTrue(!remotePumpStation.IsAbsent && remotePumpStation.IsPresent);

			Initialize();
			CreatePumpStation(LocalConfiguration);
			viewModel = new ConfigurationCompareViewModel(LocalConfiguration, RemoteConfiguration, LocalGkDevice);
			localHasDifferences = viewModel.LocalObjectsViewModel.Objects.Any(x => x.HasDifferences);
			remoteHasDifferences = viewModel.RemoteObjectsViewModel.Objects.Any(x => x.HasDifferences);
			Assert.IsTrue(localHasDifferences);
			Assert.IsTrue(remoteHasDifferences);
			localPumpStation = viewModel.LocalObjectsViewModel.Objects.FirstOrDefault(x => x.ObjectType == ObjectType.PumpStation);
			remotePumpStation = viewModel.RemoteObjectsViewModel.Objects.FirstOrDefault(x => x.ObjectType == ObjectType.PumpStation);
			Assert.IsTrue(localPumpStation.DifferenceDiscription == "Отсутствует в конфигурации прибора");
			Assert.IsTrue(localPumpStation.IsAbsent == false && localPumpStation.IsPresent == true);
			Assert.IsTrue(remotePumpStation.DifferenceDiscription == "Отсутствует в конфигурации прибора");
			Assert.IsTrue(remotePumpStation.IsAbsent == true && remotePumpStation.IsPresent == false);
		}
		void OnReadConfigFile()
		{
			var thread = new Thread(() =>
			{
				var result = FiresecManager.FiresecService.GKReadConfigurationFromGKFile(SelectedDevice.Device);

				ApplicationService.Invoke(new Action(() =>
				{
					if (!result.HasError)
					{
						ConfigurationCompareViewModel configurationCompareViewModel = null;
						WaitHelper.Execute(() =>
						{
							DescriptorsManager.Create();
							UpdateConfigurationHelper.Update(result.Result);
							UpdateConfigurationHelper.PrepareDescriptors(result.Result);
							configurationCompareViewModel = new ConfigurationCompareViewModel(XManager.DeviceConfiguration, result.Result, SelectedDevice.Device, true);
						});
						LoadingService.Close();
						if (configurationCompareViewModel.Error != null)
						{
							MessageBoxService.ShowError(configurationCompareViewModel.Error, "Ошибка при чтении конфигурации");
							return;
						}
						if (DialogService.ShowModalWindow(configurationCompareViewModel))
							ServiceFactoryBase.Events.GetEvent<ConfigurationChangedEvent>().Publish(null);
					}
					else
						MessageBoxService.ShowWarning(result.Error, "Ошибка при чтении конфигурационного файла");
				}));
			});
			thread.Name = "DeviceCommandsViewModel ReadConfigFile";
			thread.Start();
		}
		void OnReadConfiguration()
		{
			var thread = new Thread(() =>
			{
				DescriptorsManager.Create();
				var result = FiresecManager.FiresecService.GKReadConfiguration(SelectedDevice.Device);

				ApplicationService.Invoke(new Action(() =>
				{
					if (!result.HasError)
					{
						ConfigurationCompareViewModel configurationCompareViewModel = null;
						WaitHelper.Execute(() =>
						{
							UpdateConfigurationHelper.Update(result.Result);
							UpdateConfigurationHelper.PrepareDescriptors(result.Result);

							var gkDevice = result.Result.RootDevice.Children.FirstOrDefault();
							if (gkDevice != null)
							{
								foreach (var zone in result.Result.Zones)
								{
									zone.GkDatabaseParent = gkDevice;
								}
								foreach (var direction in result.Result.Directions)
								{
									direction.GkDatabaseParent = gkDevice;
								}
								foreach (var pumpStation in result.Result.PumpStations)
								{
									pumpStation.GkDatabaseParent = gkDevice;
								}
							}

							configurationCompareViewModel = new ConfigurationCompareViewModel(XManager.DeviceConfiguration, result.Result, SelectedDevice.Device, false);
						});
						LoadingService.Close();
						if (configurationCompareViewModel.Error != null)
						{
							MessageBoxService.ShowWarning(configurationCompareViewModel.Error, "Ошибка при чтении конфигурации");
							return;
						}
						if (DialogService.ShowModalWindow(configurationCompareViewModel))
							ServiceFactoryBase.Events.GetEvent<ConfigurationChangedEvent>().Publish(null);
					}
					else
					{
						LoadingService.Close();
						MessageBoxService.ShowError(result.Error, "Ошибка при чтении конфигурации");
					}
				}));
			});
			thread.Name = "DeviceCommandsViewModel ReadConfiguration";
			thread.Start();
		}
Esempio n. 5
0
		void OnCallbackOperationResult(CallbackOperationResult callbackOperationResult)
		{
			if (callbackOperationResult != null)
			{
				ApplicationService.Invoke(() =>
				{
					LoadingService.Close();

					if (callbackOperationResult.CallbackOperationResultType == CallbackOperationResultType.GetGKUsers)
					{
						if (!callbackOperationResult.HasError)
						{
							GKUsersViewModel gkUsersViewModel = null;
							WaitHelper.Execute(() =>
							{
								gkUsersViewModel = new GKUsersViewModel(callbackOperationResult.Users, callbackOperationResult.DeviceUID);
							});
							//LoadingService.Close();
							DialogService.ShowModalWindow(gkUsersViewModel);
						}
						else
						{
							//LoadingService.Close();
							MessageBoxService.ShowWarning(callbackOperationResult.Error, "Ошибка при перезаписи пользователей");
						}
					}
					if (callbackOperationResult.CallbackOperationResultType == CallbackOperationResultType.GetPmfUsers)
					{
						if (!callbackOperationResult.HasError)
						{
							ServiceFactoryBase.Events.GetEvent<GetPmfUsersEvent>().Publish(callbackOperationResult.Users);
						}
						else
						{
							//LoadingService.Close();
							MessageBoxService.ShowWarning(callbackOperationResult.Error, "Ошибка при перезаписи пользователей");
						}
					}
					if (callbackOperationResult.CallbackOperationResultType == CallbackOperationResultType.RewriteUsers)
					{
						if (!callbackOperationResult.HasError)
						{
							MessageBoxService.Show("Операция перезаписи пользователей завершилась успешно");
						}
						else
						{
							MessageBoxService.ShowWarning(callbackOperationResult.Error, "Ошибка при получении пользователей");
						}
					}
					if (callbackOperationResult.CallbackOperationResultType == CallbackOperationResultType.WriteConfiguration)
					{
						if (!callbackOperationResult.HasError)
						{
							MessageBoxService.Show("Операция записи конфигурации в прибор завершилась успешно");
						}
						else
						{
							MessageBoxService.ShowWarning(callbackOperationResult.Error, "Ошибка при записи конфигурации в прибор");
						}
					}
					if (callbackOperationResult.CallbackOperationResultType == CallbackOperationResultType.ReadConfigurationFromGKFile)
					{
						if (!callbackOperationResult.HasError)
						{
							var stream = ClientManager.RubezhService.GetServerFile(callbackOperationResult.FileName);

							if (stream != Stream.Null)
							{
								var folderName = AppDataFolderHelper.GetLocalFolder("GKFile");
								var configFileName = Path.Combine(folderName, "Config.fscp");
								if (Directory.Exists(folderName))
									Directory.Delete(folderName, true);
								Directory.CreateDirectory(folderName);

								var configFileStream = File.Create(configFileName);
								ClientManager.CopyStream(stream, configFileStream);
								configFileStream.Close();

								if (new FileInfo(configFileName).Length == 0)
								{
									MessageBoxService.ShowError("Ошибка при чтении конфигурации");
									return;
								}

								try
								{
									var zipFile = ZipFile.Read(configFileName, new ReadOptions { Encoding = Encoding.GetEncoding("cp866") });
									var fileInfo = new FileInfo(configFileName);
									var unzipFolderPath = fileInfo.Directory.FullName;
									zipFile.ExtractAll(unzipFolderPath);
									zipFile.Dispose();
									var configurationFileName = Path.Combine(unzipFolderPath, "GKDeviceConfiguration.xml");
									if (!File.Exists(configurationFileName))
									{
										MessageBoxService.ShowError("Ошибка при распаковке файла");
										return;
									}
									var deviceConfiguration = ZipSerializeHelper.DeSerialize<GKDeviceConfiguration>(configurationFileName);

									ConfigurationCompareViewModel configurationCompareViewModel = null;
									WaitHelper.Execute(() =>
									{
										DescriptorsManager.Create();
										deviceConfiguration.UpdateConfiguration();
										deviceConfiguration.PrepareDescriptors();
										configurationCompareViewModel = new ConfigurationCompareViewModel(GKManager.DeviceConfiguration, deviceConfiguration, DevicesViewModel.DeviceToCompareConfiguration, configFileName);
									});
									//LoadingService.Close();
									if (configurationCompareViewModel.Error != null)
									{
										MessageBoxService.ShowError(configurationCompareViewModel.Error, "Ошибка при чтении конфигурации");
										return;
									}
									if (DialogService.ShowModalWindow(configurationCompareViewModel))
										ServiceFactoryBase.Events.GetEvent<ConfigurationChangedEvent>().Publish(null);
								}
								catch (Exception)
								{
									MessageBoxService.ShowWarning("Ошибка: файл конфигурации содержит неправильную сигнатуру");
								}
							}
							else
							{
								//LoadingService.Close();
								MessageBoxService.ShowWarning("Ошибка при чтении конфигурационного файла");
							}
						}
						else
						{
							MessageBoxService.ShowWarning(callbackOperationResult.Error, "Ошибка при чтении конфигурации из прибора");
						}
					}
				});
			}
		}
		public void CompareMPTs()
		{
			Initialize();
			var localMpt = CreateMPT(LocalConfiguration);
			var remoteMpt = CreateMPT(RemoteConfiguration);
			var viewModel = new ConfigurationCompareViewModel(LocalConfiguration, RemoteConfiguration, LocalGkDevice);
            Assert.IsFalse(viewModel.LocalObjectsViewModel.Objects.Any(x => x.HasDifferences));
			Assert.IsFalse(viewModel.RemoteObjectsViewModel.Objects.Any(x => x.HasDifferences));

			var localMptDevice = localMpt.MPTDevices.FirstOrDefault();
			LocalConfiguration.Devices.Remove(localMptDevice.Device);
			localMpt.Invalidate(LocalConfiguration);
			viewModel = new ConfigurationCompareViewModel(LocalConfiguration, RemoteConfiguration, LocalGkDevice);
			var localMptViewModel = viewModel.LocalObjectsViewModel.Objects.FirstOrDefault(x => x.MPT != null && x.MPT.Name == localMpt.Name);
			Assert.IsTrue(viewModel.LocalObjectsViewModel.Objects.Any(x => x.HasDifferences));
			Assert.IsTrue(viewModel.RemoteObjectsViewModel.Objects.Any(x => x.HasDifferences));
			Assert.IsTrue(viewModel.LocalObjectsViewModel.Objects.FirstOrDefault(x => x.MPT != null && x.MPT.Name == localMpt.Name).DifferenceDiscription == "Отсутствует в локальной конфигурации");
			Assert.IsTrue(viewModel.RemoteObjectsViewModel.Objects.FirstOrDefault(x => x.MPT != null && x.MPT.Name == remoteMpt.Name).DifferenceDiscription == "Отсутствует в локальной конфигурации");

			Initialize();
			localMpt = CreateMPT(LocalConfiguration);
			remoteMpt = CreateMPT(RemoteConfiguration);
			var remoteMptDevice = CreateMptDevice(CreateAm1(RemoteAlsDevice));
            remoteMpt.MPTDevices.Add(remoteMptDevice);
			viewModel = new ConfigurationCompareViewModel(LocalConfiguration, RemoteConfiguration, LocalGkDevice);
			Assert.IsTrue(viewModel.LocalObjectsViewModel.Objects.FirstOrDefault(x => x.MPT != null && x.MPT.Name == localMpt.Name).DifferenceDiscription == "Не совпадают устройства");
			Assert.IsTrue(viewModel.RemoteObjectsViewModel.Objects.FirstOrDefault(x => x.MPT != null && x.MPT.Name == remoteMpt.Name).DifferenceDiscription == "Не совпадают устройства");

			remoteMpt.MPTDevices.Remove(remoteMptDevice);
			remoteMpt.Invalidate(RemoteConfiguration);
			localMpt.MPTDevices.Add(CreateMptDevice(CreateAm1(LocalAlsDevice)));
			viewModel = new ConfigurationCompareViewModel(LocalConfiguration, RemoteConfiguration, LocalGkDevice);
			Assert.IsTrue(viewModel.LocalObjectsViewModel.Objects.FirstOrDefault(x => x.MPT != null && x.MPT.Name == localMpt.Name).DifferenceDiscription == "Не совпадают устройства");
			Assert.IsTrue(viewModel.RemoteObjectsViewModel.Objects.FirstOrDefault(x => x.MPT != null && x.MPT.Name == remoteMpt.Name).DifferenceDiscription == "Не совпадают устройства");
		}