private void HandleSimpleChangeGrammar(RecognitionResult eResult) { int program; int volume; using (var context = new SwpEntities()) { volume = context.Settings.First().Volume; } if (eResult.Semantics.ContainsKey(SemanticKey.Volume)) { var v = Convert.ToInt32(eResult.Semantics["volume"].Value); if (v == 0) { volume = 0; } else { volume += v; } ChangeVolume(volume); } if (eResult.Semantics.ContainsKey("program")) { var p = Convert.ToInt32(eResult.Semantics["program"].Value); ChangeProgram(p); } }
private void InitTvContent() { TvChannel currentChannel; Setting currentSettings; using (var context = new SwpEntities()) { currentSettings = context.Settings.FirstAsync().GetAwaiter().GetResult(); currentChannel = currentSettings.TvChannel; } SetChannelDetails(currentChannel); SetProgramDetails(currentChannel); SetVolumeDetails(currentSettings.Volume); }
private void ChangeProgramByPosition(int position) { using (var context = new SwpEntities()) { var channelCount = context.TvChannels.Count(); var currentChannel = context.Settings.First().TvChannel; int nextChannel; if (currentChannel.Id + position == 0) { nextChannel = channelCount; } else { nextChannel = (position + currentChannel.Id - 1) % channelCount + 1; } ChangeProgram(nextChannel); } }
private void ChangeVolume(int volumeValue) { if (volumeValue > 10) { volumeValue = 10; } else if (volumeValue < 0) { volumeValue = 0; } using (var context = new SwpEntities()) { context.Settings.First().Volume = volumeValue; context.SaveChanges(); SetVolumeDetails(volumeValue); } }
private void SetProgram(int channelId) { using (var context = new SwpEntities()) { var currentChannel = context.TvChannels.Find(channelId); if (currentChannel == null) { speechSynthesizer.Speak(string.Format(VoiceCommand.ChannelNotFound, channelId)); return; } context.Settings.First().TvChannel = currentChannel; context.SaveChanges(); CloseProgramDescriptionPanel(); SetChannelDetails(currentChannel); SetProgramDetails(currentChannel); } }