protected override void RegisterDevice(DeviceRegistrationInfo registrationInfo) { _deviceGuid = registrationInfo.Id; _deviceKey = registrationInfo.Key; if (!_gatewayService.CheckDevice(_deviceGuid)) { // reissue device registration request RequestRegistration(); return; } var device = new Device.Device(_deviceGuid.ToString(), _deviceKey); device.Name = registrationInfo.Name; device.DeviceClass = new DeviceClass(registrationInfo.ClassName, registrationInfo.ClassVersion); device.Equipment = registrationInfo.Equipment .Select(e => new Equipment(e.Name, e.Code, e.TypeName)).ToList(); device.Network = _gatewayService.Network; DeviceService.RegisterDevice(device); _gatewayService.RegisterDevice(this); _deviceRegistered = true; LogManager.GetLogger(GetType()).InfoFormat("Device {0} registered", _deviceGuid); }
/// <summary> /// Компаратор для сравнения устройств (сортировки) /// </summary> /// <param name="x">Устройство 1</param> /// <param name="y">Устройство 2</param> /// <returns></returns> private int DevicesComparer(Device.Device x, Device.Device y) { int res; res = Device.Device.Compare(x, y); return(res); }
/// <summary> /// Функция проверки добавляемого устройства /// </summary> /// <param name="deviceName">Имя устройства</param> /// <returns></returns> private bool ValidateDevice(string deviceName) { bool isValidType = false; Device.Device device = Device.DeviceManager.GetInstance(). GetDeviceByEplanName(deviceName); Device.DeviceType deviceType = device.DeviceType; Device.DeviceSubType deviceSubType = device.DeviceSubType; Device.DeviceType[] validTypes; Device.DeviceSubType[] validSubTypes; GetDevTypes(out validTypes, out validSubTypes); if (validTypes == null) { return(true); } else { foreach (Device.DeviceType type in validTypes) { if (type == deviceType) { isValidType = true; break; } else { isValidType = false; } } if (validSubTypes != null) { bool isValidSubType = false; foreach (Device.DeviceSubType subType in validSubTypes) { if ((subType == deviceSubType) && isValidType) { isValidSubType = true; } } if (isValidSubType && isValidSubType) { return(true); } else { return(false); } } } return(isValidType); }
/// <summary> /// Получить строку с устройствами /// </summary> /// <returns></returns> private string GetDevicesString() { var devices = new List <string>(); var deviceManager = Device.DeviceManager.GetInstance(); foreach (var devIndex in deviceIndexes) { Device.Device dev = deviceManager.GetDeviceByIndex(devIndex); if (dev.Name != StaticHelper.CommonConst.Cap) { devices.Add(dev.Name); } } devices = devices.Distinct().ToList(); return(string.Join(" ", devices)); }
public DrawInfo(Style style, Device.Device dev) { this.style = style; this.dev = dev; }
/// <summary> /// Сортировка устройств для корректного отображения. /// </summary> /// <param name="devices">Устройства для сортировки</param> /// <returns></returns> private string SortDevices(string devices) { var devicesMatches = Regex.Matches(devices, Device.DeviceManager.DeviceNamePattern); if (devicesMatches.Count <= MinimalDevicesCountForCheck) { return(devices); } // valveTerminal - для вставки VTUG в старых проектах первым. Device.Device valveTerminal = null; var devicesList = new List <Device.Device>(); foreach (Match match in devicesMatches) { Device.Device device = Device.DeviceManager.GetInstance(). GetDevice(match.Value); if (device.DeviceType != Device.DeviceType.DEV_VTUG) { devicesList.Add(device); } else { valveTerminal = device; } } devicesList.Sort(DevicesComparer); if (valveTerminal != null) { devicesList.Insert(0, valveTerminal); } var sortedDevices = ""; foreach (Device.Device device in devicesList) { if (device.Description.Contains(PlusSymbol)) { // Заменяем символ плюс в комментарии, что бы не было // конфликтов. Потом вернем обратно. string replacedDeviceDescription = device.Description. Replace(PlusSymbol.ToString(), SymbolForPlusReplacing); sortedDevices += device.EPlanName + CommonConst.NewLineWithCarriageReturn + replacedDeviceDescription + CommonConst.NewLineWithCarriageReturn; } else { sortedDevices += device.EPlanName + CommonConst.NewLineWithCarriageReturn + device.Description + CommonConst.NewLineWithCarriageReturn; } } return(sortedDevices); }