public void GetSettings_DefaultValue() { var socket = new Socket(1, "Test"); var defaultSettings = SoundSocketSnifferSettings.GetDefault(); var stateStore = new SoundSnifferStateStore(); Assert.Equal(defaultSettings, stateStore.GetSettings(socket)); }
public void GetSettings_SetAndGet() { var socket = new Socket(1, "Test"); var settings = new SoundSocketSnifferSettings(TimeSpan.FromSeconds(50), TimeSpan.FromSeconds(7)); var stateStore = new SoundSnifferStateStore(); stateStore.SetSettings(socket, settings); Assert.Equal(settings, stateStore.GetSettings(socket)); }
private void _timer_Elapsed(object sender, ElapsedEventArgs e) { var sockets = _stateStore.GetSockets(); bool isPlaying = isAudioPlaying(); var lastSignal = _stateStore.GetLastSignal(); var signalDuration = _stateStore.GetSignalDuration(); foreach (var socket in sockets) { var settings = _stateStore.GetSettings(socket); var status = _stateStore.GetStatus(socket); var signalIdle = DateTime.Now - lastSignal; bool turnSocketOn = signalDuration > settings.MinimumSignalDuration && status != PowerStatus.On; bool turnSocketOff = signalIdle >= settings.OffDelay && status != PowerStatus.Off; if (turnSocketOn) { _stateStore.SetStatus(socket, PowerStatus.On); StatusChanged?.Invoke(this, new StatusChangedEventArgs("", "", socket, PowerStatus.On)); } else if (turnSocketOff) { _stateStore.SetStatus(socket, PowerStatus.Off); StatusChanged?.Invoke(this, new StatusChangedEventArgs("", "", socket, PowerStatus.Off)); } fireStatusForecastEvent(socket, signalIdle, settings.OffDelay); } if (isPlaying) { _stateStore.SetSignalDuration(signalDuration + TimeSpan.FromSeconds(((Timer)sender).Interval / 1000)); _stateStore.SetLastSignal(DateTime.Now); } else { _stateStore.SetSignalDuration(TimeSpan.FromSeconds(0)); } }