コード例 #1
0
        /// <summary>
        /// Invokes <see cref="SearchAsync(string, AutocompleteRequest)"/> with the given <paramref name="autocomleteRequest"/> and caches the results
        /// <param name="input">Search string</param>
        /// <param name="request">Autocomplete request specifying additional components in the search Url to be generated</param>
        /// </summary>
        public async Task <OperationResult <PlaceResponse> > AutocompleteAsync(string input, AutocompleteRequest autocomleteRequest = null)
        {
            //Get cached results
            var result = _cachingProvider.GetAutocompleteResult(input);

            if (result != null)
            {
                return(OperationResult <PlaceResponse> .AsSuccess(result));
            }

            OperationResult <PlaceResponse> searchResult;

            if (autocomleteRequest != null)
            {
                searchResult = await SearchAsync(input, autocomleteRequest);
            }
            else
            {
                searchResult = await SearchAsync(input, new AutocompleteRequest()
                {
                    Region = "au"
                });
            }


            if (!searchResult.IsSuccessful)
            {
                return(OperationResult <PlaceResponse> .AsFailure("Search response result is null"));
            }

            _cachingProvider.StoreAutocompleteResult(input, searchResult.Result);

            return(searchResult);
        }
コード例 #2
0
        /// <summary>
        /// Invokes <see cref="SearchAsync(string, AutocompleteRequest)"/> with the given <paramref name="autocomleteRequest"/> and caches the results
        /// <param name="input">Search string</param>
        /// <param name="request">Autocomplete request specifying additional components in the search Url to be generated</param>
        /// </summary>
        public async Task <OperationResult <PlaceResponse> > AutocompleteAsync(string input, AutocompleteRequest autocomleteRequest)
        {
            //Get cached results
            var result = _cachingProvider.GetAutocompleteResult(input);

            if (result != null)
            {
                return(OperationResult <PlaceResponse> .AsSuccess(result));
            }

            var searchResult = await SearchAsync(input, new AutocompleteRequest
            {
                Region = "au"
            })
                               .ContinueWith(response =>
            {
                if (response.Result == null)
                {
                    return(OperationResult <PlaceResponse> .AsFailure("Search response result is null"));
                }
                return(response.Result);
            })
                               .ConfigureAwait(false);

            if (searchResult.IsSuccessful)
            {
                _cachingProvider.StoreAutocompleteResult(input, searchResult.Result);
            }

            return(searchResult);
        }