public OnAirService(IActiveProcessesService activeProcessesService, IPhillipsHueService phillipsHueService) { Ensure.ArgumentNotNull(activeProcessesService, nameof(activeProcessesService)); Ensure.ArgumentNotNull(phillipsHueService, nameof(phillipsHueService)); _activeProcessesService = activeProcessesService; _phillipsHueService = phillipsHueService; _activeProcessesService.ProcessNames.Connect().Subscribe(x => { Log.Debug("{Process}", x); }); // note: throwing away subscription reference because this is a single activation singleton (ie. memory leak isn't a concern) this.WhenAnyValue(x => x._activeProcessesService.ProcessNames, x => x._activeProcessesService.WindowTitles) .Do(tuple => Log.Verbose("The following {Processes} and {WindowTitles} are currently active", tuple.Item1, tuple.Item2)) .Where(tuple => ProcessesMatch(tuple.Item1) || WindowTitlesMatch(tuple.Item2)) .Select(tuple => { if (tuple.Item1.Count > 0 || tuple.Item2.Count > 0) { Log.Information("{Matches} detected which means the light will turn on", tuple); return(true); } return(false); }) .Do(boolean => Log.Information("The IsOnAir light is now {Status}", boolean)) .ToProperty(this, x => x.IsOnAir, out _isOnAir); // note: throwing away subscription reference because this is a single activation singleton (ie. memory leak isn't a concern) this.WhenAnyValue(vm => vm.IsOnAir, vm => vm._phillipsHueService.Lights) .Subscribe(async _ => { try { await ActivateOfficeDoorLight(IsOnAir, _phillipsHueService.Lights); } catch (Exception ex) { Log.Error(ex, "Failed change the lighting state"); } }); }
public OnAirServiceBuilder WithActiveProcessesService(IActiveProcessesService activeProcessesService) => this.With(ref _activeProcessesService, activeProcessesService);