Exemple #1
0
        // 设置数据库的基本信息
        // parameters:
        //		logicNames	        LogicNameItem数组,用新的逻辑库名数组替换原来的逻辑库名数组
        //		strType	            数据库类型,以逗号分隔,可以是file,accout,目前无效,因为涉及到是文件库,还是sql库的问题
        //		strSqlDbName	    指定的新Sql数据库名称,目前无效,,如果数据库为文为文件型数据库,则返回数据源目录的名称
        //		strkeysDefault	    keys配置信息。如果为null,表示此项无效。(注:如果为""则表示要把文件内容清空)
        //		strBrowseDefault	browse配置信息。如果为null,表示此项无效。(注:如果为""则表示要把文件内容清空)
        // return:
        //		-1	出错
        //      -2  已存在同名的数据库
        //		0	成功
        public int SetInfo(LogicNameItem[] logicNames,
            string strType,
            string strSqlDbName,
            string strKeysText,
            string strBrowseText,
            out string strError)
        {
            strError = "";

            //****************对数据库加写锁***********
            m_TailNolock.AcquireWriterLock(m_nTimeOut);
#if DEBUG_LOCK
			this.container.WriteDebugInfo("SetInfo(),对'" + this.GetCaption("zh-CN") + "'数据库加写锁。");

#endif
            try
            {
                // 2008/4/30 changed
                // "" 和 null含义不同。后者表示不使用这个参数
                /*
                if (strKeysText == null)
                    strKeysText = "";
                if (strBrowseText == null)
                    strBrowseText = "";
                 * */

                if (String.IsNullOrEmpty(strKeysText) == false)
                {
                    XmlDocument dom = new XmlDocument();
                    try
                    {
                        dom.LoadXml(strKeysText);
                    }
                    catch (Exception ex)
                    {
                        strError = "加载keys配置文件内容到dom出错(1),原因:" + ex.Message;
                        return -1;
                    }
                }

                if (String.IsNullOrEmpty(strBrowseText) == false)
                {
                    XmlDocument dom = new XmlDocument();
                    try
                    {
                        dom.LoadXml(strBrowseText);
                    }
                    catch (Exception ex)
                    {
                        strError = "加载browse配置文件内容到dom出错,原因:" + ex.Message;
                        return -1;
                    }
                }

                // 可以一个逻辑库名也没有,不出错
                string strLogicNames = "";
                for (int i = 0; i < logicNames.Length; i++)
                {
                    string strLang = logicNames[i].Lang;
                    string strLogicName = logicNames[i].Value;

                    if (strLang.Length != 2
                        && strLang.Length != 5)
                    {
                        strError = "语言版本字符串长度只能是2位或者5位,'" + strLang + "'语言版本不合法";
                        return -1;
                    }

                    if (this.container.IsExistLogicName(strLogicName, this) == true)
                    {
                        strError = "数据库中已存在'" + strLogicName + "'逻辑库名";
                        return -2;
                    }
                    strLogicNames += "<caption lang='" + strLang + "'>" + strLogicName + "</caption>";
                }

                // 修改LogicName,使用全部替换的方式
                XmlNode nodeLogicName = this.PropertyNode.SelectSingleNode("logicname");
                nodeLogicName.InnerXml = strLogicNames;

                int nRet = 0;

                // 2008/5/7
                nRet = RefreshLognames(this.PureID,
                    strLogicNames,
                    out strError);
                if (nRet == -1)
                    return -1;

                // 目前不支持修改strType,strSqlDbName

                if (strKeysText != null)  // 2008/4/30
                {
                    string strKeysFileName = "";//this.GetFixedCfgFileName("keys");
                    string strDbName = this.GetCaption("zh");

                    // string strDbName = this.GetCaption("zh");

                    // return:
                    //		-1	一般性错误,比如调用错误,参数不合法等
                    //		-2	没找到节点
                    //		-3	localname属性未定义或为值空
                    //		-4	localname在本地不存在
                    //		-5	存在多个节点
                    //		0	成功
                    nRet = this.container.GetFileCfgItemLocalPath(strDbName + "/cfgs/keys",
                        out strKeysFileName,
                        out strError);
                    if (nRet != 0)
                    {
                        if (nRet != -2 && nRet != -4)
                            return -1;
                        else if (nRet == -2)
                        {
                            // return:
                            //		-1	出错
                            //		0	成功
                            nRet = this.container.SetFileCfgItem(
                                false,
                                this.GetCaption("zh") + "/cfgs",
                                null,
                                "keys",
                                out strError);
                            if (nRet == -1)
                                return -1;

                            // return:
                            //		-1	一般性错误,比如调用错误,参数不合法等
                            //		-2	没找到节点
                            //		-3	localname属性未定义或为值空
                            //		-4	localname在本地不存在
                            //		-5	存在多个节点
                            //		0	成功
                            nRet = this.container.GetFileCfgItemLocalPath(this.GetCaption("zh") + "/cfgs/keys",
                                out strKeysFileName,
                                out strError);
                            if (nRet != 0)
                            {
                                if (nRet != -4)
                                    return -1;
                            }
                        }
                    }

                    if (File.Exists(strKeysFileName) == false)
                    {
                        Stream s = File.Create(strKeysFileName);
                        s.Close();
                    }

                    nRet = DatabaseUtil.CreateXmlFile(strKeysFileName,
                        strKeysText,
                        out strError);
                    if (nRet == -1)
                        return -1;

                    // 把缓冲清空
                    this.m_keysCfg = null;
                }

                if (strBrowseText != null)  // 2008/4/30
                {
                    string strDbName = this.GetCaption("zh");

                    string strBrowseFileName = "";

                    // return:
                    //		-1	一般性错误,比如调用错误,参数不合法等
                    //		-2	没找到节点
                    //		-3	localname属性未定义或为值空
                    //		-4	localname在本地不存在
                    //		-5	存在多个节点
                    //		0	成功
                    nRet = this.container.GetFileCfgItemLocalPath(strDbName + "/cfgs/browse",
                        out strBrowseFileName,
                        out strError);
                    if (nRet != 0)
                    {
                        if (nRet != -2 && nRet != -4)
                            return -1;
                        else if (nRet == -2)
                        {
                            // return:
                            //		-1	出错
                            //		0	成功
                            nRet = this.container.SetFileCfgItem(
                                false,
                                this.GetCaption("zh") + "/cfgs",
                                null,
                                "browse",
                                out strError);
                            if (nRet == -1)
                                return -1;

                            // return:
                            //		-1	一般性错误,比如调用错误,参数不合法等
                            //		-2	没找到节点
                            //		-3	localname属性未定义或为值空
                            //		-4	localname在本地不存在
                            //		-5	存在多个节点
                            //		0	成功
                            nRet = this.container.GetFileCfgItemLocalPath(this.GetCaption("zh") + "/cfgs/browse",
                                out strBrowseFileName,
                                out strError);
                            if (nRet != 0)
                            {
                                if (nRet != -4)
                                    return -1;
                            }
                        }
                    }

                    if (File.Exists(strBrowseFileName) == false)
                    {
                        Stream s = File.Create(strBrowseFileName);
                        s.Close();
                    }

                    nRet = DatabaseUtil.CreateXmlFile(strBrowseFileName,
                        strBrowseText,
                        out strError);
                    if (nRet == -1)
                        return -1;

                    // 把缓冲清空
                    // this.m_browseCfg = null;
                    // this.m_bHasBrowse = true; // 缺省值
                    this.browse_table.Clear();
                }

                return 0;
            }
            finally
            {
                //***************对数据库解写锁************
                m_TailNolock.ReleaseWriterLock();
#if DEBUG_LOCK
				this.container.WriteDebugInfo("SetInfo(),对'" + this.GetCaption("zh-CN") + "'数据库解写锁。");
#endif
            }
        }
Exemple #2
0
        // 写配置文件
        // parameters:
        //      strCfgItemPath  全路径,带库名
        // return:
        //		-1  一般性错误
        //      -2  时间戳不匹配
        //		0	成功
        // 线程,对库集合是不安全的
        internal int WriteFileForCfgItem(
            bool bNeedLock,
            string strCfgItemPath,
            string strFilePath,
            string strRanges,
            long lTotalLength,
            byte[] baSource,
            // Stream streamSource,
            string strMetadata,
            string strStyle,
            byte[] baInputTimestamp,
            out byte[] baOutputTimestamp,
            out string strError)
        {

            if (bNeedLock == true)
            {
                //**********对数据库加写锁**************
                this.m_db_lock.AcquireWriterLock(m_nTimeOut);
#if DEBUG_LOCK
			this.container.WriteDebugInfo("Dir(),对'" + this.GetCaption("zh-CN") + "'数据库加写锁。");
#endif
            }
            try
            {
                // return:
                //		-1	一般性错误
                //		-2	时间戳不匹配
                //		0	成功
                int nRet = this.container.WriteFileForCfgItem(strFilePath,
                    strRanges,
                    lTotalLength,
                    baSource,
                    // streamSource,
                    strMetadata,
                    strStyle,
                    baInputTimestamp,
                    out baOutputTimestamp,
                    out strError);
                if (nRet <= -1)
                    return nRet;

                int nPosition = strCfgItemPath.IndexOf("/");
                if (nPosition == -1)
                {
                    strError = "'" + strCfgItemPath + "'路径不包括'/',不合法。";
                    return -1;
                }
                if (nPosition == strCfgItemPath.Length - 1)
                {
                    strError = "'" + strCfgItemPath + "'路径最后是'/',不合法。";
                    return -1;
                }
                string strPathWithoutDbName = strCfgItemPath.Substring(nPosition + 1);
                // 如果为keys对象,则把该库的KeysCfg中的dom清空
                if (strPathWithoutDbName == "cfgs/keys")
                {
                    this.m_keysCfg = null;
                }

                // 如果为browse对象
                /*
                if (strPathWithoutDbName == "cfgs/browse")
                {
                    this.m_browseCfg = null;
                    this.m_bHasBrowse = true; // 缺省值
                }
                 * */
                if (this.browse_table[strPathWithoutDbName.ToLower()] != null)
                {
                    this.browse_table.Remove(strPathWithoutDbName.ToLower());
                }

                return 0;
            }
            finally
            {
                if (bNeedLock == true)
                {

                    //**********对数据库解写锁**************
                    this.m_db_lock.ReleaseWriterLock();
#if DEBUG_LOCK
			this.container.WriteDebugInfo("Dir(),对'" + this.GetCaption("zh-CN") + "'数据库解写锁。");
#endif
                }
            }

        }
Exemple #3
0
        // 得到检索点内存对象
        // 当返回0时,keysCfg可能为null
        public int GetKeysCfg(out KeysCfg keysCfg,
            out string strError)
        {
            strError = "";
            keysCfg = null;

            // 已存在时
            if (this.m_keysCfg != null)
            {
                keysCfg = this.m_keysCfg;
                return 0;
            }

            int nRet = 0;

            string strKeysFileName = "";
     
            string strDbName = this.GetCaption("zh");
            // return:
            //		-1	一般性错误,比如调用错误,参数不合法等
            //		-2	没找到节点
            //		-3	localname属性未定义或为值空
            //		-4	localname在本地不存在
            //		-5	存在多个节点
            //		0	成功
            nRet = this.container.GetFileCfgItemLocalPath(strDbName + "/cfgs/keys",
                out strKeysFileName,
                out strError);

            // 未定义keys对象,按正常情况处理
            if (nRet == -2)
                return 0;

            // keys文件在本地不存在,按正常情况处理
            if (nRet == -4)
                return 0;

            if (nRet != 0)
                return -1;


            this.m_keysCfg = new KeysCfg();
            nRet = this.m_keysCfg.Initial(strKeysFileName,
                this.container.BinDir,
                this is SqlDatabase && this.container.SqlServerType == SqlServerType.Oracle ? "" : null,
                out strError);
            if (nRet == -1)
            {
                this.m_keysCfg = null;
                return -1;
            }

            keysCfg = this.m_keysCfg;
            return 0;
        }