private async Task <AppServiceResponseStatus> DisconnectAsync(string deviceID, AppServiceRequest request)
        {
            var device = _devices.FirstOrDefault(D => D.Id == deviceID);

            if (device == null)
            {
                return(await request.SendResponseAsync(new ValueSet()
                {
                    { Parameters.Result, false },
                    { Parameters.Details, $"Not found device by DeviceID. DeviceID=[{deviceID}]" },
                }));
            }

            try
            {
                device.DeviceStatusUpdated -= OnDeviceStatusUpdated;
                await device.DisconnectAsync();

                _connectedDevice = null;

                return(await request.SendResponseAsync(new ValueSet()
                {
                    { Parameters.Result, true },
                    { Parameters.Details, String.Empty },
                }));
            }
            catch (Exception e)
            {
                return(await request.SendResponseAsync(new ValueSet()
                {
                    { Parameters.Result, false },
                    { Parameters.Details, e.Message },
                }));
            }
        }
        private async void CleanUp()
        {
            _devices = null;

            if (_connectedDevice != null)
            {
                _connectedDevice.DeviceStatusUpdated -= OnDeviceStatusUpdated;
                await _connectedDevice.DisconnectAsync();

                _connectedDevice.Dispose();
                _connectedDevice = null;
            }
        }
        private async Task <AppServiceResponseStatus> ConnectAsync(string deviceID, string uniqueId, AppServiceRequest request)
        {
            var device = _devices.FirstOrDefault(D => D.Id == deviceID);

            if (device == null)
            {
                return(await request.SendResponseAsync(new ValueSet()
                {
                    { Parameters.Result, false },
                    { Parameters.Details, $"Not found device by DeviceID. DeviceID=[{deviceID}]" },
                }));
            }

            try
            {
                uniqueId = await device.ConnectAsync(uniqueId);

                _connectedDevice = device;
                _connectedDevice.DeviceStatusUpdated += OnDeviceStatusUpdated;

                return(await request.SendResponseAsync(new ValueSet()
                {
                    { Parameters.Result, true },
                    { Parameters.Details, JsonConvert.SerializeObject(device, Formatting.Indented) },
                    { Parameters.UniqueID, uniqueId },
                }));
            }
            catch (Exception e)
            {
                if (device.IsConnected)
                {
                    await device.DisconnectAsync();
                }

                return(await request.SendResponseAsync(new ValueSet()
                {
                    { Parameters.Result, false },
                    { Parameters.Details, e.Message },
                }));
            }
        }