示例#1
0
 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));
 }
示例#2
0
        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();
        }
示例#3
0
 private void OnRfidOptions(RfidOptions rfidOptions)
 {
     logger.Swallow(async() =>
     {
         logger.Information("Broadcasting rfid options");
         await checkpointsHub.Clients.All
         .SendCoreAsync("RfidOptions", new[] { rfidOptions });
     }).Wait(0);
 }
示例#4
0
 private void RfidOptionsChanged(RfidOptions options)
 {
     DisableRfid();
     logger.Information("Using RfidOptions: {options}", options);
     if (ShouldStartRfid(options))
     {
         logger.SwallowError(() => EnableRfid(options))
         .Wait(0);
     }
 }
示例#5
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);
        }