public VocabularyBrowserViewModel( IReduxStore <WordTutorApplication> store, ILogger logger) { if (logger is null) { throw new ArgumentNullException(nameof(logger)); } _store = store ?? throw new ArgumentNullException(nameof(store)); _logger = logger.Action("Browse Vocabulary List"); var screen = (VocabularyBrowserScreen)_store.State.CurrentScreen; var vocab = _store.State.VocabularySet.Words; _selection = screen.Selection; _modified = screen.Modified; Words = new ObservableCollection <VocabularyWord>( vocab.OrderBy(w => w.Spelling)); _screenSubscription = _store.SubscribeToReference( app => app.CurrentScreen as VocabularyBrowserScreen, RefreshFromScreen); _vocabularySubscription = _store.SubscribeToReference( app => app.VocabularySet, RefreshFromVocabularySet); AddWordCommand = new RoutedCommandSink(ItemCommands.New, AddWord); ModifyWordCommand = new RoutedCommandSink <VocabularyWord>( ItemCommands.Open, ModifyWord, CanModifyWord); }
public ModifyVocabularyWordViewModel( IReduxStore <WordTutorApplication> store, ILogger logger) { if (logger is null) { throw new ArgumentNullException(nameof(logger)); } _store = store ?? throw new ArgumentNullException(nameof(store)); var screen = _store.State.CurrentScreen as ModifyVocabularyWordScreen; var areAdding = screen?.ExistingWord is null; _logger = logger.Action( areAdding ? "Create Vocabulary Word" : "Modify Vocabulary Word"); _spelling = screen?.Spelling ?? string.Empty; _phrase = screen?.Phrase ?? string.Empty; _pronunciation = screen?.Pronunciation ?? string.Empty; _caption = areAdding ? "Add Word" : "Modify Word"; _screenSubscription = _store.SubscribeToReference( app => app.CurrentScreen as ModifyVocabularyWordScreen, RefreshFromScreen); SpeakCommand = new RoutedCommandSink <string>( VoiceCommands.StartSpeaking, Speak, CanSpeak, this); SaveCommand = new RoutedCommandSink( ItemCommands.Save, Save, CanSave); CloseCommand = new RoutedCommandSink( ItemCommands.Close, Close); }
/// <summary> /// Write details of an action /// </summary> /// <param name="logger">Logger to use for logging.</param> /// <param name="messageTemplate">Template for the message to write.</param> /// <param name="parameters">Parameters to substitute in the template.</param> public static void Action(this ILogger logger, string messageTemplate, params object[] parameters) { if (logger == null) { throw new ArgumentNullException(nameof(logger)); } logger.Action(string.Format(CultureInfo.CurrentCulture, messageTemplate, parameters)); }
/// <summary> /// Write details of several actions, using tabs to create a table /// </summary> /// <param name="logger">Logger to use for logging.</param> /// <param name="messages">The messages to write.</param> public static void Action(this ILogger logger, IEnumerable <string> messages) { if (logger == null) { throw new ArgumentNullException(nameof(logger)); } foreach (var line in Tablefy(messages)) { logger.Action(line); } }
public async Task SayAsync(string content) { using var logger = _logger.Action($"Say {content}"); try { var speech = await _renderSpeechService.RenderSpeechAsync(content).ConfigureAwait(false); _player.Stop(); speech.Seek(0, SeekOrigin.Begin); _player.Stream = speech; _player.Play(); } catch (RenderSpeechException ex) { logger.Failure(ex.Message); } }