/// <summary>
        /// Transforms HTML code so that it can be uploaded to Campaign.
        /// Allows the content of local HTML files to be transformed into JavaScript Server Pages for use in Campaign.
        /// There is no reverse method, so HTML-based JavaScript Server Pages files cannot be directly downloaded from Campaign
        /// into the format in which they are stored locally.
        /// </summary>
        /// <param name="template">Source content</param>
        /// <param name="parameters">Parameters to determine transform behaviour</param>
        /// <returns>Transformed JavaScript Server Pages content</returns>
        public IEnumerable <Template> Transform(Template template, TransformParameters parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            if (string.IsNullOrEmpty(parameters.OriginalFileName))
            {
                throw new ArgumentException("Original file name must be provided.", nameof(parameters.OriginalFileName));
            }

            var workingDirectory = Path.GetDirectoryName(parameters.OriginalFileName);

            // Process pre-includes.
            template.Code = ProcessIncludes(template.Code, workingDirectory, "pre");

            // Process function definitions.
            template.Code = ProcessFunctionDefinitions(template.Code);

            // Process html.
            template.Code = ProcessHtml(template.Code);

            // Process post-includes.
            template.Code = ProcessIncludes(template.Code, workingDirectory, "post");

            return(new[] { template });
        }
        /// <summary>
        /// Applies transforms to a workflow definition code so that multiple versions can be uploaded to Campaign.
        /// Transforms are defined in workflowName.transformName.config files, using xdt syntax, analagous to ASP.NET config transforms.
        /// </summary>
        /// <param name="template">Source content</param>
        /// <param name="parameters">Parameters to determine transform behaviour</param>
        /// <returns>A collection of transformed templates</returns>
        public IEnumerable <Template> Transform(Template template, TransformParameters parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            if (!parameters.ApplyTransforms)
            {
                return(new[] { template });
            }

            var directoryName            = Path.GetDirectoryName(parameters.OriginalFileName);
            var transformFilenamePattern = $"{Path.GetFileNameWithoutExtension(parameters.OriginalFileName)}.*{TransformFileExtension}";
            var transformFiles           = Directory.GetFiles(directoryName, transformFilenamePattern);

            var templates = new List <Template>();

            foreach (var transformFile in transformFiles)
            {
                var transformName = Regex.Replace(Path.GetFileNameWithoutExtension(transformFile), $@"^{Path.GetFileNameWithoutExtension(parameters.OriginalFileName)}\.", string.Empty);

                var doc = new XmlDocument();
                doc.LoadXml(template.Code);

                var transformation = new XmlTransformation(transformFile);
                var s = transformation.Apply(doc);
                var transformedCode     = doc.OuterXml;
                var transformedTemplate = new Template
                {
                    FileExtension = template.FileExtension,
                    Metadata      = new TemplateMetadata
                    {
                        Name   = new InternalName(null, $"{template.Metadata.Name}_{transformName}"),
                        Label  = $"{template.Metadata.Label} ({transformName.Humanize()})",
                        Schema = template.Metadata.Schema,
                    },
                    Code = transformedCode,
                };
                foreach (var property in template.Metadata.AdditionalProperties)
                {
                    transformedTemplate.Metadata.AdditionalProperties.Add(property);
                }

                templates.Add(transformedTemplate);
            }

            return(templates);
        }
Beispiel #3
0
        /// <summary>
        /// Transforms JavaSript Server Pages code so that it can be uploaded to Campaign.
        /// Allows the content of local JSSP files to be transformed for use in Campaign.
        /// There is no reverse method, so JavaScript Server Pages files cannot be directly downloaded from Campaign
        /// into the format in which they are stored locally.
        /// </summary>
        /// <param name="template">Source content</param>
        /// <param name="parameters">Parameters to determine transform behaviour</param>
        /// <returns>Transformed JavaScript Server Pages content</returns>
        public IEnumerable <Template> Transform(Template template, TransformParameters parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            if (string.IsNullOrEmpty(parameters.OriginalFileName))
            {
                throw new ArgumentException("Original file name must be provided.", nameof(parameters.OriginalFileName));
            }

            var workingDirectory = Path.GetDirectoryName(parameters.OriginalFileName);

            template.Code = ProcessIncludes(template.Code, workingDirectory);
            return(new[] { template });
        }