private int RmvSubDeviceToFile(SubDevicesInfo subDevicesInfo) { try { string content = ReadJsonFile(); SubDevInfo subDevInfo = JsonUtil.ConvertJsonStringToObject <SubDevInfo>(content); if (subDevInfo.subdevices == null) { return(0); } foreach (DeviceInfo dev in subDevicesInfo.devices) { subDevInfo.subdevices.Remove(dev.nodeId); subDevInfo.version = subDevicesInfo.version; } File.WriteAllText(path, JsonUtil.ConvertObjectToJsonString(subDevInfo)); } catch (Exception ex) { Log.Error("remove sub device fail in json file"); return(-1); } return(0); }
public SubDevicesFilePersistence() { string content = ReadJsonFile(); this.subDevInfoCache = JsonUtil.ConvertJsonStringToObject <SubDevInfo>(content); Log.Info("subDevInfo:" + subDevInfoCache.ToString()); }
private void OnEvent(RawMessage message) { DeviceEvents deviceEvents = JsonUtil.ConvertJsonStringToObject <DeviceEvents>(message.ToString()); if (deviceEvents == null) { Log.Error("invalid events"); return; } device.OnEvent(deviceEvents); }
private void OnCommandV3(RawMessage message) { CommandV3 commandV3 = JsonUtil.ConvertJsonStringToObject <CommandV3>(message.ToString()); if (commandV3 == null) { Log.Error("invalid commandV3"); return; } if (commandV3Listener != null) { commandV3Listener.OnCommandV3(commandV3); } }
private void OnPropertiesGet(RawMessage message) { string requestId = IotUtil.GetRequestId(message.Topic); PropsGet propsGet = JsonUtil.ConvertJsonStringToObject <PropsGet>(message.ToString()); if (propsGet == null) { return; } if (propertyListener != null && (propsGet.deviceId == null || propsGet.deviceId == this.deviceId)) { propertyListener.OnPropertiesGet(requestId, propsGet.serviceId); return; } device.OnPropertiesGet(requestId, propsGet); }
public void OnCommand(RawMessage message) { string requestId = IotUtil.GetRequestId(message.Topic); Command command = JsonUtil.ConvertJsonStringToObject <Command>(message.ToString()); if (command == null) { Log.Error("invalid command"); return; } if (commandListener != null && (command.deviceId == null || command.deviceId == deviceId)) { commandListener.OnCommand(requestId, command.serviceId, command.commandName, command.paras); return; } device.OnCommand(requestId, command); }