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.DeviceDetailModel Get(Guid id)
        {
            try
            {
                Entity.DeviceDetailModel dbDevice = _deviceRepository.Get(id);

                return(dbDevice);
            }
            catch (Exception ex)
            {
                _logger.Error(Constants.ACTION_EXCEPTION, "DeviceService.Get " + ex);
                return(null);
            }
        }
Example #3
0
        public Entity.DeviceDetailModel Get(Guid deviceId)
        {
            Entity.SearchResult <List <Entity.DeviceDetailModel> > listResult = new Entity.SearchResult <List <Entity.DeviceDetailModel> >();
            var result = new Entity.DeviceDetailModel();

            try
            {
                logger.InfoLog(Constants.ACTION_ENTRY, "DeviceRepository.Get");

                using (var sqlDataAccess = new SqlDataAccess(ConnectionString))
                {
                    List <System.Data.Common.DbParameter> parameters = sqlDataAccess.CreateParams(component.helper.SolutionConfiguration.CompanyId, component.helper.SolutionConfiguration.Version);
                    parameters.Add(sqlDataAccess.CreateParameter("companyGuid", component.helper.SolutionConfiguration.CompanyId, DbType.Guid, ParameterDirection.Input));
                    parameters.Add(sqlDataAccess.CreateParameter("guid", deviceId, DbType.Guid, ParameterDirection.Input));
                    System.Data.Common.DbDataReader dbDataReader = sqlDataAccess.ExecuteReader(sqlDataAccess.CreateCommand("[Device_Get]", CommandType.StoredProcedure, null), parameters.ToArray());
                    listResult.Items = DataUtils.DataReaderToList <Entity.DeviceDetailModel>(dbDataReader, null);
                    if (listResult.Items.Count > 0)
                    {
                        result = listResult.Items[0];
                        result.DeviceMediaFiles = GetMediaFiles(result.Guid.Value, "M");
                        result.DeviceImageFiles = GetMediaFiles(result.Guid.Value, "I");

                        result.DeviceAttributes = _uow.DbContext.DeviceAttribute.Where(u => u.DeviceGuid == deviceId && !u.IsDeleted).Select(g => new Entity.DeviceAttribute()
                        {
                            Guid     = g.Guid,
                            AttrGuid = g.AttrGuid,
                            AttrName = g.AttrName,
                            DispName = g.DisplayName
                        }).ToList();
                    }
                }
                logger.InfoLog(Constants.ACTION_EXIT, "DeviceRepository.Get");
            }
            catch (Exception ex)
            {
                logger.ErrorLog(Constants.ACTION_EXCEPTION, ex);
            }
            return(result);
        }