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); }
private void RegisterDevice(byte[] data) { var registrationInfo = new DeviceRegistrationInfo(); using (var stream = new MemoryStream(data)) using (var reader = new BinaryReader(stream)) { registrationInfo.Id = reader.ReadGuid(); registrationInfo.Key = reader.ReadUtfString(); registrationInfo.Name = reader.ReadUtfString(); registrationInfo.ClassName = reader.ReadUtfString(); registrationInfo.ClassVersion = reader.ReadUtfString(); registrationInfo.Equipment = reader.ReadArray(ReadEquipmentInfo); registrationInfo.Notifications = reader.ReadArray(ReadNotificationInfo); registrationInfo.Commands = reader.ReadArray(ReadCommandInfo); } RegisterDeviceCore(registrationInfo); }
/// <summary> /// Override it to handle device registration in the service specific way /// </summary> protected abstract void RegisterDevice(DeviceRegistrationInfo registrationInfo);
private void RegisterDeviceCore(DeviceRegistrationInfo deviceRegistrationInfo) { _notificationMapping = deviceRegistrationInfo.Notifications.ToDictionary(n => n.Intent); _commandMapping = deviceRegistrationInfo.Commands.ToDictionary(c => c.Name); RegisterDevice(deviceRegistrationInfo); }
private void RegisterDevice2(byte[] data) { JObject jsonData; using (var stream = new MemoryStream(data)) using (var reader = new BinaryReader(stream)) jsonData = JObject.Parse(reader.ReadUtfString()); var registrationInfo = new DeviceRegistrationInfo(); registrationInfo.Id = (Guid) jsonData["id"]; registrationInfo.Key = (string) jsonData["key"]; registrationInfo.Name = (string) jsonData["name"]; var deviceClassJson = (JObject) jsonData["deviceClass"]; registrationInfo.ClassName = (string) deviceClassJson["name"]; registrationInfo.ClassVersion = (string) deviceClassJson["version"]; var equipmentJson = (JArray) jsonData["equipment"]; if (equipmentJson == null || equipmentJson.Count == 0) { registrationInfo.Equipment = new EquipmentInfo[0]; } else { registrationInfo.Equipment = equipmentJson .Select(e => new EquipmentInfo() { Code = (string) e["code"], Name = (string) e["name"], TypeName = (string) e["type"] }) .ToArray(); } var commandsJson = (JArray) jsonData["commands"]; if (commandsJson == null || commandsJson.Count == 0) { registrationInfo.Commands = new CommandMetadata[0]; } else { registrationInfo.Commands = commandsJson .Select(c => new CommandMetadata() { Intent = (ushort) c["intent"], Name = (string) c["name"], Parameters = ParseParameterMetadata(null, c["params"]) }) .ToArray(); } var notificationsJson = (JArray)jsonData["notifications"]; if (notificationsJson == null || notificationsJson.Count == 0) { registrationInfo.Notifications = new NotificationMetadata[0]; } else { registrationInfo.Notifications = notificationsJson .Select(c => new NotificationMetadata() { Intent = (ushort) c["intent"], Name = (string) c["name"], Parameters = ParseParameterMetadata(null, c["params"]) }) .ToArray(); } RegisterDeviceCore(registrationInfo); }
private void RegisterDevice2(byte[] data) { JObject jsonData; using (var stream = new MemoryStream(data)) using (var reader = new BinaryReader(stream)) jsonData = JObject.Parse(reader.ReadUtfString()); var registrationInfo = new DeviceRegistrationInfo(); registrationInfo.Id = (Guid)jsonData["id"]; registrationInfo.Key = (string)jsonData["key"]; registrationInfo.Name = (string)jsonData["name"]; var deviceClassJson = (JObject)jsonData["deviceClass"]; registrationInfo.ClassName = (string)deviceClassJson["name"]; registrationInfo.ClassVersion = (string)deviceClassJson["version"]; var equipmentJson = (JArray)jsonData["equipment"]; if (equipmentJson == null || equipmentJson.Count == 0) { registrationInfo.Equipment = new EquipmentInfo[0]; } else { registrationInfo.Equipment = equipmentJson .Select(e => new EquipmentInfo() { Code = (string)e["code"], Name = (string)e["name"], TypeName = (string)e["type"] }) .ToArray(); } var commandsJson = (JArray)jsonData["commands"]; if (commandsJson == null || commandsJson.Count == 0) { registrationInfo.Commands = new CommandMetadata[0]; } else { registrationInfo.Commands = commandsJson .Select(c => new CommandMetadata() { Intent = (ushort)c["intent"], Name = (string)c["name"], Parameters = ParseParameterMetadata(null, c["params"]) }) .ToArray(); } var notificationsJson = (JArray)jsonData["notifications"]; if (notificationsJson == null || notificationsJson.Count == 0) { registrationInfo.Notifications = new NotificationMetadata[0]; } else { registrationInfo.Notifications = notificationsJson .Select(c => new NotificationMetadata() { Intent = (ushort)c["intent"], Name = (string)c["name"], Parameters = ParseParameterMetadata(null, c["params"]) }) .ToArray(); } RegisterDeviceCore(registrationInfo); }
protected override void RegisterDevice(DeviceRegistrationInfo registrationInfo) { _regComplete.SetResult(registrationInfo); }