慧云科技 > 首页 > 文章详情

奥杰CMS源码 - common.cs (3)

本文来源:网站建设-网站制作|网络营销专家慧云科技-

抢滩登陆

2009-6-2 20:21:57


        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        ///


        /// 获取工厂的完整根URL
        ///

        private static Regex vUrlRg = new Regex( @"^(http://[^/\?#]+/[\w/]*)admin", RegexOptions.Compiled );
        public static string GetFactoryFullUrl()
        {
            Match urlM = vUrlRg.Match( NowRequest._.Url.AbsoluteUri.ToLower() );
            if( urlM.Success )
                return urlM.Groups[1].Value + "Admin/";
            else
                return "";
        }
        public static string GetSiteRootUrl()
        {
            Match urlM = vUrlRg.Match( NowRequest._.Url.AbsoluteUri.ToLower() );
            if( urlM.Success )
                return urlM.Groups[1].Value;
            else
                return "";
        }


        ///


        /// 按名称获取全局路径
        ///

        public static string GetPath( string name )
        {
            return ReadPath( name );
        }
        public static string GetPathByPath( string path )
        {
            string n, p;
            Match m1 = replaceRg.Match( path );
            if( m1.Success ) {
                n = m1.Groups[1].Value;
                p = ReadPath( n );
                path = path.Replace( "%_" + n + "_%", p );
            }
            FileDo.RegularPath( ref path, true );
            return path;   //.Replace( @"\\", @"\" );
        }
        public static string GetPathBySite( string path, string siteRootPath )
        {
            string n;
            Match m1 = replaceRg.Match( path );
            if( m1.Success ) {
                n = m1.Groups[1].Value;
                if( n == "SiteRootPath" ) {
                    path = path.Replace( "%_SiteRootPath_%", siteRootPath );
                }
            }
            FileDo.RegularPath( ref path, true );
            return path;
        }

        private static Regex replaceRg = new Regex( @"%_([a-zA-Z]+)_%" );
        private static Regex wcReplaceRg = new Regex( @"\*_([a-zA-Z]+)_\*" );
        // 从 CommonConstDom 中递归读取系统文件夹路径
        private static string ReadPath( string name )
        {
            if( name == "AllSitesRootPath" ) return HttpRuntime.AppDomainAppPath;
            string sName = "";
            XmlElem xmlnode = CommonConstDom.GetElem( "//workPath/path[@name=‘" + name + "‘]" );
            if( xmlnode == null ) return "";

            sName = xmlnode["value"];
            if( string.IsNullOrEmpty( sName ) ) return "";

            string n, p;
            Match m1 = replaceRg.Match( sName );
            if( m1.Success ) {
                n = m1.Groups[1].Value;
                p = ReadPath( n );
                sName = sName.Replace( "%_" + n + "_%", p );
                FileDo.RegularPath( ref sName, true );
                return sName;   //.Replace( @"\\", @"\" );
                //return sName.Replace( @"\\", @"\" );
            }
            Match m2 = wcReplaceRg.Match( sName );
            if( m2.Success ) {
                n = m2.Groups[1].Value;
                p = ConfigurationSettings.AppSettings[n];
                sName = sName.Replace( "*_" + n + "_*", p );
            }
            FileDo.RegularPath( ref sName, true );
            return sName;   //.Replace( @"\\", @"\" );
            //return sName.Replace( @"\\", @"\" );
        }

        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        ///


        /// 获取 栏目字段类型 的 属性值
        ///

        public static string GetFieldTypeAttr( string typeName, string attrName )
        {
            XmlElem nod = CommonConstDom.GetElem( "//dataFieldType/type[@name=‘" + typeName + "‘]" );//columnFieldType
            if( nod == null ) return "";

            return nod[attrName.Trim()];
        }

        ///


        /// 获取指定 栏目字段类型 的 DBCMD,如果没有则创建
        ///

        public static string GetFieldTypeDbCmd( string typeName )
        {
            XmlElem nod = CommonConstDom.GetElem( "//dataFieldType/type[@name=‘" + typeName + "‘]" );//columnFieldType
            if( nod == null ) return "";

            string dbCmd = nod["dbCmd"];
            if( !string.IsNullOrEmpty( dbCmd ) )
                return dbCmd;
            else
                return nod["dbType"];
        }

        ///


        /// 获取栏目模版的 XML 字符串
        ///

        public static string GetColumnTemplateXml( string tempName )
        {
            XmlElem node = CommonConstDom.GetElem( "//columnTemplates/columnTemplate[@name=‘" + tempName + "‘]" );
            if( node == null ) return "";

            return node.InnerXml;
        }

        ///


        /// 获取不发布的文件夹名称数组
        ///

        public static String[] GetUnpublishFiles()
        {
            XmlNodeList files = CommonConstDom.GetNodes( "//unpublishFiles/file[@name=‘sys‘]" );
            string[] ret = new string[files.Count];
            int i = 0;
            foreach( XmlNode file in files ) {
                ret[i++] = XmlDo.GetAttr( "value", file );
            }
            return ret;
        }
    }
}


    /*///


    /// 获取数据库联接字符串 (全局)
    ///

    public static string GetDbConnString( string name )
    {
        XmlDomNode strxn = CommonConstDom.GetNode( "//connectionStrings/connString[@name=‘" + name + "‘]" );
        if( strxn == null ) return "";

        return strxn.GetAttr( "value" );

        try {
            return ConfigurationSettings.AppSettings[name];
        } catch( Exception ex ) {
            Todo.DebugOut( "[.GetDbConnString] By ‘" + name + "‘Error: " + ex.Message );
            return "";
        }
        //try {
        //} catch( Exception ex ) {
        //    Todo.DebugOut( "GetDbConnString By ‘" + name + "‘Error: " + ex.Message );
        //    return "";
        //}
    }/**/

    //private static Regex selReg = new Regex(@"^([a-zA-Z_]+).*");
    //public static StringDictionary SelectFieldAttrList( string typeName)
    //{
    //    Match m = selReg.Match( typeName );
    //    if( !m.Success ) return null;
    //    string name = m.Groups[1].Value;
    //    XmlDomNode nod = CommonConstDom.GetNode( "//columnFieldType/type[@name=‘" + name + "‘]" );
    //    if( nod == null ) return null;
    //    return nod.GetAttrs();
    //}
//.Attributes["value"].Value.ToString();
//Regex rg1 = new Regex( @"%_([a-z]+)_%", RegexOptions.IgnoreCase );
//string p2 = ReadPath( n2 );
//Regex rg1 = new Regex( "%_" + n2 + "_%" );
//sName = rg1.Replace( sName, p2 );
//sName = ReplaceByWebConfig( sName );

// 从 WebConfig 里读取 Factory 和 Site 磁盘路径
//private static string ReplaceByWebConfig( string sName )
//{
//    if( sName == "" ) return "";
//    string name = "";
//    Match mPath = Todo.RegMatch( sName, "\\*_([a-z]+)_\\*" );
//    if( mPath.Success ) {
//        name = mPath.Groups[1].Value;
//    }
//    string readConfigValue = sName;
//    if( name != "" ) {
//        readConfigValue = ConfigurationSettings.AppSettings[name];
//    }
//    return readConfigValue;
//}
//if( file.Attributes[""] != null ) {
            //    ret[i++] = file.Attributes["value"].Value;
            //}


RSS订阅| 关于我们| 网站地图| 加入项目| 法律条款| 友情链接| Firefox| Sitemap| 网站统计

全国免费咨询热线:400-600-6495 优惠活动咨询电话:021-62278496 Email:ajaxcms@yahoo.cn

上海慧云信息科技有限公司版权所有 2006-2009 沪ICP备09038165号

本站关键词:网站建设 高品质网站建设