public Entity.ActionStatus Verify(Entity.VerifyRuleRequest request) { Entity.ActionStatus actionStatus = new Entity.ActionStatus(true); IOT.DataResponse <IOT.VerifyRuleResult> ruleVerifyResult = _iotConnectClient.Rule.RuleVerify(new IOT.VerifyRuleModel() { deviceTemplateGuid = request.deviceTemplateGuid, expression = request.expression }).Result; if (!ruleVerifyResult.data.isValid) { actionStatus.Success = false; actionStatus.Message = ruleVerifyResult.message; } else { actionStatus.Data = new Entity.VerifyRuleResult() { isValid = ruleVerifyResult.data.isValid, attributes = ruleVerifyResult.data.attributes, tags = ruleVerifyResult.data.tags }; } return(actionStatus); }
public Entity.SearchResult <List <Entity.AllRuleResponse> > List(Entity.SearchRequest request) { Entity.SearchResult <List <Entity.AllRuleResponse> > result = new SearchResult <List <AllRuleResponse> >(); try { IOT.DataResponse <List <IOT.AllRuleResult> > rules = _iotConnectClient.Rule.All(new IoTConnect.Model.PagingModel() { PageNo = 1, PageSize = 1000 }).Result; if (rules.status && rules.data != null) { result = new Entity.SearchResult <List <Entity.AllRuleResponse> >() { Items = rules.data.Select(p => Mapper.Configuration.Mapper.Map <Entity.AllRuleResponse>(p)).ToList(), Count = rules.data.Count }; } } catch (Exception ex) { _logger.ErrorLog(ex, this.GetType().Name, MethodBase.GetCurrentMethod().Name); return(new Entity.SearchResult <List <Entity.AllRuleResponse> >()); } return(result); }
public Entity.ActionStatus AcquireDevice(string deviceUniqueId) { Entity.ActionStatus actionStatus = new Entity.ActionStatus(true); try { IOT.DataResponse <IOT.AcquireDeviceResult> acquireResult = _iotConnectClient.Device.AcquireDevice(deviceUniqueId, new IOT.AcquireDeviceModel()).Result; if (acquireResult != null && acquireResult.status) { var dbDevice = _generatorRepository.FindBy(x => x.UniqueId.Equals(deviceUniqueId)).FirstOrDefault(); dbDevice.IsProvisioned = true; dbDevice.UpdatedDate = DateTime.Now; dbDevice.UpdatedBy = SolutionConfiguration.CurrentUserId; return(_generatorRepository.Update(dbDevice)); } else { return(new ActionStatus(false, acquireResult.message)); } } catch (Exception ex) { _logger.InfoLog(Constants.ACTION_EXCEPTION, "DeviceService.AcquireDevice " + ex); actionStatus.Success = false; actionStatus.Message = ex.Message; } return(actionStatus); }
public Entity.ActionStatus AcquireDevice(string uniqueid) { Entity.ActionStatus actionStatus = new Entity.ActionStatus(true); try { IOT.DataResponse <IOT.AcquireDeviceResult> acquireResult = _iotConnectClient.Device.AcquireDevice(uniqueid, null).Result; if (acquireResult != null && acquireResult.status) { var dbDevice = _deviceRepository.FindBy(x => x.Guid.Equals(uniqueid)).FirstOrDefault(); dbDevice.IsProvisioned = true; dbDevice.UpdatedDate = DateTime.Now; dbDevice.UpdatedBy = SolutionConfiguration.CurrentUserId; return(_deviceRepository.Update(dbDevice)); } else { return(new ActionStatus(false, acquireResult.message)); } } catch (Exception ex) { _logger.ErrorLog(ex, "DeviceService.AcquireDevice " + ex); actionStatus.Success = false; actionStatus.Message = ex.Message; } return(actionStatus); }
public Entity.SearchResult <List <Entity.AllRuleResponse> > List(Entity.SearchRequest request) { Entity.SearchResult <List <Entity.AllRuleResponse> > result = new SearchResult <List <AllRuleResponse> >(); try { IOT.DataResponse <List <IOT.AllRuleResult> > rules = _iotConnectClient.Rule.All(new IoTConnect.Model.PagingModel() { PageNo = 1, PageSize = 1000 }).Result; if (rules.status && rules.data != null) { result = new Entity.SearchResult <List <Entity.AllRuleResponse> >() { Items = rules.data.Select(p => Mapper.Configuration.Mapper.Map <Entity.AllRuleResponse>(p)).ToList(), Count = rules.data.Count }; } } catch (Exception ex) { _logger.Error(Constants.ACTION_EXCEPTION, $"NotificationsService.List, Error: {ex.Message}"); return(new Entity.SearchResult <List <Entity.AllRuleResponse> >()); } return(result); }
public Entity.ActionStatus Delete(Guid id) { Entity.ActionStatus actionStatus = new Entity.ActionStatus(true); try { IOT.DataResponse <IOT.SingleRuleResult> singleRule = _iotConnectClient.Rule.Single(id.ToString()).Result; if (singleRule.data != null && singleRule.status) { var deleteRule = _iotConnectClient.Rule.Delete(id.ToString()).Result; if (deleteRule.status) { actionStatus.Success = deleteRule.status; actionStatus.Message = deleteRule.message; } else { throw new NotFoundCustomException(deleteRule.errorMessages[0].Message); } } else { throw new NotFoundCustomException(singleRule.errorMessages[0].Message); } } catch (Exception ex) { _logger.ErrorLog(ex, this.GetType().Name, MethodBase.GetCurrentMethod().Name); return(new Entity.ActionStatus { Success = false, Message = ex.Message }); } return(actionStatus); }
public Entity.ActionStatus Delete(Guid id) { Entity.ActionStatus actionStatus = new Entity.ActionStatus(true); try { IOT.DataResponse <IOT.SingleRuleResult> singleRule = _iotConnectClient.Rule.Single(id.ToString()).Result; if (singleRule.data != null && singleRule.status) { var deleteRule = _iotConnectClient.Rule.Delete(id.ToString()).Result; if (deleteRule.status) { actionStatus.Success = deleteRule.status; actionStatus.Message = deleteRule.message; } else { throw new NotFoundCustomException(deleteRule.errorMessages[0].Message); } } else { throw new NotFoundCustomException(singleRule.errorMessages[0].Message); } } catch (Exception ex) { _logger.Error(Constants.ACTION_EXCEPTION, "Notification.Delete " + ex); return(new Entity.ActionStatus { Success = false, Message = ex.Message }); } return(actionStatus); }
public Entity.ActionStatus UpdateStatus(Guid id, bool status) { Entity.ActionStatus actionStatus = new Entity.ActionStatus(true); try { IOT.DataResponse <IOT.SingleRuleResult> singleRule = _iotConnectClient.Rule.Single(id.ToString()).Result; if (singleRule == null || singleRule.data == null) { throw new NotFoundCustomException($"{CommonException.Name.NoRecordsFound} : Notification"); } else { var iotRuleDetail = _iotConnectClient.Rule.UpdateRuleStatus(id.ToString(), status).Result; actionStatus.Success = iotRuleDetail.status; actionStatus.Message = iotRuleDetail.message; } } catch (Exception ex) { _logger.ErrorLog(ex, this.GetType().Name, MethodBase.GetCurrentMethod().Name); actionStatus.Success = false; actionStatus.Message = ex.Message; } return(actionStatus); }
public Entity.BaseResponse <List <Entity.DeviceTelemetryDataResult> > GetTelemetryData(Guid deviceId) { Entity.BaseResponse <List <Entity.DeviceTelemetryDataResult> > result = new Entity.BaseResponse <List <Entity.DeviceTelemetryDataResult> >(true); try { IOT.DataResponse <List <IOT.DeviceTelemetryData> > deviceCounterResult = _iotConnectClient.Device.GetTelemetryData(deviceId.ToString()).Result; if (deviceCounterResult != null && deviceCounterResult.status) { result.Data = deviceCounterResult.data.Select(d => Mapper.Configuration.Mapper.Map <Entity.DeviceTelemetryDataResult>(d)).ToList(); Entity.DeviceDetailModel dbDevice = _deviceRepository.Get(deviceId); if (dbDevice != null && dbDevice.DeviceAttributes.Count > 0 && result.Data != null) { result.Data = (from r in result.Data join l in dbDevice.DeviceAttributes on r.templateAttributeGuid.ToUpper() equals l.AttrGuid.ToString().ToUpper() select new DeviceTelemetryDataResult { aggregateType = r.aggregateType, aggregateTypeValues = r.aggregateTypeValues, attributeDisplayName = string.IsNullOrEmpty(l.DispName) ? r.attributeName : l.DispName, attributeName = r.attributeName, attributeValue = r.attributeValue, deviceUpdatedDate = r.deviceUpdatedDate, templateAttributeGuid = r.templateAttributeGuid, DataType = r.DataType, notificationCount = r.notificationCount }).ToList(); } else { result.Data = (from r in result.Data select new DeviceTelemetryDataResult { aggregateType = r.aggregateType, aggregateTypeValues = r.aggregateTypeValues, attributeDisplayName = r.attributeName, attributeName = r.attributeName, attributeValue = r.attributeValue, deviceUpdatedDate = r.deviceUpdatedDate, templateAttributeGuid = r.templateAttributeGuid, DataType = r.DataType, notificationCount = r.notificationCount }).ToList(); } } else { result.Data = null; result.IsSuccess = false; result.Message = new UtilityHelper().IOTResultMessage(deviceCounterResult.errorMessages); } } catch (Exception ex) { _logger.ErrorLog(ex, this.GetType().Name, MethodBase.GetCurrentMethod().Name); return(new Entity.BaseResponse <List <Entity.DeviceTelemetryDataResult> >(false, ex.Message)); } return(result); }
public Entity.ActionStatus Login(Entity.LoginRequest request) { Entity.ActionStatus result = new Entity.ActionStatus(true); try { IOT.DataResponse <IOT.LoginResult> loginResult = _iotConnectClient.Login.Login(new IOT.LoginModel() { UserName = request.Username, Password = request.Password }).Result; result.Success = loginResult.status; if (loginResult != null && loginResult.status) { JwtSecurityTokenHandler hand = new JwtSecurityTokenHandler(); var tokenS = hand.ReadJwtToken(loginResult.data.access_token); var jsonValue = tokenS.Claims?.SingleOrDefault(p => p.Type == "user")?.Value; Entity.UserDetail userDetail = Newtonsoft.Json.JsonConvert.DeserializeObject <Entity.UserDetail>(jsonValue); var user = _userRepository.GetByUniqueId(r => r.Guid == Guid.Parse(userDetail.Id)); if (user == null) { return(new Entity.ActionStatus() { Success = false, Message = "User does not exist in Solution" }); } userDetail.FullName = user.FirstName.ToString() + " " + user.LastName.ToString(); result.Data = new Entity.LoginResponse { status = loginResult.data.status, data = loginResult.data.data, message = loginResult.message, token_type = loginResult.data.token_type, access_token = loginResult.data.access_token, refresh_token = loginResult.data.refresh_token, expires_in = loginResult.data.expires_in, UserDetail = userDetail }; } else { result.Message = loginResult.message; } } catch (Exception ex) { _logger.ErrorLog(ex, $"UserManager.Login {ex.Message}"); return(new Entity.ActionStatus(false, ex.Message)); } return(result); }
public Entity.BaseResponse <Entity.DeviceCounterByEntityResult> GetDeviceCountersByEntity(Guid entityGuid) { Entity.BaseResponse <Entity.DeviceCounterByEntityResult> result = new Entity.BaseResponse <Entity.DeviceCounterByEntityResult>(true); try { IOT.DataResponse <List <IOT.DeviceCounterByEntityResult> > deviceCounterResult = _iotConnectClient.Device.GetDeviceCounterByEntity(entityGuid.ToString()).Result; if (deviceCounterResult != null && deviceCounterResult.status) { result.Data = Mapper.Configuration.Mapper.Map <Entity.DeviceCounterByEntityResult>(deviceCounterResult.data.FirstOrDefault()); var device = _iotConnectClient.Device.AllDevice(new IoTConnect.Model.AllDeviceModel { entityGuid = entityGuid.ToString(), companyGuid = SolutionConfiguration.CompanyId.ToString() }).Result; if (device != null && device.Data != null && device.Data.Any()) { var resultIoT = (from r in device.Data join l in _deviceRepository.GetAll().Where(t => t.CompanyGuid.Equals(SolutionConfiguration.CompanyId) && !t.IsDeleted).ToList() on r.Guid.ToUpper() equals l.Guid.ToString().ToUpper() join e in _entityRepository.GetAll().Where(t => t.CompanyGuid.Equals(SolutionConfiguration.CompanyId) && !t.IsDeleted && t.ParentEntityGuid.HasValue && t.ParentEntityGuid.Value == entityGuid).ToList() on l.EntityGuid.ToString().ToUpper() equals e.Guid.ToString().ToUpper() select new { r.IsActive, r.IsConnected, r.Guid }).ToList(); result.Data.counters.connected = resultIoT.Where(t => t.IsConnected).Count(); result.Data.counters.disConnected = resultIoT.Where(t => !t.IsConnected).Count(); result.Data.counters.active = resultIoT.Where(t => t.IsActive).Count(); result.Data.counters.inActive = resultIoT.Where(t => !t.IsActive).Count(); result.Data.counters.total = resultIoT.Count(); } } else { result.Data = null; result.IsSuccess = false; result.Message = new UtilityHelper().IOTResultMessage(deviceCounterResult.errorMessages); } } catch (Exception ex) { _logger.ErrorLog(ex, this.GetType().Name, MethodBase.GetCurrentMethod().Name); return(new Entity.BaseResponse <Entity.DeviceCounterByEntityResult>(false, ex.Message)); } return(result); }
public Entity.SingleRuleResponse Get(Guid id) { Entity.SingleRuleResponse result = null; try { IOT.DataResponse <IOT.SingleRuleResult> response = _iotConnectClient.Rule.Single(Convert.ToString(id)).Result; if (response != null && response.data != null) { result = Mapper.Configuration.Mapper.Map <IoTConnect.Model.SingleRuleResult, Entity.SingleRuleResponse>(response.data); } } catch (Exception ex) { _logger.Error(Constants.ACTION_EXCEPTION, "NotificationService.Get " + ex); return(result); } return(result); }
public Entity.BaseResponse <Entity.DeviceCounterResult> GetDeviceCounters() { Entity.BaseResponse <Entity.DeviceCounterResult> result = new Entity.BaseResponse <Entity.DeviceCounterResult>(true); try { IOT.DataResponse <List <IOT.DeviceCounterResult> > deviceCounterResult = _iotConnectClient.Device.GetDeviceCounters("").Result; if (deviceCounterResult != null && deviceCounterResult.status) { result.Data = Mapper.Configuration.Mapper.Map <Entity.DeviceCounterResult>(deviceCounterResult.data.FirstOrDefault()); } } catch (Exception ex) { _logger.ErrorLog(ex, this.GetType().Name, MethodBase.GetCurrentMethod().Name); return(new Entity.BaseResponse <Entity.DeviceCounterResult>(false, ex.Message)); } return(result); }
public Entity.SingleRuleResponse Get(Guid id) { Entity.SingleRuleResponse result = null; try { IOT.DataResponse <IOT.SingleRuleResult> response = _iotConnectClient.Rule.Single(Convert.ToString(id)).Result; if (response != null && response.data != null) { result = Mapper.Configuration.Mapper.Map <IoTConnect.Model.SingleRuleResult, Entity.SingleRuleResponse>(response.data); } } catch (Exception ex) { _logger.ErrorLog(ex, this.GetType().Name, MethodBase.GetCurrentMethod().Name); return(result); } return(result); }
public Entity.BaseResponse <List <Entity.DeviceTelemetryDataResult> > GetTelemetryData(Guid deviceId) { Entity.BaseResponse <List <Entity.DeviceTelemetryDataResult> > result = new Entity.BaseResponse <List <Entity.DeviceTelemetryDataResult> >(true); try { IOT.DataResponse <List <IOT.DeviceTelemetryData> > deviceCounterResult = _iotConnectClient.Device.GetTelemetryData(deviceId.ToString()).Result; if (deviceCounterResult != null && deviceCounterResult.status) { result.Data = deviceCounterResult.data.Select(d => Mapper.Configuration.Mapper.Map <Entity.DeviceTelemetryDataResult>(d)).ToList(); } } catch (Exception ex) { _logger.ErrorLog(ex, this.GetType().Name, MethodBase.GetCurrentMethod().Name); return(new Entity.BaseResponse <List <Entity.DeviceTelemetryDataResult> >(false, ex.Message)); } return(result); }
public Entity.BaseResponse <Entity.DeviceCounterResult> GetDeviceCountersByEntity(Guid entityGuid) { Entity.BaseResponse <Entity.DeviceCounterResult> result = new Entity.BaseResponse <Entity.DeviceCounterResult>(true); try { IOT.DataResponse <List <IOT.DeviceCounterResult> > deviceCounterResult = _iotConnectClient.Device.GetDeviceCounters("").Result; var devicelist = _iotConnectClient.Device.AllDevice(new IoTConnect.Model.AllDeviceModel { }).Result; if (deviceCounterResult != null && deviceCounterResult.status) { result.Data = Mapper.Configuration.Mapper.Map <Entity.DeviceCounterResult>(deviceCounterResult.data.FirstOrDefault()); var device = _deviceRepository.List(new Entity.SearchRequest { CompanyId = Convert.ToString(SolutionConfiguration.CompanyId), ParentEntityId = entityGuid, PageNumber = -1, PageSize = -1, OrderBy = "", SearchText = "" }); if (device != null && device.Items.Count() > 0) { var resultIoT = (from r in device.Items join l in devicelist.Data on r.Guid.ToString().ToUpper() equals l.Guid.ToString().ToUpper() select new { l.IsActive, l.IsConnected, l.Guid }).ToList(); result.Data.connected = resultIoT.Where(t => t.IsConnected).Count(); result.Data.disConnected = resultIoT.Where(t => !t.IsConnected).Count(); result.Data.total = resultIoT.Count(); } } else { result.Data = null; result.IsSuccess = false; result.Message = new UtilityHelper().IOTResultMessage(deviceCounterResult.errorMessages); } } catch (Exception ex) { _logger.ErrorLog(ex, this.GetType().Name, MethodBase.GetCurrentMethod().Name); return(new Entity.BaseResponse <Entity.DeviceCounterResult>(false, ex.Message)); } return(result); }
public Entity.BaseResponse <Entity.DeviceCounterResult> GetDeviceCounters() { Entity.BaseResponse <Entity.DeviceCounterResult> result = new Entity.BaseResponse <Entity.DeviceCounterResult>(true); try { IOT.DataResponse <List <IOT.DeviceCounterResult> > deviceCounterResult = _iotConnectClient.Device.GetDeviceCounters("").Result; if (deviceCounterResult != null && deviceCounterResult.status) { result.Data = Mapper.Configuration.Mapper.Map <Entity.DeviceCounterResult>(deviceCounterResult.data.FirstOrDefault()); var device = _iotConnectClient.Device.AllDevice(new IoTConnect.Model.AllDeviceModel { }).Result; if (device != null && device.Data != null && device.Data.Any()) { var resultIoT = (from r in device.Data join l in _deviceRepository.GetAll().Where(t => t.CompanyGuid.Equals(SolutionConfiguration.CompanyId) && !t.IsDeleted).ToList() on r.Guid.ToUpper() equals l.Guid.ToString().ToUpper() select new { r.IsActive, r.IsConnected, r.Guid }).ToList(); result.Data.connected = resultIoT.Where(t => t.IsConnected).Count(); result.Data.disConnected = resultIoT.Where(t => !t.IsConnected).Count(); result.Data.active = resultIoT.Where(t => t.IsActive).Count(); result.Data.inActive = resultIoT.Where(t => !t.IsActive).Count(); result.Data.total = resultIoT.Count(); } } } catch (Exception ex) { _logger.ErrorLog(ex, this.GetType().Name, MethodBase.GetCurrentMethod().Name); return(new Entity.BaseResponse <Entity.DeviceCounterResult>(false, ex.Message)); } return(result); }
public Entity.BaseResponse <Entity.DeviceConnectionStatusResult> GetConnectionStatus(string uniqueId) { Entity.BaseResponse <Entity.DeviceConnectionStatusResult> result = new Entity.BaseResponse <Entity.DeviceConnectionStatusResult>(true); try { IOT.DataResponse <List <IOT.DeviceConnectionStatus> > deviceConnectionStatus = _iotConnectClient.Device.GetConnectionStatus(uniqueId).Result; if (deviceConnectionStatus != null && deviceConnectionStatus.status && deviceConnectionStatus.data != null) { result.Data = Mapper.Configuration.Mapper.Map <Entity.DeviceConnectionStatusResult>(deviceConnectionStatus.data.FirstOrDefault()); } else { result.Data = null; result.IsSuccess = false; result.Message = new UtilityHelper().IOTResultMessage(deviceConnectionStatus.errorMessages); } } catch (Exception ex) { _logger.ErrorLog(ex, this.GetType().Name, MethodBase.GetCurrentMethod().Name); return(new Entity.BaseResponse <Entity.DeviceConnectionStatusResult>(false, ex.Message)); } return(result); }
public Entity.BaseResponse <Entity.DeviceCounterByEntityResult> GetDeviceCountersByEntity(Guid entityGuid) { Entity.BaseResponse <Entity.DeviceCounterByEntityResult> result = new Entity.BaseResponse <Entity.DeviceCounterByEntityResult>(true); try { IOT.DataResponse <List <IOT.DeviceCounterByEntityResult> > deviceCounterResult = _iotConnectClient.Device.GetDeviceCounterByEntity(entityGuid.ToString()).Result; if (deviceCounterResult != null && deviceCounterResult.status) { result.Data = Mapper.Configuration.Mapper.Map <Entity.DeviceCounterByEntityResult>(deviceCounterResult.data.FirstOrDefault()); } else { result.Data = null; result.IsSuccess = false; result.Message = new UtilityHelper().IOTResultMessage(deviceCounterResult.errorMessages); } } catch (Exception ex) { _logger.ErrorLog(ex, this.GetType().Name, MethodBase.GetCurrentMethod().Name); return(new Entity.BaseResponse <Entity.DeviceCounterByEntityResult>(false, ex.Message)); } return(result); }
public Entity.ActionStatus Manage(Entity.NotificationAddRequest request) { Entity.ActionStatus actionStatus = new Entity.ActionStatus(true); var _list = new List <string>(); try { if (request.Guid == null || request.Guid == Guid.Empty) { var addRuleResult = _iotConnectClient.Rule.Add(Mapper.Configuration.Mapper.Map <IOT.AddRuleModel>(request)).Result; if (addRuleResult != null && !addRuleResult.status) { _logger.ErrorLog(new Exception($"Notification is not added in iotconnect, Error: {addRuleResult.message}") , this.GetType().Name, MethodBase.GetCurrentMethod().Name); actionStatus.Success = false; actionStatus.Message = new UtilityHelper().IOTResultMessage(addRuleResult.errorMessages); } else { if (!string.IsNullOrEmpty(addRuleResult.data.ruleGuid)) { actionStatus.Data = Get(Guid.Parse(addRuleResult.data.ruleGuid.ToUpper())); } } } else { IOT.DataResponse <IOT.SingleRuleResult> singleRule = _iotConnectClient.Rule.Single(request.Guid.ToString()).Result; if (singleRule.data == null) { _logger.ErrorLog(new Exception($"Notification is not added in iotconnect, Error: {singleRule.message}") , this.GetType().Name, MethodBase.GetCurrentMethod().Name); actionStatus.Success = false; actionStatus.Message = singleRule.errorMessages[0].Message; } else { request.IsActive = singleRule.data.isActive; var updateRuleResult = _iotConnectClient.Rule.Update(request.Guid.ToString(), Mapper.Configuration.Mapper.Map <IOT.UpdateRuleModel>(request)).Result; if (updateRuleResult != null && !updateRuleResult.status) { _logger.ErrorLog(new Exception($"Notification is not updated in iotconnect, Error: {updateRuleResult.message}") , this.GetType().Name, MethodBase.GetCurrentMethod().Name); actionStatus.Success = false; actionStatus.Message = new UtilityHelper().IOTResultMessage(updateRuleResult.errorMessages); } else { actionStatus.Data = Get(request.Guid.Value); } } } } catch (Exception ex) { _logger.ErrorLog(ex, this.GetType().Name, MethodBase.GetCurrentMethod().Name); actionStatus.Success = false; actionStatus.Message = ex.Message; } return(actionStatus); }
public Entity.BaseResponse <bool> ProvisionKit(Entity.ProvisionKitRequest request) { Entity.BaseResponse <bool> result = new Entity.BaseResponse <bool>(true); try { var repoResult = _deviceRepository.ProvisionKit(request); if (repoResult != null && repoResult.Data != null && repoResult.Data.Any()) { Entity.HardwareKit hardwareKit = repoResult.Data.FirstOrDefault(); string templateGuid = _lookupService.GetIotTemplateGuidByName(hardwareKit.KitTypeName); IOT.AddDeviceModel iotDeviceDetail = new IOT.AddDeviceModel() { DisplayName = hardwareKit.Name, entityGuid = request.WingGuid.ToString(), uniqueId = hardwareKit.UniqueId, deviceTemplateGuid = templateGuid, note = hardwareKit.Note, properties = new List <IOT.AddProperties>() }; var addDeviceResult = _iotConnectClient.Device.Add(iotDeviceDetail).Result; if (addDeviceResult != null && addDeviceResult.status && addDeviceResult.data != null) { IOT.DataResponse <IOT.AcquireDeviceResult> acquireResult = _iotConnectClient.Device.AcquireDevice(hardwareKit.UniqueId, new IOT.AcquireDeviceModel()).Result; Model.Elevator dbDevice = new Model.Elevator() { Guid = Guid.Parse(addDeviceResult.data.newid.ToUpper()), CompanyGuid = SolutionConfiguration.CompanyId, EntityGuid = request.WingGuid, TemplateGuid = Guid.Parse(templateGuid), UniqueId = hardwareKit.UniqueId, Name = hardwareKit.Name, Note = hardwareKit.Note, Description = request.Description, Specification = request.Specification, IsProvisioned = acquireResult.status, IsActive = true, IsDeleted = false, CreatedDate = DateTime.UtcNow, CreatedBy = SolutionConfiguration.CurrentUserId }; if (request.ImageFile != null) { dbDevice.Image = SaveElevatorImage(dbDevice.Guid, request.ImageFile); } Entity.ActionStatus actionStatus = _deviceRepository.Manage(dbDevice); if (!actionStatus.Success) { _logger.ErrorLog(new Exception($"Device is not added in solution database, Error: {actionStatus.Message}"), this.GetType().Name, MethodBase.GetCurrentMethod().Name); var deleteEntityResult = _iotConnectClient.Device.Delete(dbDevice.Guid.ToString()).Result; if (deleteEntityResult != null && deleteEntityResult.status) { _logger.ErrorLog(new Exception($"Device is not deleted from iotconnect, Error: {actionStatus.Message}"), this.GetType().Name, MethodBase.GetCurrentMethod().Name); actionStatus.Success = false; actionStatus.Message = "Something Went Wrong!"; } } var dbhardwareKit = _hardwareKitRepository.GetByUniqueId(t => t.KitCode == request.KitCode); if (dbhardwareKit != null) { dbhardwareKit.CompanyGuid = SolutionConfiguration.CompanyId; _hardwareKitRepository.Update(dbhardwareKit); } } else { _logger.ErrorLog(new Exception($"Device is not deleted from iotconnect, Error: {addDeviceResult.message}"), this.GetType().Name, MethodBase.GetCurrentMethod().Name); result.IsSuccess = false; result.Message = "Something Went Wrong!"; } } else { return(new Entity.BaseResponse <bool>(false, repoResult.Message)); } } catch (Exception ex) { _logger.ErrorLog(ex, $"Device.GetDeviceStatus, Error: {ex.Message}"); return(null); } return(result); }
public Entity.BaseResponse <bool> ProvisionKit(Entity.Device request) { Entity.BaseResponse <bool> result = new Entity.BaseResponse <bool>(true); try { var repoResult = _deviceRepository.ProvisionKit(new ProvisionKitRequest { DeviceGuid = new Guid(), KitCode = request.KitCode, UniqueId = request.UniqueId }); if (repoResult != null && repoResult.Data != null && repoResult.Data.Any()) { Entity.HardwareKit device = repoResult.Data.OrderBy(d => d.KitCode == request.KitCode && d.UniqueId == request.UniqueId).FirstOrDefault(); IOT.AddDeviceModel iotDeviceDetail = new IOT.AddDeviceModel() { DisplayName = device.Name, //entityGuid = request.DeviceGuid.ToString(), uniqueId = device.UniqueId, deviceTemplateGuid = device.TemplateGuid.ToString(), note = device.Note, tag = device.Tag, properties = new List <IOT.AddProperties>() }; var addDeviceResult = _iotConnectClient.Device.Add(iotDeviceDetail).Result; if (addDeviceResult != null && addDeviceResult.status && addDeviceResult.data != null) { Guid newDeviceId = Guid.Parse(addDeviceResult.data.newid.ToUpper()); IOT.DataResponse <IOT.AcquireDeviceResult> acquireResult = _iotConnectClient.Device.AcquireDevice(request.UniqueId, new IOT.AcquireDeviceModel()).Result; Entity.ActionStatus actionStatus = _deviceRepository.Manage(new Model.Device() { Guid = newDeviceId, CompanyGuid = SolutionConfiguration.CompanyId, Description = request.Description, EntityGuid = new Guid(request.EntityGuid.ToString()), Specification = request.Specification, TemplateGuid = device.TemplateGuid.Value, ParentDeviceGuid = null, TypeGuid = request.TypeGuid, UniqueId = request.UniqueId, Name = request.Name, Note = request.Note, Tag = request.Tag, IsProvisioned = acquireResult.status, IsActive = request.IsActive, IsDeleted = false, CreatedDate = DateTime.UtcNow, CreatedBy = SolutionConfiguration.CurrentUserId }); if (!actionStatus.Success) { _logger.ErrorLog(new Exception($"Device is not added in solution database, Error: {actionStatus.Message}"), this.GetType().Name, MethodBase.GetCurrentMethod().Name); var deleteEntityResult = _iotConnectClient.Device.Delete(newDeviceId.ToString()).Result; if (deleteEntityResult != null && deleteEntityResult.status) { _logger.ErrorLog(new Exception($"Device is not deleted from iotconnect"), this.GetType().Name, MethodBase.GetCurrentMethod().Name); actionStatus.Success = false; actionStatus.Message = new UtilityHelper().IOTResultMessage(deleteEntityResult.errorMessages); } } else { //Update companyid in hardware kit var hardwareKit = _hardwareKitRepository.GetByUniqueId(t => t.KitCode == request.KitCode && t.UniqueId == request.UniqueId); if (hardwareKit != null) { hardwareKit.CompanyGuid = SolutionConfiguration.CompanyId; _hardwareKitRepository.Update(hardwareKit); } result.IsSuccess = true; } } else { _logger.ErrorLog(new Exception($"Kit is not added in iotconnect, Error: {addDeviceResult.message}"), this.GetType().Name, MethodBase.GetCurrentMethod().Name); result.IsSuccess = false; result.Message = new UtilityHelper().IOTResultMessage(addDeviceResult.errorMessages); } } else { return(new Entity.BaseResponse <bool>(false, repoResult.Message)); } } catch (Exception ex) { _logger.ErrorLog(ex, this.GetType().Name, MethodBase.GetCurrentMethod().Name); return(null); } return(result); }
public Entity.ActionStatus Manage(Entity.Device request) { Entity.ActionStatus actionStatus = new Entity.ActionStatus(true); try { var dbDevice = Mapper.Configuration.Mapper.Map <Entity.Device, Model.Device>(request); if (request.Guid == null || request.Guid == Guid.Empty) { var addDeviceResult = _iotConnectClient.Device.Add(Mapper.Configuration.Mapper.Map <IOT.AddDeviceModel>(request)).Result; if (addDeviceResult != null && addDeviceResult.status && addDeviceResult.data != null) { request.Guid = Guid.Parse(addDeviceResult.data.newid.ToUpper()); IOT.DataResponse <IOT.AcquireDeviceResult> acquireResult = _iotConnectClient.Device.AcquireDevice(request.UniqueId, new IOT.AcquireDeviceModel()).Result; dbDevice.IsProvisioned = acquireResult.status; dbDevice.IsActive = true; dbDevice.Guid = request.Guid; dbDevice.CompanyGuid = SolutionConfiguration.CompanyId; dbDevice.CreatedDate = DateTime.Now; dbDevice.CreatedBy = SolutionConfiguration.CurrentUserId; actionStatus = _deviceRepository.Manage(dbDevice); actionStatus.Data = Mapper.Configuration.Mapper.Map <Model.Device, Entity.Device>(actionStatus.Data); if (!actionStatus.Success) { _logger.ErrorLog(new Exception($"Device is not added in solution database, Error: {actionStatus.Message}"), this.GetType().Name, MethodBase.GetCurrentMethod().Name); var deleteEntityResult = _iotConnectClient.Device.Delete(request.Guid.ToString()).Result; if (deleteEntityResult != null && deleteEntityResult.status) { _logger.ErrorLog(new Exception($"Device is not deleted from iotconnect"), this.GetType().Name, MethodBase.GetCurrentMethod().Name); actionStatus.Success = false; actionStatus.Message = "Something Went Wrong!"; } } } else { _logger.ErrorLog(new Exception($"Device is not added in iotconnect, Error: {addDeviceResult.message}"), this.GetType().Name, MethodBase.GetCurrentMethod().Name); actionStatus.Success = false; actionStatus.Message = new UtilityHelper().IOTResultMessage(addDeviceResult.errorMessages); } } else { var olddbDevice = _deviceRepository.FindBy(x => x.Guid.Equals(request.Guid)).FirstOrDefault(); if (olddbDevice == null) { throw new NotFoundCustomException($"{CommonException.Name.NoRecordsFound} : Device"); } var updateEntityResult = _iotConnectClient.Device.Update(request.Guid.ToString(), Mapper.Configuration.Mapper.Map <IOT.UpdateDeviceModel>(request)).Result; if (updateEntityResult != null && updateEntityResult.status && updateEntityResult.data != null) { dbDevice.CreatedDate = olddbDevice.CreatedDate; dbDevice.CreatedBy = olddbDevice.CreatedBy; dbDevice.UpdatedDate = DateTime.Now; dbDevice.UpdatedBy = SolutionConfiguration.CurrentUserId; dbDevice.CompanyGuid = SolutionConfiguration.CompanyId; actionStatus = _deviceRepository.Manage(dbDevice); actionStatus.Data = Mapper.Configuration.Mapper.Map <Model.Device, Entity.Device>(actionStatus.Data); if (!actionStatus.Success) { _logger.ErrorLog(new Exception($"Device is not updated in solution database, Error: {actionStatus.Message}"), this.GetType().Name, MethodBase.GetCurrentMethod().Name); actionStatus.Success = false; actionStatus.Message = "Something Went Wrong!"; } } else { _logger.ErrorLog(new Exception($"Device is not added in iotconnect, Error: {updateEntityResult.message}"), this.GetType().Name, MethodBase.GetCurrentMethod().Name); actionStatus.Success = false; actionStatus.Message = new UtilityHelper().IOTResultMessage(updateEntityResult.errorMessages); } } } catch (Exception ex) { _logger.ErrorLog(ex, this.GetType().Name, MethodBase.GetCurrentMethod().Name); return(new Entity.ActionStatus { Success = false, Message = ex.Message }); } return(actionStatus); }
public Entity.ActionStatus Manage(Entity.DeviceModel request) { Entity.ActionStatus actionStatus = new Entity.ActionStatus(true); try { var dbDevice = Mapper.Configuration.Mapper.Map <Entity.DeviceModel, Model.DeviceModel>(request); if (request.Guid == null || request.Guid == Guid.Empty) { request.CompanyGuid = SolutionConfiguration.CompanyId; var addDeviceResult = _iotConnectClient.Device.Add(Mapper.Configuration.Mapper.Map <IOT.AddDeviceModel>(request)).Result; if (addDeviceResult != null && addDeviceResult.status && addDeviceResult.data != null) { request.Guid = Guid.Parse(addDeviceResult.data.newid.ToUpper()); IOT.DataResponse <IOT.AcquireDeviceResult> acquireResult = _iotConnectClient.Device.AcquireDevice(request.UniqueId, new IOT.AcquireDeviceModel()).Result; //if (request.ImageFile != null) //{ // // upload image // dbDevice.Image = SaveDeviceImage(request.Guid.Value, request.ImageFile); //} dbDevice.Guid = request.Guid.Value; dbDevice.IsProvisioned = true; dbDevice.IsActive = true; dbDevice.CompanyGuid = SolutionConfiguration.CompanyId; dbDevice.CreatedDate = DateTime.Now; dbDevice.CreatedBy = SolutionConfiguration.CurrentUserId; dbDevice.TemplateGuid = request.TemplateGuid; /* * <attrbs><attrb><attrGuid>12A5CD86-F6C6-455F-B27A-EFE587ED410D</attrGuid><attrName>devTemp</attrName><dispName>Temprature1</dispName></attrb> * <attrb><attrGuid>12A5CD86-F6C6-455F-B26A-EFE587ED410D</attrGuid><attrName>devCurrent</attrName><dispName>Current1</dispName></attrb> * <attrb><attrGuid>12A5CD86-F6C6-455F-B25A-EFE587ED410D</attrGuid><attrName>devVibration</attrName><dispName>Vibration1</dispName></attrb> * </attrbs> */ var attributes = new List <attrb>(); var xmlData = string.Empty; //request.ArrayAttrbs = JsonConvert.DeserializeObject<List<attrb>>(request.attrbs); using (var stringwriter = new System.IO.StringWriter()) { var serializer = new XmlSerializer(request.attrbs.GetType()); serializer.Serialize(stringwriter, request.attrbs); xmlData = stringwriter.ToString().Replace("ArrayOfAttrb", "attrbs"); } dbDevice.attrData = xmlData; actionStatus = _deviceRepository.Manage(dbDevice); actionStatus.Data = actionStatus.Data != null ? (Guid)(actionStatus.Data) : Guid.Empty; if (!actionStatus.Success) { _logger.Error($"Device is not added in solution database, Error: {actionStatus.Message}"); var deleteEntityResult = _iotConnectClient.Device.Delete(request.Guid.Value.ToString()).Result; if (deleteEntityResult != null && deleteEntityResult.status) { _logger.Error($"Device is not deleted from iotconnect"); actionStatus.Success = false; actionStatus.Message = actionStatus.Message; } } else { //upload multiple images if (request.ImageFiles != null && request.ImageFiles.Count > 0) { UploadFiles(request.ImageFiles, dbDevice.Guid.ToString(), "I"); } //upload media files if (request.MediaFiles != null && request.MediaFiles.Count > 0) { UploadFiles(request.MediaFiles, dbDevice.Guid.ToString(), "M"); } } } else { actionStatus.Data = Guid.Empty; actionStatus.Success = false; actionStatus.Message = new UtilityHelper().IOTResultMessage(addDeviceResult.errorMessages); } } else { var olddbDevice = _deviceRepository.FindBy(x => x.Guid.Equals(request.Guid)).FirstOrDefault(); if (olddbDevice == null) { throw new NotFoundCustomException($"{CommonException.Name.NoRecordsFound} : Device"); } request.UniqueId = olddbDevice.UniqueId; request.TemplateGuid = olddbDevice.TemplateGuid; request.EntityGuid = olddbDevice.EntityGuid; var updateEntityResult = _iotConnectClient.Device.Update(request.Guid.ToString(), Mapper.Configuration.Mapper.Map <IOT.UpdateDeviceModel>(request)).Result; if (updateEntityResult != null && updateEntityResult.status) { //if (request.ImageFile != null) //{ // if (File.Exists(SolutionConfiguration.UploadBasePath + dbDevice.Image) && request.ImageFile.Length > 0) // { // //if already exists image then delete old image from server // File.Delete(SolutionConfiguration.UploadBasePath + dbDevice.Image); // } // if (request.ImageFile.Length > 0) // { // // upload new image // dbDevice.Image = SaveDeviceImage(dbDevice.Guid, request.ImageFile); // } //} //else //{ // dbDevice.Image = olddbDevice.Image; //} dbDevice.CreatedDate = olddbDevice.CreatedDate; dbDevice.CreatedBy = olddbDevice.CreatedBy; dbDevice.UpdatedDate = DateTime.Now; dbDevice.UpdatedBy = SolutionConfiguration.CurrentUserId; dbDevice.CompanyGuid = SolutionConfiguration.CompanyId; dbDevice.TemplateGuid = olddbDevice.TemplateGuid; dbDevice.TypeGuid = olddbDevice.TypeGuid; dbDevice.SensorGuid = olddbDevice.SensorGuid; dbDevice.SensorCondition = olddbDevice.SensorCondition; dbDevice.SensorValue = olddbDevice.SensorValue; dbDevice.Specification = request.Specification; var attributes = new List <attrb>(); var xmlData = string.Empty; //request.ArrayAttrbs = JsonConvert.DeserializeObject<List<attrb>>(request.attrbs); using (var stringwriter = new System.IO.StringWriter()) { var serializer = new XmlSerializer(request.attrbs.GetType()); serializer.Serialize(stringwriter, request.attrbs); xmlData = stringwriter.ToString().Replace("ArrayOfAttrb", "attrbs"); } dbDevice.attrData = xmlData; actionStatus = _deviceRepository.Manage(dbDevice); actionStatus.Data = (Guid)(actionStatus.Data); if (!actionStatus.Success) { _logger.Error($"Device is not updated in solution database, Error: {actionStatus.Message}"); actionStatus.Success = false; actionStatus.Message = "Something Went Wrong!"; actionStatus.Data = Guid.Empty; } else { //upload multiple images if (request.ImageFiles != null && request.ImageFiles.Count > 0) { UploadFiles(request.ImageFiles, dbDevice.Guid.ToString(), "I"); } //upload media files if (request.MediaFiles != null && request.MediaFiles.Count > 0) { UploadFiles(request.MediaFiles, dbDevice.Guid.ToString(), "M"); } } } else { _logger.Error($"Device is not updated in iotconnect, Error: {updateEntityResult.message}"); actionStatus.Success = false; actionStatus.Message = new UtilityHelper().IOTResultMessage(updateEntityResult.errorMessages); actionStatus.Data = Guid.Empty; } } } catch (Exception ex) { _logger.Error(Constants.ACTION_EXCEPTION, "DeviceService.Manage " + ex); return(new Entity.ActionStatus { Success = false, Message = ex.Message }); } return(actionStatus); }
public Entity.ActionStatus Manage(Entity.DeviceModel request) { Entity.ActionStatus actionStatus = new Entity.ActionStatus(true); try { var dbDevice = Mapper.Configuration.Mapper.Map <Entity.Device, Model.Device>(request); if (request.Guid == null || request.Guid == Guid.Empty) { ////provision kit with kitcode and unique id var kitDeviceList = _deviceRepository.ProvisionKit(new ProvisionKitRequest { DeviceGuid = new Guid(), KitCode = request.KitCode, UniqueId = request.UniqueId }); if (kitDeviceList != null && kitDeviceList.Data != null && kitDeviceList.Data.Any()) { string templateGuid = _lookupService.GetIotTemplateGuidByName(kitDeviceList.Data.FirstOrDefault().TemplateName); if (!string.IsNullOrEmpty(templateGuid)) { request.TemplateGuid = new Guid(templateGuid); request.CompanyGuid = SolutionConfiguration.CompanyId; var addDeviceResult = _iotConnectClient.Device.Add(Mapper.Configuration.Mapper.Map <IOT.AddDeviceModel>(request)).Result; // if (addDeviceResult != null && addDeviceResult.status && addDeviceResult.data != null) { request.Guid = Guid.Parse(addDeviceResult.data.newid.ToUpper()); IOT.DataResponse <IOT.AcquireDeviceResult> acquireResult = _iotConnectClient.Device.AcquireDevice(request.UniqueId, new IOT.AcquireDeviceModel()).Result; if (request.ImageFile != null) { // upload image dbDevice.Image = SaveDeviceImage(request.Guid.Value, request.ImageFile); } dbDevice.Guid = request.Guid.Value; dbDevice.IsProvisioned = acquireResult.status; dbDevice.IsActive = true; dbDevice.CompanyGuid = SolutionConfiguration.CompanyId; dbDevice.CreatedDate = DateTime.Now; dbDevice.CreatedBy = SolutionConfiguration.CurrentUserId; actionStatus = _deviceRepository.Manage(dbDevice); actionStatus.Data = (Guid)(actionStatus.Data); if (!actionStatus.Success) { _logger.ErrorLog(new Exception($"Device is not added in solution database, Error: {actionStatus.Message}"), this.GetType().Name, MethodBase.GetCurrentMethod().Name); var deleteEntityResult = _iotConnectClient.Device.Delete(request.Guid.Value.ToString()).Result; if (deleteEntityResult != null && deleteEntityResult.status) { _logger.ErrorLog(new Exception($"Device is not deleted from iotconnect"), this.GetType().Name, MethodBase.GetCurrentMethod().Name); actionStatus.Success = false; actionStatus.Message = new UtilityHelper().IOTResultMessage(deleteEntityResult.errorMessages); } } else { //Update companyid in hardware kit var hardwareKit = _hardwareKitRepository.GetByUniqueId(t => t.KitCode == request.KitCode && t.UniqueId == request.UniqueId); if (hardwareKit != null) { hardwareKit.CompanyGuid = SolutionConfiguration.CompanyId; _hardwareKitRepository.Update(hardwareKit); } } } else { actionStatus.Data = Guid.Empty; actionStatus.Success = false; actionStatus.Message = new UtilityHelper().IOTResultMessage(addDeviceResult.errorMessages); } } else { actionStatus.Success = false; actionStatus.Data = false; actionStatus.Message = "Unable To Locate Kit Type."; } } else { _logger.ErrorLog(new Exception($"Device KitCode or UniqueId is not valid"), this.GetType().Name, MethodBase.GetCurrentMethod().Name); actionStatus.Data = Guid.Empty; actionStatus.Success = false; actionStatus.Message = "Device KitCode or UniqueId is not valid!"; } } else { var olddbDevice = _deviceRepository.FindBy(x => x.Guid.Equals(request.Guid)).FirstOrDefault(); if (olddbDevice == null) { throw new NotFoundCustomException($"{CommonException.Name.NoRecordsFound} : Device"); } var updateEntityResult = _iotConnectClient.Device.Update(request.Guid.ToString(), Mapper.Configuration.Mapper.Map <IOT.UpdateDeviceModel>(request)).Result; if (updateEntityResult != null && updateEntityResult.status) { if (request.ImageFile != null) { if (File.Exists(SolutionConfiguration.UploadBasePath + dbDevice.Image) && request.ImageFile.Length > 0) { //if already exists image then delete old image from server File.Delete(SolutionConfiguration.UploadBasePath + dbDevice.Image); } if (request.ImageFile.Length > 0) { // upload new image dbDevice.Image = SaveDeviceImage(dbDevice.Guid, request.ImageFile); } } else { dbDevice.Image = olddbDevice.Image; } dbDevice.CreatedDate = olddbDevice.CreatedDate; dbDevice.CreatedBy = olddbDevice.CreatedBy; dbDevice.UpdatedDate = DateTime.Now; dbDevice.UpdatedBy = SolutionConfiguration.CurrentUserId; dbDevice.CompanyGuid = SolutionConfiguration.CompanyId; dbDevice.TemplateGuid = olddbDevice.TemplateGuid; actionStatus = _deviceRepository.Manage(dbDevice); actionStatus.Data = (Guid)(actionStatus.Data); if (!actionStatus.Success) { _logger.ErrorLog(new Exception($"Device is not updated in solution database, Error: {actionStatus.Message}"), this.GetType().Name, MethodBase.GetCurrentMethod().Name); actionStatus.Success = false; actionStatus.Message = "Something Went Wrong!"; } } else { _logger.ErrorLog(new Exception($"Device is not updated in iotconnect, Error: {updateEntityResult.message}"), this.GetType().Name, MethodBase.GetCurrentMethod().Name); actionStatus.Success = false; actionStatus.Message = new UtilityHelper().IOTResultMessage(updateEntityResult.errorMessages); } } } catch (Exception ex) { _logger.ErrorLog(ex, this.GetType().Name, MethodBase.GetCurrentMethod().Name); return(new Entity.ActionStatus { Success = false, Message = ex.Message }); } return(actionStatus); }
public Entity.BaseResponse <bool> ProvisionKit(Entity.ProvisionKitRequest request) { Entity.BaseResponse <bool> result = new Entity.BaseResponse <bool>(true); try { Entity.BaseResponse <List <Entity.KitDevice> > kitDeviceList = _deviceRepository.ProvisionKit(request); if (kitDeviceList != null && kitDeviceList.Data != null && kitDeviceList.Data.Any()) { List <Entity.KitDevice> deviceList = kitDeviceList.Data.OrderBy(d => d.ParentDeviceGuid.HasValue).ToList(); string templateGuid = _lookupService.GetIotTemplateGuidByName(deviceList.FirstOrDefault().TemplateName); if (!string.IsNullOrEmpty(templateGuid)) { List <Model.Device> lstAddedDevice = new List <Model.Device>(); bool IsDeviceAdded = true; foreach (var device in deviceList) { string tagName = string.Empty; if (device.ParentDeviceGuid.HasValue) { var kitType = _kitTypeAttributeRepository.FindBy(t => t.Guid == device.TagGuid).FirstOrDefault(); if (kitType != null) { tagName = kitType.Tag.ToString(); } else { throw new Exception("Device tag is not exists in solution."); } } IOT.AddDeviceModel iotDeviceDetail = new IOT.AddDeviceModel() { DisplayName = device.Name, entityGuid = request.GreenHouseGuid.ToString(), uniqueId = device.UniqueId, deviceTemplateGuid = templateGuid,// device.TemplateGuid.ToString(), parentDeviceGuid = device.ParentDeviceGuid.ToString(), note = device.Note, tag = tagName,//device.Tag, properties = new List <IOT.AddProperties>() }; var addDeviceResult = _iotConnectClient.Device.Add(iotDeviceDetail).Result; if (addDeviceResult != null && addDeviceResult.status && addDeviceResult.data != null) { Guid newDeviceId = Guid.Parse(addDeviceResult.data.newid.ToUpper()); IOT.DataResponse <IOT.AcquireDeviceResult> acquireResult = _iotConnectClient.Device.AcquireDevice(device.UniqueId, new IOT.AcquireDeviceModel()).Result; var intUpdated = deviceList.Where(d => d.ParentDeviceGuid == device.Guid).Select(d => d.ParentDeviceGuid = newDeviceId).Count(); lstAddedDevice.Add(new Model.Device() { Guid = newDeviceId, CompanyGuid = SolutionConfiguration.CompanyId, GreenHouseGuid = request.GreenHouseGuid, TemplateGuid = device.TemplateGuid, ParentDeviceGuid = device.ParentDeviceGuid, Type = null, UniqueId = device.UniqueId, Name = device.Name, Note = device.Note, Tag = tagName,//device.Tag, IsProvisioned = acquireResult.status, IsActive = true, IsDeleted = false, CreatedDate = DateTime.UtcNow, CreatedBy = SolutionConfiguration.CurrentUserId }); } else { IsDeviceAdded = false; _logger.ErrorLog(new Exception($"Kit is not added in iotconnect, Error: {addDeviceResult.message}"), this.GetType().Name, MethodBase.GetCurrentMethod().Name); result.IsSuccess = false; result.Message = new UtilityHelper().IOTResultMessage(addDeviceResult.errorMessages); break; } } if (IsDeviceAdded && lstAddedDevice != null && lstAddedDevice.Any()) { foreach (var device in lstAddedDevice) { Entity.ActionStatus actionStatus = _deviceRepository.Manage(device); if (!actionStatus.Success) { _logger.ErrorLog(new Exception($"Device is not added in solution database, Error: {actionStatus.Message}"), this.GetType().Name, MethodBase.GetCurrentMethod().Name); var deleteEntityResult = _iotConnectClient.Device.Delete(device.Guid.ToString()).Result; if (deleteEntityResult != null && deleteEntityResult.status) { _logger.ErrorLog(new Exception($"Device is not deleted from iotconnect"), this.GetType().Name, MethodBase.GetCurrentMethod().Name); actionStatus.Success = false; actionStatus.Message = "Something Went Wrong!"; } } } } if (result.IsSuccess) { result.Message = "Kit Added Successfully!"; //Update companyid in hardware kit var hardwareKit = _hardwareKitRepository.GetByUniqueId(t => t.KitCode == request.KitCode); if (hardwareKit != null) { hardwareKit.CompanyGuid = SolutionConfiguration.CompanyId; _hardwareKitRepository.Update(hardwareKit); } } } else { result.IsSuccess = false; result.Data = false; result.Message = "Unable To Locate Kit Type."; } } else { result.IsSuccess = false; result.Data = false; result.Message = "Invalid Kit Details.Please Correct It!"; } } catch (Exception ex) { _logger.ErrorLog(ex, this.GetType().Name, MethodBase.GetCurrentMethod().Name); return(null); } return(result); }