Esempio n. 1
0
File: Host.cs Progetto: gvhung/dp2
        // 2017/2/9
        // 检查不同实例的 dp2kernel 中所用的 SQL 数据库名是否发生了重复和冲突
        // return:
        //      -1  检查过程出错
        //      0   没有冲突
        //      1   发生了冲突。报错信息在 strError 中
        int CheckSqlDbNames(out string strError)
        {
            strError = "";

            Hashtable name_table   = new Hashtable();   // sqldbname --> InstanceValue
            Hashtable prefix_table = new Hashtable();   // prefix --> InstanceValue

            for (int i = 0; ; i++)
            {
                string   strInstanceName = "";
                string   strDataDir      = "";
                string   strCertSN       = "";
                string[] existing_urls   = null;
                bool     bRet            = GetInstanceInfo("dp2Kernel",
                                                           i,
                                                           out strInstanceName,
                                                           out strDataDir,
                                                           out existing_urls,
                                                           out strCertSN);
                if (bRet == false)
                {
                    break;
                }
                if (string.IsNullOrEmpty(strDataDir))
                {
                    continue;
                }

                // 检查不同实例的 dp2kernel 中所用的 SQL 数据库名是否发生了重复和冲突
                // return:
                //      -1  检查过程出错
                //      0   没有冲突
                //      1   发生了冲突。报错信息在 strError 中
                int nRet = InstallHelper.CheckDatabasesXml(
                    strInstanceName,
                    strDataDir,
                    prefix_table,
                    name_table,
                    out strError);
                if (nRet == -1)
                {
                    return(-1);
                }
                if (nRet == 1)
                {
                    return(1);
                }
#if NO
                string      strFileName = Path.Combine(strDataDir, "databases.xml");
                XmlDocument dom         = new XmlDocument();
                try
                {
                    dom.Load(strFileName);
                }
                catch (Exception ex)
                {
                    strError = "文件 '" + strFileName + "' 装入 XMLDOM 时出错: " + ex.Message;
                    return(-1);
                }

                // 检查 dbs/@instancename
                string       strInstancePrefix = "";
                XmlAttribute prefix            = dom.DocumentElement.SelectSingleNode("dbs/@instancename") as XmlAttribute;
                if (prefix != null)
                {
                    strInstancePrefix = prefix.Value;
                }

                if (prefix_table.ContainsKey(strInstancePrefix))
                {
                    InstanceValue data = (InstanceValue)prefix_table[strInstancePrefix];
                    strError = "实例 '" + strInstanceName + "' (" + strFileName + ") 中 dbs 元素 instancename 属性值 '" + strInstancePrefix + "' 和实例 '" + data.Instance + "' 的用法重复了";
                    return(1);
                }
                else
                {
                    InstanceValue data = new InstanceValue();
                    data.Instance = strInstanceName;
                    data.Value    = strInstancePrefix;
                    prefix_table[strInstancePrefix] = data;
                }

                // 检查 sqlserverdb/@name
                XmlNodeList name_nodes = dom.DocumentElement.SelectNodes("dbs/database/property/sqlserverdb/@name");
                foreach (XmlAttribute attr in name_nodes)
                {
                    string value = attr.Value;
                    if (string.IsNullOrEmpty(value))
                    {
                        continue;
                    }
                    value = value.ToLower();
                    if (name_table.ContainsKey(value))
                    {
                        InstanceValue data = (InstanceValue)name_table[value];
                        strError = "实例 '" + strInstanceName + "' 中 SQL 数据库名 '" + value + "' 和实例 '" + data.Instance + "' 中另一 SQL 数据库名重复了";
                        return(1);
                    }

                    {
                        InstanceValue data = new InstanceValue();
                        data.Instance     = strInstanceName;
                        data.Value        = value;
                        name_table[value] = data;
                    }
                }
#endif
            }

            return(0);
        }