// GET: DvController/Details/5 public async Task <ActionResult> Details(int id) { DeviceDTO model = null; var token = User.FindFirst(claim => claim.Type == System.Security.Claims.ClaimTypes.UserData)?.Value; using (HttpClient client = new HttpClient()) { client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); client.SetBearerToken(token.Split(" ")[1]); string endpoint = apiBaseUrl + "/Device/" + id; using (var Response = await client.GetAsync(endpoint)) { if (Response.StatusCode == System.Net.HttpStatusCode.OK) { var data = Response.Content.ReadAsStringAsync().Result; var li = JsonConvert.DeserializeObject <List <DeviceDTO> >(data); //JsonSerializer.Deserialize<List<DeviceDTO>>(data); if (li.Count > 0) { model = li[0]; } } } } return(View(model)); }
public IActionResult UpdateDevice([FromBody] DeviceDTO device) { var deviceResult = _deviceManagementService.GetDevice(device.DeviceId); if (deviceResult is DeviceSuccessResult) { var accountResult = _accountService.GetItem(deviceResult.Item.AccountId); if (accountResult is AccountSuccessResult) { var deviceUpdateResult = _deviceManagementService.UpdateDevice(accountResult.Item, deviceResult.Item); if (deviceUpdateResult is DeviceSuccessResult) { return(Ok()); } else { return(BadRequest(deviceUpdateResult.Data)); } } else if (accountResult is AccountNotFoundResult) { return(NotFound("Specified user account was not found.")); } else { return(BadRequest(accountResult.Data)); } } else { return(BadRequest(deviceResult.Data)); } }
public DeviceDTO UpdateDevice(DeviceDTO device) { if (device == null) { throw new ArgumentNullException(nameof(device)); } var target = this.dbContext.Devices .Include(d => d.DeviceSensors) .Include(d => d.User) .Single(d => d.Id == device.Id); if (target != null) { target.IntervalInSeconds = device.IntervalInSeconds; target.IsPublic = device.IsPublic; target.IsActivated = device.IsActivated; foreach (var s in device.Sensors) { var deviceSensor = target.DeviceSensors.FirstOrDefault(ds => ds.SensorId == s.Id); deviceSensor.MinValue = s.MinValue; deviceSensor.MaxValue = s.MaxValue; deviceSensor.IsNotificationOn = s.IsNotificationOn; } this.dbContext.Devices.Update(target); this.dbContext.SaveChanges(); } return(new DeviceDTO(target)); }
public DeviceDTO CreateDevice(DeviceDTO device, Guid userId) { var newDevice = new Device() { Id = Guid.NewGuid(), DeviceName = device.DeviceName, IsPublic = device.IsPublic, IsActivated = device.IsActivated, IsDeleted = false, IntervalInSeconds = device.IntervalInSeconds, UserId = userId }; foreach (var sensor in device.Sensors) { newDevice.DeviceSensors.Add(new DeviceSensor() { DeviceId = newDevice.Id, SensorId = sensor.Id, MinValue = sensor.MinValue, MaxValue = sensor.MaxValue, IsNotificationOn = sensor.IsNotificationOn }); } this.dbContext.Devices.Add(newDevice); this.dbContext.SaveChanges(); return(new DeviceDTO(newDevice)); }
public bool GetLogin(LoginModel model) { ISignMap signMap = new Map(); IService service = new WCFService(); //Socket service = new Socket(); AccountDTO accountDTO = new AccountDTO(); string host = System.Net.Dns.GetHostName(); DeviceDTO deviceDTO = new DeviceDTO { DeviceIp = Dns.GetHostEntry(host).AddressList[0].ToString(), DeviceName = host, DeviceTime = DateTime.Now.ToLongTimeString() }; accountDTO = service.LoginService(signMap.LoginModelToLoginDTO(model), deviceDTO); if (accountDTO != null) { MyUser.SetNewUser(signMap.AccountDTOToUserModel(accountDTO)); return(true); } return(false); }
public ActionResult SearchDevice(string id) { deviceService devService = new deviceService(); DeviceDTO device = devService.GetById(id); return(Json(device)); }
public async Task <ActionResult> Create(DeviceDTO createDevice) { try { var device = new Device() { Name = createDevice.Name, PushAuth = createDevice.PushAuth, PushEndpoint = createDevice.PushEndpoint, PushP256DH = createDevice.PushP256DH, UserId = createDevice.UserId }; if (_context.Devices.Any(x => x.PushAuth == device.PushAuth)) { return(BadRequest("This device is already registered")); } _context.Devices.Add(device); await _context.SaveChangesAsync(); return(Ok(device)); }catch (Exception e) { return(BadRequest(e)); } }
public async Task <ActionResult> Update(int id, DeviceDTO updateDevice) { try { var old = await this._context.Devices.FirstOrDefaultAsync(x => x.Id == id); var updateDTO = new Device() { Name = updateDevice.Name, PushAuth = updateDevice.PushAuth, PushEndpoint = updateDevice.PushEndpoint, PushP256DH = updateDevice.PushP256DH, UserId = updateDevice.UserId }; var update = new Device(); update.BuildUpdateObj(updateDTO, old); old.UpdateModifiedFields(update); this._context.Entry(old).State = EntityState.Modified; await _context.SaveChangesAsync(); return(Ok(old)); } catch (Exception e) { return(BadRequest(e)); } }
public async Task <string> AddNewDevice(DeviceDTO device) { device.DeviceTagName = UniqueIdGenerator.GetUniqueId(); await _devicerepo.AddDevice(device); return(device.DeviceTagName); }
public void TestRegisterMultipleDevicesOnExistingAccountSucceeds() { var newDevice = new DeviceDTO { Name = "TestDevice1", MACAddress = "1234567" }; var account = _mockAccountRepository.GetItems(a => a.Name == "TestAccount1") .ToList() .FirstOrDefault(); Assert.IsNotNull(account); Assert.IsInstanceOfType(account, typeof(AccountSuccessResult)); var registrationResult = _deviceManagementService.RegisterDevice(account.Item, new DeviceDTO { Name = "TestDevice1", MACAddress = "1234567" }); Assert.IsInstanceOfType(registrationResult, typeof(DeviceRegistrationSuccessResult)); registrationResult = _deviceManagementService.RegisterDevice(account.Item, new DeviceDTO { Name = "TestDevice2", MACAddress = "12345678" }); Assert.IsInstanceOfType(registrationResult, typeof(DeviceRegistrationSuccessResult)); var devices = _deviceManagementService.GetDevices(account.Item); Assert.AreEqual(2, devices.Count); }
public async Task <ActionResult> Create(DeviceDTO model) { try { var token = User.FindFirst(claim => claim.Type == System.Security.Claims.ClaimTypes.UserData)?.Value; using (HttpClient client = new HttpClient()) { StringContent content = new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, "application/json"); string endpoint = apiBaseUrl + "/Device"; client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); client.SetBearerToken(token.Split(" ")[1]); using (var Response = await client.PostAsync(endpoint, content)) { if (Response.StatusCode == System.Net.HttpStatusCode.OK) { string data = Response.Content.ReadAsStringAsync().Result; ViewBag.RetVal = 1; //return RedirectToAction("index"); } } } } catch { ViewBag.RetVal = -1; } return(View(model)); }
public AccountDTO GetLogin(LoginDTO loginDTO, DeviceDTO deviceDTO) { if (loginDTO.Username == null) { return(null); } if (loginDTO.Password == null) { return(null); } string result = null; AccountDTO account = new AccountDTO(); LoginModel model = map.LoginDTOToLoginModel(loginDTO); using (UserRepository repository = new UserRepository()) { account = map.UserToAccountDTO(repository.GetUserByLoginPassword(model.Username, model.Password)); } if (account != null) { result = hash.ComputeHash(account.Login, account.Password); UserList.Accounts.TryAdd(result, map.AccountDTOToAccountModel(account)); account.Token = result; using (DeviceRepository repository = new DeviceRepository()) { repository.AddDeviceToUser(deviceMap.DeviceDTOToDevice(deviceDTO), UserList.Accounts[result].Id); repository.Save(); } } else { result = null; } return(account); }
public Device UpdateDevice(DeviceDTO _deviceDTO) { try { Device data = new Device { Id = _deviceDTO.Id, Imei = _deviceDTO.Imei, SimCardNumber = _deviceDTO.SimCardNumber, Enabled = _deviceDTO.Enabled, Created = _deviceDTO.Created, CreatedBy = _deviceDTO.CreatedBy }; using (var context = new DeviceManagementPortalContext()) { context.Entry(data).State = Microsoft.EntityFrameworkCore.EntityState.Modified; context.SaveChanges(); } return(data); } catch (Exception ex) { throw ex; } }
public Device( IRemoteDeviceFactory remoteDeviceFactory, IMetaPubSub metaMessenger, DeviceDTO dto) { _remoteDeviceFactory = remoteDeviceFactory; _metaMessenger = metaMessenger; PropertyChanged += Device_PropertyChanged; _metaMessenger.TrySubscribeOnServer <HideezMiddleware.IPC.Messages.DeviceConnectionStateChangedMessage>(OnDeviceConnectionStateChanged); _metaMessenger.TrySubscribeOnServer <HideezMiddleware.IPC.Messages.DeviceInitializedMessage>(OnDeviceInitialized); _metaMessenger.TrySubscribeOnServer <HideezMiddleware.IPC.Messages.DeviceFinishedMainFlowMessage>(OnDeviceFinishedMainFlow); _metaMessenger.TrySubscribeOnServer <HideezMiddleware.IPC.Messages.DeviceOperationCancelledMessage>(OnOperationCancelled); _metaMessenger.TrySubscribeOnServer <HideezMiddleware.IPC.Messages.DeviceProximityChangedMessage>(OnDeviceProximityChanged); _metaMessenger.TrySubscribeOnServer <HideezMiddleware.IPC.Messages.DeviceBatteryChangedMessage>(OnDeviceBatteryChanged); _metaMessenger.TrySubscribeOnServer <HideezMiddleware.IPC.Messages.DeviceProximityLockEnabledMessage>(OnDeviceProximityLockEnabled); _metaMessenger.TrySubscribeOnServer <HideezMiddleware.IPC.Messages.LockDeviceStorageMessage>(OnLockDeviceStorage); _metaMessenger.TrySubscribeOnServer <HideezMiddleware.IPC.Messages.LiftDeviceStorageLockMessage>(OnLiftDeviceStorageLock); _metaMessenger.Subscribe <SendPinMessage>(OnPinReceived); _metaMessenger.Subscribe <SessionSwitchMessage>(OnSessionSwitch); RegisterDependencies(); LoadFrom(dto); }
public DataToSend Processing(DataToSend inputData) { ISocketService socketService = new SocketService(); DataToSend outputData = new DataToSend(); LoginMap loginMap = new LoginMap(); DeviceMap deviceMap = new DeviceMap(); AccountMap accountMap = new AccountMap(); RegistrationMap registrationMap = new RegistrationMap(); if (inputData.Action == MessageSocketData.SocketObj.Action.Login) { Console.WriteLine("Login..."); LoginDTO loginDTO = loginMap.MapTo(inputData.FirstObject as LoginSocket); DeviceDTO deviceDTO = deviceMap.MapTo(inputData.SecondObject as DeviceSocket); AccountDTO accountDTO = new AccountDTO(); accountDTO = socketService.CheckUser(loginDTO, deviceDTO); outputData.FirstObject = accountMap.MapFrom(accountDTO); } if (inputData.Action == MessageSocketData.SocketObj.Action.Registration) { Console.WriteLine("Registration..."); RegistrationDTO registrationDTO = registrationMap.MapTo(inputData.FirstObject as RegistrationSocket); bool answer = socketService.GetRegistration(registrationDTO); outputData.Boolean = answer; } return(outputData); }
public IActionResult RegisterDevice([FromRoute] int accountId, [FromBody] DeviceDTO device) { var accountResult = _accountService.GetItem(accountId); if (accountResult is AccountSuccessResult) { var deviceRegistrationResult = _deviceManagementService.RegisterDevice(accountResult.Item, device); if (deviceRegistrationResult is DeviceRegistrationSuccessResult) { return(Created(Url.RouteUrl(deviceRegistrationResult.Item.DeviceId), deviceRegistrationResult.Item.DeviceId)); } else { return(BadRequest(deviceRegistrationResult.Data)); } } else if (accountResult is AccountNotFoundResult) { //Failed to locate the account. return(NotFound("Specified user account was not found.")); } else { return(BadRequest(accountResult.Data)); } }
private void InitializeProperties(DeviceDTO initialValues) { this.IsConnected = initialValues.Present == 1; this.InitializeMetaInformation(initialValues); this.InitializeSwitchStuff(initialValues); this.IsAThermostat = (initialValues.FunctionBitmask & Device.BIT_NO6) != 0; this.InitializeTemperatureStuff(initialValues); }
/// <summary> /// method which converts userdevice entity to dto by using mapper /// </summary> /// <param name="userdeviceentity">takes user device entity as input</param> /// <returns>returns user device dto</returns> public UserDeviceDTO UserDeviceEntityDTOMapper(UserDeviceEntity userdeviceentity) { //convertig entity to data transfer object using mapper UserDeviceDTO userdevicedto = DataProvider.ResponseObjectMapper <UserDeviceDTO, UserDeviceEntity>(userdeviceentity); DeviceDTO devicedto = DataProvider.ResponseObjectMapper <DeviceDTO, UserDeviceEntity>(userdeviceentity); userdevicedto.device = devicedto; return(userdevicedto); }
private void InitializeTemperatureStuff(DeviceDTO initialValues) { this.CanSenseTemperature = (initialValues.FunctionBitmask & Device.BIT_NO8) != 0; if (this.CanSenseTemperature) { this.TemperatureFeature = new TemperatureFeature(initialValues.Temperature); } }
public static IDevice Map(DeviceDTO device) { return(new ExampleDevice() { Id = device.Id, Name = device.Name, Enabled = device.Enabled }); }
public AccountDTO CheckUser(LoginDTO login, DeviceDTO deviceDTO) { ILogin loginlogic = new SignLogic(); AccountDTO accountDTO = new AccountDTO(); accountDTO = loginlogic.GetLogin(login, deviceDTO); return(accountDTO); }
private void InitializeSwitchStuff(DeviceDTO initialValues) { this.IsASwitch = (initialValues.FunctionBitmask & Device.BIT_NO9) != 0; if (this.IsASwitch) { this.SwitchFeature = new SwitchFeature(initialValues.Switch, this._httpService, this._ain); } }
public List <DeviceDTO> GetAllDevices() { ICollection <Device> devices = devRep.GetAll(); List <DeviceDTO> res = new List <DeviceDTO>(); foreach (Device d in devices) { res.Add(DeviceDTO.Convert(d)); } return(res); }
public IHttpActionResult PostDevice([FromBody] DeviceDTO deviceDTO) { deviceDTO.DateCreated = DateTime.UtcNow; deviceDTO.DeviceCode = Guid.NewGuid().ToString(); Device device = Mapper.Map <DeviceDTO, Device>(deviceDTO); deviceService.AddDevice(device); deviceService.SaveDevice(); deviceDTO.DeviceID = device.DeviceID; return(CreatedAtRoute("DefaultApi", new { id = device.DeviceID }, deviceDTO)); }
public Device DeviceDTOToDevice(DeviceDTO deviceDTO) { Device device = new Device { DeviceId = deviceDTO.DeviceId, DeviceIp = deviceDTO.DeviceIp, DeviceName = deviceDTO.DeviceName, DeviceTime = deviceDTO.DeviceTime }; return(device); }
public DeviceDTO DeviceToDeviceDTO(Device device) { DeviceDTO deviceDTO = new DeviceDTO { DeviceId = device.DeviceId, DeviceIp = device.DeviceIp, DeviceName = device.DeviceName, DeviceTime = device.DeviceTime }; return(deviceDTO); }
public IActionResult Post([FromBody] DeviceDTO _deviceDTO) { try { var data = _serviceDevice.CreateDevice(_deviceDTO); return(Ok(data)); } catch (Exception ex) { return(BadRequest(ex)); } }
public async Task <IActionResult> Post([FromBody] DeviceDTO body) { Device device = new Device(); device.Type = body.Type; device.Name = body.Name; device.Street = data.Streets.FirstOrDefault(x => x.Name == body.Street); data.Devices.Add(device); await data.SaveChangesAsync(); return(Ok()); }
/// <summary> /// method which converts userdevice dto to entity by using mapper, first maps devicedto with userdeviceentity /// </summary> /// <param name="userdevicedto">takes user device dto as input</param> /// <returns>returns user backend entity</returns> public UserDeviceEntity UserDeviceDTOEntityMapper(UserDeviceDTO userdevicedto) { //converting input device data transfer object(dto) list to userdevice entity list by using property mapper DeviceDTO devicedto = userdevicedto.device; UserDeviceEntity userdeviceentity = DataProvider.ResponseObjectMapper <UserDeviceEntity, DeviceDTO>(devicedto); //adding missing properties like userID, partitionkey and Rowkey to entity userdeviceentity.DeviceID = string.Concat(userdevicedto.UserID, CoreConstants.AzureTables.UnderScore, userdevicedto.device.DeviceName); userdeviceentity.UserID = userdevicedto.UserID; userdeviceentity.PartitionKey = string.Concat(CoreConstants.AzureTables.UserDevicePK, userdeviceentity.UserID); userdeviceentity.RowKey = userdeviceentity.DeviceID; return(userdeviceentity); }
void AddDevice(DeviceDTO dto) { if (!_devices.ContainsKey(dto.Id)) { var device = new Device(_remoteDeviceFactory, _metaMessenger, dto); device.PropertyChanged += Device_PropertyChanged; if (_devices.TryAdd(device.Id, device)) { DevicesCollectionChanged?.Invoke(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, device)); } } }