public ISourceBlock <Pipeline.Telemetry.V0.IGameTelemetry> CreateTelemetrySource() { var mmReader = new MemoryMappedFileReader <Contrib.Data.Shared>(Contrib.Constant.SharedMemoryName); var telemetry = new Telemetry(); return(PollingSource.Create <Pipeline.Telemetry.V0.IGameTelemetry>(_config.PollingInterval, () => telemetry.Transform(mmReader.Read()))); }
public void PollsAtTheConfiguredInterval() { var source = PollingSource.Create(PollingInterval, () => DateTime.Now); var start = DateTime.Now; for (var i = 0; i < (Timeout / PollingInterval); i++) { var timePassed = source.Receive(Timeout).Subtract(start); Assert.Equal(i * PollingInterval.TotalSeconds, timePassed.TotalSeconds, DecimalDigitPrecision); } source.Complete(); }
public void DoesNotEmitWhenFunctionThrows() { var startEmitting = DateTime.Now.Add(Timeout / 2); var source = PollingSource.Create(PollingInterval, () => { var now = DateTime.Now; if (now < startEmitting) { throw new Exception("BOOM!"); } else { return(now); } }); Assert.True(source.Receive(Timeout) > startEmitting); source.Complete(); }
private ISourceBlock <RunningGame> GameProcessPoller(Config config, IEnumerable <IGameProcessInfo> gameProcessInfos) { Dictionary <string, string> gameByProcess = GameByProcess(gameProcessInfos); Func <IEnumerable <string>, IEnumerable <string?> > keepOne = new KeepOne <string>(gameByProcess.Keys).Call; var transformer = new TransformManyBlock <IEnumerable <string>, RunningGame>( processNames => keepOne(processNames).Select(processName => { if (processName == null) { _logger.LogInformation("The game has been closed"); return(new RunningGame(null)); } var game = gameByProcess.GetValueOrDefault(processName); _logger.LogInformation("Found game {string?} (process {string?})", game, processName); return(new RunningGame(game)); }) ); var source = PollingSource.Create(config.PollingInterval, () => Process.GetProcesses().Select(p => p.ProcessName)); source.LinkTo(transformer); transformer.Completion.ContinueWith(_ => source.Complete()); return(transformer); }