static void Main(string[] args) { List <Product> products = new List <Product>(); products.Add(new Product() { Name = "Samsung Galaxy Note 8", Suggest = new CompletionField() { Input = new[] { "Samsung Galaxy Note 8", "Galaxy Note 8", "Note 8" } } }); products.Add(new Product() { Name = "Samsung Galaxy S8", Suggest = new CompletionField() { Input = new[] { "Samsung Galaxy S8", "Galaxy S8", "S8" } } }); products.Add(new Product() { Name = "Apple Iphone 8", Suggest = new CompletionField() { Input = new[] { "Apple Iphone 8", "Iphone 8" } } }); products.Add(new Product() { Name = "Apple Iphone X", Suggest = new CompletionField() { Input = new[] { "Apple Iphone X", "Iphone X" } } }); products.Add(new Product() { Name = "Apple iPad Pro", Suggest = new CompletionField() { Input = new[] { "Apple iPad Pro", "iPad Pro" } } }); var connectionSettings = new ConnectionSettings(new Uri("http://localhost:9200")); IAutocompleteService autocompleteService = new AutocompleteService(connectionSettings); string productSuggestIndex = "product_suggest"; bool isCreated = autocompleteService.CreateIndexAsync(productSuggestIndex).Result; if (isCreated) { autocompleteService.IndexAsync(productSuggestIndex, products).Wait(); } }
public async Task GetByTerm_ExistingValidSearchTerm_ListOfOccurrences() { var repository = new Mock <IAutocompleteRepository>(); var existingValidSearchTerm = "bu"; repository.Setup(r => r.GetByTerm(existingValidSearchTerm)).ReturnsAsync(new List <UserActivityResponse> { new UserActivityResponse { Event = "buy", TimeStamp = new DateTimeOffset(DateTime.Now) }, new UserActivityResponse { Event = "buy", TimeStamp = new DateTimeOffset(DateTime.Now) }, new UserActivityResponse { Event = "build", TimeStamp = new DateTimeOffset(DateTime.Now) } }); var service = new AutocompleteService(repository.Object); var result = await service.GetByTerm(existingValidSearchTerm); Assert.Equal(3, result.ToList().Count); }
private bool TryRegisterAutocompleteServer() { Object sessionRValueValue = GetSession(); bool returnValue = false; if (sessionRValueValue != null && sessionRValueValue != sessionCache) { AutocompleteService autocompleteService = AutocompleteClient.GetAutocompleteService(); if (autocompleteService != null) { try { ((IClientChannel)autocompleteService).Close(); } catch { } } sessionCache = sessionRValueValue; MethodInfo methodInfo = fsiAssembly.GetType("Microsoft.VisualStudio.FSharp.Interactive.Session+Session").GetMethod("get_Input"); dynamic fsiProcess = methodInfo.Invoke((Object)sessionRValueValue, null); fsiProcess.Invoke("printfn \"Registering Autocomplete provider\";;"); fsiProcess.Invoke(String.Format("#r \"{0}\";;", typeof(AutocompleteServer).Assembly.Location)); fsiProcess.Invoke(String.Format("FSharp.Interactive.Intellisense.Lib.AutocompleteServer.StartServer({0});;", sessionRValueValue.GetHashCode())); returnValue = true; System.Threading.Tasks.Task.Delay(4000).ContinueWith((t) => { // activate session try { autocompleteService = AutocompleteClient.SetAutocompleteServiceChannel(sessionRValueValue.GetHashCode()); autocompleteService.Ping(); var comple = autocompleteService.GetCompletions("sys", IntellisenseProviderType.Combined); fsiProcess.Invoke("printfn \"Autocomplete provider registration complete\";;"); } catch (Exception ex) { Debug.WriteLine(ex); } }); } else { AutocompleteService autocompleteService = AutocompleteClient.GetAutocompleteService(); if (autocompleteService != null) { try { autocompleteService.Ping(); } catch { } } } return(returnValue); }
public async Task GetByTerm_EmptyTerm_ArgumentNullException() { var repository = new Mock <IAutocompleteRepository>(); repository.Setup(r => r.GetByTerm(It.IsAny <string>())) .ReturnsAsync(It.IsAny <IEnumerable <UserActivityResponse> >()); var service = new AutocompleteService(repository.Object); await Assert.ThrowsAsync <ArgumentNullException>(() => service.GetByTerm(string.Empty)); }
public async void ExecuteNotFoundReturnsEmpty() { var request = new AutocompleteRequest { Key = "a", Term = "" }; var json = LaraUI.JSON.Stringify(request); var result = await AutocompleteService.Execute(json); Assert.Equal(string.Empty, result); }
public static AutocompleteService SetAutocompleteServiceChannel(int channelId) { lock (syncRoot) { try { autocompleteService = AutocompleteServer.StartClient(channelId); } catch (Exception ex) { Debug.WriteLine("Can't instantiate ipc service channel: " + ex.ToString()); } } return(autocompleteService); }
public async Task Places() { var apiKey = KeyHelper.GetApiKey(); var googleApiKey = KeyHelper.GetGoogleApiKey(); var httpClient = new HttpClient(); httpClient.BaseAddress = UrlHelper.GetStagingUri(); var autocompleteService = new AutocompleteService(apiKey, httpClient); var result = await autocompleteService.Palaces(new Api.Requests.AutocompleteRequest("adaptive", new GoogleApiKey(googleApiKey))); Assert.IsTrue(result.IsSuccess); }
public Api(ApiKeys apiKeys, HttpClient httpClient = null) { Security = new Security(apiKeys, httpClient: httpClient); findService = new FindService(apiKeys.AddressLookupKey, httpClient: httpClient); autocompleteService = new AutocompleteService(apiKeys.AddressLookupKey, httpClient: httpClient); getService = new GetService(apiKeys.AddressLookupKey, httpClient: httpClient); typeaheadService = new TypeaheadService(apiKeys.AddressLookupKey, httpClient: httpClient); EmailNotifications = new EmailNotifications(apiKeys.AdministrationKey, httpClient: httpClient); usageService = new UsageService(apiKeys.AdministrationKey, httpClient: httpClient); distanceService = new DistanceService(apiKeys.AddressLookupKey, httpClient: httpClient); Subscription = new SubscriptionService(apiKeys.AdministrationKey, httpClient: httpClient); Plans = new PlansService(apiKeys.AdministrationKey, httpClient: httpClient); Webhooks = new Webhooks(apiKeys.AdministrationKey, httpClient: httpClient); Account = new Account(apiKeys.AdministrationKey, httpClient: httpClient); Invoice = new InvoiceService(apiKeys.AdministrationKey, httpClient: httpClient); PrivateAddress = new PrivateAddressService(apiKeys.AdministrationKey, httpClient: httpClient); DirectDebt = new DirectDebtService(apiKeys.AdministrationKey, httpClient: httpClient); }
public async Task Postcodes() { var apiKey = KeyHelper.GetApiKey(); var googleApiKey = KeyHelper.GetGoogleApiKey(); var httpClient = new HttpClient(); httpClient.BaseAddress = UrlHelper.GetStagingUri(); var autocompleteService = new AutocompleteService(apiKey, httpClient); var sessionToken = new SessionToken(Guid.NewGuid().ToString()); var ipAddress = new IpAddress("192.168.0.1"); var result = await autocompleteService.Postcodes(new Api.Requests.AutocompleteRequest("pe15 0", new GoogleApiKey(googleApiKey), sessionToken: sessionToken, ipAddress: ipAddress)); Assert.IsTrue(result.IsSuccess); }
public async Task GetByTerm_NonExistingValidSearchTerm_EmptyList() { var repository = new Mock <IAutocompleteRepository>(); repository.Setup(r => r.GetByTerm("bu")).ReturnsAsync(new List <UserActivityResponse> { new UserActivityResponse { Event = "buy", TimeStamp = new DateTimeOffset(DateTime.Now) }, new UserActivityResponse { Event = "buy", TimeStamp = new DateTimeOffset(DateTime.Now) }, new UserActivityResponse { Event = "build", TimeStamp = new DateTimeOffset(DateTime.Now) } }); var service = new AutocompleteService(repository.Object); var result = await service.GetByTerm("xx"); Assert.Empty(result); }
public async void AutocompleteServiceRun() { LaraUI.InternalContext.Value = Context; var x = new AutocompleteElement(); var provider = new MyProvider(); var options = new AutocompleteOptions { Provider = provider, AutoFocus = true, MinLength = 2, Strict = true, }; var doc = new Document(new MyPage(), 100); var bridge = new Mock <IJsBridge>(); Context.JSBridge = bridge.Object; doc.Body.AppendChild(x); x.Start(options); var service = new AutocompleteService(); var request = new AutocompleteRequest { Key = x.AutocompleteId, Term = "B" }; Context.RequestBody = LaraUI.JSON.Stringify(request); var text = await service.Execute(); var response = LaraUI.JSON.Parse <AutocompleteResponse>(text); Assert.Equal(3, response.Suggestions !.Count); var item = response.Suggestions[0]; Assert.Equal("Red", item.Label); Assert.Equal("R", item.Code); }
void ICompletionSource.AugmentCompletionSession(ICompletionSession session, IList <CompletionSet> completionSets) { ITextSnapshot snapshot = textBuffer.CurrentSnapshot; SnapshotPoint?triggerPoint = session.GetTriggerPoint(snapshot); if (triggerPoint == null) { return; } SnapshotPoint end = triggerPoint.Value; SnapshotPoint start = end; // go back to either a delimiter, a whitespace char or start of line. while (start > 0) { SnapshotPoint prev = start - 1; if (IsWhiteSpaceOrDelimiter(prev.GetChar())) { break; } start += -1; } var span = new SnapshotSpan(start, end); // The ApplicableTo span is what text will be replaced by the completion item ITrackingSpan applicableTo1 = snapshot.CreateTrackingSpan(span, SpanTrackingMode.EdgeInclusive); String statement = applicableTo1.GetText(applicableTo1.TextBuffer.CurrentSnapshot); AutocompleteService autocomplteService = AutocompleteClient.GetAutocompleteService(); IEnumerable <StatementCompletion> completions = new List <StatementCompletion>(); if (autocomplteService != null) { try { completions = autocomplteService.GetCompletions(statement, intellisenseProviderType); } catch (Exception ex) { Debug.WriteLine(ex.ToString()); } } compList = new List <Completion>(); bool prependDot = statement.EndsWith("."); foreach (StatementCompletion completion in completions) { //StatementCompletion completion = StatementCompletion.FromTuple(tuple.Item1, tuple.Item2); string str = completion.Text; var glyph = sourceProvider.GlyphService.GetGlyph(CompletionTypeToStandardGlyphGroup(completion.CompletionType), StandardGlyphItem.GlyphItemPublic); compList.Add(new Completion(str, prependDot ? "." + str : str, str, glyph, null)); } var applicableTo = FindTokenSpanAtPosition(session.GetTriggerPoint(textBuffer), session); CompletionSet completionSet = new CompletionSet( "F# completions", //the non-localized title of the tab "F# completions", //the display title of the tab applicableTo, compList, null); // Following code doesn't work: //ExposedObject.From(completionSet)._filterMatchType = // Microsoft.VisualStudio.Language.Intellisense.CompletionMatchType.MatchInsertionText; completionSets.Add(completionSet); }