public async Task <List <DeviceServiceResponse> > GetDevices(short count) { //limit the range of results to 1-200 var limit = count < 1 ? 1 : count > 200 ? 200 : count; var query = await _amazonDynamoDB.QueryAsync(BuildQueryRequest("unhealthy")); if (query != null) { var devices = DynamoDeviceMapper.Map(query.Items.Take(limit).ToList()); _logger.LogInformation(String.Format("Found {0} Unhealthy devices", devices.Count)); //If there are less than {count} unhealthy devices, //then pull the remainder of healthy ordered devices by registration date. if (devices.Count < limit) { //re-write queryRequest to only include healthy devices query = await _amazonDynamoDB.QueryAsync(BuildQueryRequest("healthy")); var healthyDevices = DynamoDeviceMapper.Map(query.Items.Take(limit).ToList()); devices.AddRange(healthyDevices); } return(DeviceMapper.MapDevices(devices)); } return(new List <DeviceServiceResponse>()); }
public async Task <Models.DTO.Device> Create( string userId, string tenantId, RegisterDevice device, CancellationToken cancellationToken) { if (!ObjectId.TryParse(device.TypeId, out var deviceId)) { throw new ArgumentException("Invalid TypeId"); } var type = await _typeRepository.Get( deviceId, tenantId, cancellationToken) ?? throw new ArgumentException("Type not found."); var newDevice = DeviceMapper.MapToDomain( device, type, userId, tenantId); await _deviceRepository.Create( newDevice, cancellationToken); return(DeviceMapper.MapToDto(newDevice)); }
public List <DeviceGridVM> Get() { List <DeviceGridVM> result = null; result = _deviceService.GetAll(User.Identity.Name).Select(x => DeviceMapper.MapToVM(x)).ToList(); return(result); }
// PUT: api/Device/5 public DeviceGridVM Put(DeviceVM dev) { var mappedDevice = DeviceMapper.MapToDev(dev); _deviceService.Edit(mappedDevice); return(DeviceMapper.MapToVM(mappedDevice)); }
public DeviceGridVM Post([FromBody] DeviceVM devVm) { var newDev = DeviceMapper.MapToDev(devVm); newDev.UserEmail = User.Identity.Name; _deviceService.Add(newDev); return(DeviceMapper.MapToVM(newDev)); }
public void RemoveMapper(DeviceMapper mapper) { this.config.Mappers.Remove(mapper); var serializeObject = JsonConvert.SerializeObject(this.config); Properties.Settings.Default.Devices = serializeObject; Properties.Settings.Default.Save(); }
public IActionResult GetDeviceDetails(long id) { try { return(Ok(DeviceMapper.map(itemRepository.GetDeviceById(id)))); } catch (Exception) { return(BadRequest()); } }
public static IList <Device> GetDevices() { var list = new List <Device>(); var waveInDevices = WaveIn.DeviceCount; for (int deviceIndex = 0; deviceIndex < waveInDevices; deviceIndex++) { list.Add(DeviceMapper.Map(deviceIndex, WaveIn.GetCapabilities(deviceIndex))); } return(list); }
public async Task <DeviceServiceResponse> RegisterDevice(Device device) { if (String.IsNullOrEmpty(device.RegistrationDate)) { device.RegistrationDate = DateTime.UtcNow.ToString("s"); } await _dbContext.SaveAsync <Device>(device, default(System.Threading.CancellationToken)); Device deviceResponse = await _dbContext.LoadAsync <Device>(device.SerialNumber); //create a service object to hide the secret return(DeviceMapper.MapDevice(deviceResponse)); }
public async Task <Models.DTO.Device> Delete( string id, string userId, CancellationToken cancellationToken) { if (!ObjectId.TryParse(id, out var deviceId)) { throw new ArgumentException("Invalid Id, cannot cast to ObjectId."); } var device = await _deviceRepository.Delete( deviceId, userId, cancellationToken); return(DeviceMapper.MapToDto(device)); }
public HttpResponseMessage Create(Hl7.Fhir.Model.Device fhirDevice) { HttpResponseMessage message = new HttpResponseMessage(); Device device = DeviceMapper.MapResource(fhirDevice); device = (Device)ControllerUtils.AddMetadata(device, ControllerUtils.CREATE); db.Devices.Add(device); db.SaveChanges(); message.Content = new StringContent("Device created!", Encoding.UTF8, "text/html"); message.StatusCode = HttpStatusCode.Created; message.Headers.Location = new Uri(Url.Link("SpecificDevice", new { id = device.DeviceId })); return(message); }
private async Task UpdateDeviceInfo() { var callDt = DateTime.UtcNow; _lastStateUpdate ??= callDt - StateUpdateInterval; var nextAvailableCallDt = _lastStateUpdate - StateUpdateInterval; if (callDt < nextAvailableCallDt) { return; } var response = await Client.GetAsync(DevicesUri); if (!response.IsSuccessStatusCode) { throw new AuthenticationException(); } var body = await response.Content.ReadAsStringAsync(); var parsed = JsonConvert.DeserializeObject <DevicesResponse>(body); foreach (var device in parsed.Items.Select(e => DeviceMapper.MapResponse(e, this))) { var serial = device.SerialNumber; if (serial == null) { continue; } if (Devices.ContainsKey(serial)) { Devices[serial] = device; } else { Devices.Add(serial, device); } } _lastStateUpdate = DateTime.UtcNow; }
public async Task <StationDevices> Get() { string url = string.Format("{0}?access_token={1}&app_type=app_station", _uri, _authenticationToken.Token); var deviceListResponce = await _httpWrapper.ReadGet <DeviceListResponse>(url); //var client = new HttpClient(); //HttpResponseMessage response = client.GetAsync(url).Result; //if (!response.IsSuccessStatusCode) //{ // Trace.WriteLine("DevicesList Failed!"); // throw new NetatmoReadException("Failed to read devices. Status code: " + response.StatusCode); //} //var deviceListResponce = response.Content.ReadAsAsync<DeviceListResponse>().Result; return(DeviceMapper.Map(deviceListResponce.body)); }
public async Task <DeviceServiceResponse> GetDeviceBySerialNumber(string serialNumber) { try { var device = await _dbContext.LoadAsync <Device>(serialNumber); if (device != null) { //create and map a service object to hide the device's secret return(DeviceMapper.MapDevice(device)); } } catch (Exception ex) { _logger.LogError(ex, string.Format("An error occured fetching device for serial number: {0}", serialNumber)); throw ex; } return(null); }
public HttpResponseMessage Read(int deviceId, string _format = "application/xml+FHIR", bool _summary = false) { HttpResponseMessage message = new HttpResponseMessage(); Device device = db.Devices.Find(deviceId); if (device == null) { message.StatusCode = HttpStatusCode.NotFound; message.Content = new StringContent("Device with id " + deviceId + " not found!", Encoding.UTF8, "text/html"); return(message); } Hl7.Fhir.Model.Device fhirDevice = DeviceMapper.MapModel(device); string fixedFormat = ControllerUtils.FixMimeString(_format); string payload = ControllerUtils.Serialize(fhirDevice, fixedFormat, _summary); message.Content = new StringContent(payload, Encoding.UTF8, fixedFormat); return(message); }
public HttpResponseMessage Update(Hl7.Fhir.Model.Device fhirDevice, int deviceId) { HttpResponseMessage message = new HttpResponseMessage(); if (deviceId != int.Parse(fhirDevice.Id)) { message.StatusCode = HttpStatusCode.BadRequest; message.Content = new StringContent("Mismatch of Device ID! Provided " + deviceId + " in URL but found " + fhirDevice.Id + "in payload!", Encoding.UTF8, "text/html"); return(message); } Device device = DeviceMapper.MapResource(fhirDevice); device = (Device)ControllerUtils.AddMetadata(device, ControllerUtils.UPDATE); db.Entry(device).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!DeviceExists(deviceId)) { message.StatusCode = HttpStatusCode.NotFound; message.Content = new StringContent("Device with id " + deviceId + " not found!", Encoding.UTF8, "text/html"); return(message); } else { throw; } } message.StatusCode = HttpStatusCode.OK; return(message); }
public async Task <ResultResponseMessage> NewAsync(DeviceRequestMessage request) { var modelResult = DeviceMapper.FromMessage(request?.DeviceMessage); if (!modelResult.IsModelResultValid()) { return(await Task.FromResult(modelResult.ToResultResponseMessage(request))); } modelResult = await ManagerService.NewAsync(modelResult.Model); if (!modelResult.IsModelResultValid()) { return(await Task.FromResult(modelResult.ToResultResponseMessage(request))); } await SendEvent(request.DeviceMessage, request.GetHeader(Headers.Protocol)); var result = modelResult.ToResultResponseMessage(request); result.CreateResponseNoContent(); return(await Task.FromResult(result)); }
public async Task <Models.DTO.Device> Update( string id, string userId, string tenantId, UpdateDevice device, CancellationToken cancellationToken) { if (!ObjectId.TryParse(id, out var deviceId)) { throw new ArgumentException("Invalid Id, cannot cast to ObjectId."); } var deviceToUpdate = DeviceMapper.MapToDomain( deviceId, userId, tenantId, device); var updatedDevice = await _deviceRepository.Update( deviceToUpdate, cancellationToken); return(DeviceMapper.MapToDto(updatedDevice)); }
public void Save_DeviceSummary_ValuesIncrement() { DeviceMapper deviceMapper = new DeviceMapper(this.client, this.database); Guid applicationId = Guid.NewGuid(); Guid deviceId = Guid.NewGuid(); DeviceSummary expected = new DeviceSummary() { ApplicationId = applicationId, Count = 2, Date = date, PlatformId = platform, Version = version, Carriers = new List <Aggregate <string> >() { new Aggregate <string>() { Key = "o2", Count = 2 } }, Locales = new List <Aggregate <string> >() { new Aggregate <string>() { Key = "EN", Count = 2 } }, ManufacturerModels = new List <ManufacturerModelAggregate>() { new ManufacturerModelAggregate("HTC", "OneX") { Count = 2 } }, OperatingSystems = new List <Aggregate <string> >() { new Aggregate <string>() { Key = "2.2.2.2", Count = 2 } }, Resolutions = new List <Resolution>() { new Resolution(900, 300) { Count = 2 } } }; DeviceSummary summary = new DeviceSummary() { ApplicationId = applicationId, Date = date, Version = version, PlatformId = platform, Locales = new List <Aggregate <string> >() { new Aggregate <string>("EN") }, Carriers = new List <Aggregate <string> >() { new Aggregate <string>("o2") }, ManufacturerModels = new List <ManufacturerModelAggregate>() { new ManufacturerModelAggregate("HTC", "OneX") }, OperatingSystems = new List <Aggregate <string> >() { new Aggregate <string>("2.2.2.2") }, Resolutions = new List <Resolution>() { new Resolution(900, 300) } }; deviceMapper.Save(summary); deviceMapper.Save(summary); IMongoQuery query = Query.And ( Query <DeviceSummary> .EQ <DateTime>(mem => mem.Date, date), Query <DeviceSummary> .EQ <Guid>(mem => mem.ApplicationId, applicationId), Query <DeviceSummary> .EQ <string>(mem => mem.Version, version), Query <DeviceSummary> .EQ <PlatformType>(mem => mem.PlatformId, platform) ); DeviceSummary actual = this.GetCollection <DeviceSummary>().FindOne(query); actual.ShouldHave().AllPropertiesBut(x => x.Id) .IncludingNestedObjects().EqualTo(expected); }