public SearchConnectionConfiguration(SearchServiceModel elasticConfiguration) { var uriBuilder = new UriBuilder { Host = elasticConfiguration.Host, Port = elasticConfiguration.Port }; Settings = new ConnectionSettings(uriBuilder.Uri); Settings.DefaultIndex(elasticConfiguration.IndexName); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMvc(); var elasticConfigSection = Configuration.GetSection("ElasticConfiguration"); var elasticConfig = new SearchServiceModel { Host = elasticConfigSection.GetValue <string>("Host"), IndexName = elasticConfigSection.GetValue <string>("IndexName"), Port = elasticConfigSection.GetValue <int>("Port") }; services.Configure <SearchServiceModel>(elasticConfigSection); SearchConnectionConfiguration settings = new SearchConnectionConfiguration(elasticConfig); services.AddSingleton <SearchConnectionConfiguration>(settings); }
public static async Task RetrieveSearchServices(WebSearchService[] services, IApplicationCache cache, SearchCriteria criteria, bool allNew = false) { foreach (var webService in services) { var type = webService.ServiceType; var service = new SearchServiceModel() { Criteria = criteria, Type = type }; var key = service.GetRedisKey(); try { if (!allNew && await cache.Exists(key)) { webService.ServiceModel = (JsonConvert.DeserializeObject <SearchServiceModel>(await cache.GetString(key))); continue; } } catch { //Something wrong with the service so we'll have to return a new one } webService.ServiceModel = new SearchServiceModel() { Criteria = criteria, MaxPage = 0, Page = 0, PageKey = "", Type = type, Pages = new int[] { 0 }, Searched = false }; } }
public string ConvertWithPage(SearchServiceModel search, string pagekey) { return(SearchEndpoints.DHGatePageUrl.Replace("{SEARCH}", search.Criteria.SearchText.Replace(" ", "+")).Replace("{PAGE}", (search.Page + 1).ToString()).Replace("{KEY}", pagekey)); }
public HomeController(IOptions <SearchServiceModel> elastic, SearchConnectionConfiguration settings) { _searchServiceModel = elastic.Value; _searchConnectionConfiguration = settings; }
public virtual Task <SearchResultOverview> SearchItems(SearchServiceModel model) { this.ServiceModel = model; return(this.SearchItems()); }
public string Convert(SearchServiceModel model) { var qs = new Dictionary <string, string>(); var search = model.Criteria; qs.Add("SearchText", search.SearchText.Replace(" ", "+")); if (search.PriceFrom.HasValue) { qs.Add("minPrice", search.PriceFrom.ToString()); } if (search.PriceTo.HasValue) { qs.Add("maxPrice", search.PriceTo.ToString()); } if (search.ShipFrom != null) { qs.Add("shipFromCountry", search.ShipFrom); } if (search.ShipTo != null) { qs.Add("shipCountry", search.ShipTo); } if (search.FreeShipping.HasValue) { qs.Add("isFreeShip", search.FreeShipping.Value.YesOrNo()); } if (search.SaleItems.HasValue) { qs.Add("isOnSale", search.SaleItems.Value.YesOrNo()); } if (search.AppOnly.HasValue) { qs.Add("isMobileExclusive", search.AppOnly.Value.YesOrNo()); } if (search.QuantityMax.HasValue) { qs.Add("maxQuantity", search.QuantityMax.Value.ToString()); } if (search.QuantityMin.HasValue) { qs.Add("minQuantity", search.QuantityMin.Value.ToString()); } qs.Add("page", (model.Page).ToString()); var strings = new List <string>(); foreach (var key in qs.Keys) { strings.Add($"{key}={qs[key]}"); } return(SearchEndpoints.AliexpressSearchUrl + String.Join("&", strings)); }
//Function that actually goes out and gets Aliexpress search and converts it async Task <SearchResultOverview> searchItems(SearchServiceModel search) { var resultTasks = new List <Task <string> >(); SearchResultOverview results = null; foreach (var page in search.Pages) { search.Page = page; string endpoint = new AliexpressQueryString().Convert(search); #region Error Tracking //Add breadcrumb for error monitoring var crumb = new Breadcrumb("AliexpressService") { Message = $"GET {endpoint}", Data = new Dictionary <string, string>() { { "Aliexpress URL", endpoint } } }; raven.AddTrail(crumb); #endregion try { resultTasks.Add((await http.Get(endpoint)).Content.ReadAsStringAsync()); } catch (Exception e) { var sentry = new SentryEvent(e); await raven.CaptureNetCoreEventAsync(sentry); } } var responses = await Task.WhenAll(resultTasks); foreach (var response in responses) { try { var result = new AliexpressPageDecoder().ScrapeSearchResults(response); if (results == null) { results = result; this.ServiceModel.PopulateState(results); } else { results.Items.AddRange(result.Items); } } catch (Exception e) { var sentry = new SentryEvent(e); await raven.CaptureNetCoreEventAsync(sentry); } } if (results != null && results.Items.Count > 0) { StoreSearchItems(results.Items); } return((results != null) ? results : new SearchResultOverview()); }