Esempio n. 1
0
        public async Task <IActionResult> Get([FromQuery] Guid id)
        {
            m_logger.LogDebug(LogEventId.GetDeviceStart, string.Format("Starting request to get device with id {0}", id));

            var request = new GetDeviceRequest(id);

            var response = await m_processor.Run(request);

            if (!response.Success)
            {
                m_logger.LogDebug(LogEventId.GetDeviceEnd, string.Format("Ending request to get device, No device found with Id {0}", id));

                return(NotFound());
            }

            DeviceModel model = new DeviceModel
            {
                BluetoothName = response.Device.BluetoothName,
                MacAddress    = response.Device.MacAddress,
                Manufacturer  = response.Device.Manufacturer,
                Model         = response.Device.Model
            };

            m_logger.LogDebug(LogEventId.GetDeviceEnd, string.Format("Ending request to get device, Device found with Id {0}", id));

            return(Ok(model));
        }
 public async static Task<Device> GetAsync(string id, IEnumerable<string> fields = null)
 {
     var request = new GetDeviceRequest() { Id = id};
     if (fields != null)
         request.Fields.AddRange(fields);
     var response = await request.ExecuteAsync();
     if (response.Status.IsSuccessful == false)
         throw response.Status.ToFault();
     Debug.Assert(response.Device != null, "For a successful get call, device should always be returned.");
     return response.Device;
 }
Esempio n. 3
0
 public async Task<IResponse<Device>> Get(GetDeviceRequest request)
 {
     var deviceExist = await this.deviceRepository
         .ExistAsync(x => x.Id == request.Id);
     if (!deviceExist)
     {
         throw new HttpError(HttpStatusCode.NotFound, "");
     }
   
     return
         ResponseFactory.CreateResponse<GetDeviceResponse, Device>(
             await this.deviceManager.GetDeviceAsync(request.Id));
 }
Esempio n. 4
0
 public async Task<Device> GetDeviceAsync(byte deviceId)
 {
     var request = new GetDeviceRequest { Id = deviceId };
     var response = await this.restClient.GetAsync(request);
     return response != null ? response.Result : null;
 }