示例#1
0
        /// <summary>
        /// Compiles masters page and builds a <see cref="PageTemplateDescriptor" />.
        /// Returns <value>True</value> if there's no compilation errors
        /// </summary>
        /// <param name="filePath">The file path.</param>
        /// <param name="masterPage">The master page.</param>
        /// <param name="pageTemplateDescriptor">The page template descriptor.</param>
        /// <param name="renderingInfo">The rendering info.</param>
        /// <param name="loadingException">The loading exception.</param>
        /// <returns></returns>
        internal bool LoadMasterPage(
            string filePath,
            out MasterPage masterPage,
            out MasterPagePageTemplateDescriptor pageTemplateDescriptor,
            out MasterPageRenderingInfo renderingInfo,
            out Exception loadingException)
        {
            string virtualPath = ConvertToVirtualPath(filePath);

            try
            {
                masterPage = CompilationHelper.CompileMasterPage(virtualPath);
            }
            catch (Exception ex)
            {
                Log.LogError(LogTitle, "Failed to compile master page file '{0}'", virtualPath);
                Log.LogError(LogTitle, ex);

                loadingException       = ex is TargetInvocationException ? ex.InnerException : ex;
                masterPage             = null;
                pageTemplateDescriptor = null;
                renderingInfo          = null;
                return(false);
            }

            if (!(masterPage is MasterPagePageTemplate))
            {
                pageTemplateDescriptor = null;
                renderingInfo          = null;
                loadingException       = null;
                return(true);
            }

            try
            {
                ParseTemplate(virtualPath,
                              filePath,
                              masterPage as MasterPagePageTemplate,
                              out pageTemplateDescriptor,
                              out renderingInfo);
            }
            catch (Exception ex)
            {
                Log.LogError(LogTitle, "Failed to load master page template file '{0}'", virtualPath);
                Log.LogError(LogTitle, ex);

                loadingException       = ex;
                pageTemplateDescriptor = null;
                renderingInfo          = null;
                return(false);
            }

            loadingException = null;
            return(true);
        }
示例#2
0
        internal static void ParseTemplate(string virtualPath,
                                           string filePath,
                                           MasterPagePageTemplate masterPage,
                                           out MasterPagePageTemplateDescriptor pageTemplateDescriptor,
                                           out MasterPageRenderingInfo renderingInfo)
        {
            string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(filePath);

            string csFile = GetCodebehindFilePath(filePath);

            IDictionary <string, PropertyInfo>      placeholderProperties;
            Func <MasterPagePageTemplateDescriptor> constructor = () => new MasterPagePageTemplateDescriptor(filePath, csFile);

            pageTemplateDescriptor = TemplateDefinitionHelper.BuildPageTemplateDescriptor(masterPage, constructor, out placeholderProperties);

            if (pageTemplateDescriptor.Title == null)
            {
                pageTemplateDescriptor.Title = fileNameWithoutExtension;
            }

            renderingInfo = new MasterPageRenderingInfo(virtualPath, placeholderProperties);
        }
        /// <summary>
        /// Compiles masters page and builds a <see cref="PageTemplateDescriptor" />.
        /// Returns <value>True</value> if there's no compilation errors
        /// </summary>
        /// <param name="filePath">The file path.</param>
        /// <param name="masterPage">The master page.</param>
        /// <param name="pageTemplateDescriptor">The page template descriptor.</param>
        /// <param name="renderingInfo">The rendering info.</param>
        /// <param name="loadingException">The loading exception.</param>
        /// <returns></returns>
        internal bool LoadMasterPage(
            string filePath,
            out MasterPage masterPage,
            out MasterPagePageTemplateDescriptor pageTemplateDescriptor,
            out MasterPageRenderingInfo renderingInfo,
            out Exception loadingException)
        {
            string virtualPath = ConvertToVirtualPath(filePath);

            try
            {
                masterPage = CompilationHelper.CompileMasterPage(virtualPath);
            }
            catch (Exception ex)
            {
                Log.LogError(LogTitle, "Failed to compile master page file '{0}'", virtualPath);
                Log.LogError(LogTitle, ex);

                loadingException = ex is TargetInvocationException ? ex.InnerException : ex;
                masterPage = null;
                pageTemplateDescriptor = null;
                renderingInfo = null;
                return false;
            }

            if (!(masterPage is MasterPagePageTemplate))
            {
                pageTemplateDescriptor = null;
                renderingInfo = null;
                loadingException = null;
                return true;
            }

            try
            {
                ParseTemplate(virtualPath,
                                filePath,
                                masterPage as MasterPagePageTemplate,
                                out pageTemplateDescriptor,
                                out renderingInfo);
            }
            catch (Exception ex)
            {
                Log.LogError(LogTitle, "Failed to load master page template file '{0}'", virtualPath);
                Log.LogError(LogTitle, ex);

                loadingException = ex;
                pageTemplateDescriptor = null;
                renderingInfo = null;
                return false;
            }

            loadingException = null;
            return true;
        }
        internal static void ParseTemplate(string virtualPath, 
            string filePath,
            MasterPagePageTemplate masterPage,
            out MasterPagePageTemplateDescriptor pageTemplateDescriptor,
            out MasterPageRenderingInfo renderingInfo)
        {
            string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(filePath);

            string csFile = GetCodebehindFilePath(filePath);

            IDictionary<string, PropertyInfo> placeholderProperties;
            Func<MasterPagePageTemplateDescriptor> constructor = () => new MasterPagePageTemplateDescriptor(filePath, csFile);

            pageTemplateDescriptor = TemplateDefinitionHelper.BuildPageTemplateDescriptor(masterPage, constructor, out placeholderProperties);

            if (pageTemplateDescriptor.Title == null)
            {
                pageTemplateDescriptor.Title = fileNameWithoutExtension;
            }

            renderingInfo = new MasterPageRenderingInfo(virtualPath, placeholderProperties);
        }