public async Task GetListAsyncReturnsExpectedValue() { string tenantId = this.rand.NextString(); List <DeviceGroupConditionModel> conditions = new List <DeviceGroupConditionModel>(); List <DeviceModel> devices = new List <DeviceModel> { this.entityHelper.CreateDevice(), this.entityHelper.CreateDevice(), }; DeviceListModel deviceListModel = new DeviceListModel { Items = devices, }; this.mockRequestHelper .Setup(r => r.ProcessRequestAsync <DeviceListModel>( It.Is <HttpMethod>(m => m == HttpMethod.Get), It.Is <string>(url => url.Contains(MockApiUrl)), It.Is <string>(s => s == tenantId), It.IsAny <NameValueCollection>())) .ReturnsAsync(deviceListModel); DeviceListModel response = await this.client.GetListAsync(conditions, tenantId); this.mockRequestHelper .Verify( r => r.ProcessRequestAsync <DeviceListModel>( It.Is <HttpMethod>(m => m == HttpMethod.Get), It.Is <string>(url => url.Contains(MockApiUrl)), It.Is <string>(s => s == tenantId), It.IsAny <NameValueCollection>()), Times.Once); Assert.Equal(deviceListModel, response); }
/// <summary> /// 获取设备列表 /// </summary> /// <param name="deviceIds"></param> /// <returns></returns> public static DeviceListModel GetDeviceList(string deviceIds, int pi, int pc) { DeviceListModel dlm = null; //dlm.Items = new List<DeviceListInfo>(); try { APIDeviceListModel model = new APIDeviceListModel(); model.LoginType = 0; model.Id = 1; model.PageNo = pi; model.PageCount = pc; model.AllIds = deviceIds; model.Type = 0; model.MapType = "baidu"; model.LastTime = DateTime.Now.AddDays(-10); dlm = HttpApi.GetApiResult <DeviceListModel>("Device/ListDevice", model); ReadResource.ExecBack(dlm, "ListDevice"); } catch (Exception ex) { dlm.State = -1; dlm.Message = ex.Message; LogHelper.ErrorLog(ex); } return(dlm); }
public async Task <IActionResult> Get([FromRoute] string username) { var user = await _userRepository.GetFirstOrDefaultAsync( predicate : x => x.UserName == username, disableTracking : true, include : "UserArduinos.Arduino"); var devices = new List <DeviceDetailsModel>(); foreach (var device in user.UserArduinos) { devices.Add(new DeviceDetailsModel { Id = device.Arduino.Id.ToString(), Name = device.Arduino.Name, Observation = device.Arduino.Observation, MacAddress = device.Arduino.MacAdrress }); } var deviceList = new DeviceListModel { UserId = user.Id.ToString(), Username = user.UserName, User = user.Name, DeviceList = devices }; return(Response(deviceList)); }
protected override object CreateListModel(IPagedList <Device> source, int pageSize) { List <DeviceListModel> result = new List <DeviceListModel>(); foreach (Device item in source) { DeviceListModel listModel = new DeviceListModel() { Id = item.Id, CreateTime = item.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"), DeviceNumber = item.DeviceNumber, DeviceTypeName = item.DeviceType == 1 ? "手机" : "平板", PlatformName = item.Platform == 1 ? "IOS" : "Android" }; result.Add(listModel); } var gridModel = new DataSourceResult <DeviceListModel>(pageSize) { Data = result, Total = source.TotalCount, PageCount = source.TotalPages }; return(gridModel); }
public string deviceList(int page, int rows) { DeviceListModel pl = new DeviceListModel(page, rows); string json = JsonConvert.SerializeObject(pl); return(json); }
/// <summary> /// 监控页面的获取设备列表 /// </summary> /// <param name="pi"></param> /// <param name="pc"></param> /// <returns></returns> public JsonResult AjaxGetMonitorList(int pi, int pc) { List <DeviceAndUser> dus = DeviceLogic.GetDeviceList(AuthUser.UserTypeId.Value, AuthUser.Id, pi, pc); string deviceIds = ""; foreach (var du in dus) { deviceIds += du.APIDeviceId + ","; } deviceIds = deviceIds.TrimEnd(','); DeviceListModel list = DeviceData.GetDeviceList(deviceIds, pi, pc); DeviceListResult res = new DeviceListResult(); res.Items = new List <DeviceInfo>(); if (list.Items.Count > 0) { list.Items.ForEach(p => { DeviceAndUser du = dus.FirstOrDefault(t => t.APIDeviceId == p.Id); if (du != null) { DeviceInfo di = new DeviceInfo(); di.Id = du.DeviceId; di.APIId = du.APIDeviceId ?? 0; di.Battery = p.Battery; di.Icon = du.IconId ?? 0; di.Model = p.Model; di.IMEI = du.Imei; di.Latitude = Convert.ToDecimal(WebHelper.GetLatLngString(p.Latitude)); di.Longitude = Convert.ToDecimal(WebHelper.GetLatLngString(p.Longitude)); di.ServerUtcDate = p.ServerUtcDate.AddHours(8); di.DeviceUtcDate = p.DeviceUtcDate.AddHours(8); di.Type = p.Type; di.Sim = p.Sim; di.Status = p.Status; if (DateTime.Now.AddMinutes(-15) < di.ServerUtcDate) { di.Status = 2; } di.UserId = du.UserId; di.UserName = string.IsNullOrWhiteSpace(du.UserName) ? du.LoginName : du.UserName; di.Sex = du.Sex ?? 2; res.Items.Add(di); } }); } else { res.State = State.Falid; res.Message = list.Message; } return(Json(res)); }
public async Task <DeviceListModel> PrepareDeviceListModel(DeviceSearchModel searchModel) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } var devices = await _deviceService.GetDevicesAsync( storeIds : searchModel.SelectedStoreIds.ToArray(), serialNo : searchModel.SearchSerialNo, pageIndex : searchModel.Page - 1, pageSize : searchModel.PageSize); var model = new DeviceListModel { Data = devices.Select(device => { var devicesModel = device.ToModel <DeviceModel>(); devicesModel.SerialNo = device.SerialNo; devicesModel.ModelNo = device.ModelNo; devicesModel.SelectedStoreId = device.StoreId; devicesModel.StoreName = device.Store != null ? device.Store.P_BranchNo + " - " + device.Store.P_Name : string.Empty; devicesModel.CreatedOn = _dateTimeHelper.ConvertToUserTime(device.CreatedOnUtc, DateTimeKind.Utc); devicesModel.LastActivityDate = _dateTimeHelper.ConvertToUserTime(device.ModifiedOnUtc.GetValueOrDefault(DateTime.UtcNow), DateTimeKind.Utc); return(devicesModel); }), Total = devices.TotalCount }; // sort if (searchModel.Sort != null && searchModel.Sort.Any()) { foreach (var s in searchModel.Sort) { model.Data = await model.Data.Sort(s.Field, s.Dir); } } // filter if (searchModel.Filter?.Filters != null && searchModel.Filter.Filters.Any()) { var filter = searchModel.Filter; model.Data = await model.Data.Filter(filter); model.Total = model.Data.Count(); } return(model); }
public ActionResult DeviceList(UISmokeDetectorStatus?uiStatus) { ViewBag.status = uiStatus; DeviceListModel model = new DeviceListModel(); if (curentUser.UserType == UserType.Installer) { QF_SmokeDetector filter = new QF_SmokeDetector(); filter.InstallerSysNo = curentUser.ManagerSysNo.Value; filter.Status = uiStatus; filter.PageIndex = 0; filter.PageSize = 10; filter.SortFields = "InstalledTime desc"; var allsmks = SmokeDetectorServices.LoadSmokeDetectorsByInstaller(curentUser.ManagerSysNo.Value).Where(e => e.Status != SmokeDetectorStatus.Delete).ToList(); model.CountInfo = new SmokeDetectorCount { ALLSmokeCount = allsmks.Count, OfflineCount = (allsmks.Where(e => e.UIStatus == UISmokeDetectorStatus.OffLine) ?? new List <SmokeDetector>()).Count(), OnlineCount = (allsmks.Where(e => e.UIStatus == UISmokeDetectorStatus.Online) ?? new List <SmokeDetector>()).Count(), LowPowerCount = (allsmks.Where(e => e.UIStatus == UISmokeDetectorStatus.LowPowerWarning) ?? new List <SmokeDetector>()).Count(), WarningCount = (allsmks.Where(e => e.UIStatus == UISmokeDetectorStatus.FireWarning) ?? new List <SmokeDetector>()).Count(), }; //model.CountInfo.OnlineCount = model.CountInfo.ALLSmokeCount - model.CountInfo.OfflineCount; var result = SmokeDetectorServices.QuerySmokeDetectorList(filter); model.DeviceList = new QueryResult <QR_SmokeDetector>(); model.DeviceList = result; } else { QF_UserDetector filter = new QF_UserDetector(); filter.PageIndex = 0; filter.PageSize = 10; filter.Status = uiStatus; filter.ClientSysNo = curentUser.UserSysNo; model.CountInfo = SmokeDetectorServices.LoadUserSmokeDetectorCount(curentUser.UserSysNo); QueryResult <QR_SmokeDetector> list = SmokeDetectorServices.LoadUserSmokeDeletetorList(filter); model.DeviceList = new QueryResult <QR_SmokeDetector>(); model.DeviceList = list; } ViewBag.UserType = curentUser.UserType; return(View(model)); }
public override async Task <ConversionApiModel> ConvertAsync(string tenantId, string operationId = null) { ValueListApiModel deviceGroups = null; try { deviceGroups = await this.StorageAdapterClient.GetAllAsync(this.Entity, tenantId); } catch (Exception e) { this.Logger.LogError(e, "Unable to query {entity} using storage adapter. OperationId: {operationId}. TenantId: {tenantId}", this.Entity, operationId, tenantId); throw e; } if (deviceGroups.Items.Count() == 0 || deviceGroups == null) { string errorMessage = $"No entities were receieved from storage adapter to convert to {this.Entity}. OperationId: {operationId}. TenantId: {tenantId}"; this.Logger.LogError(new Exception(errorMessage), errorMessage); throw new ResourceNotFoundException("No entities were receieved from storage adapter to convert to rules."); } DeviceGroupListModel deviceGroupModels = new DeviceGroupListModel(); try { List <DeviceGroupModel> items = new List <DeviceGroupModel>(); foreach (ValueApiModel group in deviceGroups.Items) { try { DeviceGroupDataModel dataModel = JsonConvert.DeserializeObject <DeviceGroupDataModel>(group.Data); DeviceGroupModel individualModel = new DeviceGroupModel(group.Key, group.ETag, dataModel); items.Add(individualModel); } catch (Exception) { this.Logger.LogInformation("Unable to convert a device group to the proper reference data model for {entity}. OperationId: {operationId}. TenantId: {tenantId}", this.Entity, operationId, tenantId); } } if (items.Count() == 0) { throw new ResourceNotSupportedException("No device groups were able to be converted to the proper rule reference data model."); } deviceGroupModels.Items = items; } catch (Exception e) { this.Logger.LogError(e, "Unable to convert {entity} queried from storage adapter to appropriate data model. OperationId: {operationId}. TenantId: {tenantId}", this.Entity, operationId, tenantId); throw e; } Dictionary <DeviceGroupModel, DeviceListModel> deviceMapping = new Dictionary <DeviceGroupModel, DeviceListModel>(); foreach (DeviceGroupModel deviceGroup in deviceGroupModels.Items) { try { DeviceListModel devicesList = await this.iotHubManager.GetListAsync(deviceGroup.Conditions, tenantId); if (devicesList.Items.Count() > 0) { deviceMapping.Add(deviceGroup, devicesList); } } catch (Exception e) { // Do not throw an exception here, attempt to query other device groups instead to get as much data as possible // Log all device groups that could not be retreived this.Logger.LogError(e, "Unable to get list of devices for devicegroup {deviceGroup} from IotHubManager. OperationId: {operationId}. TenantId: {tenantId}", deviceGroup.Id, operationId, tenantId); } } if (deviceMapping.Count() == 0) { string groups = $"[{string.Join(", ", deviceGroupModels.Items.Select(group => group.Id))}]"; string errorMessage = $"No Devices were found for any {this.Entity}. OperationId: {operationId}. TenantId: {tenantId}\n{groups}"; this.Logger.LogError(new Exception(errorMessage), errorMessage); throw new ResourceNotFoundException($"No Devices were found for any {this.Entity}."); } string fileContent = null; try { // Write a file in csv format: // deviceId,groupId // mapping contains devices groups, and a list model of all devices within each device group // create a new csv row for each device and device group combination string fileContentRows = string.Join("\n", deviceMapping.Select(mapping => { return(string.Join("\n", mapping.Value.Items.Select(device => $"{device.Id},{mapping.Key.Id}"))); })); // Add the rows and the header together to complete the csv file content fileContent = $"{CsvHeader}\n{fileContentRows}"; } catch (Exception e) { this.Logger.LogError(e, "Unable to serialize the {entity} data models for the temporary file content. OperationId: {operationId}. TenantId: {tenantId}", this.Entity, operationId, tenantId); throw e; } string blobFilePath = await this.WriteFileContentToBlobAsync(fileContent, tenantId, operationId); ConversionApiModel conversionResponse = new ConversionApiModel { TenantId = tenantId, BlobFilePath = blobFilePath, Entities = deviceGroups, OperationId = operationId, }; this.Logger.LogInformation("Successfully Completed {entity} conversion\n{model}", this.Entity, JsonConvert.SerializeObject(conversionResponse)); return(conversionResponse); }
public void Configuration(IAppBuilder app) { DeviceList = new DeviceListModel(db.device.ToList(), db.device.ToList().Count); ConfigureAuth(app); }