Exemple #1
0
        void Client_MqttMsgPublishReceived(object sender, MqttMsgPublishEventArgs e)
        {
            string topic   = e.Topic;
            string message = Encoding.UTF8.GetString(e.Message, 0, e.Message.Length);

            string[] splitTopic  = topic.Split('/');
            int      rpcActionId = int.Parse(splitTopic[splitTopic.Length - 1]);

            Hashtable deserializedObject = JsonSerializer.DeserializeString(message) as Hashtable;

            if (topic.StartsWith(RPC_REQUEST_TOPIC))
            {
                TBRpcRequest rpcRequest = new TBRpcRequest((string)deserializedObject["method"], deserializedObject["params"], rpcActionId);

                if (OnRpcRequestTopic != null)
                {
                    OnRpcRequestTopic(this, new RpcEventArgs(rpcRequest));
                }
            }
            else if (topic.StartsWith(RPC_RESPONSE_TOPIC))
            {
                string error = (string)deserializedObject["error"];


                if (error != null)
                {
                    RpcError rpcError = new RpcError(error, rpcActionId);

                    if (OnRpcError != null)
                    {
                        OnRpcError(this, new RpcEventArgs(rpcError));
                    }
                }
                else if (OnRpcResponseTopic != null)
                {
                    TBRpcResponse rpcResponse = new TBRpcResponse(rpcActionId);
                    OnRpcResponseTopic(this, new RpcEventArgs(rpcResponse));
                }
            }

            else if (topic == ATTRIBUTES_TOPIC)
            {
            }
            else if (topic.StartsWith(ATTRIBUTES_TOPIC_RESPONSE))
            {
                TBAttributesResponse tBAttributesResponse = new TBAttributesResponse(deserializedObject["client"], deserializedObject["shared"], rpcActionId);
                if (OnAttributesResponseTopic != null)
                {
                    OnAttributesResponseTopic(this, new RpcEventArgs(tBAttributesResponse));
                }
            }
        }
 public RpcEventArgs(RpcError RpcError)
 {
     this.RpcError = RpcError;
 }