/// <summary> /// Updates the suggestion source of a suggestion. /// </summary> /// <param name="index">The index of a suggestion.</param> /// <param name="suggestionSource">The new suggestion source.</param> public void UpdateSuggestionSource(int index, SuggestionSource suggestionSource) { Validation.CheckArgument <ArgumentOutOfRangeException>((index >= 0) && (index < _suggestionSources.Count), $"{nameof(index)} is out of range."); _suggestionSources[index] = suggestionSource; CheckObjectInvariant(); }
public void TestSizeForTwoSuggestions(string suggestion1, SuggestionSource source1, string suggestion2, SuggestionSource source2, bool isCancelled, string userInput) { // The text in the telemetry data is like // { "Found":[["Get-AzSubscription",3],["Get-AzSecurityPricing -DefaultProfile <IAzureContextContainer>",1]],"IsCanclled":"False","UserInput":"ge" } var commandLineSuggestion = new CommandLineSuggestion(); commandLineSuggestion.AddSuggestion(new PredictiveSuggestion(suggestion1, null), suggestion1, source1); commandLineSuggestion.AddSuggestion(new PredictiveSuggestion(suggestion2, null), suggestion2, source2); var suggestionSession = new SuggestionSession() { FoundSuggestion = commandLineSuggestion, IsCancellationRequested = isCancelled, UserInput = userInput, IsSuggestionComplete = true, }; var expectedSize = GetSuggestionTelemetryData.PropertyNameFound.Length + SuggestionSessionTests._AdditionalSizeForKey + suggestion1.Length + SuggestionSessionTests._AdditionalSizeForString + 1 // For the one digit of source1 + SuggestionSessionTests._AdditionalSizeForTwoElementArray // for [,] + suggestion2.Length + SuggestionSessionTests._AdditionalSizeForString + 1 // for the one digit of source2 + SuggestionSessionTests._AdditionalSizeForTwoElementArray // for [,] + SuggestionSessionTests._AdditionalSizeForTwoElementArray // for [,] in Found + GetSuggestionTelemetryData.PropertyNameUserInput.Length + SuggestionSessionTests._AdditionalSizeForKey + userInput.Length + SuggestionSessionTests._AdditionalSizeForString + GetSuggestionTelemetryData.PropertyNameIsCancelled.Length + SuggestionSessionTests._AdditionalSizeForKey + isCancelled.ToString(CultureInfo.InvariantCulture).Length; Assert.Equal(expectedSize, suggestionSession.EstimateTelemetrySize); }
public void TestSizeForAcceptSuggestion(string suggestion, SuggestionSource source, bool isCancelled, string userInput, string acceptedSuggestion) { // The text in the telemetry data is like // { "Found":[["Get-AzSubscription",3]],"IsCanclled":"False","UserInput":"ge","Accepted":"Get-AzSubscription" } var commandLineSuggestion = new CommandLineSuggestion(); commandLineSuggestion.AddSuggestion(new PredictiveSuggestion(suggestion, null), suggestion, source); var suggestionSession = new SuggestionSession() { FoundSuggestion = commandLineSuggestion, IsCancellationRequested = isCancelled, UserInput = userInput, AcceptedSuggestion = acceptedSuggestion, IsSuggestionComplete = true, }; var expectedSize = GetSuggestionTelemetryData.PropertyNameFound.Length + SuggestionSessionTests._AdditionalSizeForKey + suggestion.Length + SuggestionSessionTests._AdditionalSizeForString + 1 // For the one digit of source + SuggestionSessionTests._AdditionalSizeForTwoElementArray // for [,] + SuggestionSessionTests._AdditionalSizeForArrayBracket // for [] in Found + GetSuggestionTelemetryData.PropertyNameUserInput.Length + SuggestionSessionTests._AdditionalSizeForKey + userInput.Length + SuggestionSessionTests._AdditionalSizeForString + GetSuggestionTelemetryData.PropertyNameIsCancelled.Length + SuggestionSessionTests._AdditionalSizeForKey + isCancelled.ToString(CultureInfo.InvariantCulture).Length + SuggestionAcceptedTelemetryData.PropertyNameAccepted.Length + SuggestionSessionTests._AdditionalSizeForKey + acceptedSuggestion.Length + SuggestionSessionTests._AdditionalSizeForString; Assert.Equal(expectedSize, suggestionSession.EstimateTelemetrySize); }
Suggestions(string keyword, string subtitle, SearchSource searchSource) { SuggestionSource source = _settings.SelectedSuggestion; if (source != null) { List <string> suggestions = await source.Suggestions(keyword); IEnumerable <Result> resultsFromSuggestion = suggestions.Select(o => new Result { Title = o, SubTitle = subtitle, Score = 5, IcoPath = searchSource.IconPath, Action = c => { Process.Start(searchSource.Url.Replace("{q}", Uri.EscapeDataString(o))); return(true); } }); return(resultsFromSuggestion); } return(new List <Result>()); }
private async Task <IEnumerable <Result> > Suggestions(string keyword, string subtitle, WebSearch webSearch) { var source = SuggestionSource.GetSuggestionSource(_settings.WebSearchSuggestionSource, Context); if (source != null) { var suggestions = await source.GetSuggestions(keyword); var resultsFromSuggestion = suggestions.Select(o => new Result { Title = o, SubTitle = subtitle, Score = 5, IcoPath = webSearch.IconPath, Action = c => { Process.Start(webSearch.Url.Replace("{q}", Uri.EscapeDataString(o))); return(true); } }); return(resultsFromSuggestion); } return(new List <Result>()); }
/// <summary> /// Adds a new suggestion. /// </summary> /// <param name="predictiveSuggestion">The suggestion to show to the user.</param> /// <param name="sourceText">The text that used to construct <paramref name="predictiveSuggestion"/>.</param> /// <param name="suggestionSource">The source where the suggestion is from.</param> /// <returns>True if the suggestion is added. Otherwise, it returns false.</returns> public bool AddSuggestion(PredictiveSuggestion predictiveSuggestion, string sourceText, SuggestionSource suggestionSource) { Validation.CheckArgument(predictiveSuggestion, $"{nameof(predictiveSuggestion)} cannot be null."); Validation.CheckArgument(!string.IsNullOrWhiteSpace(predictiveSuggestion.SuggestionText), $"{nameof(predictiveSuggestion)} cannot have a null or whitespace suggestion text."); Validation.CheckArgument(!string.IsNullOrWhiteSpace(sourceText), $"{nameof(sourceText)} cannot be null or whitespace."); for (var i = 0; i < _predictiveSuggestions.Count; ++i) { if (string.Equals(_predictiveSuggestions[i].SuggestionText, predictiveSuggestion.SuggestionText, StringComparison.Ordinal)) { return(false); } } _predictiveSuggestions.Add(predictiveSuggestion); _sourceTexts.Add(sourceText); _suggestionSources.Add(suggestionSource); CheckObjectInvariant(); return(true); }
/// <summary> /// Adds a new suggestion. /// </summary> /// <param name="predictiveSuggestion">The suggestion to show to the user.</param> /// <param name="sourceText">The text that used to construct <paramref name="predictiveSuggestion"/>.</param> /// <param name="suggestionSource">The source where the suggestion is from.</param> public void AddSuggestion(PredictiveSuggestion predictiveSuggestion, string sourceText, SuggestionSource suggestionSource) { Validation.CheckArgument(predictiveSuggestion, $"{nameof(predictiveSuggestion)} cannot be null."); Validation.CheckArgument(!string.IsNullOrWhiteSpace(predictiveSuggestion.SuggestionText), $"{nameof(predictiveSuggestion)} cannot have a null or whitespace suggestion text."); Validation.CheckArgument(!string.IsNullOrWhiteSpace(sourceText), $"{nameof(sourceText)} cannot be null or whitespace."); _predictiveSuggestions.Add(predictiveSuggestion); _sourceTexts.Add(sourceText); _suggestionSources.Add(suggestionSource); CheckObjectInvariant(); }