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 ... ");
                }
            }
        }
Exemple #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;
        }