public static void InvokeRpcMethod(TBRpcRequest rpcRequest)
        {
            string ssss = rpcRequest.RpcMethod;

            string rpcMethod = (string)calledMethods[(object)rpcRequest.RpcMethod];

            if (rpcMethod != null)
            {
                calledType.GetMethod(rpcMethod).Invoke(null, new object[] { rpcRequest });
            }
        }
예제 #2
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));
                }
            }
        }
예제 #3
0
 public void SendRPCRequest(TBRpcRequest rpcRequest)
 {
     tbRequestId++;
     rpcRequest.RpcRequestId = tbRequestId;
     client.Publish(RPC_REQUEST_TOPIC + tbRequestId, Encoding.UTF8.GetBytes(rpcRequest.ToJson()), QoS, false);
 }
예제 #4
0
 public RpcEventArgs(TBRpcRequest RpcRequest)
 {
     this.RpcRequest = RpcRequest;
 }