Пример #1
0
        public IActionResult updateSensor([FromBody] SensorDataArg reqArg)
        {
            ServiceConfiguration conf = ServiceConfiguration.Instance;

            RegistryResponse response = sensorRegistry.updateSensorRecord(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()));
        }
Пример #2
0
        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;
        }