Example #1
0
 static void ValidateIPAddress(XDevice device)
 {
     if (device.Driver.DriverType == XDriverType.GK)
     {
         var address = device.GetGKIpAddress();
         if (!CheckIpAddress(address))
         {
             Errors.Add(new DeviceValidationError(device, "Не задан IP адрес", ValidationErrorLevel.CannotWrite));
         }
     }
 }
Example #2
0
		public JournalViewModel(XDevice device)
		{
			Title = "Журнал событий ГК " + device.GetGKIpAddress();
			ReadCommand = new RelayCommand(OnRead);
			SaveToFileCommand = new RelayCommand(OnSaveToFile);
			JournalItems = new ObservableCollection<JournalItemViewModel>();
			Device = device;

			XManager.UpdateConfiguration();
			XManager.CreateStates();
			DescriptorsManager.Create();
			DescriptorsManager.CreateDynamicObjectsInXManager();
		}
Example #3
0
        public static string GetIpAddress(XDevice device)
        {
            XDevice gkDevice = null;
            switch (device.Driver.DriverType)
            {
                case XDriverType.GK:
                    gkDevice = device;
                    break;

                case XDriverType.KAU:
                    gkDevice = device.Parent;
                    break;

                default:
                    throw new Exception("Получить IP адрес можно только у ГК или в КАУ");
            }
            var ipAddress = gkDevice.GetGKIpAddress();
            if (ipAddress == null)
            {
                throw new Exception("Не задан IP адрес");
            }
            return ipAddress;
        }
Example #4
0
		public static string GetIpAddress(XDevice device)
		{
			XDevice gkDevice = null;
            switch (device.DriverType)
            {
                case XDriverType.GK:
                    gkDevice = device;
                    break;

                case XDriverType.KAU:
				case XDriverType.RSR2_KAU:
                    gkDevice = device.Parent;
                    break;

                default:
                    {
                        Logger.Error("XManager.GetIpAddress Получить IP адрес можно только у ГК или в КАУ");
                        throw new Exception("Получить IP адрес можно только у ГК или в КАУ");
                    }
            }
			var ipAddress = gkDevice.GetGKIpAddress();
			return ipAddress;
		}
Example #5
0
		public static bool IsValidIpAddress(XDevice device)
		{
			if (device.DriverType == XDriverType.GK)
			{
				const string pattern = @"^([01]\d\d?|[01]?[1-9]\d?|2[0-4]\d|25[0-3])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])$";
				var address = device.GetGKIpAddress();
				if (string.IsNullOrEmpty(address) || !Regex.IsMatch(address, pattern))
				{
					return false;
				}
			}
			return true;
		}
		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;
		}