コード例 #1
0
ファイル: AppCenter.cs プロジェクト: zszqwe/dp2
        // 将远程书目库名替换为本地书目库名
        // return:
        //      -1  出错
        //      0   没有找到对应的本地书目库
        //      1   找到,并已经替换
        public int ReplaceBiblioRecPath(
            string strServer,
            ref string strRecPath,
            out string strError)
        {
            strError = "";

            string strDbName = ResPath.GetDbName(strRecPath);
            string strID     = ResPath.GetRecordId(strRecPath);

            foreach (ItemDbCfg cfg in this.ItemDbs)
            {
                if (cfg.ReplicationServer != strServer)
                {
                    continue;
                }
                if (strDbName == cfg.ReplicationDbName)
                {
                    strRecPath = cfg.BiblioDbName + "/" + strID;
                    return(1);
                }
            }

            strRecPath = "";
            return(0);
        }
コード例 #2
0
        public int BuildLocateParam(string strBiblioRecPath,
                                    string strIndex,
                                    out List <string> locateParam,
                                    out string strError)
        {
            strError    = "";
            locateParam = null;

            int nRet = 0;

            string strBiblioDbName = ResPath.GetDbName(strBiblioRecPath);
            string strOrderDbName  = "";

            // 根据书目库名, 找到对应的事项库名
            // return:
            //      -1  出错
            //      0   没有找到(书目库)
            //      1   找到
            nRet = this.GetItemDbName(strBiblioDbName,
                                      out strOrderDbName,
                                      out strError);
            if (nRet == -1)
            {
                goto ERROR1;
            }
            if (nRet == 0)
            {
                strError = "书目库 '" + strBiblioDbName + "' 没有找到";
                goto ERROR1;
            }
            if (String.IsNullOrEmpty(strOrderDbName) == true)
            {
                strError = "书目库名 '" + strBiblioDbName + "' 对应的" + this.ItemName + "库名没有定义";
                goto ERROR1;
            }

            string strParentID = ResPath.GetRecordId(strBiblioRecPath);


            locateParam = new List <string>();
            locateParam.Add(strOrderDbName);
            locateParam.Add(strParentID);
            locateParam.Add(strIndex);

            return(0);

ERROR1:
            return(-1);
        }
コード例 #3
0
        int LoadItems(string strBiblioRecPath,
                      out string strError)
        {
            strError = "";

            this.listView_items.Items.Clear();

            if (String.IsNullOrEmpty(strBiblioRecPath) == true)
            {
                /*
                 * strError = "strBiblioRecPath参数不能为空";
                 * return -1;
                 */
                return(0);
            }

            if (this.Items == null)
            {
                this.Items = new BookItemCollection();
            }
            else
            {
                this.Items.Clear();
            }

            // 检索出所有关联到种记录id的册记录
            long lRet = SearchItems(ResPath.GetRecordId(strBiblioRecPath),
                                    out strError);

            if (lRet == -1)
            {
                return(-1);
            }

            return(0);
        }
コード例 #4
0
        // 保存册信息
        // (如何删除册信息还是一个棘手的问题)
        int SaveItems(out string strError)
        {
            strError = "";

            if (this.Items == null)
            {
                strError = "Items尚未初始化";
                return(-1);
            }

            for (int i = 0; i < this.Items.Count; i++)
            {
                BookItem item = this.Items[i];

                // 跳过没有修改过的事项
                if (item.Changed == false)
                {
                    continue;
                }

                // 新事项
                if (item.RecPath == "")
                {
                    item.RecPath = this.ItemDbName + "/?";
                }

                if (item.Parent == "")
                {
                    if (String.IsNullOrEmpty(this.BiblioRecPath) == true)
                    {
                        strError = "因BiblioRecPath成员为空,无法构造册信息。";
                        return(-1);
                    }
                    item.Parent = ResPath.GetRecordId(this.BiblioRecPath);
                }

                string strXml = "";

                int nRet = item.BuildRecord(
                    out strXml,
                    out strError);
                if (nRet == -1)
                {
                    strError = "第 " + Convert.ToString(i + 1) + " 行构造册记录时出错: " + strError;
                    return(-1);
                }

                byte[] baOutputTimestamp = null;

                nRet = this.SearchPanel.SaveRecord(
                    this.ServerUrl,
                    item.RecPath,
                    strXml,
                    item.Timestamp,
                    true,
                    out baOutputTimestamp,
                    out strError);
                if (nRet == -1)
                {
                    strError = "第 " + Convert.ToString(i + 1) + " 行保存册记录时出错: " + strError;
                    return(-1);
                }
                item.Timestamp = baOutputTimestamp;
                item.Changed   = false;
                // 事项颜色会发生变化
                item.RefreshItemColor();
            }

            return(0);
        }
コード例 #5
0
ファイル: BackupTask.cs プロジェクト: hoku850/dp2
        // parameters:
        //      strBackupFileName   备份文件名。扩展名应为 .dp2bak
        // return:
        //      -1  出错
        //      0   处理被中断
        //      1   成功
        int BackupDatabase(
            RmsChannel channel,
            string strRecPathFileName,
            BreakPointInfo info,
            string strBackupFileName,
            out BreakPointInfo breakpoint,
            out string strError)
        {
            strError = "";

            breakpoint = new BreakPointInfo();
            breakpoint.BackupFileName = strBackupFileName;

            this._stop.BeginLoop();
            try
            {
                ExportUtil export_util = new ExportUtil();
                export_util.SafeMode = true;
                export_util.TempDir  = this.App.TempDir;
                int nRet = export_util.Begin(null,
                                             strBackupFileName,
                                             out strError);
                if (nRet == -1)
                {
                    return(-1);
                }

                try
                {
                    List <string> lines = new List <string>();
                    using (StreamReader sr = new StreamReader(strRecPathFileName, Encoding.UTF8))
                    {
                        long lTotalLength = sr.BaseStream.Length;

                        // 跳过断点位置前,以前已经处理过的行
                        if (info != null &&
                            string.IsNullOrEmpty(info.DbName) == false &&
                            string.IsNullOrEmpty(info.RecID) == false)
                        {
                            while (true)
                            {
                                if (this.Stopped == true)
                                {
                                    strError = "中断";
                                    WriteStateFile(strBackupFileName, "abort");  // 表示文件创建过程被中断。文件内容不完整
                                    return(0);
                                }

                                string line = sr.ReadLine();
                                if (line == null)
                                {
                                    break;
                                }
                                string strDbName = ResPath.GetDbName(line);
                                string strID     = ResPath.GetRecordId(line);

                                if (info.DbName == strDbName && info.RecID == strID)
                                {
                                    break;
                                }
                            }
                        }

                        this.AppendResultText("开始写入大备份文件" + strBackupFileName + "\r\n");

                        while (true)
                        {
                            if (this.Stopped == true)
                            {
                                strError = "中断";
                                WriteStateFile(strBackupFileName, "abort");  // 表示文件创建过程被中断。文件内容不完整
                                return(0);
                            }

                            string line = sr.ReadLine();
                            if (line != null)
                            {
                                lines.Add(line);
                            }

                            if (lines.Count >= BATCH_SIZE ||
                                (line == null && lines.Count > 0))
                            {
                                RmsBrowseLoader loader = new RmsBrowseLoader();
                                loader.Channel  = channel;
                                loader.Format   = "id,xml,timestamp,metadata";
                                loader.RecPaths = lines;

                                foreach (Record record in loader)
                                {
                                    if (this.Stopped == true)
                                    {
                                        strError = "中断";
                                        WriteStateFile(strBackupFileName, "abort");  // 表示文件创建过程被中断。文件内容不完整
                                        return(0);
                                    }

                                    // TODO: 检查 RecordBody 是否为 null
                                    nRet = export_util.ExportOneRecord(
                                        channel,
                                        this._stop,
                                        this.App.WsUrl,
                                        record.Path,
                                        record.RecordBody.Xml,
                                        record.RecordBody.Metadata,
                                        record.RecordBody.Timestamp,
                                        out strError);
                                    if (nRet == -1)
                                    {
                                        WriteStateFile(strBackupFileName, "error");  // 表示文件创建过程出错
                                        return(-1);
                                    }

                                    breakpoint.DbName = ResPath.GetDbName(record.Path);
                                    breakpoint.RecID  = ResPath.GetRecordId(record.Path);

                                    long lCurrent = sr.BaseStream.Position;

                                    SetProgressText(m_nRecordCount.ToString() + " " + record.Path + " " + GetPercent((double)lCurrent, lTotalLength));

                                    // 每 100 条显示一行
                                    if ((m_nRecordCount % 100) == 0)
                                    {
                                        this.AppendResultText("已输出记录 " + record.Path + "  " + (m_nRecordCount + 1).ToString() + "\r\n");
                                    }
                                    m_nRecordCount++;
                                }

                                lines.Clear();
                            }

                            if (line == null)
                            {
                                break;
                            }
                        }

                        Debug.Assert(lines.Count == 0, "");
                        breakpoint = null;
                    }
                }
                finally
                {
                    export_util.End();
                }

                WriteStateFile(strBackupFileName, "finish");  // 表示文件已经创建完成
                return(1);
            }
            catch (Exception ex)
            {
                strError = "BackupDatabase() 出现异常: " + ExceptionUtil.GetDebugText(ex);
                WriteStateFile(strBackupFileName, "error");  // 表示文件创建过程出错
                return(-1);
            }
            finally
            {
                this._stop.EndLoop();
            }
        }
コード例 #6
0
        // 一次操作循环
        public override void Worker()
        {
            // 系统挂起的时候,不运行本线程
            // 2007/12/18
            //if (this.App.HangupReason == HangupReason.LogRecover)
            //    return;
            if (this.App.ContainsHangup("LogRecover") == true)
            {
                return;
            }

            // 2012/2/4
            if (this.App.PauseBatchTask == true)
            {
                return;
            }

            bool   bFirst   = true;
            string strError = "";
            int    nRet     = 0;

            BatchTaskStartInfo startinfo = this.StartInfo;

            if (startinfo == null)
            {
                startinfo = new BatchTaskStartInfo();   // 按照缺省值来
            }
            // 通用启动参数
            bool bLoop = true;

            nRet = ParseMessageMonitorParam(startinfo.Param,
                                            out bLoop,
                                            out strError);
            if (nRet == -1)
            {
                this.AppendResultText("启动失败: " + strError + "\r\n");
                return;
            }

            this.Loop = bLoop;

            string strID = "";

            nRet = ParseMessageMonitorStart(startinfo.Start,
                                            out strID,
                                            out strError);
            if (nRet == -1)
            {
                this.AppendResultText("启动失败: " + strError + "\r\n");
                this.Loop = false;
                return;
            }

            //
            bool   bPerDayStart   = false; // 是否为每日一次启动模式
            string strMonitorName = "messageMonitor";

            {
                string strLastTime = "";

                nRet = ReadLastTime(
                    strMonitorName,
                    out strLastTime,
                    out strError);
                if (nRet == -1)
                {
                    string strErrorText = "从文件中获取 " + strMonitorName + " 每日启动时间时发生错误: " + strError;
                    this.AppendResultText(strErrorText + "\r\n");
                    this.App.WriteErrorLog(strErrorText);
                    return;
                }

                string strStartTimeDef = "";
                //      bRet    是否到了每日启动时间
                bool   bRet           = false;
                string strOldLastTime = strLastTime;

                // return:
                //      -2  strLastTime 格式错误
                //      -1  一般错误
                //      0   没有找到startTime配置参数
                //      1   找到了startTime配置参数
                nRet = IsNowAfterPerDayStart(
                    strMonitorName,
                    ref strLastTime,
                    out bRet,
                    out strStartTimeDef,
                    out strError);
                if (nRet == -1 || nRet == -2)
                {
                    string strErrorText = "获取 " + strMonitorName + " 每日启动时间时发生错误: " + strError;
                    this.AppendResultText(strErrorText + "\r\n");
                    this.App.WriteErrorLog(strErrorText);
                    if (nRet == -2)
                    {
                        // 删除断点文件,避免下次继续报错
                        WriteLastTime(strMonitorName, "");
                    }
                    return;
                }

                // 如果nRet == 0,表示没有配置相关参数,则兼容原来的习惯,每次都作
                if (nRet == 0)
                {
                }
                else if (nRet == 1)
                {
                    if (bRet == false)
                    {
                        if (this.ManualStart == true)
                        {
                            this.AppendResultText("已试探启动任务 '" + this.Name + "',但因没有到每日启动时间 " + strStartTimeDef + " 而未能启动。(上次任务处理结束时间为 " + DateTimeUtil.LocalTime(strLastTime) + ")\r\n");
                        }

                        // 2014/3/31
                        if (string.IsNullOrEmpty(strOldLastTime) == true &&
                            string.IsNullOrEmpty(strLastTime) == false)
                        {
                            this.AppendResultText("史上首次启动此任务。已把当前时间当作上次任务处理结束时间 " + DateTimeUtil.LocalTime(strLastTime) + " 写入了断点记忆文件\r\n");
                            WriteLastTime(strMonitorName, strLastTime);
                        }

                        return; // 还没有到每日时间
                    }

                    bPerDayStart = true;
                }

                this.App.WriteErrorLog((bPerDayStart == true ? "(定时)" : "(不定时)") + strMonitorName + " 启动。");
            }

            AppendResultText("开始新一轮循环");

            RmsChannel channel = this.RmsChannels.GetChannel(this.App.WsUrl);

            string strMessageDbName = this.App.MessageDbName;

            if (String.IsNullOrEmpty(strMessageDbName) == true)
            {
                AppendResultText("尚未配置消息库名(<message dbname='...' />)");
                this.Loop = false;
                return;
            }

            if (String.IsNullOrEmpty(this.App.MessageReserveTimeSpan) == true)
            {
                AppendResultText("尚未配置消息保留期限(<message reserveTimeSpan='...' />");
                this.Loop = false;
                return;
            }

            // 解析期限值
            string strPeriodUnit = "";
            long   lPeriodValue  = 0;

            nRet = LibraryApplication.ParsePeriodUnit(
                this.App.MessageReserveTimeSpan,
                out lPeriodValue,
                out strPeriodUnit,
                out strError);
            if (nRet == -1)
            {
                strError = "消息保留期限 值 '" + this.App.MessageReserveTimeSpan + "' 格式错误: " + strError;
                AppendResultText(strError);
                this.Loop = false;
                return;
            }

            AppendResultText("开始处理消息库 " + strMessageDbName + " 的循环");

            // string strID = "1";
            int nRecCount = 0;

            for (; ; nRecCount++)
            {
                // 系统挂起的时候,不运行本线程
                // 2008/2/4
                if (this.App.ContainsHangup("LogRecover") == true)
                {
                    break;
                }
                // 2012/2/4
                if (this.App.PauseBatchTask == true)
                {
                    break;
                }

                if (this.Stopped == true)
                {
                    break;
                }

                string strStyle = "";
                strStyle = "data,content,timestamp,outputpath";

                if (bFirst == true)
                {
                    strStyle += "";
                }
                else
                {
                    strStyle += ",next";
                }

                string strPath = strMessageDbName + "/" + strID;

                string strXmlBody        = "";
                string strMetaData       = "";
                string strOutputPath     = "";
                byte[] baOutputTimeStamp = null;

                //
                SetProgressText((nRecCount + 1).ToString() + " " + strPath);

                // 获得资源
                // return:
                //		-1	出错。具体出错原因在this.ErrorCode中。this.ErrorInfo中有出错信息。
                //		0	成功
                long lRet = channel.GetRes(strPath,
                                           strStyle,
                                           out strXmlBody,
                                           out strMetaData,
                                           out baOutputTimeStamp,
                                           out strOutputPath,
                                           out strError);
                if (lRet == -1)
                {
                    if (channel.ErrorCode == ChannelErrorCode.NotFound)
                    {
                        if (bFirst == true)
                        {
                            // 第一条没有找到, 但是要强制循环进行
                            bFirst = false;
                            goto CONTINUE;
                        }
                        else
                        {
                            if (bFirst == true)
                            {
                                strError = "数据库 " + strMessageDbName + " 记录 " + strID + " 不存在。处理结束。";
                            }
                            else
                            {
                                strError = "数据库 " + strMessageDbName + " 记录 " + strID + " 是最末一条记录。处理结束。";
                            }
                            break;
                        }
                    }
                    else if (channel.ErrorCode == ChannelErrorCode.EmptyRecord)
                    {
                        bFirst = false;
                        // 把id解析出来
                        strID = ResPath.GetRecordId(strOutputPath);
                        goto CONTINUE;
                    }

                    goto ERROR1;
                }

                bFirst = false;

                // 把id解析出来
                strID = ResPath.GetRecordId(strOutputPath);

                try
                {
                    // 处理
                    nRet = DoOneRecord(
                        lPeriodValue,
                        strPeriodUnit,
                        strOutputPath,
                        strXmlBody,
                        baOutputTimeStamp,
                        out strError);
                }
                catch (Exception ex)
                {
                    strError = "DoOneRecord exception: " + ExceptionUtil.GetDebugText(ex);
                    this.AppendResultText(strError + "\r\n");
                    this.SetProgressText(strError);
                    nRet = -1;
                }
                if (nRet == -1)
                {
                    AppendResultText("DoOneRecord() error : " + strError + "。\r\n");
                }


CONTINUE:
                continue;
            } // end of for

            // 正常结束,复位断点
            this.App.RemoveBatchTaskBreakPointFile(this.Name);
            this.StartInfo.Start = "";

            AppendResultText("针对消息库 " + strMessageDbName + " 的循环结束。共处理 " + nRecCount.ToString() + " 条记录。\r\n");

            {
                Debug.Assert(this.App != null, "");

                // 写入文件,记忆已经做过的当日时间
                string strLastTime = DateTimeUtil.Rfc1123DateTimeStringEx(this.App.Clock.UtcNow.ToLocalTime());  // 2007/12/17 changed // DateTime.UtcNow // 2012/5/27
                WriteLastTime(strMonitorName,
                              strLastTime);
                string strErrorText = (bPerDayStart == true ? "(定时)" : "(不定时)") + strMonitorName + "结束。共处理记录 " + nRecCount.ToString() + " 个。";
                this.App.WriteErrorLog(strErrorText);
            }

            return;

ERROR1:
            // 记忆断点
            this.StartInfo.Start = MemoBreakPoint(
                strID //strRecordID,
                );


            this.Loop       = true; // 便于稍后继续重新循环?
            startinfo.Param = MakeMessageMonitorParam(
                bLoop);


            AppendResultText("MessageMonitor thread error : " + strError + "\r\n");
            this.App.WriteErrorLog("MessageMonitor thread error : " + strError + "\r\n");
            return;
        }
コード例 #7
0
        // 校验起止号
        // return:
        //      0   不存在记录
        //      1   存在记录
        static int VerifyRange(RmsChannel channel,
                               string strDbName,
                               string strInputStartNo,
                               string strInputEndNo,
                               out string strOutputStartNo,
                               out string strOutputEndNo,
                               out string strError)
        {
            strError         = "";
            strOutputStartNo = "";
            strOutputEndNo   = "";

            bool bStartNotFound = false;
            bool bEndNotFound   = false;

            // 如果输入参数中为空,则假定为“全部范围”
            if (strInputStartNo == "")
            {
                strInputStartNo = "1";
            }

            if (strInputEndNo == "")
            {
                strInputEndNo = "9999999999";
            }


            bool bAsc = true;

            Int64 nStart = 0;
            Int64 nEnd   = 9999999999;


            try
            {
                nStart = Convert.ToInt64(strInputStartNo);
            }
            catch
            {
            }


            try
            {
                nEnd = Convert.ToInt64(strInputEndNo);
            }
            catch
            {
            }


            if (nStart > nEnd)
            {
                bAsc = false;
            }
            else
            {
                bAsc = true;
            }

            string strPath  = strDbName + "/" + strInputStartNo;
            string strStyle = "outputpath";

            if (bAsc == true)
            {
                strStyle += ",next,myself";
            }
            else
            {
                strStyle += ",prev,myself";
            }

            string strResult;
            string strMetaData;

            byte[] baOutputTimeStamp;
            string strOutputPath;

            string strError0 = "";

            string strStartID = "";
            string strEndID   = "";

            // 获得资源
            // return:
            //		-1	出错。具体出错原因在this.ErrorCode中。this.ErrorInfo中有出错信息。
            //		0	成功
            long lRet = channel.GetRes(strPath,
                                       strStyle,
                                       out strResult,
                                       out strMetaData,
                                       out baOutputTimeStamp,
                                       out strOutputPath,
                                       out strError0);

            if (lRet == -1)
            {
                if (channel.ErrorCode == ChannelErrorCode.NotFound)
                {
                    strStartID     = strInputStartNo;
                    bStartNotFound = true;
                }
                else
                {
                    strError += "校验startno时出错: " + strError0 + " ";
                }
            }
            else
            {
                // 取得返回的id
                strStartID = ResPath.GetRecordId(strOutputPath);
            }

            if (strStartID == "")
            {
                strError = "strStartID为空..." + (string.IsNullOrEmpty(strError) == false ? " : " + strError : "");
                return(-1);
            }

            strPath = strDbName + "/" + strInputEndNo;

            strStyle = "outputpath";
            if (bAsc == true)
            {
                strStyle += ",prev,myself";
            }
            else
            {
                strStyle += ",next,myself";
            }

            // 获得资源
            // return:
            //		-1	出错。具体出错原因在this.ErrorCode中。this.ErrorInfo中有出错信息。
            //		0	成功
            lRet = channel.GetRes(strPath,
                                  strStyle,
                                  out strResult,
                                  out strMetaData,
                                  out baOutputTimeStamp,
                                  out strOutputPath,
                                  out strError0);
            if (lRet == -1)
            {
                if (channel.ErrorCode == ChannelErrorCode.NotFound)
                {
                    strEndID     = strInputEndNo;
                    bEndNotFound = true;
                }
                else
                {
                    strError += "校验endno时出错: " + strError0 + " ";
                }
            }
            else
            {
                // 取得返回的id
                strEndID = ResPath.GetRecordId(strOutputPath);
            }

            if (strEndID == "")
            {
                strError = "strEndID为空..." + (string.IsNullOrEmpty(strError) == false ? " : " + strError : "");;
                return(-1);
            }

            ///
            bool bSkip = false;

            Int64 nTemp = 0;

            try
            {
                nTemp = Convert.ToInt64(strStartID);
            }
            catch
            {
                strError = "strStartID值 '" + strStartID + "' 不是数字...";
                return(-1);
            }

            if (bAsc == true)
            {
                if (nTemp > nEnd)
                {
                    bSkip = true;
                }
            }
            else
            {
                if (nTemp < nEnd)
                {
                    bSkip = true;
                }
            }

            if (bSkip == false)
            {
                strOutputStartNo = strStartID;
            }


            ///

            bSkip = false;

            try
            {
                nTemp = Convert.ToInt64(strEndID);
            }
            catch
            {
                strError = "strEndID值 '" + strEndID + "' 不是数字...";
                return(-1);
            }
            if (bAsc == true)
            {
                if (nTemp < nStart)
                {
                    bSkip = true;
                }
            }
            else
            {
                if (nTemp > nStart)
                {
                    bSkip = true;
                }
            }

            if (bSkip == false)
            {
                strOutputEndNo = strEndID;
            }

            if (bStartNotFound == true && bEndNotFound == true)
            {
                return(0);
            }

            return(1);
        }
コード例 #8
0
ファイル: ArriveMonitor.cs プロジェクト: zhangandding/dp2
        // 一次操作循环
        public override void Worker()
        {
            // 系统挂起的时候,不运行本线程
            // 2007/12/18 
            if (this.App.ContainsHangup("LogRecover") == true)
                return;

            // 2012/2/4
            if (this.App.PauseBatchTask == true)
                return;

            if (string.IsNullOrEmpty(this.App.ArrivedDbName))
            {
                this.AppendResultText("启动失败: 当前 library.xml 中没有配置预约到书库参数\r\n");
                return;
            }

            bool bFirst = true;
            string strError = "";
            int nRet = 0;

            BatchTaskStartInfo startinfo = this.StartInfo;
            if (startinfo == null)
                startinfo = new BatchTaskStartInfo();   // 按照缺省值来

            // 通用启动参数
            bool bLoop = true;
            nRet = ParseArriveMonitorParam(startinfo.Param,
                out bLoop,
                out strError);
            if (nRet == -1)
            {
                this.AppendResultText("启动失败: " + strError + "\r\n");
                return;
            }

            this.Loop = bLoop;

            string strID = "";
            nRet = ParseArriveMonitorStart(startinfo.Start,
                out strID,
                out strError);
            if (nRet == -1)
            {
                this.AppendResultText("启动失败: " + strError + "\r\n");
                this.Loop = false;
                return;
            }

            ////

            //
            bool bPerDayStart = false;  // 是否为每日一次启动模式
            string strMonitorName = "arriveMonitor";
            {
                string strLastTime = "";

                nRet = ReadLastTime(
                    strMonitorName,
                    out strLastTime,
                    out strError);
                if (nRet == -1)
                {
                    string strErrorText = "从文件中获取 " + strMonitorName + " 每日启动时间时发生错误: " + strError;
                    this.AppendResultText(strErrorText + "\r\n");
                    this.App.WriteErrorLog(strErrorText);
                    return;
                }

                string strStartTimeDef = "";
                //      bRet    是否到了每日启动时间
                bool bRet = false;
                string strOldLastTime = strLastTime;

                // return:
                //      -2  strLastTime 格式错误
                //      -1  一般错误
                //      0   没有找到startTime配置参数
                //      1   找到了startTime配置参数
                nRet = IsNowAfterPerDayStart(
                    strMonitorName,
                    ref strLastTime,
                    out bRet,
                    out strStartTimeDef,
                    out strError);
                if (nRet == -1 || nRet == -2)
                {
                    string strErrorText = "获取 " + strMonitorName + " 每日启动时间时发生错误: " + strError;
                    this.AppendResultText(strErrorText + "\r\n");
                    this.App.WriteErrorLog(strErrorText);
                    if (nRet == -2)
                    {
                        WriteLastTime(strMonitorName, "");
                    }
                    return;
                }

                // 如果nRet == 0,表示没有配置相关参数,则兼容原来的习惯,每次都作
                if (nRet == 0)
                {

                }
                else if (nRet == 1)
                {
                    if (bRet == false)
                    {
                        if (this.ManualStart == true)
                            this.AppendResultText("已试探启动任务 '" + this.Name + "',但因没有到每日启动时间 " + strStartTimeDef + " 而未能启动。(上次任务处理结束时间为 " + DateTimeUtil.LocalTime(strLastTime) + ")\r\n");

                        // 2014/3/31
                        if (string.IsNullOrEmpty(strOldLastTime) == true
                            && string.IsNullOrEmpty(strLastTime) == false)
                        {
                            this.AppendResultText("史上首次启动此任务。已把当前时间当作上次任务处理结束时间 " + DateTimeUtil.LocalTime(strLastTime) + " 写入了断点记忆文件\r\n");
                            WriteLastTime(strMonitorName, strLastTime);
                        }

                        return; // 还没有到每日时间
                    }

                    bPerDayStart = true;
                }

                this.App.WriteErrorLog((bPerDayStart == true ? "(定时)" : "(不定时)") + strMonitorName + " 启动。");
            }

            this.AppendResultText("开始新一轮循环\r\n");

            RmsChannel channel = this.RmsChannels.GetChannel(this.App.WsUrl);

            this._calendarTable.Clear();

            int nRecCount = 0;
            for (; ; nRecCount++)
            {
#if NO
                // 系统挂起的时候,不运行本线程
                // 2008/2/4
                if (this.App.HangupReason == HangupReason.LogRecover)
                    break;
#endif

                if (this.Stopped == true)
                    break;

                string strStyle = "";
                strStyle = "data,content,timestamp,outputpath";

                if (bFirst == true)
                    strStyle += "";
                else
                {
                    strStyle += ",next";
                }

                string strPath = this.App.ArrivedDbName + "/" + strID;

                string strXmlBody = "";
                string strMetaData = "";
                string strOutputPath = "";
                byte[] baOutputTimeStamp = null;

                // 
                this.SetProgressText((nRecCount + 1).ToString() + " " + strPath);
                this.AppendResultText("正在处理 " + (nRecCount + 1).ToString() + " " + strPath + "\r\n");

                // 获得资源
                // return:
                //		-1	出错。具体出错原因在this.ErrorCode中。this.ErrorInfo中有出错信息。
                //		0	成功
                long lRet = channel.GetRes(strPath,
                    strStyle,
                    out strXmlBody,
                    out strMetaData,
                    out baOutputTimeStamp,
                    out strOutputPath,
                    out strError);
                if (lRet == -1)
                {
                    if (channel.ErrorCode == ChannelErrorCode.NotFound)
                    {
                        if (bFirst == true)
                        {
                            // 第一条没有找到, 但是要强制循环进行
                            bFirst = false;
                            goto CONTINUE;
                        }
                        else
                        {
                            if (bFirst == true)
                            {
                                strError = "记录 " + strID + " 不存在。处理结束。";
                            }
                            else
                            {
                                strError = "记录 " + strID + " 是最末一条记录。处理结束。";
                            }
                            break;
                        }

                    }
                    else if (channel.ErrorCode == ChannelErrorCode.EmptyRecord)
                    {
                        bFirst = false;
                        // 把id解析出来
                        strID = ResPath.GetRecordId(strOutputPath);
                        goto CONTINUE;
                    }

                    goto ERROR1;
                }

#if NO
                string strLibraryCode = "";
                nRet = this.App.GetLibraryCode(strOutputPath,   // ???? BUG
                    out strLibraryCode,
                    out strError);
                if (nRet == -1)
                    goto ERROR1;

#endif


                bFirst = false;

                // 把id解析出来
                strID = ResPath.GetRecordId(strOutputPath);

                // 处理
                nRet = DoOneRecord(
                    // calendar,
                    strOutputPath,
                    strXmlBody,
                    baOutputTimeStamp,
                    out strError);
                if (nRet == -1)
                    goto ERROR1;

            CONTINUE:
                continue;
            } // end of for

            this.AppendResultText("循环结束。共处理 " + nRecCount.ToString() + " 条记录。\r\n");

            {
                Debug.Assert(this.App != null);

                // 写入文件,记忆已经做过的当日时间
                string strLastTime = DateTimeUtil.Rfc1123DateTimeStringEx(this.App.Clock.UtcNow.ToLocalTime()); // 2007/12/17 changed // DateTime.UtcNow // 2012/5/27
                WriteLastTime(strMonitorName,
                    strLastTime);
                string strErrorText = (bPerDayStart == true ? "(定时)" : "(不定时)") + strMonitorName + "结束。共处理记录 " + nRecCount.ToString() + " 个。";
                this.App.WriteErrorLog(strErrorText);

            }

            return;
        ERROR1:
            this.AppendResultText("预约到书管理 后台任务出错: " + strError + "\r\n");
            this.App.WriteErrorLog("预约到书管理 后台任务出错: " + strError);
            return;
        }
コード例 #9
0
        int RebuildDatabase(BreakPointInfo info,
                            out string strError)
        {
            strError = "";

            RmsChannel channel = RmsChannels.GetChannel(this.App.WsUrl);

            if (channel == null)
            {
                strError = "get channel error";
                return(-1);
            }

            // 恢复为最大范围
            string strStartNo = "1";
            string strEndNo   = "9999999999";

            string strOutputStartNo = "";
            string strOutputEndNo   = "";

            if (string.IsNullOrEmpty(info.RecID) == false)
            {
                strStartNo = info.RecID;
            }
            // 校验起止号
            // return:
            //      0   不存在记录
            //      1   存在记录
            int nRet = VerifyRange(channel,
                                   info.DbName,
                                   strStartNo,
                                   strEndNo,
                                   out strOutputStartNo,
                                   out strOutputEndNo,
                                   out strError);

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

            if (nRet == 0)
            {
                return(0);
            }

            strStartNo = strOutputStartNo;
            strEndNo   = strOutputEndNo;

            Int64 nStart;
            Int64 nEnd;
            Int64 nCur;

            if (Int64.TryParse(strStartNo, out nStart) == false)
            {
                strError = "数据库 '" + info.DbName + "' 起始记录 ID '" + strStartNo + "' 不合法";
                return(-1);
            }
            if (Int64.TryParse(strEndNo, out nEnd) == false)
            {
                strError = "数据库 '" + info.DbName + "' 结束记录 ID '" + strEndNo + "' 不合法";
                return(-1);
            }
            // Refresh数据库定义
            long lRet = channel.DoRefreshDB(
                "begin",
                info.DbName,
                false,  // bClearKeysAtBegin == true ? true : false,
                out strError);

            if (lRet == -1)
            {
                return(-1);
            }

            string strID = strStartNo;

            try
            {
                bool bFirst = true;     // 是否为第一次取记录

                // 循环
                for (; ;)
                {
                    if (this.Stopped == true)
                    {
                        strError = "中断";
                        return(-1);
                    }
                    // string strDirectionComment = "";

                    string strStyle = "";

                    strStyle = "timestamp,outputpath";  // 优化

                    strStyle += ",forcedeleteoldkeys";

                    if (bFirst == true)
                    {
                        // 注:如果不校验首号,只有强制循环的情况下,才能不需要next风格
                        strStyle += "";
                    }
                    else
                    {
                        strStyle += ",next";
                        // strDirectionComment = "的后一条记录";
                    }

                    string strPath       = info.DbName + "/" + strID;
                    string strOutputPath = "";

                    bool bFoundRecord = false;

                    bool bNeedRetry = true;

                    int nRedoCount = 0;
REDO_REBUILD:
                    // 获得资源
                    // return:
                    //		-1	出错。具体出错原因在this.ErrorCode中。this.ErrorInfo中有出错信息。
                    //		0	成功
                    lRet = channel.DoRebuildResKeys(strPath,
                                                    strStyle,
                                                    out strOutputPath,
                                                    out strError);
                    if (lRet == -1)
                    {
                        if (channel.ErrorCode == ChannelErrorCode.NotFound)
                        {
                            if (bFirst == true)
                            {
                                // 如果不要强制循环,此时也不能结束,否则会让用户以为数据库里面根本没有数据
                                // AutoCloseMessageBox.Show(this, "您为数据库 " + info.DbName + " 指定的首记录 " + strID + strDirectionComment + " 不存在。\r\n\r\n(注:为避免出现此提示,可在操作前勾选“校准首尾ID”)\r\n\r\n按 确认 继续向后找...");
                                bFirst = false;
                                goto CONTINUE;
                            }
                            else
                            {
                                Debug.Assert(bFirst == false, "");

                                if (bFirst == true)
                                {
                                    strError = "记录 " + strID + "(后一条) 不存在。处理结束。";
                                }
                                else
                                {
                                    strError = "记录 " + strID + " 是最末一条记录。处理结束。";
                                }

                                return(0);
                            }
                        }
                        else if (channel.ErrorCode == ChannelErrorCode.EmptyRecord)
                        {
                            bFirst = false;
                            // bFoundRecord = false;
                            // 把id解析出来
                            strID = ResPath.GetRecordId(strOutputPath);
                            goto CONTINUE;
                        }

                        // 允许重试
                        if (bNeedRetry == true)
                        {
                            if (nRedoCount < 10)
                            {
                                nRedoCount++;
                                goto REDO_REBUILD;
                            }
                        }
                        else
                        {
                            return(-1);
                        }
                    } // end of nRet == -1

                    bFirst = false;

                    bFoundRecord = true;

                    // 把id解析出来
                    strID = ResPath.GetRecordId(strOutputPath);

                    info.RecID = strID; // 记忆

                    // 每 100 条显示一行
                    if ((m_nRecordCount % 100) == 0)
                    {
                        this.AppendResultText("已重建检索点 记录 " + strOutputPath + "  " + (m_nRecordCount + 1).ToString() + "\r\n");
                    }

#if NO
                    if (String.IsNullOrEmpty(strRealStartNo) == true)
                    {
                        strRealStartNo = strID;
                    }

                    strRealEndNo = strID;
#endif

CONTINUE:

                    // 是否超过循环范围
                    if (Int64.TryParse(strID, out nCur) == false)
                    {
                        strError = "数据库 '" + info.DbName + "' 当前记录 ID '" + strID + "' 不合法";
                        return(-1);
                    }
#if NO
                    try
                    {
                        nCur = Convert.ToInt64(strID);
                    }
                    catch
                    {
                        // ???
                        nCur = 0;
                    }
#endif

                    if (nCur > nEnd)
                    {
                        break;
                    }

                    if (bFoundRecord == true)
                    {
                        m_nRecordCount++;
                    }

                    //
                    //


                    SetProgressText((nCur - nStart + 1).ToString());

                    // 对已经作过的进行判断
                    if (nCur >= nEnd)
                    {
                        break;
                    }
                }
            }
            finally
            {
#if NO
                if (bClearKeysAtBegin == true)
                {
                    // 结束Refresh数据库定义
                    lRet = channel.DoRefreshDB(
                        "end",
                        info.DbName,
                        false, // 此参数此时无用
                        out strError);

                    if (lRet == -1)
                    {
                        return(-1);
                    }
                }
#endif
            }

            return(0);
        }
コード例 #10
0
        protected override void Render(HtmlTextWriter output)
        {
            int    nRet          = 0;
            long   lRet          = 0;
            string strError      = "";
            string strOutputPath = "";
            string strItemXml    = "";

            LibraryApplication app         = (LibraryApplication)this.Page.Application["app"];
            SessionInfo        sessioninfo = (SessionInfo)this.Page.Session["sessioninfo"];

            string strItemRecPath = "";

            RmsChannel channel = sessioninfo.Channels.GetChannel(app.WsUrl);

            if (channel == null)
            {
                strError = "channel == null";
                goto ERROR1;
            }

            if (String.IsNullOrEmpty(this.Barcode) == false)
            {
                // 获得册记录
                // return:
                //      -1  error
                //      0   not found
                //      1   命中1条
                //      >1  命中多于1条
                nRet = app.GetItemRecXml(
                    channel,
                    this.Barcode,
                    out strItemXml,
                    out strOutputPath,
                    out strError);
                if (nRet == 0)
                {
                    strError = "册条码号为 '" + this.Barcode + "' 的册记录没有找到";
                    goto ERROR1;
                }

                if (nRet == -1)
                {
                    goto ERROR1;
                }

                strItemRecPath = strOutputPath;
            }


            string strItemDbName   = "";
            string strBiblioRecID  = "";
            string strBiblioDbName = "";


            // 若需要同时取得种记录
            if ((this.DispStyle & DispStyle.Biblio) == DispStyle.Biblio)
            {
                string strBiblioRecPath = "";

                if (String.IsNullOrEmpty(this.BiblioRecPath) == true)
                {
                    /*
                     * // 准备工作: 映射数据库名
                     * nRet = app.GetGlobalCfg(sessioninfo.Channels,
                     *  out strError);
                     * if (nRet == -1)
                     *  goto ERROR1;
                     * */

                    strItemDbName = ResPath.GetDbName(strOutputPath);
                    // string strBiblioDbName = "";

                    // 根据实体库名, 找到对应的书目库名
                    // return:
                    //      -1  出错
                    //      0   没有找到
                    //      1   找到
                    nRet = app.GetBiblioDbNameByItemDbName(strItemDbName,
                                                           out strBiblioDbName,
                                                           out strError);
                    if (nRet == -1)
                    {
                        goto ERROR1;
                    }
                    if (nRet == 0)
                    {
                        strError = "实体库名 '" + strItemDbName + "' 没有找到对应的书目库名";
                        goto ERROR1;
                    }


                    XmlDocument dom = new XmlDocument();
                    try
                    {
                        dom.LoadXml(strItemXml);
                    }
                    catch (Exception ex)
                    {
                        strError = "册记录XML装载到DOM出错:" + ex.Message;
                        goto ERROR1;
                    }

                    strBiblioRecID = DomUtil.GetElementText(dom.DocumentElement, "parent"); //
                    if (String.IsNullOrEmpty(strBiblioRecID) == true)
                    {
                        strError = "册记录XML中<parent>元素缺乏或者值为空, 因此无法定位种记录";
                        goto ERROR1;
                    }

                    strBiblioRecPath = strBiblioDbName + "/" + strBiblioRecID;
                }
                else
                {
                    strBiblioRecPath = this.BiblioRecPath;

                    strBiblioDbName = ResPath.GetDbName(this.BiblioRecPath);

                    if (String.IsNullOrEmpty(strItemDbName) == true)
                    {
                        // 根据书目库名, 找到对应的实体库名
                        // return:
                        //      -1  出错
                        //      0   没有找到
                        //      1   找到
                        nRet = app.GetItemDbName(strBiblioDbName,
                                                 out strItemDbName,
                                                 out strError);
                        if (nRet == -1)
                        {
                            goto ERROR1;
                        }
                    }

                    strBiblioRecID = ResPath.GetRecordId(this.BiblioRecPath);
                }

                string strBiblioXml = "";


                string strMetaData = "";
                byte[] timestamp   = null;
                lRet = channel.GetRes(strBiblioRecPath,
                                      out strBiblioXml,
                                      out strMetaData,
                                      out timestamp,
                                      out strOutputPath,
                                      out strError);
                if (lRet == -1)
                {
                    strError = "获得种记录 '" + strBiblioRecPath + "' 时出错: " + strError;
                    goto ERROR1;
                }

                // 需要从内核映射过来文件
                string strLocalPath = "";
                nRet = app.MapKernelScriptFile(
                    sessioninfo,
                    strBiblioDbName,
                    "./cfgs/loan_biblio.fltx",
                    out strLocalPath,
                    out strError);
                if (nRet == -1)
                {
                    goto ERROR1;
                }

                // 将种记录数据从XML格式转换为HTML格式
                string strBiblio = "";
                // 2006/11/28 changed
                string strFilterFileName = strLocalPath;    // app.CfgDir + "\\biblio.fltx";
                if (string.IsNullOrEmpty(strBiblioXml) == false)
                {
                    nRet = app.ConvertBiblioXmlToHtml(
                        strFilterFileName,
                        strBiblioXml,
                        strBiblioRecPath,
                        out strBiblio,
                        out strError);
                    if (nRet == -1)
                    {
                        goto ERROR1;
                    }
                }
                else
                {
                    strBiblio = "";
                }
                // output.Write(strBiblio);
                LiteralControl literal = (LiteralControl)FindControl("biblio");
                literal.Text = strBiblio;
            }

            if ((this.DispStyle & DispStyle.Items) == DispStyle.Items)
            {
                this.ItemConverter = app.NewItemConverter(
                    app.CfgDir + "\\itemopac.cs",
                    app.CfgDir + "\\itemopac.cs.ref",
                    out strError);
                if (this.ItemConverter == null)
                {
                    goto ERROR1;
                }
                this.ItemConverter.App = app;


                // 检索出该种的所有册
                sessioninfo.ItemLoad += new ItemLoadEventHandler(SessionInfo_ItemLoad);
                tempOutput            = "";
                // tempOutput = output;
                try
                {
                    nRet = sessioninfo.SearchItems(
                        app,
                        strItemDbName,
                        strBiblioRecID,
                        out strError);
                    if (nRet == -1)
                    {
                        goto ERROR1;
                    }
                }
                finally
                {
                    sessioninfo.ItemLoad -= new ItemLoadEventHandler(SessionInfo_ItemLoad);
                    //tempOutput = null;

                    this.ItemConverter = null;
                }

                LiteralControl literal = (LiteralControl)FindControl("items");
                literal.Text = tempOutput;
                tempOutput   = "";
            }

            else if ((this.DispStyle & DispStyle.Item) == DispStyle.Item)
            {
                string strResult = "";
                // 取得册信息
                // 将册记录数据从XML格式转换为HTML格式
                nRet = app.ConvertItemXmlToHtml(
                    app.CfgDir + "\\itemxml2html.cs",
                    app.CfgDir + "\\itemxml2html.cs.ref",
                    strItemXml,
                    strItemRecPath, // 2009/10/18
                    out strResult,
                    out strError);
                if (nRet == -1)
                {
                    goto ERROR1;
                }

                // output.Write(strResult);
                LiteralControl literal = (LiteralControl)FindControl("items");
                literal.Text = strResult;
            }


            base.Render(output);

            return;

ERROR1:
            output.Write(strError);
        }
コード例 #11
0
ファイル: MessageCenter.cs プロジェクト: zszqwe/dp2
        // 根据消息记录路径获得消息
        // 不检查消息是否属于特定用户
        int GetMessageByPath(
            RmsChannel channel,
            string strPath,
            MessageLevel messagelevel,
            out MessageData data,
            out string strError)
        {
            data = new MessageData();

            string strMetaData = "";

            byte[] timestamp     = null;
            string strXml        = "";
            string strOutputPath = "";

            long lRet = channel.GetRes(strPath,
                                       out strXml,
                                       out strMetaData,
                                       out timestamp,
                                       out strOutputPath,
                                       out strError);

            if (lRet == -1)
            {
                // text-level: 内部错误
                strError = "获得消息记录 '" + strPath + "' 时出错: " + strError;
                return(-1);
            }

            XmlDocument dom = new XmlDocument();

            try
            {
                dom.LoadXml(strXml);
            }
            catch (Exception ex)
            {
                // text-level: 内部错误
                strError = "装载XML记录进入DOM时出错: " + ex.Message;
                return(-1);
            }


            data.strSender = DomUtil.GetElementText(dom.DocumentElement,
                                                    "sender");
            data.strRecipient = DomUtil.GetElementText(dom.DocumentElement,
                                                       "recipient");
            data.strSubject = DomUtil.GetElementText(dom.DocumentElement,
                                                     "subject");
            data.strCreateTime = DomUtil.GetElementText(dom.DocumentElement,
                                                        "date");
            data.strMime = DomUtil.GetElementText(dom.DocumentElement,
                                                  "mime");

            data.strSize = DomUtil.GetElementText(dom.DocumentElement,
                                                  "size");

            string strTouched = DomUtil.GetElementText(dom.DocumentElement,
                                                       "touched");

            if (strTouched == "1")
            {
                data.Touched = true;
            }
            else
            {
                data.Touched = false;
            }

            data.strRecordID = ResPath.GetRecordId(strOutputPath);

            if (messagelevel == MessageLevel.Full)
            {
                data.strBody = DomUtil.GetElementText(dom.DocumentElement,
                                                      "content");
            }

            data.strUserName = DomUtil.GetElementText(dom.DocumentElement,
                                                      "username");

            // 恒定为中文名称
            data.strBoxType = DomUtil.GetElementText(dom.DocumentElement,
                                                     "box");

            data.TimeStamp = timestamp;

            // 修改touched元素值
            if (messagelevel == MessageLevel.Full &&
                data.Touched == false)
            {
                DomUtil.SetElementText(dom.DocumentElement,
                                       "touched", "1");

                byte[] output_timestamp = null;
                //string strOutputPath = "";

                lRet = channel.DoSaveTextRes(strPath,
                                             dom.OuterXml,
                                             false,
                                             "content,ignorechecktimestamp",
                                             timestamp,
                                             out output_timestamp,
                                             out strOutputPath,
                                             out strError);
                if (lRet == -1)
                {
                    // text-level: 内部错误
                    strError = "写回记录 '" + strPath + "' 时出错: " + strError;
                    return(-1);
                }
                data.Touched   = true;
                data.TimeStamp = output_timestamp;
            }

            return(1);
        }
コード例 #12
0
ファイル: MessageCenter.cs プロジェクト: zszqwe/dp2
        // 保存消息到"草稿"箱
        // parameters:
        //      strOldRecordID  原来在草稿箱中的记录id。如果有此id,用覆盖方式写入,否则用追加方式写入
        public int SaveMessage(
            RmsChannelCollection Channels,
            string strRecipient,
            string strSender,
            string strSubject,
            string strMime,
            string strBody,
            string strOldRecordID,
            byte [] baOldTimeStamp,
            out byte[] baOutputTimeStamp,
            out string strOutputID,
            out string strError)
        {
            strError          = "";
            baOutputTimeStamp = null;
            strOutputID       = "";

            XmlDocument dom = new XmlDocument();

            dom.LoadXml("<root />");

            DomUtil.SetElementText(dom.DocumentElement,
                                   "sender", strSender);
            DomUtil.SetElementText(dom.DocumentElement,
                                   "recipient", strRecipient);
            DomUtil.SetElementText(dom.DocumentElement,
                                   "subject", strSubject);
            DomUtil.SetElementText(dom.DocumentElement,
                                   "date", DateTimeUtil.Rfc1123DateTimeStringEx(DateTime.UtcNow.ToLocalTime()));
            DomUtil.SetElementText(dom.DocumentElement,
                                   "size", Convert.ToString(strBody.Length));
            DomUtil.SetElementText(dom.DocumentElement,
                                   "touched", "0");
            DomUtil.SetElementText(dom.DocumentElement,
                                   "username", strSender);
            DomUtil.SetElementText(dom.DocumentElement,
                                   "box", MessageCenter.TEMP);
            DomUtil.SetElementTextPure(dom.DocumentElement,
                                       "content", strBody);
            DomUtil.SetElementText(dom.DocumentElement,
                                   "mime", strMime);

            RmsChannel channel = Channels.GetChannel(this.ServerUrl);

            // byte[] timestamp = null;
            // byte[] output_timestamp = null;
            string strOutputPath = "";

            string strPath = "";

            if (String.IsNullOrEmpty(strOldRecordID) == true)
            {
                strPath = this.MessageDbName + "/?";
            }
            else
            {
                strPath = this.MessageDbName + "/" + strOldRecordID;
            }

            // 写回册记录
            long lRet = channel.DoSaveTextRes(strPath,
                                              dom.OuterXml,
                                              false,
                                              "content,ignorechecktimestamp",
                                              baOldTimeStamp,
                                              out baOutputTimeStamp,
                                              out strOutputPath,
                                              out strError);

            if (lRet == -1)
            {
                return(-1);
            }

            strOutputID = ResPath.GetRecordId(strOutputPath);

            return(0);
        }
コード例 #13
0
        // 创建一个评注记录
        public int CreateCommentInfo(
            string strBiblioRecPath,
            string strCommentXml,
            out string strNewCommentRecPath,
            out string strNewXml,
            out byte[] baNewTimestamp,
            out string strError)
        {
            strError             = "";
            strNewCommentRecPath = "";
            strNewXml            = "";
            baNewTimestamp       = null;

            LoginState loginstate = Global.GetLoginState(this.Page);

            if (loginstate == LoginState.NotLogin)
            {
                strError = "尚未登录, 不能创建评注";
                return(-1);
            }
            if (loginstate == LoginState.Public)
            {
                strError = "访客身份, 不能创建评注";
                return(-1);
            }

            OpacApplication app         = (OpacApplication)this.Page.Application["app"];
            SessionInfo     sessioninfo = (SessionInfo)this.Page.Session["sessioninfo"];

            Debug.Assert(String.IsNullOrEmpty(sessioninfo.UserID) == false, "");


            EntityInfo info = new EntityInfo();

            info.RefID = Guid.NewGuid().ToString();

            string strTargetBiblioRecID = ResPath.GetRecordId(strBiblioRecPath);

            XmlDocument comment_dom = new XmlDocument();

            try
            {
                comment_dom.LoadXml(strCommentXml);
            }
            catch (Exception ex)
            {
                strError = "XML装载到DOM时发生错误: " + ex.Message;
                return(-1);
            }

            DomUtil.SetElementText(comment_dom.DocumentElement,
                                   "parent", strTargetBiblioRecID);

            info.Action       = "new";
            info.NewRecPath   = "";
            info.NewRecord    = comment_dom.OuterXml;
            info.NewTimestamp = null;

            //
            EntityInfo[] comments = new EntityInfo[1];
            comments[0] = info;

            EntityInfo[] errorinfos = null;

            long lRet = sessioninfo.Channel.SetComments(null,
                                                        strBiblioRecPath,
                                                        comments,
                                                        out errorinfos,
                                                        out strError);

            if (lRet == -1)
            {
                strError = "创建评注记录时发生错误: " + strError;
                return(-1);
            }

            /*
             * LibraryServerResult result = app.CommentItemDatabase.SetItems(sessioninfo,
             *  strBiblioRecPath,
             *  comments,
             *  out errorinfos);
             * if (result.Value == -1)
             * {
             *  strError = result.ErrorInfo;
             *  return -1;
             * }
             * */

            if (errorinfos != null && errorinfos.Length > 0)
            {
                int nErrorCount = 0;
                for (int i = 0; i < errorinfos.Length; i++)
                {
                    EntityInfo error = errorinfos[i];
                    if (error.ErrorCode != ErrorCodeValue.NoError)
                    {
                        if (String.IsNullOrEmpty(strError) == false)
                        {
                            strError += "; ";
                        }
                        strError += errorinfos[0].ErrorInfo;
                        nErrorCount++;
                    }
                    else
                    {
                        strNewCommentRecPath = error.NewRecPath;
                        strNewXml            = error.NewRecord;
                        baNewTimestamp       = error.NewTimestamp;
                    }
                }
                if (nErrorCount > 0)
                {
                    return(-1);
                }
            }

            return(1);
        }