示例#1
0
        /// <summary>
        /// 获得模板变量列表
        /// </summary>
        /// <param name="skinName">皮肤名</param>
        /// <returns></returns>
        public static DataTable GetTemplateVarList(string forumpath, string skinName)
        {
            Discuz.Cache.DNTCache cache = Discuz.Cache.DNTCache.GetCacheService();
            DataTable             dt    = cache.RetrieveSingleObject("/" + skinName + "/TemplateVariable") as DataTable;

            if (dt != null)
            {
                return(dt);
            }
            else
            {
                DataSet  dsSrc    = new DataSet("template");
                string[] filename = new string[1] {
                    Utils.GetMapPath(forumpath + "templates/" + skinName + "/templatevariable.xml")
                };

                if (Utils.FileExists(filename[0]))
                {
                    dsSrc.ReadXml(filename[0]);

                    if (dsSrc.Tables.Count == 0)
                    {
                        DataTable templatevariable = new DataTable("TemplateVariable");
                        templatevariable.Columns.Add("id", System.Type.GetType("System.Int32"));
                        templatevariable.Columns.Add("variablename", System.Type.GetType("System.String"));
                        templatevariable.Columns.Add("variablevalue", System.Type.GetType("System.String"));
                        dsSrc.Tables.Add(templatevariable);
                    }
                }
                else
                {
                    DataTable templatevariable = new DataTable("TemplateVariable");
                    templatevariable.Columns.Add("id", System.Type.GetType("System.Int32"));
                    templatevariable.Columns.Add("variablename", System.Type.GetType("System.String"));
                    templatevariable.Columns.Add("variablevalue", System.Type.GetType("System.String"));
                    dsSrc.Tables.Add(templatevariable);
                }

                cache.AddSingleObject("/" + skinName + "/TemplateVariable", dsSrc.Tables[0], filename);
                return(dsSrc.Tables[0]);
            }
        }