public IResponseBase Execute(IRequestParameter parameters) { var result = new Response <MenuResponse>(); try { _request = (MenuRequest)parameters; _isRoot = _request.Url.Equals(Config.Params.HrefPrefix + "root"); result = CacheMemory.Get <Response <MenuResponse> >(Config.CacheKeys.Menu); if (result == null || string.IsNullOrWhiteSpace(result.template)) { if (_request.Url.StartsWith(Config.Params.HrefPrefix)) { _request.Url = _request.Url.Remove(0, Config.Params.HrefPrefix.Length); } var config = BuildAPIConfig(parameters); result = GetResponse(config); result.template = Config.ResponseTemplates.Menu; if (_isRoot && _errors.Count == 0) { CacheMemory.SetAndExpiresHoursAsync(Config.CacheKeys.Menu, result, 4); } } } catch (Exception ex) { if (_isRoot) { _errors.Add(ex.Handle("Menu.Execute", ErrorSeverity.FollowUp, ErrorType.RequestError)); } } return(result); }
public IResponseBase Execute(IRequestParameter parameters) { var result = new Response <ProductDetailResponse>(); try { _request = (ProductDetailRequest)parameters; var cacheKey = string.Format(Config.CacheKeys.ProductDetails, _request.Id, _request.Color); result = CacheMemory.Get <Response <ProductDetailResponse> >(cacheKey); if (result == null || string.IsNullOrWhiteSpace(result.resultset.Product.ProductId)) { var config = BuildAPIConfig(parameters); result = GetResponse(config); if (!result.errors.Any() && !string.IsNullOrEmpty(result.resultset.Product.ProductId)) { CacheMemory.SetAndExpiresHoursAsync(cacheKey, result, 1); } } } catch (Exception ex) { _errors.Add(ex.Handle("ProductDetail.Execute", ErrorSeverity.FollowUp, ErrorType.RequestError)); } return(result); }
public static HrefLookup Load(ICore core) { _core = core; var result = CacheMemory.Get <HrefLookup>(Config.CacheKeys.HrefLookup); if (result != null && result.HasData) { return(result); } result = LoadFromDiskAndCache(Config.Params.HrefLookupDirectory); if (result != null || result.HasData) { CacheMemory.SetAndExpiresHoursAsync(Config.CacheKeys.HrefLookup, result, 4); } return(result); }
public static RecommendedProducts Load(string productID, ICore core) { var result = new RecommendedProducts(); var cacheKey = string.Format(Config.CacheKeys.RecommendProducts, productID); result = CacheMemory.Get <RecommendedProducts>(cacheKey); if (result == null || result.Products == null) { var request = GetRequest(productID, core); var response = core.RequestManager.Communicate(request); result.Products = ParseRecommendedProducts(response.XDocument); result.Breadcrumb = ParseBreadcrumb(productID, response.XDocument); CacheMemory.SetAndExpiresHoursAsync(cacheKey, result, 1); } return(result); }
public static List <Price> GetByID(ICore core, string productID) { var result = new List <Price>(); _core = core; var cacheKey = string.Format(Config.CacheKeys.ProductPricing, productID); result = CacheMemory.Get <List <Price> >(cacheKey); if (result == null || !result.Any()) { var resultResponse = MakeRequest(productID); result = Parse(resultResponse); CacheMemory.SetAndExpiresHoursAsync(cacheKey, result, 1); } return(result); }
public IResponseBase Execute(IRequestParameter parameters) { var result = new Response <CategoryResponse>(); try { _request = (CategoryRequest)parameters; var hrefLookup = HrefLookup.Load(_core); var catid = hrefLookup.Forward.Get(ParsingHelper.GetHrefWithoutQueryString(_request.Href)); var cacheKey = string.Format(Config.CacheKeys.Category, catid); result = CacheMemory.Get <Response <CategoryResponse> >(cacheKey); if (result == null || string.IsNullOrWhiteSpace(result.resultset.CategoryID)) { var forwardDate = GetDateFromRequest(); var maddash = new PaylessMadCms(_core); result.resultset = maddash.GetCategoryData(catid, forwardDate); var config = BuildAPIConfig(parameters, catid); var apiResponse = DWClient.GetAPIResponse <ProductSearchResult>(config); if (apiResponse.ResponseStatus.Code == HttpStatusCode.OK) { result.resultset.Filters = new ExtendedFilter(apiResponse.Model.Refinements, null, hrefLookup); } result.resultset.CategoryID = catid; if (result.errors.Count == 0) { CacheMemory.SetAndExpiresHoursAsync(cacheKey, result, 1); } } } catch (Exception ex) { _errors.Add(ex.Handle("Category.Execute", ErrorSeverity.FollowUp, ErrorType.RequestError)); } return(result); }