public static Dictionary <string, IEnumerable <StrandsWebTemplateData> > LoadAllWebTemplates() { try { StrandsApiClient strandsApiClient = new StrandsApiClient(StrandsSettings.GetApiID(SiteContext.CurrentSiteName)); var groups = from webTemplate in strandsApiClient.GetAvailableWebTemplates() group webTemplate by webTemplate.Type into webTemplateGroups orderby webTemplateGroups.Key select webTemplateGroups; return(groups.ToDictionary( g => g.Key.ToStringRepresentation(), g => g.OrderBy(GetTemplateOrder).Select(EncodeWebTemplate))); } catch (StrandsException ex) { EventLogProvider.LogException("Strands Recommender", "LOADALLWEBTEMPLATES", ex); // Since it is not possible to send exception with custom properties via AJAX when request failed, // throw regular exception and provide nice UI message as its base message throw new Exception(ex.UIMessage, ex); } }
/// <summary> /// Initializes the control properties. /// </summary> protected void SetupControl() { try { // Generate Strands javascript library code StrandsScriptRenderer renderer = new StrandsScriptRenderer(Page, StrandsSettings.GetApiID(SiteContext.CurrentSiteName)); renderer.RenderCultureScript(DocumentContext.CurrentDocumentCulture.CultureCode); if (ECommerceContext.CurrentCurrency != null) { renderer.RenderCurrencyScript(ECommerceContext.CurrentCurrency.CurrencyCode); } renderer.RenderLibraryScript(); var template = ParseRecommendationTemplate(RecommendationID); if (UseCustomTransformation()) { RenderCustomTransformation(renderer, template); } // Sets template as tpl attribute in Strands div element. Strands portal uses it to determine, what recommendation template should be loaded. strandsRecs.Attributes.Add("tpl", template.ID); FillTemplateAttributes(template.Type); } catch (Exception ex) { EventLogProvider.LogException("Strands Recommender", "STRANDS", ex); if (ex is StrandsException) { HandleError(((StrandsException)ex).UIMessage); } else { HandleError(ex.Message); } } }
/// <summary> /// Loads names of all available email templates from Strands API. /// </summary> /// <returns>Collection containing names of all available email templates</returns> private List <string> LoadEmailTemplateNames() { var provider = new StrandsApiClient(StrandsSettings.GetApiID(SiteContext.CurrentSiteName)); try { // Return collection if everything is alright return(provider.GetAvailableEmailTemplates().Select(HTMLHelper.HTMLEncode).ToList()); } catch (StrandsException ex) { ProcessErrorMessage(ex, ex.UIMessage ?? ex.Message); return(null); } catch (Exception ex) { // Usually an exception thrown when there is a problem when communicating with Strands ProcessErrorMessage(ex, GetString("strands.exception")); return(null); } }
public static string LoadSpecificEmailTemplate(string name) { try { if (name == null) { throw new ArgumentNullException("name"); } var provider = new StrandsApiClient(StrandsSettings.GetApiID(SiteContext.CurrentSiteName)); string template = provider.GetEmailTemplate(name); template = AddTitleParameter(template); return(template); } catch (Exception ex) { EventLogProvider.LogException("Strands Recommender", "LOADSPECIFISEMAILTEMPLATE", ex); throw; } }