Ejemplo n.º 1
0
        public OverlayService(IStatisticProvider statisticProvider,
                              IRecordDataProvider recordDataProvider,
                              IOverlayEntryProvider overlayEntryProvider,
                              IAppConfiguration appConfiguration,
                              ILogger <OverlayService> logger)
            : base(ExceptionAction)
        {
            _statisticProvider    = statisticProvider;
            _recordDataProvider   = recordDataProvider;
            _overlayEntryProvider = overlayEntryProvider;
            _appConfiguration     = appConfiguration;
            _logger = logger;

            _refreshPeriod          = _appConfiguration.OSDRefreshPeriod;
            _numberOfRuns           = _appConfiguration.SelectedHistoryRuns;
            SecondMetric            = _appConfiguration.SecondMetricOverlay;
            ThirdMetric             = _appConfiguration.ThirdMetricOverlay;
            IsOverlayActiveStream   = new Subject <bool>();
            _runHistoryOutlierFlags = Enumerable.Repeat(false, _numberOfRuns).ToArray();

            _logger.LogDebug("{componentName} Ready", this.GetType().Name);
            SetOverlayEntries(overlayEntryProvider?.GetOverlayEntries());
            overlayEntryProvider.EntryUpdateStream.Subscribe(x =>
            {
                SetOverlayEntries(overlayEntryProvider?.GetOverlayEntries());
            });

            _runHistory = Enumerable.Repeat("N/A", _numberOfRuns).ToList();
            SetRunHistory(_runHistory.ToArray());
            SetRunHistoryAggregation(string.Empty);
            SetRunHistoryOutlierFlags(_runHistoryOutlierFlags);
            SetIsCaptureTimerActive(false);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        public OverlayViewModel(IOverlayService overlayService, IOverlayEntryProvider overlayEntryProvider,
                                IAppConfiguration appConfiguration, IEventAggregator eventAggregator, ISensorService sensorService, IRTSSService rTSSService)
        {
            _overlayService       = overlayService;
            _overlayEntryProvider = overlayEntryProvider;
            _appConfiguration     = appConfiguration;
            _eventAggregator      = eventAggregator;
            _sensorService        = sensorService;
            _rTSSService          = rTSSService;
            var configSubject = new Subject <object>();

            ConfigSwitchCommand = new DelegateCommand <object>(configSubject.OnNext);
            configSubject
            .Select(obj => Convert.ToInt32(obj)).DistinctUntilChanged()
            .SelectMany(index =>
            {
                return(Observable.FromAsync(() => _overlayEntryProvider.SwitchConfigurationTo(index))
                       .SelectMany(_ => _sensorService.OnDictionaryUpdated.Take(1)));
            })
            .StartWith(Enumerable.Empty <IOverlayEntry>())
            .SelectMany(_ => _overlayEntryProvider.GetOverlayEntries())
            .ObserveOnDispatcher()
            .Subscribe(entries =>
            {
                OverlayEntries.Clear();
                OverlayEntries.AddRange(entries);
                OnUseRunHistoryChanged();
            });

            SaveConfigCommand = new DelegateCommand(
                () => _overlayEntryProvider.SaveOverlayEntriesToJson());

            ResetDefaultsCommand = new DelegateCommand(
                async() => await OnResetDefaults());

            UpdateHpyerlinkText = "To use the overlay, install the latest" + Environment.NewLine +
                                  "RivaTuner  Statistics  Server  (RTSS)";

            SetGlobalHookEventOverlayHotkey();
            SetGlobalHookEventResetHistoryHotkey();
        }
Ejemplo n.º 4
0
        public OverlayViewModel(IOverlayService overlayService, IOverlayEntryProvider overlayEntryProvider,
                                IAppConfiguration appConfiguration, IEventAggregator eventAggregator)
        {
            _overlayService       = overlayService;
            _overlayEntryProvider = overlayEntryProvider;
            _appConfiguration     = appConfiguration;
            _eventAggregator      = eventAggregator;

            if (IsOverlayActive)
            {
                _overlayService.ShowOverlay();
            }

            IsRTSSInstalled     = !string.IsNullOrEmpty(RTSSUtils.GetRTSSFullPath());
            UpdateHpyerlinkText = "To use the overlay, install the latest" + Environment.NewLine +
                                  "RivaTuner  Statistics  Server  (RTSS)";

            OverlayEntries.AddRange(_overlayEntryProvider.GetOverlayEntries());

            SetGlobalHookEventOverlayHotkey();
            SetGlobalHookEventResetHistoryHotkey();
        }
Ejemplo n.º 5
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));
        }
Ejemplo n.º 6
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));
        }