Ejemplo n.º 1
0
    /// <summary>
    /// HTML encodes templates ID and Title fields, so it can be safely rendered.
    /// </summary>
    /// <param name="template">Template whose fields will be encoded.</param>
    /// <returns>The same instance as was passed in <paramref name="template"/>, but with encoded properties</returns>
    private static StrandsWebTemplateData EncodeWebTemplate(StrandsWebTemplateData template)
    {
        template.ID    = HTMLHelper.HTMLEncode(template.ID);
        template.Title = HTMLHelper.HTMLEncode(template.Title);

        return(template);
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Gets integer value from the right side of the ID of the provided Strands template.
    /// </summary>
    /// <param name="webTemplate">Strands web template. Its ID will be parsed to get order</param>
    /// <example>For template ID PROD-4 returns 4, for template ID home_8 returns 8 etc.</example>
    /// <returns>Integer value of template ID</returns>
    private static int GetTemplateOrder(StrandsWebTemplateData webTemplate)
    {
        var splittedText = Regex.Split(webTemplate.ID, "[-_]");

        if (splittedText.Length == 2)
        {
            return(ValidationHelper.GetInteger(splittedText[1], 0));
        }

        return(0);
    }
    /// <summary>
    /// Renders script for custom transformation.
    /// </summary>
    /// <param name="renderer">Instance of Strands script renderer</param>
    /// <param name="template">Selected template</param>
    /// <exception cref="StrandsException">Transformation does not exist</exception>
    private void RenderCustomTransformation(StrandsScriptRenderer renderer, StrandsWebTemplateData template)
    {
        var transformation = TransformationInfoProvider.GetTransformation(CustomTransformation);

        if (transformation == null)
        {
            throw new StrandsException("[StrandsRecommendations.ParseRecommendationTemplate]: Cannot load the transformation specified in the web part.", ResHelper.GetString("strands.recommendations.transformations.errorloadingtransformation"));
        }
        if (transformation.TransformationType != TransformationTypeEnum.jQuery)
        {
            throw new StrandsException("[StrandsRecommendations.ParseRecommendationTemplate]: Transformation type has to be of type jQuery.", ResHelper.GetString("strands.recommendations.transformations.wrongtype"));
        }

        renderer.RenderCustomizedRendererScript(transformation, template.ID, strandsRecs.ClientID);
    }
    /// <summary>
    /// Renders script for custom transformation.
    /// </summary>
    /// <param name="renderer">Instance of Strands script renderer</param>
    /// <param name="template">Selected template</param>
    /// <exception cref="StrandsException">Transformation does not exist</exception>
    private void RenderCustomTransformation(StrandsScriptRenderer renderer, StrandsWebTemplateData template)
    {
        var transformation = TransformationInfoProvider.GetTransformation(CustomTransformation);

        if (transformation == null)
        {
            throw new StrandsException("[StrandsRecommendations.ParseRecommendationTemplate]: Cannot load the transformation specified in the web part.", ResHelper.GetString("strands.recommendations.transformations.errorloadingtransformation"));
        }
        if (transformation.TransformationType != TransformationTypeEnum.jQuery)
        {
            throw new StrandsException("[StrandsRecommendations.ParseRecommendationTemplate]: Transformation type has to be of type jQuery.", ResHelper.GetString("strands.recommendations.transformations.wrongtype"));
        }

        renderer.RenderCustomizedRendererScript(transformation, template.ID, strandsRecs.ClientID);
    }
    /// <summary>
    /// Gets integer value from the right side of the ID of the provided Strands template.
    /// </summary>
    /// <param name="webTemplate">Strands web template. Its ID will be parsed to get order</param>
    /// <example>For template ID PROD-4 returns 4, for template ID home_8 returns 8 etc.</example>
    /// <returns>Integer value of template ID</returns>
    private static int GetTemplateOrder(StrandsWebTemplateData webTemplate)
    {
        var splittedText = Regex.Split(webTemplate.ID, "[-_]");
        if (splittedText.Length == 2)
        {
            return ValidationHelper.GetInteger(splittedText[1], 0);
        }

        return 0;
    }
    /// <summary>
    /// HTML encodes templates ID and Title fields, so it can be safely rendered.
    /// </summary>
    /// <param name="template">Template whose fields will be encoded.</param>
    /// <returns>The same instance as was passed in <paramref name="template"/>, but with encoded properties</returns>
    private static StrandsWebTemplateData EncodeWebTemplate(StrandsWebTemplateData template)
    {
        template.ID = HTMLHelper.HTMLEncode(template.ID);
        template.Title = HTMLHelper.HTMLEncode(template.Title);

        return template;
    }