Example #1
0
        public OverlayService(IStatisticProvider statisticProvider,
                              ISensorService sensorService,
                              IOverlayEntryProvider overlayEntryProvider,
                              IAppConfiguration appConfiguration,
                              ILogger <OverlayService> logger,
                              IRecordManager recordManager,
                              IRTSSService rTSSService)
        {
            _statisticProvider    = statisticProvider;
            _overlayEntryProvider = overlayEntryProvider;
            _appConfiguration     = appConfiguration;
            _logger                 = logger;
            _recordManager          = recordManager;
            _rTSSService            = rTSSService;
            _numberOfRuns           = _appConfiguration.SelectedHistoryRuns;
            SecondMetric            = _appConfiguration.SecondMetricOverlay;
            ThirdMetric             = _appConfiguration.ThirdMetricOverlay;
            IsOverlayActiveStream   = new BehaviorSubject <bool>(_appConfiguration.IsOverlayActive);
            _runHistoryOutlierFlags = Enumerable.Repeat(false, _numberOfRuns).ToArray();

            _logger.LogDebug("{componentName} Ready", this.GetType().Name);

            IsOverlayActiveStream.AsObservable()
            .Select(isActive =>
            {
                if (isActive)
                {
                    _rTSSService.ResetOSD();
                    return(sensorService.OnDictionaryUpdated
                           .SelectMany(_ => _overlayEntryProvider.GetOverlayEntries()));
                }
                else
                {
                    _rTSSService.ReleaseOSD();
                    return(Observable.Empty <IOverlayEntry[]>());
                }
            }).Switch()
            .Subscribe(entries =>
            {
                _rTSSService.SetOverlayEntries(entries);
                _rTSSService.CheckRTSSRunningAndRefresh();
            });

            _runHistory = Enumerable.Repeat("N/A", _numberOfRuns).ToList();
            _rTSSService.SetRunHistory(_runHistory.ToArray());
            _rTSSService.SetRunHistoryAggregation(string.Empty);
            _rTSSService.SetRunHistoryOutlierFlags(_runHistoryOutlierFlags);
            _rTSSService.SetIsCaptureTimerActive(false);
        }
Example #2
0
        public OverlayService(IStatisticProvider statisticProvider,
                              ISensorService sensorService,
                              IOverlayEntryProvider overlayEntryProvider,
                              IAppConfiguration appConfiguration,
                              ILogger <OverlayService> logger,
                              IRecordManager recordManager,
                              IRTSSService rTSSService,
                              IOverlayEntryCore overlayEntryCore)
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            _statisticProvider    = statisticProvider;
            _overlayEntryProvider = overlayEntryProvider;
            _appConfiguration     = appConfiguration;
            _logger           = logger;
            _recordManager    = recordManager;
            _sensorService    = sensorService;
            _rTSSService      = rTSSService;
            _overlayEntryCore = overlayEntryCore;

            _numberOfRuns           = _appConfiguration.SelectedHistoryRuns;
            SecondMetric            = _appConfiguration.RunHistorySecondMetric;
            ThirdMetric             = _appConfiguration.RunHistoryThirdMetric;
            IsOverlayActiveStream   = new BehaviorSubject <bool>(_appConfiguration.IsOverlayActive);
            _runHistoryOutlierFlags = Enumerable.Repeat(false, _numberOfRuns).ToArray();

            _logger.LogDebug("{componentName} Ready", this.GetType().Name);

            Task.Run(async() => await InitializeOverlayEntryDict())
            .ContinueWith(t =>
            {
                IsOverlayActiveStream
                .AsObservable()
                .Select(isActive =>
                {
                    if (isActive)
                    {
                        _rTSSService.CheckRTSSRunning().Wait();
                        _rTSSService.OnOSDOn();
                        _rTSSService.ClearOSD();
                        return(_onDictionaryUpdated.
                               SelectMany(_ => _overlayEntryProvider.GetOverlayEntries()));
                    }
                    else
                    {
                        _rTSSService.ReleaseOSD();
                        return(Observable.Empty <IOverlayEntry[]>());
                    }
                })
                .Switch()
                .Subscribe(async entries =>
                {
                    _rTSSService.SetOverlayEntries(entries);
                    await _rTSSService.CheckRTSSRunningAndRefresh();
                });
            });



            _sensorService.SensorSnapshotStream
            .Sample(_sensorService.OsdUpdateStream.Select(timespan => Observable.Concat(Observable.Return(-1L), Observable.Interval(timespan))).Switch())
            .Where((_, idx) => idx == 0 || IsOverlayActive)
            .SubscribeOn(Scheduler.Default)
            .Subscribe(sensorData =>
            {
                UpdateOverlayEntries(sensorData.Item2);
                _onDictionaryUpdated.OnNext(_overlayEntryCore.OverlayEntryDict.Values.ToArray());
            });

            _runHistory = Enumerable.Repeat("N/A", _numberOfRuns).ToList();
            _rTSSService.SetRunHistory(_runHistory.ToArray());
            _rTSSService.SetRunHistoryAggregation(string.Empty);
            _rTSSService.SetRunHistoryOutlierFlags(_runHistoryOutlierFlags);
            _rTSSService.SetIsCaptureTimerActive(false);

            stopwatch.Stop();
            _logger.LogInformation(GetType().Name + " {initializationTime}s initialization time", Math.Round(stopwatch.ElapsedMilliseconds * 1E-03, 1));
        }
Example #3
0
        public OverlayService(IStatisticProvider statisticProvider,
                              ISensorService sensorService,
                              IOverlayEntryProvider overlayEntryProvider,
                              IAppConfiguration appConfiguration,
                              ILogger <OverlayService> logger,
                              IRecordManager recordManager,
                              IRTSSService rTSSService)
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            _statisticProvider    = statisticProvider;
            _overlayEntryProvider = overlayEntryProvider;
            _appConfiguration     = appConfiguration;
            _logger                 = logger;
            _recordManager          = recordManager;
            _rTSSService            = rTSSService;
            _numberOfRuns           = _appConfiguration.SelectedHistoryRuns;
            SecondMetric            = _appConfiguration.SecondMetricOverlay;
            ThirdMetric             = _appConfiguration.ThirdMetricOverlay;
            IsOverlayActiveStream   = new BehaviorSubject <bool>(_appConfiguration.IsOverlayActive);
            _runHistoryOutlierFlags = Enumerable.Repeat(false, _numberOfRuns).ToArray();

            _logger.LogDebug("{componentName} Ready", this.GetType().Name);

            IsOverlayActiveStream.AsObservable()
            .Select(isActive =>
            {
                if (isActive)
                {
                    TryCloseRTSS();
                    _rTSSService.CheckRTSSRunning().Wait();
                    _rTSSService.ResetOSD();
                    return(sensorService.OnDictionaryUpdated
                           .SelectMany(_ => _overlayEntryProvider.GetOverlayEntries()));
                }
                else
                {
                    // OSD status logging
                    Task.Run(async() =>
                    {
                        var processId = await _rTSSService.ProcessIdStream.Take(1);
                        try
                        {
                            _logger.LogInformation("Is process {detectedProcess} detected: {isDetected}", processId, _rTSSService.IsProcessDetected(processId));
                        }
                        catch
                        {
                            _logger.LogError("Error while checking RTSS core process detection");
                        }

                        //try
                        //{
                        //    _logger.LogInformation("Is OS locked: {isLocked}", _rTSSService.IsOSDLocked());
                        //}
                        //catch
                        //{
                        //    _logger.LogError("Error while checking RTSS core OSD lock status");
                        //}
                    }).Wait();

                    _rTSSService.ReleaseOSD();
                    return(Observable.Empty <IOverlayEntry[]>());
                }
            }).Switch()
            .SubscribeOn(Scheduler.Default)
            .Subscribe(async entries =>
            {
                _rTSSService.SetOverlayEntries(entries);
                await _rTSSService.CheckRTSSRunningAndRefresh();
            });

            _runHistory = Enumerable.Repeat("N/A", _numberOfRuns).ToList();
            _rTSSService.SetRunHistory(_runHistory.ToArray());
            _rTSSService.SetRunHistoryAggregation(string.Empty);
            _rTSSService.SetRunHistoryOutlierFlags(_runHistoryOutlierFlags);
            _rTSSService.SetIsCaptureTimerActive(false);

            stopwatch.Stop();
            _logger.LogInformation(GetType().Name + " {initializationTime}s initialization time", Math.Round(stopwatch.ElapsedMilliseconds * 1E-03, 1));
        }