Esempio n. 1
0
        public override void OnSubdevPropertiesSet(string requestId, PropsSet propsSet)
        {
            if (propsSet.deviceId == null)
            {
                return;
            }

            string nodeId = IotUtil.GetNodeIdFromDeviceId(propsSet.deviceId);

            if (nodeId == null)
            {
                return;
            }

            Session session = nodeIdToSesseionDic[nodeId];

            if (session == null)
            {
                Log.Error("session is null ,nodeId:" + nodeId);

                return;
            }

            // 这里我们直接把对象转成string发给子设备,实际场景中可能需要进行一定的编解码转换
            session.channel.WriteAndFlushAsync(JsonUtil.ConvertObjectToJsonString(propsSet));

            // 为了简化处理,我们在这里直接回响应。更合理做法是在子设备处理完后再回响应
            GetClient().RespondPropsSet(requestId, IotResult.SUCCESS);

            Log.Info("WriteAndFlushAsync " + propsSet);
        }
        private void OnPropertiesSet(RawMessage message)
        {
            string requestId = IotUtil.GetRequestId(message.Topic);

            PropsSet propsSet = JsonUtil.ConvertJsonStringToObject <PropsSet>(message.ToString());

            if (propsSet == null)
            {
                return;
            }

            // 只处理直连设备的,子设备的由AbstractGateway处理
            if (propertyListener != null && (propsSet.deviceId == null || propsSet.deviceId == this.deviceId))
            {
                propertyListener.OnPropertiesSet(requestId, propsSet.services);

                return;
            }

            device.OnPropertiesSet(requestId, propsSet);
        }
        /// <summary>
        /// 属性设置回调,,由SDK自动调用
        /// </summary>
        /// <param name="requestId">请求ID</param>
        /// <param name="propsSet">属性设置请求</param>
        public void OnPropertiesSet(string requestId, PropsSet propsSet)
        {
            foreach (ServiceProperty serviceProp in propsSet.services)
            {
                IService deviceService = GetService(serviceProp.serviceId);

                if (deviceService != null)
                {
                    // 如果部分失败直接返回
                    IotResult result = deviceService.OnWrite(serviceProp.properties);
                    if (result.resultCode != IotResult.SUCCESS.resultCode)
                    {
                        client.RespondPropsSet(requestId, result);

                        return;
                    }
                }
            }

            client.RespondPropsSet(requestId, IotResult.SUCCESS);
        }
Esempio n. 4
0
 /// <summary>
 /// 子设备属性设置,网关需要转发给子设备,需要子类实现
 /// </summary>
 /// <param name="requestId">请求ID</param>
 /// <param name="propsSet">属性设置</param>
 public abstract void OnSubdevPropertiesSet(string requestId, PropsSet propsSet);