private DequeueMessagesDto RetrieveItems(DeviceListDto devices, Func <IEnumerable <DeviceIdWithOpHint>, DequeueResults> retrieveFunc) { EnsureSingleDevice(devices.DeviceIds); var dequeueHint = DeviceEntryRegistry.Instance.GetDequeueHint(devices.DeviceIds); var cacheItems = _messageCache.Get(dequeueHint.ToCacheIndices()); var deviceIdWithOpHintList = ItemConverters.ToDeviceIdWithOpHint(dequeueHint); foreach (var hint in deviceIdWithOpHintList) { if (hint.Index.HasValue && cacheItems.MissingDevices.Contains(hint.DeviceId)) { hint.Index = null; } } var dequeueEntries = retrieveFunc(deviceIdWithOpHintList); DeviceEntryRegistry.Instance.Merge(dequeueEntries.Messages); DeviceEntryRegistry.Instance.Merge(dequeueEntries.UnknownEntries); _messageCache.Remove(cacheItems.CacheItems.Keys); return(ItemConverters.GetDequeueMessagesDto(dequeueEntries.Messages, cacheItems)); }
public static DeviceListDto ToDeviceList(IReadOnlyCollection <DeviceEntry> commitEntries) { var deviceList = new DeviceListDto(); deviceList.DeviceIds = commitEntries.Select(d => d.Id).ToList(); return(deviceList); }
public async Task <IActionResult> Details(string id) { var dto = new DeviceListDto(); dto.DeviceId = id; var rm = RegistryManager.CreateFromConnectionString(_configuration["IotHubConnectionString"]); return(View(dto)); }
public DeviceListDto Commit(DeviceListDto devices) { EnsureSingleDevice(devices.DeviceIds); var commitHint = DeviceEntryRegistry.Instance.GetCommitHint(devices.DeviceIds); var commitEntries = _persistentStorage.Commit(commitHint); DeviceEntryRegistry.Instance.Merge(commitEntries); return(ItemConverters.ToDeviceList(commitEntries)); }
public static DeviceListDto ToDeviceListDto(IEnumerable <EnqueueResult> enqueueResults) { var deviceListDto = new DeviceListDto() { DeviceIds = new List <long>() }; foreach (var enqueueResult in enqueueResults) { deviceListDto.DeviceIds.Add(enqueueResult.Id); } return(deviceListDto); }
public async Task <IActionResult> Index() { var rm = RegistryManager.CreateFromConnectionString(_configuration["IotHubConnectionString"]); var devicesQuery = rm.CreateQuery("SELECT DeviceId FROM devices"); var devices = await devicesQuery.GetNextAsJsonAsync(); var list = new List <DeviceListDto>(); foreach (var device in devices) { var json = JsonConvert.DeserializeObject <JObject>(device); var dto = new DeviceListDto { DeviceId = json.Value <string>("DeviceId") }; list.Add(dto); } return(View(list)); }
public DequeueMessagesDto Peek(DeviceListDto devices) { return(RetrieveItems(devices, _persistentStorage.Peek)); }
//vraca uredjaje u zavisnosti od vrijednosti parametara public async Task <DeviceListDto> GetDevicesByCriteria(DeviceParams deviceParams) { var devices = _context.Devices .Include(d => d.DevicePropertyValues) .Include(d => d.DeviceType).ThenInclude(d => d.DeviceTypeProperty) .Include(d => d.DeviceType).ThenInclude(d => d.ParentDeviceType).ThenInclude(d => d.DeviceTypeProperty) .AsQueryable(); //ako postoji Name parametar, vraca uredjaje koji sadrze zadato ime if (!string.IsNullOrEmpty(deviceParams.Name)) { var searchName = deviceParams.Name.Trim().ToLowerInvariant(); devices = devices.Where(d => d.Name.Contains(searchName)); } //ako postoji Type parametar, vraca uredjaje odgovarajuceg tipa if (!string.IsNullOrEmpty(deviceParams.Type)) { var searchType = deviceParams.Type.Trim().ToLowerInvariant(); devices = devices.Where(d => d.DeviceType.Name.Contains(searchType)); //ukoliko postoje Type i PropertyValue parametri //vraca uredjaje tog tipa sa odgovarajucim vrijednostima osobina if (!string.IsNullOrEmpty(deviceParams.PropertyValue)) { var searchPropertyValue = deviceParams.PropertyValue.Trim().ToLowerInvariant(); devices = devices.Where(d => d.DevicePropertyValues .Any(p => p.Value.Contains(searchPropertyValue))); } } //ako postoji compare operator (<,>,<=,>=) i cijena, vraca odgovarajuce uredjaje if (!string.IsNullOrEmpty(deviceParams.CompareOperator) && deviceParams.Price != null) { switch (deviceParams.CompareOperator) { case "<": devices = devices.Where(d => d.Price < deviceParams.Price); break; case ">": devices = devices.Where(d => d.Price > deviceParams.Price); break; case ">=": devices = devices.Where(d => d.Price >= deviceParams.Price); break; case "<=": devices = devices.Where(d => d.Price <= deviceParams.Price); break; case "=": devices = devices.Where(d => d.Price == deviceParams.Price); break; default: devices = devices.OrderByDescending(d => d.Price); break; } } //izvrsava paging na osnovu zadatih vriijednosti parametara var pagedDevices = await devices .Skip(deviceParams.PageSize *(deviceParams.PageNumber - 1)) .Take(deviceParams.PageSize) .ToListAsync(); var devicesMapped = _mapper.Map <IEnumerable <DeviceToReturnDto> >(pagedDevices); var objectToReturn = new DeviceListDto(devicesMapped, devices.Count()); return(objectToReturn); }
public DeviceListDto Commit([FromBody] DeviceListDto deviceList) { return(_messagingService.Commit(deviceList)); }
public DequeueMessagesDto Peek([FromBody] DeviceListDto deviceList) { return(_messagingService.Peek(deviceList)); }