Пример #1
0
        // 得到浏览格式内存对象
        // parameters:
        //      strBrowseName   浏览文件的文件名或者全路径
        //                      例如 cfgs/browse 。因为已经是在特定的数据库中获得配置文件,所以无需指定库名部分
        // return:
        //      -1  error
        //      0   not found
        //      1   found
        public int GetBrowseCfg(
            string strBrowseName,
            out BrowseCfg browseCfg,
            out string strError)
        {
            strError = "";
            browseCfg = null;

            strBrowseName = strBrowseName.ToLower();
            /*
            if (this.m_bHasBrowse == false)
                return 0;
             * */

            /*
            // 已存在时
            if (this.m_browseCfg != null)
            {
                browseCfg = this.m_browseCfg;
                return 0;
            }
             * */
            browseCfg = (BrowseCfg)this.browse_table[strBrowseName];
            if (browseCfg != null)
            {
                return 1;
            }

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

            // strDbName + "/cfgs/browse"
 * */
            string strBrowsePath = this.GetCaption("zh") + "/" + strBrowseName;

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

            if (nRet != 0)
            {
                return -1;
            }


            browseCfg = new BrowseCfg();
            nRet = browseCfg.Initial(strBrowseFileName,
                this.container.BinDir,
                out strError);
            if (nRet == -1)
            {
                browseCfg = null;
                return -1;
            }

            this.browse_table[strBrowseName] = browseCfg;
            return 1;
        }
Пример #2
0
        // 写配置文件
        // parameters:
        //      strCfgItemPath  全路径,带库名
        // return:
        //		-1  一般性错误
        //      -2  时间戳不匹配
        //		0	成功
        // 线程,对库集合是不安全的
        internal int WriteFileForCfgItem(string strCfgItemPath,
            string strFilePath,
            string strRanges,
            long lTotalLength,
            byte[] baSource,
            Stream streamSource,
            string strMetadata,
            string strStyle,
            byte[] baInputTimestamp,
            out byte[] baOutputTimestamp,
            out string strError)
        {
            //**********对数据库加写锁**************
            this.m_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; // 缺省值
                }

                return 0;
            }
            finally
            {
                //**********对数据库解写锁**************
                this.m_lock.ReleaseWriterLock();
#if DEBUG_LOCK
			this.container.WriteDebugInfo("Dir(),对'" + this.GetCaption("zh-cn") + "'数据库解写锁。");
#endif
            }

        }
Пример #3
0
        // 得到浏览格式内存对象
        // 当return 0时,可能browseCfg为null
        public int GetBrowseCfg(out BrowseCfg browseCfg,
            out string strError)
        {
            strError = "";
            browseCfg = null;

            if (this.m_bHasBrowse == false)
                return 0;

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

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

            if (nRet != 0)
            {
                return -1;
            }

            this.m_browseCfg = new BrowseCfg();
            nRet = this.m_browseCfg.Initial(strBrowseFileName,
                this.container.BinDir,
                out strError);
            if (nRet == -1)
            {
                this.m_browseCfg = null;
                return -1;
            }

            browseCfg = this.m_browseCfg;
            return 0;
        }
Пример #4
0
        // 设置数据库的基本信息
        // parameters:
        //		logicNames	        LogicNameItem数组,用新的逻辑库名数组替换原来的逻辑库名数组
        //		strType	            数据库类型,以逗号分隔,可以是file,accout,目前无效,因为涉及到是文件库,还是sql库的问题
        //		strSqlDbName	    指定的新Sql数据库名称,目前无效,,如果数据库为文为文件型数据库,则返回数据源目录的名称
        //		strkeysDefault	    keys配置信息
        //		strBrowseDefault	browse配置信息
        // 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
            {
                if (strKeysText == null)
                    strKeysText = "";
                if (strBrowseText == null)
                    strBrowseText = "";

                if (strKeysText != "")
                {
                    XmlDocument dom = new XmlDocument();
                    try
                    {
                        dom.LoadXml(strKeysText);
                    }
                    catch (Exception ex)
                    {
                        strError = "加载keys配置文件内容到dom出错,原因:" + ex.Message;
                        return -1;
                    }
                }
                if (strBrowseText != "")
                {
                    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.m_propertyNode.SelectSingleNode("logicname");
                nodeLogicName.InnerXml = strLogicNames;


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

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



                string strBrowseFileName = "";

                // return:
                //		-1	一般性错误,比如调用错误,参数不合法等
                //		-2	没找到节点
                //		-3	localname属性未定义或为值空
                //		-4	localname在本地不存在
                //		-5	存在多个节点
                //		0	成功
                nRet = this.container.GetFileCfgItemLacalPath(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(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.GetFileCfgItemLacalPath(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; // 缺省值


                return 0;
            }
            finally
            {
                //***************对数据库解写锁************
                m_TailNolock.ReleaseWriterLock();
#if DEBUG_LOCK
				this.container.WriteDebugInfo("SetInfo(),对'" + this.GetCaption("zh-cn") + "'数据库解写锁。");
#endif
            }
        }