public Task SendDataMessage(Guid instanceId, Guid dataId) { var message = new InstanceCollectedDataMessage { InstanceId = instanceId, CollectedDataId = dataId }; return(_azureQueueSender.SendAsync(_instanceDataQueueClient, message)); }
public async Task <CollectedDataDto> AddEntityAsync(CollectedDataDto collectedDataDto) { if (collectedDataDto?.Id == Guid.Empty) { collectedDataDto.Id = Guid.NewGuid(); } var mappedEntity = _mapper.Map <CollectedDataDto, CollectedData>(collectedDataDto); await _repository.AddEntity(mappedEntity); // Thresholds Validator await _thresholdsValidatorCore.Validate(collectedDataDto); var message = new InstanceCollectedDataMessage { CollectedDataId = mappedEntity.Id, InstanceId = mappedEntity.ClientId }; await _serviceBusProvider.SendDataMessage(message); return(collectedDataDto); }
public Task SendDataMessage(InstanceCollectedDataMessage message) { return(_azureQueueSender.SendAsync(_instanceDataQueueClient, message)); }
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); }