protected override void Handle(SensorLifetimeRequest request) { RegistryResponse regResponse = LocalRegistry .getSensorRecord(request.NewEvent.SensorName); if (request.NewEvent.lifeStage == LifetimeStages.Startup) { if (regResponse.status == RegistryStatus.noSuchRecord) { LocalRegistry.addSensorRecord(request.NewEvent.SensorName, request.NewEvent.IpAddress, request.NewEvent.ListeningPort, request.NewEvent.LastReadIndex); } else { logger.LogMessage("Startup event for ALREADY registered sensor ... "); } } else { // shutdown event received if (regResponse.status == RegistryStatus.ok) { LocalRegistry.removeSensorRecord(request.NewEvent.SensorName); } else { logger.LogMessage("Shutdown event for NOT registered sensor ... "); } } }
public IActionResult postSensor([FromBody] SensorDataArg reqArg) { Console.WriteLine($"Sensor add trough post request: {reqArg.SensorName}"); RegistryResponse response = sensorRegistry.addSensorRecord(reqArg.SensorName, reqArg.IpAddress, reqArg.PortNum, reqArg.LastReadIndex); if (response.status == RegistryStatus.ok) { return(new OkObjectResult(response.singleData)); } return(new BadRequestObjectResult("Registry response: " + response.status.ToString())); }
protected override async Task Handle( SensorUpdateRequest request, CancellationToken cancellationToken) { RegistryResponse regResponse = LocalRegistry .getSensorRecord(request.NewEvent.SensorName); if (regResponse.status == RegistryStatus.ok) { LocalRegistry.updateSensorRecord( request.NewEvent.SensorName, request.NewEvent.IpAddress, request.NewEvent.ListeningPort, request.NewEvent.LastReadIndex); } else if (regResponse.status == RegistryStatus.noSuchRecord) { // we received event from sensor that is still not registered // this request will check if that sensor is still alive // and return it's info if it is alive var result = await mediator.Send(new CheckSensorInfoRequest( request.NewEvent.SensorName, request.NewEvent.IpAddress, request.NewEvent.ListeningPort)); if (result != null) { LocalRegistry.addSensorRecord( result.SensorName, result.IpAddress, result.ListeningPort, result.LastReadIndex); } } return; }