Esempio n. 1
0
        /// <summary>
        /// Replaces previous extracted references to Tridion items in the template.
        /// </summary>
        /// <param name="newReferences"></param>
        public override void PerformSubstituteReferences(string[] newReferences)
        {
            RazorHandler handler = new RazorHandler(TemplateId.ToString(), WebDavUrl, Content);

            handler.Initialize();
            List <string> references = handler.GetImportReferences();

            List <string> dwReferences = new List <string>();
            int           count        = newReferences.Length - references.Count;

            for (int i = 0; i < count; i++)
            {
                dwReferences.Add(newReferences[i]);
            }

            _dwHandler.PerformSubstituteReferences(dwReferences.ToArray());

            if (handler.Config.ImportSettings.ReplaceRelativePaths)
            {
                foreach (string path in references)
                {
                    if (!path.StartsWith("tcm:") && !path.StartsWith("/webdav/"))
                    {
                        Content = Content.Replace(path, GetRelativeImportPath(path));
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Compiles the template. If there are any compilation errors, an error will be thrown at save time.
        /// </summary>
        private void ValidateCompilation()
        {
            RazorHandler handler = new RazorHandler(TemplateId.ToString(), WebDavUrl, Content);

            handler.Initialize();
            handler.CompileOnly(DateTime.Now);
        }
        /// <summary>
        /// Execute the specified template in the context of the given package. The mediator is expected to be able to handle the template, 
        /// as it is called based on the template types configuration.  
        /// </summary>
        /// <param name="engine">The Tridion engine invoking the templating.</param>
        /// <param name="template">The Tridion Template to execute.</param>
        /// <param name="package">The Tridion package with both the inputs and the outputs of the template.</param>
        public void Transform(Engine engine, Template template, Package package)
        {
            RazorHandler handler = new RazorHandler(template.Id.ToString(), template.WebDavUrl, template.Content, template);
            handler.Initialize();

            string output = handler.CompileAndExecute(template.RevisionDate, engine, package);

            if (_config.ExtractBinaries)
                output = ExtractBinaries(output, engine, package);

            package.PushItem(Package.OutputName, package.CreateStringItem(ContentType.Html, output));
        }
        /// <summary>
        /// Execute the specified template in the context of the given package. The mediator is expected to be able to handle the template,
        /// as it is called based on the template types configuration.
        /// </summary>
        /// <param name="engine">The Tridion engine invoking the templating.</param>
        /// <param name="template">The Tridion Template to execute.</param>
        /// <param name="package">The Tridion package with both the inputs and the outputs of the template.</param>
        public void Transform(Engine engine, Template template, Package package)
        {
            RazorHandler handler = new RazorHandler(template.Id.ToString(), template.WebDavUrl, template.Content, template);

            handler.Initialize();

            string output = handler.CompileAndExecute(template.RevisionDate, engine, package);

            if (_config.ExtractBinaries)
            {
                output = ExtractBinaries(output, engine, package);
            }

            package.PushItem(Package.OutputName, package.CreateStringItem(ContentType.Html, output));
        }
Esempio n. 5
0
        /// <summary>
        /// Extarcts the references to Tridion items from the template content. It is allowed to have values in the result that are not valid Tridion references.
        /// </summary>
        /// <returns></returns>
        public override string[] PerformExtractReferences()
        {
            TemplatingLogger log = TemplatingLogger.GetLogger(this.GetType());

            string[] dwReferences = _dwHandler.PerformExtractReferences();

            RazorHandler handler = new RazorHandler(TemplateId.ToString(), WebDavUrl, Content);

            handler.Initialize();

            List <string> imports    = handler.GetImportReferences();
            List <string> references = dwReferences.ToList();

            foreach (string path in imports)
            {
                if (!path.ToLower().StartsWith("tcm:") && !path.ToLower().StartsWith("/webdav/"))
                {
                    references.Add(GetRelativeImportPath(path));
                }
                else
                {
                    if (path.StartsWith("/webdav/"))
                    {
                        string[] pathParts   = path.Split('/');
                        string[] webDavParts = WebDavUrl.Split('/');

                        if (pathParts[2] != webDavParts[2])
                        {
                            pathParts[2] = webDavParts[2];
                        }

                        references.Add(String.Join("/", pathParts));
                    }
                    else if (TcmUri.IsValid(path))
                    {
                        TcmUri uri = new TcmUri(path);
                        if (uri.PublicationId != TemplateId.PublicationId)
                        {
                            uri = new TcmUri(uri.ItemId, uri.ItemType, TemplateId.PublicationId);
                        }
                        references.Add(uri.ToString());
                    }
                }
            }

            return(references.ToArray());
        }
        /// <summary>
        /// Extarcts the references to Tridion items from the template content. It is allowed to have values in the result that are not valid Tridion references.
        /// </summary>
        /// <returns></returns>
        public override string[] PerformExtractReferences()
        {
            TemplatingLogger log = TemplatingLogger.GetLogger(this.GetType());

            string[] dwReferences = _dwHandler.PerformExtractReferences();

            RazorHandler handler = new RazorHandler(TemplateId.ToString(), WebDavUrl, Content);
            handler.Initialize();

            List<string> imports = handler.GetImportReferences();
            List<string> references = dwReferences.ToList();

            foreach (string path in imports)
            {
                if (!path.ToLower().StartsWith("tcm:") && !path.ToLower().StartsWith("/webdav/"))
                {
                    references.Add(GetRelativeImportPath(path));
                }
                else
                {
                    if (path.StartsWith("/webdav/"))
                    {
                        string[] pathParts = path.Split('/');
                        string[] webDavParts = WebDavUrl.Split('/');

                        if (pathParts[2] != webDavParts[2])
                        {
                            pathParts[2] = webDavParts[2];
                        }

                        references.Add(String.Join("/", pathParts));
                    }
                    else if (TcmUri.IsValid(path))
                    {
                        TcmUri uri = new TcmUri(path);
                        if (uri.PublicationId != TemplateId.PublicationId)
                        {
                            uri = new TcmUri(uri.ItemId, uri.ItemType, TemplateId.PublicationId);
                        }
                        references.Add(uri.ToString());
                    }
                }
            }

            return references.ToArray();
        }
 /// <summary>
 /// Compiles the template. If there are any compilation errors, an error will be thrown at save time.
 /// </summary>
 private void ValidateCompilation()
 {
     RazorHandler handler = new RazorHandler(TemplateId.ToString(), WebDavUrl, Content);
     handler.Initialize();
     handler.CompileOnly(DateTime.Now);
 }
        /// <summary>
        /// Replaces previous extracted references to Tridion items in the template.
        /// </summary>
        /// <param name="newReferences"></param>
        public override void PerformSubstituteReferences(string[] newReferences)
        {
            RazorHandler handler = new RazorHandler(TemplateId.ToString(), WebDavUrl, Content);
            handler.Initialize();
            List<string> references = handler.GetImportReferences();

            List<string> dwReferences = new List<string>();
            int count = newReferences.Length - references.Count;

            for (int i = 0; i < count; i++)
            {
                dwReferences.Add(newReferences[i]);
            }

            _dwHandler.PerformSubstituteReferences(dwReferences.ToArray());

            if (handler.Config.ImportSettings.ReplaceRelativePaths)
            {
                foreach (string path in references)
                {
                    if (!path.StartsWith("tcm:") && !path.StartsWith("/webdav/"))
                    {
                        Content = Content.Replace(path, GetRelativeImportPath(path));
                    }
                }
            }
        }