Exemplo n.º 1
0
        /// <summary>
        /// Resolves the layout virtual path and ensures that file exist on the specified location.
        /// </summary>
        /// <param name="template">The template.</param>
        /// <returns>
        /// If the provided template is not in pure MVC mode returns null.
        /// If the provided template is in pure MVC mode returns virtual path like "~/SfLayouts/some_title.master" and ensures that this path is pointing to existing resource.
        /// Otherwise returns null. 
        /// </returns>
        public virtual string GetVirtualPath(Pages.Model.IPageTemplate template)
        {
            if (template.GetTemplateFramework() != PageTemplateFramework.Mvc)
                return null;

            string templateName;
            var strictTemplate = template as PageTemplate;
            if (strictTemplate != null && strictTemplate.Name != null)
            {
                templateName = strictTemplate.Name;
            }
            else
            {
                var hasTitle = template as IHasTitle;
                if (hasTitle != null)
                    templateName = hasTitle.GetTitle();
                else
                    templateName = null;
            }

            if (templateName == null)
                return null;

            var virtualBuilder = this.CreateLayoutVirtualPathBuilder();
            var layoutVirtualPath = virtualBuilder.BuildPathFromName(templateName);
            var doesLayoutExist = VirtualPathManager.FileExists(layoutVirtualPath);

            if (!doesLayoutExist)
                layoutVirtualPath = null;

            return layoutVirtualPath;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Resolves the layout virtual path and ensures that file exist on the specified location.
        /// </summary>
        /// <param name="template">The template.</param>
        /// <returns>
        /// If the provided template is not in pure MVC mode returns null.
        /// If the provided template is in pure MVC mode returns virtual path like "~/SfLayouts/some_title.master" and ensures that this path is pointing to existing resource.
        /// Otherwise returns null. 
        /// </returns>
        public virtual string GetVirtualPath(Pages.Model.IPageTemplate template)
        {
            if (template.GetTemplateFramework() != PageTemplateFramework.Mvc)
                return null;

            var iHasTitle = template as IHasTitle;

            if (iHasTitle == null)
                return null;

            string templateTitle = iHasTitle.GetTitle();
            var vpBuilder = new LayoutVirtualPathBuilder();
            var layoutVirtualPath = vpBuilder.BuildPathFromTitle(templateTitle);
            var doesLayoutExist = VirtualPathManager.FileExists(layoutVirtualPath);

            if (!doesLayoutExist)
                layoutVirtualPath = null;

            return layoutVirtualPath;
        }