示例#1
0
        /// <summary>
        /// Creates a template under the specified path using the given template.
        /// </summary>
        /// <param name="parentPath">Target location where the templates are copied to.</param>
        /// <param name="templatePath">The template is to be copied.</param>
        /// <returns></returns>
        public static Content CreateTemplated(string parentPath, string templatePath)
        {
            if (parentPath == null)
            {
                throw new ArgumentNullException("parentPath");
            }
            if (templatePath == null)
            {
                throw new ArgumentNullException("templatePath");
            }

            var parentNode = Node.LoadNode(parentPath);

            if (parentNode == null)
            {
                throw new InvalidOperationException(String.Format("Couldn't create a content from a template. ParentNode couldn't be loaded from {0} path.", parentPath));
            }

            var templateNode = Node.LoadNode(templatePath);

            if (templateNode == null)
            {
                throw new InvalidOperationException(String.Format("Couldn't create a content from a template. TemplateNode couldn't be loaded from {0} path.", templatePath));
            }

            return(ContentTemplate.CreateTemplated(parentNode, templateNode, null));
        }
示例#2
0
        /// <summary>
        /// Creates a template with the specified parameter based upon the contenttypename and
        /// </summary>
        /// <param name="contentTypeName">Specifies a CTD name.</param>
        /// <param name="templateName">Specified a template name for the CTD.</param>
        /// <param name="targetPath">Specifies a path of the target location where the template is copied to.</param>
        /// <returns></returns>
        public static Content CreateTemplated(string contentTypeName, string templateName, string targetPath)
        {
            if (String.IsNullOrEmpty(contentTypeName))
            {
                throw new ArgumentException("contentTypeName");
            }
            if (String.IsNullOrEmpty(templateName))
            {
                throw new ArgumentException("templateName");
            }
            if (String.IsNullOrEmpty(targetPath))
            {
                throw new ArgumentException("targetPath");
            }

            var targetNode = Node.LoadNode(targetPath);

            if (targetNode == null)
            {
                throw new InvalidOperationException(String.Format("{0} node couldn't be loaded.", targetPath));
            }

            var templatesForContentType = GetTemplatesForType <Node>(contentTypeName);
            var template = from t in templatesForContentType
                           where t.Name.Equals(templateName)
                           select t;

            if (template.Count() < 1)
            {
                throw new InvalidOperationException(String.Format("There is no template with {0} name for {1} contentType.", templateName, contentTypeName));
            }

            var templateNode = template.FirstOrDefault();

            return(ContentTemplate.CreateTemplated(targetNode, templateNode, null));
        }