示例#1
0
        private async Task GenerateAndSendCollectedData(Guid instanceId, CancellationToken stoppingToken)
        {
            CollectedDataDto dto = null;

            using (var scope = _scopeFactory.CreateScope())
            {
                var repo   = scope.ServiceProvider.GetRequiredService <IDataAccumulatorRepository <CollectedData> >();
                var mapper = scope.ServiceProvider.GetRequiredService <IMapper>();

                var data = CollectedDataService.GetFakeData(instanceId, DateTime.UtcNow);

                await repo.AddEntity(data);

                data = await repo.GetEntityByInternalIdAsync(data.InternalId);

                dto = mapper.Map <CollectedData, CollectedDataDto>(data);
            }

            //var info = new PercentageInfo
            //{
            //    Id = dto.Id,
            //    Time = dto.Time,
            //    RamUsagePercent = dto.RamUsagePercent,
            //    InterruptsTimePercent = dto.InterruptsTimePercent,
            //    LocalDiskFreeSpacePercent = dto.LocalDiskFreeSpacePercent,
            //    CpuUsagePercent = dto.CpuUsagePercent
            //};

            await _hubContext.Clients.Group(instanceId.ToString()).SendAsync("InstanceDataTick", dto, stoppingToken); // TODO: change to dto
        }
示例#2
0
        public virtual ActionResult <IEnumerable <CollectedDataDto> > GetDataForBuilder()
        {
            var data     = new List <CollectedDataDto>(20);
            var dateTime = DateTime.UtcNow;

            for (var i = 0; i < 20; i++)
            {
                var entity = CollectedDataService.GetFakeData(Guid.Empty, dateTime.AddSeconds(10 * i));
                entity.Id = Guid.NewGuid();
                var dto = _mapper.Map <CollectedData, CollectedDataDto>(entity);
                data.Add(dto);
            }

            return(Ok(data));
        }