/// <inheritdoc/> public async Task <bool> DeleteRecordByIdAsync(int id) { var recordFound = await _sensorContext.Records.FirstOrDefaultAsync(r => r.Id == id); if (recordFound == null) { _logger.LogError(RecordsConstants.RECORD_NOT_FOUND); return(false); } _sensorContext.Remove(recordFound); await _sensorContext.SaveChangesAsync(new CancellationToken()); await _recordDeletedEventProducer.Publish(recordFound.Id); return(true); }
public static Task BroadcastTopic <T>(this IEventProducer producer, T data, string exchange = null) { _ = producer ?? throw new ArgumentNullException(nameof(producer)); return(producer.Publish(new EventItem { EventType = EventType.Topic, Data = ObjectToBytes(data), Exchange = string.IsNullOrEmpty(exchange) ? typeof(T).FullName : exchange })); }
/// <inheritdoc/> public async Task <bool> DeleteSensorByIdAsync(int id) { var sensorFound = await _sensorContext.Sensors.FirstOrDefaultAsync(s => s.Id == id); if (sensorFound == null) { _logger.LogError(SensorsConstants.SENSOR_NOT_FOUND); return(false); } _sensorContext.Remove(sensorFound); await _recordService.DeleteAllRecordsBySensorIdAsync(sensorFound.Id); await _sensorContext.SaveChangesAsync(new CancellationToken()); await _sensorDeletedEventProducer.Publish(sensorFound.Id); return(true); }
/// <inheritdoc/> public async Task <bool> DeleteProfileByIdAsync(Guid id) { var profileFound = await _profileContext.Profiles.FirstOrDefaultAsync(p => p.Id == id); if (profileFound == null) { _logger.Error(ProfileConstants.PROFILE_NOT_FOUND); return(false); } _profileContext.Remove(profileFound); await _profileContext.SaveChangesAsync(new CancellationToken()); // Publish event on user deleted (profile + account). await _userDeletedEventProducer.Publish(new UserDTO { ProfileId = profileFound.Id, AccountId = profileFound.AccountId, }); return(true); }
/// <inheritdoc/> public async Task <bool> DeleteAccountByIdAsync(Guid accountId) { var account = await _identityContext.Accounts.FirstOrDefaultAsync(a => a.Id == accountId); if (account == null) { Log.Error(AccountConstants.ACCOUNT_NOT_FOUND); return(false); } _identityContext.Remove(account); await _identityContext.SaveChangesAsync(new CancellationToken()); await _accountDeletedEventProducer.Publish(accountId); return(true); }
private void PublishStateChangeFailed(IEventProducer eventProducer, string environment, string state, Exception ex) { eventProducer.Publish(new ServiceHostStateChangeFailed() { Environment = environment, Process = this.Process, State = state, Exception = ex }); }
private void PublishStateChange(IEventProducer eventProducer, string environment, string state) { eventProducer.Publish(new ServiceHostStateChange() { Environment = environment, Process = this.Process, State = state }); }
private void PublishStateChangeFailed(IEventProducer eventProducer, string state, Exception ex) { eventProducer.Publish(new ServiceHostComponentStateChangeFailed() { Environment = this.Environment, Process = this.Process, ServiceComponent = this.ServiceComponentData.FriendlyName, State = state, Exception = ex }); }