Пример #1
0
        // Rename to Get
        public async Task <T> CommandAsync <T>(RemoteCommands command)
        {
            if (_connectedRemoteSystem == null)
            {
                Debug.WriteLine("You are using CommandAsync() but you are not connected to a remote system");
                return(default(T));
            }

            //Debug.WriteLine("Sending " + command + " to " + _connectedRemoteSystem.EndPoint.Address + ":" + _connectedRemoteSystem.EndPoint.Port);
            //string response = await _socketService.SendReceiveMessageAsync(_connectedRemoteSystem.EndPoint, JsonConvert.SerializeObject(new RemoteParameter() { Command = command }));

            var parameter = JsonConvert.SerializeObject(new RemoteParameter()
            {
                Command = command
            });

            string response = await _bluetoothService.GetAsync(parameter);

            if (response == null)
            {
                return(default(T));
            }

            if (typeof(T) == response.GetType())
            {
                return((T)(object)response);
            }

            return(JsonConvert.DeserializeObject <T>(response));
        }