public void SetRfidOptions(RfidOptions rfidOptions, bool publishUpdate = true) { logger.Information($"Persisting RfidOptions {rfidOptions}"); rfidOptions.Timestamp = systemClock.UtcNow.UtcDateTime; StorageService.Repo.Upsert(rfidOptions); logger.Swallow(() => messageHub.Publish(rfidOptions)); }
private async Task EnableRfid(RfidOptions options) { logger.Information("Starting RFID"); stream = factory.CreateStream(options.GetConnectionString()); disposable = new CompositeDisposable(stream, stream.Tags.Subscribe(x => { if (options.PersistTags) { logger.Swallow(() => storageService.AppendTag(mapper.Map <Tag>(x))); } AppendRiderId(x.TagId); })); aggregator = TimestampAggregatorConfigurations.ForCheckpoint(TimeSpan.FromMilliseconds(options.CheckpointAggregationWindowMs)); disposable.Add(stream.Connected.CombineLatest(stream.Heartbeat, (con, hb) => new ReaderStatus { IsConnected = con, Heartbeat = hb }) .Subscribe(OnReaderStatus) ); disposable.Add(checkpoints.Subscribe(aggregator)); disposable.Add(aggregator.Subscribe(OnCheckpoint)); disposable.Add(aggregator.AggregatedCheckpoints.Subscribe(OnCheckpoint)); await stream.Start(); }
private void OnRfidOptions(RfidOptions rfidOptions) { logger.Swallow(async() => { logger.Information("Broadcasting rfid options"); await checkpointsHub.Clients.All .SendCoreAsync("RfidOptions", new[] { rfidOptions }); }).Wait(0); }
private void RfidOptionsChanged(RfidOptions options) { DisableRfid(); logger.Information("Using RfidOptions: {options}", options); if (ShouldStartRfid(options)) { logger.SwallowError(() => EnableRfid(options)) .Wait(0); } }
private bool ShouldStartRfid(RfidOptions options) { if (options.Enabled && systemClock.UtcNow.UtcDateTime - options.Timestamp > TimeSpan.FromDays(1)) { options.Enabled = false; storageService.SetRfidOptions(options, false); return(false); } return(options.Enabled); }