public List <Entity.LookupItem> GetSensors(Guid templateId, Guid deviceId) { List <Entity.LookupItem> result = new List <Entity.LookupItem>(); try { var template = _kitTypeRepository.FindBy(t => !t.IsDeleted).FirstOrDefault();//.Name == SolutionConfiguration.DefaultIoTTemplateName if (template != null) { var childAttribute = (from child in _kitTypeAttributeRepository.FindBy(t => t.KittypeGuid == template.Guid && t.ParentTemplateAttributeGuid != null) select child.ParentTemplateAttributeGuid).ToList(); result.AddRange(from device in _deviceRepository.FindBy(t => t.Guid == deviceId) join attribute in _kitTypeAttributeRepository.FindBy(t => t.KittypeGuid == template.Guid) on device.Tag equals attribute.Tag where !childAttribute.Contains(attribute.Guid) select new Entity.LookupItem() { Text = string.Format("{0}", attribute.LocalName), Value = attribute.Guid.ToString() }); } } catch (Exception ex) { _logger.ErrorLog(ex, this.GetType().Name, MethodBase.GetCurrentMethod().Name); } return(result); }
public List <Entity.TagLookup> GetTagLookup(Guid templateId) { List <Entity.TagLookup> result = new List <Entity.TagLookup>(); var template = _kitTypeRepository.FindBy(t => t.Guid == templateId).FirstOrDefault(); if (template != null) { result.Add(new Entity.TagLookup() { tag = template.Tag, templateTag = true }); result.AddRange(from t in _kitTypeAttributeRepository.FindBy(t => t.TemplateGuid == templateId) select new Entity.TagLookup() { tag = t.LocalName, templateTag = false }); } //var taglookup = _iotConnectClient.Template.TagLookUp(templateID).Result; //if (taglookup != null && taglookup.data != null && taglookup.data.Any()) //{ // result = (from r in taglookup.data.Where(t => (!string.IsNullOrWhiteSpace(t.tag))) select new Entity.TagLookup() { tag = r.tag, templateTag = r.templateTag }).ToList(); //} return(result); }
public List <Entity.TagLookup> GetTagLookup(Guid templateId) { List <Entity.TagLookup> result = new List <Entity.TagLookup>(); var template = _kitTypeRepository.FindBy(t => t.Guid == templateId).FirstOrDefault(); if (template != null) { result.Add(new Entity.TagLookup() { tag = template.Tag, templateTag = true }); result.AddRange(from t in _kitTypeAttributeRepository.FindBy(t => t.TemplateGuid == templateId) select new Entity.TagLookup() { tag = t.LocalName, templateTag = false }); } return(result); }
public string GetAttributeNameFromSolutionDB(Guid attributeId) { string attributeName = string.Empty; try { attributeName = _kitTypeAttributeRepository.FindBy(x => x.Guid.Equals(attributeId)).FirstOrDefault().LocalName; } catch (Exception ex) { _logger.ErrorLog(ex, this.GetType().Name, MethodBase.GetCurrentMethod().Name); } return(attributeName); }
public Entity.ActionStatus Manage(Entity.KitVerifyRequest hardwareKit, bool isEdit = false) { Entity.ActionStatus actionStatus = new Entity.ActionStatus(true); try { foreach (var kit in hardwareKit.HardwareKits) { foreach (var device in kit.KitDevices) { if (string.IsNullOrWhiteSpace(device.Tag)) { continue; } var tagGuid = Guid.Parse(device.Tag); var kitAttribute = _kitTypeAttributeRepository.FindBy(t => t.Guid.Equals(tagGuid)).FirstOrDefault(); if (kitAttribute != null) { device.Tag = kitAttribute.Tag; device.AttributeName = kitAttribute.LocalName; } } } var verifyResult = _hardwareKitRepository.VerifyHardwareKit(hardwareKit, isEdit); if (verifyResult.Success) { actionStatus = _hardwareKitRepository.SaveHardwareKit(hardwareKit, isEdit); } else { List <BulkUploadResponse> errorResult = verifyResult.Data; if (errorResult != null) { foreach (var error in errorResult) { if (string.IsNullOrWhiteSpace(error.tag)) { continue; } var tag = error.tag; var kitAttribute = _kitTypeAttributeRepository.FindBy(t => t.Tag.Equals(error.tag) && t.LocalName.Equals(error.attributename)).FirstOrDefault(); if (kitAttribute != null) { error.tag = kitAttribute.Guid.ToString(); } } } actionStatus.Data = errorResult;// verifyResult.Data; actionStatus.Success = verifyResult.Success; actionStatus.Message = "Hardware kit already exist"; } } 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 { 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); }