public IResponseBase Execute(IRequestParameter parameters) { var result = new Response <PowerReviewsResponse>(); try { _request = (PowerReviewsRequest)parameters; _request.Sort = (!string.IsNullOrEmpty(_request.Sort)) ? _request.Sort : "created_date desc"; var cacheKey = string.Format(Config.PowerReview.CacheKeyReviews, _request.ProductId, _request.PageNumber, _request.Sort); result = CacheMemory.Get <Response <PowerReviewsResponse> >(cacheKey); if (result == null || result.resultset.Reviews.Count == 0) { var communicationRequest = BuildUrl(parameters); _response = Communicate(communicationRequest); result = ParseResponse(_response); if (result.resultset.Reviews.Count > 0) { //per lead's request. only cache the first page if (_request.PageNumber == 0) { CacheMemory.SetAndExpiresMinutesAsync(cacheKey, result, Config.PowerReview.Cache_TTL_InMinutes); } } } } catch (Exception ex) { _errors.Add(ex.Handle("PowerReviewGetReviews.Execute", ErrorSeverity.FollowUp, ErrorType.RequestError)); } return(result); }
public IResponseBase Execute(IRequestParameter parameters) { var result = new Response <PowerReviewAvgRateResponse>(); try { _request = (PowerReviewAvgRateRequest)parameters; var cacheKey = string.Format(Config.PowerReview.CacheKeyAvgRate, _request.ProductId); result = CacheMemory.Get <Response <PowerReviewAvgRateResponse> >(cacheKey); if (result == null || result.resultset.AvgRates.Count == 0) { var communicationRequest = BuildUrl(parameters); _response = Communicate(communicationRequest); result = ParseResponse(_response); if (result.resultset.AvgRates.Count > 0) { if (Config.PowerReview.IsCacheEnabled) { CacheMemory.SetAndExpiresMinutesAsync(cacheKey, result, Config.PowerReview.Cache_TTL_InMinutes); } } } } catch (Exception ex) { _errors.Add(ex.Handle("PowerReviewGetAvgRates.Execute", ErrorSeverity.FollowUp, ErrorType.RequestError)); } return(result); }
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 async Task <object> Get([FromQuery] string name, string cache) { return(await Task.Run(async() => { try { var isCache = (string.IsNullOrWhiteSpace(cache)) ? "yes" : "no"; if (isCache == "no") { await CacheMemory.Remove(name); } var jsonResults = await CacheMemory.Get <IList <Form> >(name); if (jsonResults != null) { return jsonResults; } var form = await Form.Get(name); await CacheMemory.SetAndExpiresDays(name, form, 1); return form; } catch (Exception ex) { Trace.TraceError(ex.ToString()); return null; } })); }
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 IResponseBase Execute(IRequestParameter parameters) { var result = new Response <AutoCompleteSearchResponse>(); try { _request = (AutocompleteSearchRequest)parameters; var cacheKey = string.Format(Config.AutocompleteSearch.CacheName, _request.SearchToken); result = CacheMemory.Get <Response <AutoCompleteSearchResponse> >(cacheKey); if (result == null || result.resultset.SearchItem.Items.Count == 0) { var communicationRequest = BuildUrl(parameters); _response = Communicate(communicationRequest); result = ParseResponse(_response); if (result.resultset.SearchItem.Items.Count > 0) { if (Config.AutocompleteSearch.IsCacheEnabled && _request.SearchToken.Length > 2) { CacheMemory.SetAndExpiresMinutesAsync(cacheKey, result, Config.AutocompleteSearch.Cache_TTL_InMin); } } } } catch (Exception) { //don't fail/performace the UI because mad search errors. //allow user to search again. return(new Response <AutoCompleteSearchResponse>()); } return(result); }
public async Task <object> Get([FromQuery] string name, string lang, string cache) { return(await Task.Run(async() => { try { var keyword = name; var language = (string.IsNullOrWhiteSpace(lang)) ? "eng" : lang; var cacheKey = $"label:{name}:{language}"; await AddCorOptions(); var isCache = (string.IsNullOrWhiteSpace(cache)) ? "yes" : "no"; if (isCache == "no") { await CacheMemory.Remove(cacheKey); } var jsonResults = await CacheMemory.Get <List <DictionaryItem> >(cacheKey); if (jsonResults != null) { return jsonResults; } List <DictionaryItem> labels = await Labels.Get(keyword, language); await CacheMemory.SetAndExpiresDays(cacheKey, labels, 1); return labels; } catch (Exception ex) { await Tracer.Exception("LabelController:Get", ex); return null; } })); }
public async Task <object> Get([FromQuery] string name, string cache) { return(await Task.Run(async() => { try { await AddCorOptions(); var isCache = (string.IsNullOrWhiteSpace(cache)) ? "yes" : "no"; if (isCache == "no") { await CacheMemory.Remove(name); } var jsonResults = await CacheMemory.Get <List <Media> >(name); if (jsonResults != null) { return jsonResults; } var media = await Medias.Get(name); await CacheMemory.SetAndExpiresDays(name, media, 1); return media; } catch (Exception ex) { Trace.TraceError((ex.ToString())); return null; } })); }
public async Task <object> Get([FromQuery] string name, string cache) { return(await Task.Run(async() => { try { await AddCorOptions(); var isCache = (string.IsNullOrWhiteSpace(cache)) ? "yes" : "no"; if (isCache == "no") { await CacheMemory.Remove(name); } var jsonResults = await CacheMemory.Get <object>(name); if (jsonResults != null) { return jsonResults; } var datasource = await DataSource.Get(name); await CacheMemory.SetAndExpiresDays(name, datasource, 1); return datasource; } catch (Exception ex) { Trace.TraceError(ex.ToString()); return Json(new object()); } })); }
public async Task <object> Get([FromQuery] string cache) { return(await Task.Run(async() => { try { await AddCorOptions(); var isCache = (string.IsNullOrWhiteSpace(cache)) ? "yes" : "no"; if (isCache == "no") { await CacheMemory.Remove("menu"); } var jsonResults = await CacheMemory.Get <IList <Menu> >("menu"); if (jsonResults != null) { return jsonResults; } var menu = await Menu.Get(); await CacheMemory.SetAndExpiresDays("menu", menu, 1); return menu; } catch (Exception ex) { await Tracer.Exception("MenuController:Get", ex); return null; } })); }
public async Task <object> Get([FromQuery] string emailto, string emailfrom, string emailsubject, string emailtext, string emailattachment, string emailtype, string cache) { return(await Task.Run(async() => { try { if (emailto == null) { return new[] { "status", "need emailto" } } ; if (emailfrom == null) { return new[] { "status", "need emailfrom" } } ; if (emailsubject == null) { return new[] { "status", "need emailsubject" } } ; if (emailtext == null) { return new[] { "status", "need emailtext" } } ; var cacheKey = $"email:{emailfrom}:{emailsubject.Trim().Replace(" ", "").ToLower()}"; if (cache != null) { if (cache == "no") { await CacheMemory.Remove(cacheKey); } } var jsonResults = await CacheMemory.Get <object>(cacheKey); if (jsonResults != null) { return new[] { "status", "No eamil not sent. Waiting for cache to expired" } } ; await AddCorOptions(); await Email.Send(emailto, emailfrom, emailsubject, emailtext); var results = new [] { "status", "OK" }; await CacheMemory.SetAndExpiresSeconds(cacheKey, results, 10); return results; } catch (Exception ex) { await Tracer.Exception("SendEmailController:Get", ex); return null; } })); }
public IResponseBase Execute(IRequestParameter parameters) { var href = CacheMemory.Get <HrefLookup>(cacheKey); var result = new Response <HrefLookup> { resultset = href }; return(result); }
private static async Task GetHumidityHistogram(string humidityQueueKey, COREALL sensor) { var humidityQueueTemp = await CacheMemory.Get <FixedQueue <decimal> >(humidityQueueKey) ?? new FixedQueue <decimal>(); humidityQueueTemp.Enqueue(sensor.Humidity); await CacheMemory.SetAndExpiresDays(humidityQueueKey, humidityQueueTemp, 1); sensor.HumidityHistogram = humidityQueueTemp; }
private static async Task GetKelvinHistogram(string kelvinQueueKey, COREALL sensor) { var kelvkinQueueTemp = await CacheMemory.Get <FixedQueue <decimal> >(kelvinQueueKey) ?? new FixedQueue <decimal>(); kelvkinQueueTemp.Enqueue(sensor.Kelvin); await CacheMemory.SetAndExpiresDays(kelvinQueueKey, kelvkinQueueTemp, 1); sensor.KelvinHistogram = kelvkinQueueTemp; }
private static async Task GetCelciusHistogram(string celciusQueueKey, COREALL sensor) { var celciusQueueTemp = await CacheMemory.Get <FixedQueue <decimal> >(celciusQueueKey) ?? new FixedQueue <decimal>(); celciusQueueTemp.Enqueue(sensor.Celcius); await CacheMemory.SetAndExpiresDays(celciusQueueKey, celciusQueueTemp, 1); sensor.CelciusHistogram = celciusQueueTemp; }
private static async Task GetFehrenheitHistogram(string fehrenheitQueueKey, COREALL sensor) { var fehrenheitQueueTemp = await CacheMemory.Get <FixedQueue <decimal> >(fehrenheitQueueKey) ?? new FixedQueue <decimal>(); fehrenheitQueueTemp.Enqueue(sensor.Fahrenheit); await CacheMemory.SetAndExpiresDays(fehrenheitQueueKey, fehrenheitQueueTemp, 1); sensor.FahrenheitHistogram = fehrenheitQueueTemp; }
private static async Task GetPpmHistogram(string ppmQueueKey, COREALL sensor) { var ppmQueueTemp = await CacheMemory.Get <FixedQueue <decimal> >(ppmQueueKey) ?? new FixedQueue <decimal>(); ppmQueueTemp.Enqueue(sensor.PPM.Measurement); await CacheMemory.SetAndExpiresDays(ppmQueueKey, ppmQueueTemp, 1); sensor.PPM.Histogram = ppmQueueTemp; }
private Response <MenuResponse> GetResponse(DWClientConfig config) { var result = new Response <MenuResponse>(); try { var dwCategoryDataCachekey = string.Format(Config.CacheKeys.DWCategoryData, config.Path); var apiResponse = CacheMemory.Get <APIResponse <DemandWare.Models.DTOs.Category> >(dwCategoryDataCachekey); if (_isRoot && result.resultset.Menu.Count == 0) { apiResponse = null; } if (apiResponse == null || apiResponse.Model == null) { try { apiResponse = DWClient.GetAPIResponse <DemandWare.Models.DTOs.Category>(config); if (apiResponse != null && apiResponse.ResponseStatus.Code == HttpStatusCode.OK && apiResponse._errors == null) { //CacheMemory.SetAndExpiresHoursAsync(dwCategoryDataCachekey, apiResponse, 4); result.resultset = new MenuResponse(apiResponse.Model, _request.Path); if (_isRoot || _request.KeepTraversing) { SetMenuItems(result); if (_isRoot) { Update_MenuBy_CmsAndFtpFile(result); } } } else { if (apiResponse != null) { _errors.Add(new SiteError { Message = new ErrorMessage(Config.Constants.GenericError, apiResponse.ResponseStatus.Message) }); } } } catch (Exception) {} } } catch (Exception ex) { if (_isRoot) { _errors.Add(ex.Handle("Menu.GetResponse", ErrorSeverity.FollowUp, ErrorType.RequestError)); } } return(result); }
public InitResponse GetInitData(DateTime?forwardDate = null) { var result = new InitResponse(); result = CacheMemory.Get <InitResponse>(Config.CacheKeys.CmsInit); if (result == null || result.SessionID == null) { _homepageData = _tabletCms.GetMetaData("home_page_data"); _homepageDataProperties = (IDictionary <string, object>)_homepageData; _heroBanners = _tabletCms.GetMetaData("hero_banners"); _heroBannersDictionary = (IDictionary <string, object>)_heroBanners; try { if (!forwardDate.HasValue) { forwardDate = DateTime.Now; } } catch (Exception) { forwardDate = DateTime.Now; } result.TabletBanners = GetTabletBanners(forwardDate.Value); result.HeroBanners = GetHeroBanners(forwardDate.Value); result.ContentRows = GetContentRows(forwardDate.Value); result.FeatureImages = _mobileCms.GetImages("feature_images"); result.FeatureImagesB = _mobileCms.GetImages("feature_images_b"); result.Banners = _mobileCms.GetImages("banners"); result.CheckoutPromoMessage = GetCheckoutPromoMessage(); result.SecondaryBanners = _mobileCms.GetImages("banners-b"); var scriptToggleMetaData = _mobileCms.GetMetaData("script_toggles"); try { if (scriptToggleMetaData != null) { result.ScriptToggles = new Dictionary <string, object>(scriptToggleMetaData); } } catch (Exception) { result.ScriptToggles = new Dictionary <string, object>(); } SetPlpPromosInCache(); CacheMemory.SetAndExpiresMinutesAsync(Config.CacheKeys.CmsInit, result, 5); } return(result); }
public async Task <object> Get([FromQuery] string name, string serial, string version, string lic, string author, string value, string cache) { return(await Task.Run(async() => { try { var cacheKey = $"sensor:{serial}:ENS210"; var fehrenheitQueueKey = $"fehrenheitListKey:{serial}:ENS210"; var celciusQueueKey = $"celciusListKey:{serial}:ENS210"; var kelvinQueueKey = $"kelvinListKey:{serial}:ENS210"; var humidityQueueKey = $"humidityListKey:{serial}:ENS210"; var ppmQueueKey = $"ppmListKey:{serial}:ENS210"; await AddCorOptions(); var isCache = (string.IsNullOrWhiteSpace(cache)) ? "yes" : "no"; if (isCache == "no") { await CacheMemory.Remove(cacheKey); } var jsonResults = await CacheMemory.Get <COREALL>(cacheKey); if (jsonResults != null) { return jsonResults; } var sensor = await ICoreall.Get(serial, value); sensor.LastRecord = DateTime.Now.ToString(CultureInfo.CurrentCulture); sensor.Version = version ?? string.Empty; sensor.Lic = lic ?? string.Empty; sensor.Author = author ?? string.Empty; sensor.Name = name ?? string.Empty; await GetFehrenheitHistogram(fehrenheitQueueKey, sensor); await GetCelciusHistogram(celciusQueueKey, sensor); await GetKelvinHistogram(kelvinQueueKey, sensor); await GetHumidityHistogram(humidityQueueKey, sensor); await GetPpmHistogram(ppmQueueKey, sensor); await CacheMemory.SetAndExpiresDays(cacheKey, sensor, 1); return sensor; } catch (Exception ex) { await Tracer.Exception("COREALLController:Get", ex); return null; } })); }
public IResponseBase Execute(IRequestParameter parameters) { var result = new Response <SearchResponse>(); _request = (SearchRequest)parameters; try { if (_request.Href != null) { var cacheKey = string.Format(Config.CacheKeys.Search, _request.Href, _request.Page, _request.PageSize); IsViewAllProductSearch = _request.Href.Contains("view-all"); IsEmailCamPaign = _request.Href.ToLower().Contains("utm_medium=email"); result = CacheMemory.Get <Response <SearchResponse> >(cacheKey); if (result.resultset != null && string.IsNullOrWhiteSpace(result.resultset.Href)) { _hrefLookup = HrefLookup.Load(_core); var config = BuildAPIConfig(parameters); if (config != null) { result = GetResponse(config); } if (result.resultset.Filters != null && result.resultset.Filters.FilterSections != null) { result.resultset.Filters.FilterSections = SelectSpecifiedSize(result.resultset.Filters.FilterSections); } var href = ParsingHelper.GetHrefWithoutQueryString(_request.Href); result.resultset.CategoryID = _hrefLookup.Forward.Get(href); var resultVideos = CacheMemory.Get <Dictionary <string, PaylessMadCms.PromoSlot> >(Config.CacheKeys.CmsVideos); if (resultVideos != null && resultVideos.Keys.Contains(href)) { result.resultset.Promo = resultVideos[href]; } if (!_errors.Any() && result.resultset.Products.Any()) { CacheMemory.SetAndExpiresMinutesAsync(cacheKey, result, 15); } } } } catch (Exception ex) { _errors.Add(ex.Handle(string.Format("Search.Execute({0}):{1}-{2}", ex.LineNumber(), ex.Message, ex.StackTrace), 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 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 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 Dictionary <string, string> BrandImageLookup() { var result = new Dictionary <string, string>(); result = CacheMemory.Get <Dictionary <string, string> >(Config.CacheKeys.CmsBrandImages); if (result == null || result.Count == 0) { var brandImagesData = _tabletCms.GetMetaData("brand_images"); foreach (var brand in brandImagesData) { var properties = (IDictionary <string, object>)brand.Value; if (properties.ContainsKey("brand") && properties.ContainsKey("image")) { result.Add(brand.Value.brand, brand.Value.image); } } CacheMemory.SetAndExpiresMinutesAsync(Config.CacheKeys.CmsBrandImages, result, 15); } return(result); }
public async Task <object> Get([FromQuery] string name, string serial, string version, string lic, string author, string value, string cache) { return(await Task.Run(async() => { try { var cacheKey = $"sensor:{serial}:IAQCORE"; await AddCorOptions(); var isCache = (string.IsNullOrWhiteSpace(cache)) ? "yes" : "no"; if (isCache == "no") { await CacheMemory.Remove(cacheKey); } var jsonResults = await CacheMemory.Get <IAQCORE>(cacheKey); if (jsonResults != null) { return jsonResults; } var sensor = await IiAQCOREs.Get(serial, value); sensor.LastRecord = DateTime.Now.ToString(CultureInfo.CurrentCulture); sensor.Version = version ?? string.Empty; sensor.Lic = lic ?? string.Empty; sensor.Author = author ?? string.Empty; sensor.Name = name ?? string.Empty; await CacheMemory.SetAndExpiresSeconds(cacheKey, sensor, 30); return sensor; } catch (Exception ex) { await Tracer.Exception("IAQCOREController:Get", ex); return null; } })); }
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); }