public void LoadDevice_Test() { // Arrange DeviceModel deviceModel = new DeviceModel(_producerAccess) { Id = 76, Name = "Panel KTP900 Basic", ArticleNumber = "DSF98-DS9F8-DS98F", ProducerName = "SIEMENS", Location = "A2", Quantity = 13, ProjectId = 5 }; var deviceDetailsVM = new DeviceDetailsViewModel(_eventAggregator, _producerAccess, _deviceAccess); // Act deviceDetailsVM.LoadDevice(deviceModel); // Assert Assert.Equal(deviceModel.Id, deviceDetailsVM.Device.Id); Assert.Equal(deviceModel.Name, deviceDetailsVM.Device.Name); Assert.Equal(deviceModel.ArticleNumber, deviceDetailsVM.Device.ArticleNumber); Assert.Equal(deviceModel.ProducerName, deviceDetailsVM.Device.ProducerName); Assert.Equal(deviceModel.Location, deviceDetailsVM.Device.Location); Assert.Equal(deviceModel.Quantity, deviceDetailsVM.Device.Quantity); Assert.Equal(deviceModel.ProjectId, deviceDetailsVM.Device.ProjectId); }
public IHttpActionResult GetDeviceDetails(string deviceId) { var userId = User.Identity.GetUserId(); UserDeviceService userDeviceService = new UserDeviceService(); Device device = userDeviceService.GetById(deviceId); if (device != null) { if (device.AppUserId == userId) { DeviceDetailsViewModel deviceDetailsViewModel = new DeviceDetailsViewModel() { ConnectionState = device.ConnectionState, LastPing = device.LastPing, Id = device.Id, ActualState = device.ActualState, Name = device.Name, SecretKey = device.SecretKey }; return(Ok(deviceDetailsViewModel)); } return(BadRequest("Device does not available")); } return(BadRequest("Device does not exist")); }
public void DeleteButton_Test() { // Arrange DeviceModel deviceModel = new DeviceModel(_producerAccess) { Id = 76, Name = "Panel KTP900 Basic", ArticleNumber = "DSF98-DS9F8-DS98F", ProducerName = "SIEMENS", Location = "A2", Quantity = 13, ProjectId = 5 }; var deviceDetailsVM = new DeviceDetailsViewModel(_eventAggregator, _producerAccess, _deviceAccess); deviceDetailsVM.Device = deviceModel; deviceDetailsVM.LoadProducersRun(); // Act deviceDetailsVM.DeleteButton(); // Assert Assert.True(deviceDetailsVM.DeviceDeleteResult); }
public async Task <IActionResult> Details(int deviceId) { var result = new DeviceDetailsViewModel { Device = await _deviceService.GetDeviceByIdAsync(deviceId), Events = _deviceService.GetEventsForADevice(deviceId) }; return(View(result)); }
public ViewResult DeviceDetails(int?id) { var userid = userManager.GetUserId(HttpContext.User); DeviceDetailsViewModel deviceDetailsViewModel = new DeviceDetailsViewModel() { Device = _deviceRepository.GetDevice(id ?? 1), PageTitle = "Device Details", ObservationList = from c in context.Observations join u in context.Devices on c.DeviceId equals u.DeviceId join a in context.ApplicationUsers on u.UserId equals a.Id where a.Id == userid select c }; return(View(deviceDetailsViewModel)); }
public DeviceDetailsViewModel GetDeviceDetails(int id) { var deviceDetails = this.devicesService.GetDeviceDetails(id); var d = new DeviceDetailsViewModel(); d.Id = deviceDetails.Id; d.Name = deviceDetails.Name; d.Status = deviceDetails.Status; d.Type = deviceDetails.Type; d.Temperature = deviceDetails.Temperature; return(d); }
public void CreateViewModel_Test() { // Arrange List <string> producersNameList = GenerateProducersNameList(); // Act var deviceDetailsVM = new DeviceDetailsViewModel(_eventAggregator, _producerAccess, _deviceAccess); deviceDetailsVM.LoadProducersRun(); // Assert Assert.IsType <BindableCollection <string> >(deviceDetailsVM.Producers); Assert.Equal(producersNameList.Count, deviceDetailsVM.Producers.Count); Assert.Equal(producersNameList[0], deviceDetailsVM.Producers[0]); Assert.Equal(producersNameList[3], deviceDetailsVM.Producers[3]); }
public async Task <IActionResult> Device(int id) { var device = await _deviceService.GetDeviceByID(id); if (device == null) { return(NotFound()); } var readings = device.ACDeviceReading.AsQueryable().OrderByDescending(r => r.ReadingDateTime); var viewModel = new DeviceDetailsViewModel() { Device = device, LatestReading = readings.FirstOrDefault() }; return(View(viewModel)); }
public IActionResult Details(int id) { var device = _deviceRepository.GetDeviceById(id); if (device == null) { return(NotFound()); } var deviceDetailsViewModel = new DeviceDetailsViewModel() { Id = device.Id, Name = device.Name, ManufacturerName = device.Manufacturer.Name, TypeName = device.Type.Name, OperatingSystemName = device.OperatingSystem.Name, OSversionName = device.OSversion.Name, ProcessorName = device.Processor.Name, RAMamountSize = device.RAMamount.Size, UserName = device.User.Name }; return(View(deviceDetailsViewModel)); }
async Task Run(DeviceDetailsViewModel config, Action <string> log) { var client = DeviceClient.CreateFromConnectionString(config.ConnectionString); var port = new SerialPort(config.ComPortName, 57600, Parity.None, 8, StopBits.One); port.DataReceived += async(s, e) => { var buffer = new byte[port.BytesToRead]; var read = port.Read(buffer, 0, buffer.Length); var id = buffer[0]; var cmd = buffer[1]; var cmdlen = buffer[2]; log($"{read} bytes from {id}: cmd={cmd} len={cmdlen}"); var sensor = config.Sensors.Single(xx => xx.CommandId + 0x80 == cmd); var readValue = System.BitConverter.ToSingle(buffer, 3); log($"READ {sensor.Name}={readValue}"); await Send(client, sensor, readValue); //switch (cmd) //{ // case 0x80 + 0x01: // var readTemperatureValue = System.BitConverter.ToSingle(buffer, 3); // log($"READ REMPERATURE={readTemperatureValue}"); // await client.Send("t", "temperature", readTemperatureValue); // break; // break; // case 0x80 + 0x02: // var readHumidityValue = System.BitConverter.ToSingle(buffer, 3); // log($"READ HUMIDITY={readHumidityValue}"); // await client.Send("h", "humidity", readHumidityValue); // break; // case 0x80 + 0x04: // var readFlexValue = System.BitConverter.ToSingle(buffer, 3); // log($"READ FLEX={readFlexValue}"); // await client.Send("fl", "flex", readFlexValue); // break; // case 0x80 + 0x08: // var readForceValue = System.BitConverter.ToSingle(buffer, 3); // log($"READ FORCE={readForceValue}"); // await client.Send("fr", "force", readForceValue); // break; //} }; port.Open(); var requestT1 = new byte[] { 1, 1, 0 }; var requestH1 = new byte[] { 1, 2, 0 }; var requestFL1 = new byte[] { 1, 4, 0 }; var requestFR1 = new byte[] { 1, 8, 0 }; try { while (true) { //log("Sending T1"); //port.Write(requestT1, 0, requestT1.Length); //await Task.Delay(5000); //log("Sending H1"); //port.Write(requestH1, 0, requestH1.Length); //await Task.Delay(5000); //log("Sending FL1"); //port.Write(requestFL1, 0, requestFL1.Length); //await Task.Delay(5000); //log("Sending FR1"); //port.Write(requestFR1, 0, requestFR1.Length); //await Task.Delay(5000); foreach (var sensor in config.Sensors) { log($"Sending {sensor.Name}"); port.Write(new byte[] { config.SerialId, sensor.CommandId, 0 }, 0, 3); await Task.Delay(5000); } } } catch (Exception ex) { throw ex; } finally { port.Close(); } }
public IActionResult AddNewDevice(DeviceDetailsViewModel device) { if (ModelState.IsValid) { //check if manufacturer exists. If not, create it. Manufacturer manufacturer = _manufacturerRepository.GetManufacturerByName(device.ManufacturerName); if (manufacturer == null) { Manufacturer newManufacturer = new Manufacturer() { Name = device.ManufacturerName }; _manufacturerRepository.AddNewManufacturer(newManufacturer); manufacturer = _manufacturerRepository.GetManufacturerByName(device.ManufacturerName); } Models.Type type = _typeRepository.GetTypeByName(device.TypeName); if (type == null) { Models.Type newType = new Models.Type() { Name = device.TypeName }; _typeRepository.AddNewType(newType); type = _typeRepository.GetTypeByName(device.TypeName); } Models.OperatingSystem operatingSystem = _operatingSystemRepository.GetOperatingSystemByName(device.OperatingSystemName); if (operatingSystem == null) { Models.OperatingSystem newOS = new Models.OperatingSystem() { Name = device.OperatingSystemName }; _operatingSystemRepository.AddNewOperatingSystem(newOS); operatingSystem = _operatingSystemRepository.GetOperatingSystemByName(device.OperatingSystemName); } OSversion osVersion = _osVersionRepository.GetOSversionByName(device.OSversionName); if (osVersion == null) { OSversion newOSversion = new OSversion() { Name = device.OSversionName }; _osVersionRepository.AddNewOSversion(newOSversion); osVersion = _osVersionRepository.GetOSversionByName(device.OSversionName); } Processor processor = _processorRepository.GetProcessorByName(device.ProcessorName); if (processor == null) { Processor newProcessor = new Processor() { Name = device.ProcessorName }; _processorRepository.AddNewProcessor(newProcessor); processor = _processorRepository.GetProcessorByName(device.ProcessorName); } RAMamount ramAmount = _ramAmountRepository.GetRAMamountBySize(device.RAMamountSize); if (ramAmount == null) { RAMamount newRAMamount = new RAMamount() { Size = device.RAMamountSize }; _ramAmountRepository.AddNewRAMamount(newRAMamount); ramAmount = _ramAmountRepository.GetRAMamountBySize(device.RAMamountSize); } User user = _userRepository.GetUserByName(device.UserName); Device newDevice = new Device() { Name = device.Name, ManufacturerId = manufacturer.ManufacturerId, Manufacturer = manufacturer, TypeId = type.Id, Type = type, OperatingSystemId = operatingSystem.Id, OperatingSystem = operatingSystem, OSversionId = osVersion.Id, OSversion = osVersion, ProcessorId = processor.Id, Processor = processor, RAMamountId = ramAmount.Id, RAMamount = ramAmount, UserId = user.Id, User = user }; _deviceRepository.AddNewDevice(newDevice); return(RedirectToAction("DeviceAdded")); } else { return(View(device)); } }