解析ZCSJEnity的函数

来源:互联网 发布:wto国际贸易统计数据库 编辑:程序博客网 时间:2024/06/12 16:37

IBuild平台中解析ZCSJEnity的connect加密字符串变成oracle连接字符串的函数

        //解析ZCSJ的connect字符串        private string analisysConStr(string uncodeStr)        {            string outputstr = "";            string user = "";            string password = "";            string server = "";            string database = "";            string port = "";            //字符串示例            //{             //     SERVER =; INSTANCE = sde:oracle$orcl; DATABASE =; USER = sde; PASSWORD = sde; AUTHENTICATION = DBMS; VERSION = SDE.DEFAULT;            //     SERVER=;INSTANCE=sde:oracle$10.0.0.7/TDHZ2009;DATABASE=;USER=sde2016;PASSWORD=sde2016;AUTHENTICATION=DBMS;VERSION=SDE.DEFAULT;            //}            //            if (string.IsNullOrEmpty(uncodeStr))                return outputstr;            uncodeStr = SouthGIS.DB.Utility.EncryptUtil.DecryptString(uncodeStr).Trim();            List<string> strList = uncodeStr.Split(';').ToList();            foreach (string str in strList)            {                if (str.Contains("SERVER="))                {                    if (str.Length > 7)                        server = str.Substring(7);                    continue;                }                else if (str.Contains("DATABASE="))                {                    if (str.Length > 9)                        database = str.Substring(9);                    continue;                }                else if (str.Contains("INSTANCE="))                {                    if (str.Length > 9)                    {                        string temp = "";                        temp = str.Split('$')[1];                        if (temp.Contains('/'))                        {                            server = temp.Split('/')[0];                            database = temp.Split('/')[1];                        }                        else                        {                            server = "";                            database = temp;                        }                    }                    continue;                }                else if (str.Contains("USER="))                {                    if (str.Length > 5)                        user = str.Substring(5);                    continue;                }                else if (str.Contains("PASSWORD="))                {                    if (str.Length > 9)                        password = str.Substring(9);                    continue;                }            }            //解析服务器端口            if (server.Contains(":"))            {                string tStr = server.Split(':')[0];                port = server.Split(':')[1];                server = tStr;            }            server = server == "" ? "localhost" : server;            port = port == "" ? "1521" : port;            outputstr =                $@"Password={password};User ID={                        user                    };Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST={server})(PORT={                        port                    })))(CONNECT_DATA = (SERVICE_NAME = {database})))";            return outputstr;        }