public async Task ActivateSmartDeviceAsync(ActivateSmartDeviceRequest activateSmartDeviceRequest, Guid partnerId) { LoginRequest loginRequest = new LoginRequest() { Login = activateSmartDeviceRequest.SerialNumber, Password = activateSmartDeviceRequest.DefaultPassword }; SmartDevice smartDevice = await GetSmartDeviceByLoginPassword(loginRequest); if (smartDevice.Mode != SmartDeviceMode.Inactive) { throw new Exception(_localizer["The smart device cannot be activated."]); } bool smartDeviceReceivedMessage = await _smartDeviceHubService.TrySendActivateMessageAsync( smartDevice.Id, activateSmartDeviceRequest.NewPassword); if (!smartDeviceReceivedMessage) { throw new Exception(_localizer["The smart device is not connected to the service."]); } smartDevice.Activate(partnerId, _passwordService.GeneratePassword(activateSmartDeviceRequest.NewPassword)); await _dbContext.SaveChangesAsync(); }
public async Task Block(SmartDevice smartDevice) { smartDevice.Mode = SmartDeviceMode.Blocked; await _dbContext.SaveChangesAsync(); await _smartDeviceHubService.SendUpdateMessageAsync(smartDevice.Id); }
public SmartDevicesController() { _context = new SmartDeviceContext(); _lstSmartDevices = new List <SmartDevice>(); int id = 0; var cars = _context.Car.ToList(); foreach (var car in cars) { SmartDevice sd = new SmartDevice(); sd.Name = car.Name; sd.ID = ++id; sd.dbId = car.id; sd.Type = car.Type; sd.Location = car.location; sd.Status = car.Status; _lstSmartDevices.Add(sd); } var fridges = _context.Fridge.ToList(); foreach (var fridge in fridges) { SmartDevice sd = new SmartDevice(); sd.Name = fridge.Name; sd.ID = ++id; sd.Type = fridge.Type; sd.dbId = fridge.id; sd.Location = fridge.location; sd.Status = fridge.Status; _lstSmartDevices.Add(sd); } }
public async Task <ActionResult> Details(string id) { //var item = await SmartMonitorDataManager<SmartDevice>.GetItemAsync(id); SmartDevice item = BlobTable <SmartDevice> .GetItem(id); return(PartialView(item)); }
public string GetStateOfSingleSmartDevice(string id) { ObjectId _id = ObjectId.Parse(id); SmartDevice sd = _context.GetSingleSmartDeviceFromCollection(_id); return(sd.State); }
public bool CheckIfSingleSmartDeviceIsDisabled(string id) { ObjectId _id = ObjectId.Parse(id); SmartDevice sd = _context.GetSingleSmartDeviceFromCollection(_id); return(sd.Disabled); }
public void SetSpecificPropertyOfSingleSmartDevice(string id, string propertyName, string propertyValue) { ObjectId _id = ObjectId.Parse(id); SmartDevice sd = _context.GetSingleSmartDeviceFromCollection(_id); _context.SetPropertyOfSingleSmartDevice(sd, propertyName, propertyValue); }
public async Task <ActionResult <SmartDevice> > PostDevice(SmartDevice device) { _context.Devices.Add(device); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(Get), new { id = device.DeviceId }, device)); }
public SmartDevice GetSingleSmartDeviceFromCollection(ObjectId id) { var filter = Builders <SmartDevice> .Filter.Eq(x => x.Id, id); SmartDevice sd = _context.db.GetCollection <SmartDevice>(_smartDeviceCollName).Find <SmartDevice>(filter).FirstOrDefault(); return(sd); }
private async Task DeleteSmartDevice(UserIdentity identity, SmartDevice smartDevice) { _dbContext.Remove(smartDevice); await _dbContext.SaveChangesAsync(); _dbContext.Remove(identity); await _dbContext.SaveChangesAsync(); }
public void ChangeSmartDeviceState(SmartDevice device, string state) { IMongoCollection <SmartDevice> _smartDevices = GetSmartDevicesMongoCollection(); var filter = Builders <SmartDevice> .Filter.Eq(x => x.Id, device.Id); device.State = state; _smartDevices.ReplaceOne(filter, device); }
public void SmartDeviceSwitchOne(SmartDevice sd) { sd.Disabled = false; IMongoCollection <SmartDevice> _smartDevices = GetSmartDevicesMongoCollection(); var filter = Builders <SmartDevice> .Filter.Eq(x => x.Id, sd.Id); _smartDevices.ReplaceOne(filter, sd); }
public async Task UpdateConfigurationAsync( SmartDevice smartDevice, UpdateSmartDeviceConfigurationRequest updateSmartDeviceConfigurationRequest) { smartDevice.IsCaching = (bool)updateSmartDeviceConfigurationRequest.IsCaching; smartDevice.IsTurnedOn = (bool)updateSmartDeviceConfigurationRequest.IsTurnedOn; await _dbContext.SaveChangesAsync(); await _smartDeviceHubService.SendUpdateMessageAsync(smartDevice.Id); }
public void SetPropertyOfSingleSmartDevice(SmartDevice sd, string propertyName, string propertyValue) { IMongoCollection <SmartDevice> _smartDevices = _context.db.GetCollection <SmartDevice>(_smartDeviceCollName); var filter = Builders <SmartDevice> .Filter.Eq(x => x.Id, sd.Id); System.Reflection.PropertyInfo prop = typeof(SmartDevice).GetProperty(propertyName); prop.SetValue(sd, propertyValue); _smartDevices.ReplaceOne(filter, sd); }
public void CheckIfSingleSmartDeviceIsDisabledAndSwitchOn(string id) { ObjectId _id = ObjectId.Parse(id); SmartDevice sd = _context.GetSingleSmartDeviceFromCollection(_id); if (sd.Disabled) { _context.SmartDeviceSwitchOne(sd); } }
public async Task <ActionResult> EditAsync([Bind(Include = "RowKey,Name,UserId,DeviceId,DeviceKey,Description,SerialNumber,Platform, Manufacturer, Model,GpsTracking,Latitude,Longitude,Completed")] SmartDevice item) { if (ModelState.IsValid) { //await SmartMonitorDataManager<SmartDevice>.UpdateItemAsync(item.Id, item); BlobTable <SmartDevice> .Upsert(item.Id, item); return(RedirectToAction("Index")); } return(View(item)); }
public async Task <IActionResult> DeleteDevice(int id) { SmartDevice device = await _context.Devices.FindAsync(id); if (device == null) { return(NotFound()); } _context.Devices.Remove(device); await _context.SaveChangesAsync(); return(NoContent()); }
public void AddSmartDevice(string type, string name, string state, string localization, bool disabled) { SmartDevice sd = new SmartDevice { Type = type, Name = name, Localization = localization, Disabled = disabled, State = state, }; _context.AddSmartDeviceToCollection(sd); }
public void DeleteSmartDeviceFromCollection_WhenToDeleteSmartDeviceExistInDatabase_DoesNotThrow() { ObjectId newId = ObjectId.Parse("5cab1c94117778a2581069cf"); SmartDevice smartDevice = new SmartDevice { Id = newId, Name = "TEST", }; _context.AddSmartDeviceToCollection(smartDevice); Assert.DoesNotThrow(() => _context.DeleteSmartDeviceFromCollection(newId)); }
public async Task <CreatedData> CreateDeviceAsync(int animalId, string name, string deviceType) { var device = new SmartDevice { AnimalId = animalId, Name = name, DeviceType = _mapper.Map <DeviceType>(deviceType) }; _context.SmartDevices.Add(device); await _context.SaveChangesAsync(); return(new CreatedData(device.SmartDeviceId)); }
public void AddSmartDeviceToCollection_WhenDeviceWithSuchIdExistsInDatabase_ThrowsMongoDriverWriteException() { SmartDevice smartDevice = new SmartDevice { Id = _existingDeviceId, Name = "TEST" }; var result = _context.GetSmartDevicesCollection("Name"); var addedSmartDevice = result.Where(z => z.Id == smartDevice.Id).FirstOrDefault(); Assert.That(() => _context.AddSmartDeviceToCollection(smartDevice), Throws.TypeOf <MongoDB.Driver.MongoWriteException>()); }
public async Task <IActionResult> Block([FromRoute] Guid smartDeviceId) { try { SmartDevice smartDevice = await _smartDeviceService.GetByIdAsync(smartDeviceId); await _smartDeviceService.Block(smartDevice); return(Ok()); } catch (Exception e) { return(BadRequest(new BadRequestResponseMessage(e.Message))); } }
static void InitRGB() { computer.Detect_NZXT_USB_Products(); // search for smart devices while (computer.Properties.SmartDevices == null) // wait until search is complete { Thread.Sleep(10); } //get instance of smart device and create a new custom light channel smartDevice = SmartDevice.Instance(); lightChannel = new Channel() { TabIndex = "CUSTOM", CustomTab = Custom.InitDefault(20) }; }
public void AddSmartDeviceToCollection_CheckIfSmartDeviceIsAddedToDatabase() { SmartDevice smartDevice = new SmartDevice { Id = ObjectId.Parse("5cab1c95187374a2581069cf"), Name = "TEST" }; _context.AddSmartDeviceToCollection(smartDevice); var result = _context.GetSmartDevicesCollection("Name"); var addedSmartDevice = result.Where(z => z.Id == smartDevice.Id).FirstOrDefault(); Assert.That(() => addedSmartDevice != null); _context.DeleteSmartDeviceFromCollection(smartDevice.Id); }
public async Task <ActionResult> DeleteAsync(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } //SmartDevice item = await SmartMonitorDataManager<SmartDevice>.GetItemAsync(id); SmartDevice item = BlobTable <SmartDevice> .GetItem(id); if (item == null) { return(HttpNotFound()); } return(View(item)); }
public async Task <IActionResult> UpdateConfiguration( [FromRoute] Guid smartDeviceId, [FromBody] UpdateSmartDeviceConfigurationRequest updateSmartDeviceConfigurationRequest) { Guid partnerId = Guid.Parse(User.Identity.Name); try { SmartDevice smartDevice = await _smartDeviceService.GetSmartDeviceByIdAndPartnerIdAsync(smartDeviceId, partnerId); await _smartDeviceService.UpdateConfigurationAsync(smartDevice, updateSmartDeviceConfigurationRequest); return(Ok()); } catch (Exception e) { return(BadRequest(new BadRequestResponseMessage(e.Message))); } }
public void ChangeSmartDeviceState_WhenDuringOperationsSmartDeviceWasDeleted_ResultIsEqual() { ObjectId newId = ObjectId.Parse("5cab1c94187378a2581069cf"); SmartDevice smartDevice = new SmartDevice { Id = newId, Name = "TEST", State = null }; _context.AddSmartDeviceToCollection(smartDevice); _context.DeleteSmartDeviceFromCollection(newId); Assert.DoesNotThrow(() => _context.ChangeSmartDeviceState(smartDevice, "TEST")); }
public void SmartDeviceSwitchOne_WhenDisabledPropertyIsTrue_ResultIsExpected() { ObjectId newId = ObjectId.Parse("5aab1c94187378a2581069cf"); SmartDevice smartDevice = new SmartDevice { Id = newId, Name = "TEST", }; _context.AddSmartDeviceToCollection(smartDevice); _context.SmartDeviceSwitchOne(smartDevice); Assert.AreEqual(smartDevice.Disabled, false); _context.DeleteSmartDeviceFromCollection(newId); }
private async Task <string> CreateIoTDevice(SmartDevice item) { string deviceKey = ""; var registryManager = RegistryManager.CreateFromConnectionString(ConfigurationManager.AppSettings["IoTHubConnectionString"]); try { item.DeviceId = Guid.NewGuid().ToString(); var device = await registryManager.AddDeviceAsync(new Device(item.DeviceId)); item.DeviceKey = device.Authentication.SymmetricKey.PrimaryKey; } catch (DeviceAlreadyExistsException) { } return(deviceKey); }
public async Task <IActionResult> Register([FromBody] SmartDeviceRegisterRequest smartDeviceRegisterRequest) { SmartDevice smartDevice = new SmartDevice ( smartDeviceRegisterRequest.SerialNumber, smartDeviceRegisterRequest.Password ); try { await _smartDeviceService.RegisterUserAsync(smartDevice); return(Ok()); } catch (Exception exception) { return(BadRequest(new BadRequestResponseMessage(exception.Message))); } }