Exemple #1
0
        private void listView_records_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.listView_records.SelectedItems.Count == 0)
            {
                this.textBox_worksheet.Text   = "";
                this.marcEditor_record.Marc   = "";
                this.textBox_description.Text = "";
            }
            else
            {
                LogItemInfo info = (LogItemInfo)this.listView_records.SelectedItems[0].Tag;
                if (info != null)
                {
                    this.textBox_worksheet.Text = info.Encoding.GetString(info.OriginData).Replace(MarcUtil.SUBFLD, '$');
                    string strMARC = DtlpChannel.GetDt1000LogRecord(info.OriginData, info.Encoding);
                    this.marcEditor_record.Marc         = strMARC;
                    this.marcEditor_record.DocumentOrgX = 0;
                    this.marcEditor_record.DocumentOrgY = 0;

                    string strOperCode    = "";
                    string strOperComment = "";
                    string strOperPath    = "";
                    string strError       = "";

                    int nRet = DtlpChannel.ParseDt1000LogRecord(strMARC,
                                                                out strOperCode,
                                                                out strOperComment,
                                                                out strOperPath,
                                                                out strError);
                    if (nRet == -1)
                    {
                        this.textBox_description.Text = strError;
                    }
                    else
                    {
                        if (strOperCode == "12")
                        {
                            this.textBox_description.Text = "操作: " + strOperComment + "\r\n数据库名: " + strOperPath;
                        }
                        else
                        {
                            this.textBox_description.Text = "操作: " + strOperComment + "\r\n路径: " + strOperPath;
                        }
                    }
                }
                else
                {
                    this.textBox_worksheet.Text   = "(no origin data)";
                    this.marcEditor_record.Marc   = "";
                    this.textBox_description.Text = "";
                }
            }
        }
Exemple #2
0
        // 获得日志记录
        // return:
        //      -1  出错
        //      0   日志文件不存在
        //      1   日志文件存在
        int GetLogRecords(string strServerAddr,
                          string strLogFileName,
                          out string strError)
        {
            strError = "";
            int nStartIndex = 0;

            stop.OnStop += new StopEventHandler(this.DoStop);
            stop.SetMessage("正在从服务器获得日志记录 ...");
            stop.BeginLoop();

            this.Update();
            this.MainForm.Update();

            try
            {
                string strPath = strServerAddr + "/log/" + strLogFileName + "/" + nStartIndex.ToString();

                bool bFirst = true;

                string strDate   = "";
                int    nRecID    = -1;
                string strOffset = "";

                int nStyle = 0;

                for (int i = nStartIndex; ; i++)
                {
                    Application.DoEvents();     // 出让界面控制权

                    if (stop != null)
                    {
                        if (stop.State != 0)
                        {
                            strError = "用户中断";
                            return(-1);
                        }
                    }

                    byte[] baPackage = null;

                    if (bFirst == true)
                    {
                    }
                    else
                    {
                        strPath = strServerAddr + "/log/" + strDate /*strLogFileName*/ + "/" + nRecID.ToString() + "@" + strOffset;
                    }

                    Encoding encoding = this.Channel.GetPathEncoding(strPath);

                    stop.SetMessage("正在获得日志记录 " + strPath);

                    int nRet = this.Channel.Search(strPath,
                                                   DtlpChannel.RIZHI_STYLE | nStyle,
                                                   out baPackage);
                    if (nRet == -1)
                    {
                        int errorcode = this.Channel.GetLastErrno();
                        if (errorcode == DtlpChannel.GL_NOTEXIST)
                        {
                            if (bFirst == true)
                            {
                                break;
                            }
                        }

                        // 更换新通道
                        if (errorcode == DtlpChannel.GL_INTR ||
                            errorcode == DtlpChannel.GL_SEND ||
                            errorcode == DtlpChannel.GL_RECV)
                        {
                            this.Channel = channelArray.CreateChannel(0);
                        }

                        strError = "获取日志记录:\r\n"
                                   + "路径: " + strPath + "\r\n"
                                   + "错误码: " + errorcode + "\r\n"
                                   + "错误信息: " + this.Channel.GetErrorString(errorcode) + "\r\n";
                        return(-1);
                    }


                    // 解析出记录
                    Package package = new Package();
                    package.LoadPackage(baPackage,
                                        encoding);
                    package.Parse(PackageFormat.Binary);

                    // 获得下一路径
                    string strNextPath = "";
                    strNextPath = package.GetFirstPath();
                    if (String.IsNullOrEmpty(strNextPath) == true)
                    {
                        if (this.checkBox_loop.Checked == true)
                        {
                            i--;
                            continue;
                        }

                        if (bFirst == true)
                        {
                            strError = "文件 " + strLogFileName + "不存在";
                            return(0);
                        }
                        // strError = "检索 '" + strPath + "' 响应包中路径部分不存在 ...";
                        // return -1;
                        break;
                    }

                    // 获得记录内容
                    byte[] baContent = null;
                    nRet = package.GetFirstBin(out baContent);
                    if (nRet != 1)
                    {
                        baContent = null;       // 但是为空包
                    }



                    // 处理记录


                    string strMARC = DtlpChannel.GetDt1000LogRecord(baContent, encoding);

                    string strOperCode    = "";
                    string strOperComment = "";
                    string strOperPath    = "";

                    nRet = DtlpChannel.ParseDt1000LogRecord(strMARC,
                                                            out strOperCode,
                                                            out strOperComment,
                                                            out strOperPath,
                                                            out strError);
                    if (nRet == -1)
                    {
                        strOperComment = strError;
                    }

                    LogItemInfo info = new LogItemInfo();
                    info.Index      = i;
                    info.Offset     = GetStartOffs(strOffset);
                    info.OriginData = baContent;
                    info.Encoding   = encoding;

                    ListViewItem item = new ListViewItem();
                    item.Text = i.ToString();
                    item.SubItems.Add(info.Offset);
                    item.SubItems.Add(strOperComment);
                    item.SubItems.Add(strOperPath);
                    item.Tag = info;

                    this.listView_records.Items.Add(item);

                    // 将日志记录路径解析为日期、序号、偏移
                    // 一个日志记录路径的例子为:
                    // /ip/log/19991231/0@1234~5678
                    // parameters:
                    //		strLogPath		待解析的日志记录路径
                    //		strDate			解析出的日期
                    //		nRecID			解析出的记录号
                    //		strOffset		解析出的记录偏移,例如1234~5678
                    // return:
                    //		-1		出错
                    //		0		正确
                    nRet = DtlpChannel.ParseLogPath(strNextPath,
                                                    out strDate,
                                                    out nRecID,
                                                    out strOffset,
                                                    out strError);
                    if (nRet == -1)
                    {
                        return(-1);
                    }

                    // ModiOffset(ref strOffset);

                    bFirst = false;
                }


                return(1);   // 日志文件存在,已获得了记录
            }
            finally
            {
                stop.EndLoop();
                stop.OnStop -= new StopEventHandler(this.DoStop);
                stop.Initial("");
            }
        }