public void Visit(IAsyncMvvmCommand command) { var errorTitleKey = string.Concat(command.Name, TitleResourceKeySuffix); var errorContentKey = string.Concat(command.Name, ContentResourceKeySuffix); var errorTitle = _resources.Get(errorTitleKey); var errorContent = _resources.Get(errorContentKey); var isDefault = command.SetDefaultError(async(ct, ex) => { await _messageDialog.Show(ct, errorTitle, errorContent); }); if (isDefault && (string.IsNullOrEmpty(errorTitle) || string.IsNullOrEmpty(errorContent))) { var sb = new StringBuilder(); sb.AppendLine(string.Concat("Resources missing for command ", command.Name)); sb.AppendLine("Missing resources keys :"); if (string.IsNullOrEmpty(errorTitle)) { sb.AppendLine(errorTitleKey); } if (string.IsNullOrEmpty(errorContent)) { sb.AppendLine(errorContentKey); } throw new InvalidOperationException(sb.ToString()); } }
/// <summary> /// Observe the settings panel activation and adds command. /// </summary> /// <param name="observer"></param> /// <returns></returns> public IDisposable Subscribe(IObserver <Unit> observer) { return(Observable.Defer(() => { var settingsPane = SettingsPane.GetForCurrentView(); return Observable.FromEventPattern <TypedEventHandler <SettingsPane, SettingsPaneCommandsRequestedEventArgs>, SettingsPaneCommandsRequestedEventArgs>( h => settingsPane.CommandsRequested += h, h => settingsPane.CommandsRequested -= h, _dispatcher); }) .Do(args => { var settingsArgs = args.EventArgs; foreach (var commandDefinition in _commandDefinitions.Where(d => d.Command(_viewModel.Value).CanExecute(null))) { CommandDefinition definition = commandDefinition; settingsArgs.Request.ApplicationCommands.Add(new SettingsCommand( commandDefinition.Id, _resources.Get(commandDefinition.TitleKey), command => definition.Command(_viewModel.Value).Execute(null))); } }) .SelectUnit() .Subscribe(observer)); }