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 }
public async Task <CollectedDataDto> AddEntityAsync(CollectedDataDto collectedDataDto) { var mappedEntity = _mapper.Map <CollectedDataDto, CollectedData>(collectedDataDto); await _repository.AddEntity(mappedEntity); return(collectedDataDto); }
public async Task <IActionResult> Put(Guid id, [FromBody] CollectedDataDto collectedDataDto) { try { collectedDataDto.Id = id; await _dataAccumulatorService.UpdateEntityAsync(collectedDataDto); return(NoContent()); } catch (NotFoundException e) { return(NotFound()); } }
public async Task <IActionResult> Post([FromBody] CollectedDataDto collectedDataDto) { try { var collectedData = await _dataAggregatorService.AddEntityAsync(collectedDataDto); return(CreatedAtRoute("GetDataAggregator", new { id = collectedDataDto.Id }, collectedData)); } catch (Exception e) { LogError(e); Console.WriteLine(e); return(StatusCode(500)); } }
public async Task <CollectedDataDto> UpdateEntityAsync(CollectedDataDto collectedDataDto) { var entity = await _repository.GetEntityByInstanceIdAsync(collectedDataDto.Id); if (entity == null) { return(null); } var mappedEntity = _mapper.Map <CollectedDataDto, CollectedData>(collectedDataDto); mappedEntity.InternalId = entity.InternalId; await _repository.UpdateEntity(mappedEntity); return(collectedDataDto); }
public async Task <IActionResult> Put(Guid id, [FromBody] CollectedDataDto collectedDataDto) { try { collectedDataDto.Id = id; await _dataAggregatorService.UpdateEntityAsync(collectedDataDto); return(NoContent()); } catch (NotFoundException e) { return(NotFound()); } catch (Exception e) { LogError(e); Console.WriteLine(e); return(StatusCode(500)); } }
public async Task <IActionResult> Post([FromBody] CollectedDataDto collectedDataDto) { var collectedData = await _dataAccumulatorService.AddEntityAsync(collectedDataDto); return(CreatedAtRoute("GetDataAccumulator", new { id = 213 }, collectedData)); }
private async Task <MessageProcessResponse> OnProcessAsync(InstanceCollectedDataMessage arg, CancellationToken stoppingToken) { if (stoppingToken.IsCancellationRequested) { using (LogContext.PushProperty("ClassName", this.GetType().FullName)) using (LogContext.PushProperty("Source", this.GetType().Name)) { _logger.LogError("Cancellation was requested, stopping token."); } return(MessageProcessResponse.Abandon); } CollectedDataDto collectedDataDto = null; InstanceCheckedDto instanceCheckedDto = null; using (var scope = _scopeFactory.CreateScope()) { var repo = scope.ServiceProvider.GetRequiredService <IDataAccumulatorRepository <CollectedData> >(); var uow = scope.ServiceProvider.GetRequiredService <IUnitOfWork>(); var mapper = scope.ServiceProvider.GetRequiredService <IMapper>(); var data = await repo.GetEntityIdAsync(arg.CollectedDataId); if (data != null) { var result = await uow.InstanceRepository.UpateLastCheckedAsync(arg.InstanceId, data.Time); if (result != null) { await uow.SaveAsync(); instanceCheckedDto = new InstanceCheckedDto { InstanceGuidId = result.GuidId, OrganizationId = result.OrganizationId, StatusCheckedAt = result.StatusCheckedAt }; } collectedDataDto = mapper.Map <CollectedData, CollectedDataDto>(data); } else { return(MessageProcessResponse.Abandon); // No such entity } } var tasks = new List <Task>(2); if (collectedDataDto != null) { tasks.Add(_dashboardsHubContext.Clients.Group(collectedDataDto.ClientId.ToString()).SendAsync("InstanceDataTick", collectedDataDto)); _logger.LogInformation("Information Message with instanceData to Dashboards hub clients was sent."); } if (instanceCheckedDto != null) { tasks.Add(_dashboardsHubContext.Clients.Group(instanceCheckedDto.OrganizationId.ToString()).SendAsync("InstanceStatusCheck", instanceCheckedDto)); _logger.LogInformation("Information Message with instance check tome to Dashboards hub clients was sent."); } await Task.WhenAll(tasks); return(MessageProcessResponse.Complete); }