Beispiel #1
0
        // 构造函数
        // paramter:
        //		dbColl  数据库集合指针
        //		user    帐户对象指针
        //		dom     检索式DOM
        public Query(DatabaseCollection dbColl,
            User user,
            XmlDocument dom)
        {
            m_dbColl = dbColl;
            m_oUser = user;
            m_dom = dom;

            // 从dom里找到warnging的处理级别信息
            string strWarningLevel = "";
            XmlNode nodeWarningLevel = dom.SelectSingleNode("//option");
            if (nodeWarningLevel != null)
                strWarningLevel = DomUtil.GetAttr(nodeWarningLevel, "warning");

            if (StringUtil.RegexCompare(@"\d", strWarningLevel) == true)
                m_nWarningLevel = Convert.ToInt32(strWarningLevel);
        }
Beispiel #2
0
        private long m_lObjectStartSize = 0x7ffffffe;   // 10 * 1024;    // 大于等于这个尺寸的对象将存储在对象文件中。-1表示永远不使用对象目录

        public SqlDatabase(DatabaseCollection container)
            : base(container)
        { }
Beispiel #3
0
 public FileDatabase(DatabaseCollection container)
     : base(container)
 { }
Beispiel #4
0
        public int FastAppendTaskCount = 0; // 启动 fast mode 的嵌套次数
        // public bool IsDelayWriteKey = false;    // 是否处在延迟写入keys的状态 2013/2/16

        internal Database(DatabaseCollection container)
        {
            this.container = container;
        }
Beispiel #5
0
        /*
        public int UseCount
        {
            get
            {
                return this.m_nUseCount;
            }
        }
         */

        // 初始化用户对象
        // 线程不安全。因为被调用时尚未进入集合,也没有必要线程安全
        // parameters:
        //      dom         用户记录dom
        //      strResPath  记录路径 全路径 库名/记录号
        //      db          所从属的数据库
        //      strError    out参数,返回出错信息
        // return:
        //      -1  出错
        //      0   成功
        internal int Initial(string strRecPath,
            XmlDocument dom,
            Database db,
            DatabaseCollection dbs,
            out string strError)
        {
            strError = "";
            int nRet = 0;

            this.RecPath = strRecPath;
            this.m_dom = dom;
            // this.m_db = db;

            XmlNode root = this.m_dom.DocumentElement;
            XmlNode nodeName = root.SelectSingleNode("name");
            if (nodeName != null)
                this.Name = DomUtil.GetNodeText(nodeName).Trim();

            // 用户所拥有的数据库
            this.aOwnerDbName = null;

            if (String.IsNullOrEmpty(this.Name) == false)
            {
                List<string> aOwnerDbName = null;

                nRet = dbs.GetOwnerDbNames(this.Name,
                    out aOwnerDbName,
                    out strError);
                if (nRet == -1)
                    return -1;

                this.aOwnerDbName = aOwnerDbName;
            }




            XmlNode nodePassword = root.SelectSingleNode("password");
            if (nodePassword != null)
                SHA1Password = DomUtil.GetNodeText(nodePassword).Trim();

            XmlNode nodeRightsItem = root.SelectSingleNode("rightsItem");
            if (nodeRightsItem != null)
            {
                strError = "帐户记录为旧版本,根元素下已经不支持<rightsItem>元素。";
                return -1;
            }

            // 没有<server>元素是否按出错处理
            this.m_nodeServer = root.SelectSingleNode("server");
            if (this.m_nodeServer == null)
            {
                strError = "帐户记录未定义<server>元素。";
                return -1;
            }

            this.cfgRights = new CfgRights();
            // return:
            //      -1  出错
            //      0   成功
            nRet = this.cfgRights.Initial(this.m_nodeServer,
                out strError);
            if (nRet == -1)
                return -1;

            return 0;
        }
Beispiel #6
0
        // TODO: 改进为可以重复调用。然后被 Dispose() 调用
        // 关闭
        public void Close()
        {
            eventClose.Set();	// 令工作线程退出

            // 等待工作线程真正退出
            // 因为可能正在回写数据库
            eventFinished.WaitOne(5000, false); // 最多5秒

            if (this.Dbs != null)
            {
                try
                {
                    this.Dbs.Close();
                }
                catch (Exception ex)
                {
                    this.WriteErrorLog("Dbs Close() error : " + ex.Message);
                }
                // this.Dbs.WriteErrorLog("在GlobalInfo.Close()处保存database.xml");
            }

            try
            {
                if (this.Users != null)
                {
                    this.Users.Close();
                    this.Users = null;
                }
            }
            catch (Exception ex)
            {
                this.WriteErrorLog("Users Close() error : " + ex.Message);
            }

            if (this.ResultSets != null)
            {
                try
                {
                    this.ResultSets.Clean(new TimeSpan(0, 0, 0));   // 立即全部清除
                }
                catch (Exception ex)
                {
                    this.WriteErrorLog("释放 ResultSets 遇到异常:" + ExceptionUtil.GetDebugText(ex));
                }
            }


            this.WriteErrorLog("kernel application 成功降落。");

            this.Dbs = null;
        }
Beispiel #7
0
        // 初始化GlobalInfo
        // parameters:
        //		strDataDir	数据目录
        //		strError	out参数,返回出错信息
        // return:
        //		-1	error
        //		0	successed
        public int Initial(string strDataDir,
            string strBinDir,
            out string strError)
        {
            strError = "";
            int nRet = 0;

            DateTime start = DateTime.Now;

            this.DataDir = strDataDir;

            this.SessionDir = PathUtil.MergePath(this.DataDir, "session");

            // 清除 session 目录中的全部下级目录

            // 日志文件
            string strLogDir = this.DataDir + "\\log";
            try
            {
                PathUtil.CreateDirIfNeed(strLogDir);
            }
            catch (Exception ex)
            {
                DirectoryInfo di = new DirectoryInfo(this.DataDir);
                if (di.Exists == false)
                    strError = "创建日志目录出错: '" + ex.Message + "', 原因是上级目录 '" + this.DataDir + "' 不存在...";
                else
                    strError = "创建日志目录出错: " + ex.Message;
                return -1;
            }

            this.LogDir = strLogDir;

            // this.m_strLogFileName = strLogDir + "\\log.txt";
            this.m_strDebugFileName = strLogDir + "\\debug.txt";

            this.WriteErrorLog("kernel application 开始初始化");

            CleanSessionDir(this.SessionDir);

            // 全局结果集目录
            string strResultSetDir = Path.Combine(this.DataDir, "resultsets");
            try
            {
                PathUtil.CreateDirIfNeed(strResultSetDir);
            }
            catch (Exception ex)
            {
                DirectoryInfo di = new DirectoryInfo(this.DataDir);
                if (di.Exists == false)
                    strError = "创建全局结果集目录出错: '" + ex.Message + "', 原因是上级目录 '" + this.DataDir + "' 不存在...";
                else
                    strError = "创建全局结果集目录出错: " + ex.Message;
                return -1;
            }

            // 清除以前遗留的结果集文件
            CleanResultSetDir(strResultSetDir);

            this.ResultsetDir = strResultSetDir;

            this.ResultSets.ResultsetDir = strResultSetDir;

            // 初始化数据库集合
            this.Dbs = new DatabaseCollection();
            try
            {
                nRet = this.Dbs.Initial(
                    this,
                    // strDataDir,
                    strBinDir,
                    out strError);
                if (nRet == -1)
                    return -1;
            }
            catch (Exception ex)
            {
                strError = "dbs的Initialize()抛出异常:" + ex.Message;
                return -1;
            }

            // 检验各个数据库记录尾号
            // return:
            //      -1  出错
            //      0   成功
            // 线:安全
            nRet = this.Dbs.CheckDbsTailNo(out strError);
            if (nRet == -1)
            {
                // 虽然发生错误,但是初始化过程继续进行
                this.WriteErrorLog("ERR001 首次校验数据库尾号发生错误:" + strError);
            }

            /*
            // 初始化用户库集合
            UserDatabaseCollection userDbs = new UserDatabaseCollection();
            // 初始化用户库集合对象
            // paramter:
            //		dbColl  总数据库集合
            //      strError    out参数,返回出错信息
            // return:
            //      -1  出错
            //      0   成功
            // 线:安全
            nRet = userDbs.Initial(this.Dbs,
                out strError);
            if (nRet == -1)
                return -1;
             */

            // 初始化用户集合
            this.Users = new UserCollection();
            nRet = this.Users.Initial(this,
                out strError);
            if (nRet == -1)
                return -1;

            // 把帐户集合对象的指针传给DatabaseCollection对象。
            // this.Dbs.UserColl = Users;

            // 启动工作线程
            StartWorkerThread();

            TimeSpan delta = DateTime.Now - start;
            this.WriteErrorLog("kernel application 成功初始化。初始化操作耗费时间 " + delta.TotalSeconds.ToString() + " 秒");
            return 0;
        }