Exemple #1
0
        public string GetFullTemplate(string skinID)
        {
            m_IncludedSkinFile = false;
            m_IncludedFiles    = new List <TemplateFile>();

            string path = this.FilePath;

            if (m_BaseFile != null)
            {
                if (File.Exists(path) == false)
                {
                    path = m_BaseFile.FilePath;
                }
                else
                {
                    m_IncludedSkinFile = true;
                }
            }

            string content = File.ReadAllText(path, Encoding.Default);

            MatchEvaluator callback = delegate(Match match)
            {
                string includeVirtualPath = match.Groups[1].Value;

                includeVirtualPath = GetIncludeFileVirtualPath(includeVirtualPath);

                TemplateFile includeFile = null;

                if (TemplateManager.GetTemplateFiles().TryGetValue(includeVirtualPath, out includeFile))
                {
                    if (skinID != MaxLabs.bbsMax.Consts.DefaultSkinID)
                    {
                        includeFile = includeFile.GetSkin(skinID);
                    }

                    string includePath = IOUtil.MapPath(includeVirtualPath);

                    //includeFile.ResetWatcher();

                    m_IncludedFiles.Add(includeFile);

                    string result = includeFile.GetFullTemplate(skinID);

                    if (m_IncludedSkinFile == false && includeFile.m_IncludedSkinFile)
                    {
                        m_IncludedSkinFile = true;
                    }

                    //开始处理包含文件的参数
                    string          includeParams = match.Groups["param"].Value;
                    MatchCollection matchs        = Pool <TemplateAttributeListRegex> .Instance.Matches(includeParams);

                    foreach (Match param in matchs)
                    {
                        //应该计算索引位置,否则会存在误判和错误替换
                        result = result.Replace("$" + param.Groups["name"].Value, param.Groups["value"].Value);
                    }

                    return(result);
                }
                else
                {
                    return(string.Empty);
                }
            };

            //content = regex_pager.Replace(content, delegate(Match match) {
            //    return OnMatchPager(match, skinID);
            //});
            content = regex_pager4.Replace(content, delegate(Match match)
            {
                return(OnMatchPager(match, skinID));
            });

            content = s_MatchNotes.Replace(content, string.Empty);

            content = s_MatchInclude.Replace(content, callback);

            content = s_MatchPreInclude.Replace(content, callback);

            content = regex_fast_css.Replace(content, new MatchEvaluator(ReplaceFast));
            content = regex_fast_js.Replace(content, new MatchEvaluator(ReplaceFast));



            content = content.Trim();

            return(content);

            //StringBuilder sb = new StringBuilder();

            //string vpath = path.Substring(Globals.GetPath(SystemDirecotry.Root).Length);

            //sb.AppendLine("<!--begin ").Append(vpath).AppendLine("-->");
            //sb.Append(content.Trim());
            //sb.AppendLine("<!--end ").Append(vpath).AppendLine("-->");

            //return sb.ToString();
        }
Exemple #2
0
        private string OnMatchPager(Match match, string skinID)
        {
            if (match.Groups["param"].Success == false)
            {
                return(match.Value);
            }

            string param = match.Groups["param"].Value;

            string name        = null;
            string skin        = null;
            string ajaxpanelid = null;
            string ajaxloader  = null;

            string buttonCount  = null;
            string totalRecords = null;
            string pageSize     = null;
            string pageNumber   = null;

            string urlFormat = null;

            foreach (Match paramMatch in regex_param.Matches(param))
            {
                string paramName  = paramMatch.Groups[GN_PARAM_NAME].Value;
                string paramValue = paramMatch.Groups[GN_PARAM_VALUE].Value;

                switch (paramName.ToLower())
                {
                case "id":
                case "name":
                    name = paramValue.ToLower();
                    break;

                case "skin":
                    skin = paramValue.ToLower();
                    break;

                case "ajaxpanelid":
                    ajaxpanelid = paramValue.ToLower();
                    break;

                case "ajaxloader":
                    ajaxloader = paramValue.ToLower();
                    break;

                case "buttoncount":
                    buttonCount = paramValue;
                    break;

                case "count":
                case "totalrecords":
                    totalRecords = paramValue;
                    break;

                case "pagesize":
                    pageSize = paramValue;
                    break;

                case "page":
                case "pagenumber":
                    pageNumber = paramValue;
                    break;

                case "urlformat":
                    urlFormat = paramValue.Replace("\"", "\\\"");
                    break;

                default:
                    break;
                }
            }
            if (string.IsNullOrEmpty(name))
            {
                name = string.Concat("__max_", ajaxLoaderIndex.ToString());
                ajaxLoaderIndex++;
            }

            if (skin == null)
            {
                skin = string.Empty;
            }

            //if (string.IsNullOrEmpty(ajaxpanelid))
            //    ajaxpanelid = string.Empty;

            if (string.IsNullOrEmpty(ajaxloader))
            {
                ajaxloader = string.Concat("__max_", ajaxLoaderIndex.ToString());
                ajaxLoaderIndex++;
            }

            skin = GetIncludeFileVirtualPath(skin);

            TemplateFile skinFile = null;

            if (TemplateManager.GetTemplateFiles().TryGetValue(skin, out skinFile))
            {
                StringBuilder builder = new StringBuilder();

                builder.Append("{=$__SetCurrentPager(");

                AppendPagerStringParam(builder, name, false);
                AppendPagerStringParam(builder, ajaxpanelid, false);
                AppendPagerStringParam(builder, ajaxloader, false);

                AppendPagerNumberParam(builder, pageSize, false);
                AppendPagerNumberParam(builder, pageNumber, false);
                AppendPagerNumberParam(builder, totalRecords, false);
                AppendPagerNumberParam(builder, buttonCount, false);

                AppendPagerStringParam(builder, urlFormat, true);
                //.Append(name).Append("\", ")

                //.Append("\"").Append(ajaxpanelid).Append("\", ")

                //.Append("\"").Append(ajaxloader).Append("\", ")


                //.Append(pageSize).Append(", ")


                //.Append(pageNumber).Append(", ")


                //.Append(totalRecords).Append(", ")


                //.Append(buttonCount).Append(", ")


                //.Append(urlFormat.Replace("\"", "\\\"")).Append(")");

                builder.Append(")}");
                builder.Append(skinFile.GetFullTemplate(skinID));

                return(builder.ToString());
            }

            return("找不到所需的包含文件");
        }
Exemple #3
0
        public void GenerateAspxCode(string skinID, TemplateFile templateFile, string[] templateImports)
        {
            string template = templateFile.GetFullTemplate(skinID);

            string checkString = ReadCheckString(templateFile);
            string newCheckString = GetNewCheckString(template);

            if (checkString != newCheckString)
            {
                #region 需要重新解析模板    

                m_Document = TemplateElement.CreateDocument(template, templateFile);

                m_CodeHead = new StringBuffer();
                m_CodeBody = new StringBuffer(template.Length);

                GenerateAspxCodeHead1(templateFile);

                GenerateAspxCode(m_Document, new ScopeData(null));

                GenerateAspxCodeHead2(templateFile, templateImports, skinID);

                string aspxCode = string.Concat("<%--", newCheckString, "--%>\r\n", m_CodeHead.ToString(), m_CodeBody.ToString());

                try
                {
                    using (StreamWriter writer = new StreamWriter(templateFile.ParsedFilePath, false, Encoding.UTF8))
                    {
                        writer.Write(aspxCode);
                    }
                }
                catch (Exception ex)
                {
                    LogHelper.CreateErrorLog(ex, templateFile.FileName + "写入文件时出错");
                }

                LogHelper.CreateDebugLog(templateFile.FileName + "发生了重新解析,并写入磁盘");

                #endregion
            }

            TryBuildTempWebConfig();
        }