public void Page_Init(object sender, EventArgs e) { // When user selects item in the first dropdown (hourly, daily, weekly), display correct second drop down ddlMainFrequency.SelectedIndexChanged += (s, ea) => DisplayCorrectExtendedDropDownList(); // Bind to the event when settings page is being saved and perform a Strands setup call after page is saved SettingsGroupViewerControl settingsGroupViewer = ControlsHelper.GetParentControl <SettingsGroupViewerControl>(this); // Do nothing if this form control is not placed under SettingsGroupViewerControl control (can happen in form control preview for example) if (settingsGroupViewer != null) { settingsGroupViewer.SettingsSave.After += (s, ea) => { if (StrandsSettings.IsStrandsEnabled(SiteContext.CurrentSiteName)) { try { var setupCall = new StrandsSetupCall(); setupCall.DoWithDefaults(); } catch (Exception ex) { EventLogProvider.LogException("Strands Recommender", "SETUPCALL", ex); } } }; } }
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); } }
protected void Page_Load(object sender, EventArgs e) { // Register custom style sheet file CssRegistration.RegisterCssLink(Page, "~/CMSModules/StrandsRecommender/StyleSheets/InsertEmailWidget.css"); List <string> emailTemplates = null; // If Strands is disabled (no API key present in settings), show common warning message if (StrandsSettings.IsStrandsEnabled(SiteContext.CurrentSiteName)) { emailTemplates = LoadEmailTemplateNames(); // If there is no template available, show warning message if ((emailTemplates != null) && !emailTemplates.Any()) { AddWarning(GetString("strands.notemplates")); } } else { AddWarning(GetString("strands.notoken")); } RegisterScripts(emailTemplates); SetLabelMoreInformationText(); }
protected void Page_Load(object sender, EventArgs e) { if (!StrandsSettings.IsStrandsEnabled(CurrentSite.SiteName)) { ddlTemplates.Visible = false; // Ensures OK button won't update template hdnSelectedTemplate.Value = null; lblNoToken.Visible = true; lblNoToken.Text = GetString("strands.notoken"); } else { ddlTemplates.Items.Add(new ListItem(GetString("general.loading"))); RegisterScripts(); } }
/// <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; } }
/// <summary> /// Load event handler. /// </summary> protected void Page_Load(object sender, EventArgs e) { // Contains definition for position of error label CSSHelper.RegisterCSSLink(Page, "~/CMSWebparts/StrandsRecommender/StrandsRecommendations.css"); if (!StrandsSettings.IsStrandsEnabled(SiteContext.CurrentSiteName)) { // If Strands is not currently available, stop processing webpart StopProcessing = true; HandleError(GetString("strands.notoken")); } else if (CookieHelper.CurrentCookieLevel < CookieLevel.Visitor) { // Do nothing, if user has decided to forbid cookie usage to under Visitor level, because Strands library uses Cookies under the hood StopProcessing = true; HandleError(); } else { SetupControl(); } }