// 校准转出范围的首尾号 // return: // -1 出错 // 0 没有改变首尾号 // 1 校准后改变了首尾号 // 2 书目库中没有记录 public int VerifyRange(out string strError) { strError = ""; string strPath; byte[] baPackage; string strMinNumber; string strMaxNumber; int nRet; int style = DtlpChannel.JH_STYLE; int nErrorNo; bool bChanged = false; string strVersion; if (this.channel == null) this.channel = this.Channels.CreateChannel(0); Debug.Assert(m_strStartNumber != "", "m_strStartNumber值不能为空"); Debug.Assert(m_strEndNumber != "", "m_strEndNumber值不能为空"); // 校准最大号 //REDO1: strPath = m_strDBPath; // GetDTLPVersion(m_strDBPath, strVersion); // 可以将库名再去除,效果更好 strVersion = "0.9"; if (strVersion == "0.9") strPath += "/ctlno/9999999"; // 7位 else strPath += "/ctlno/9999999999"; // 10位 nRet = channel.Search(strPath, style | DtlpChannel.PREV_RECORD, out baPackage); if (nRet <= 0) { nErrorNo = channel.GetLastErrno(); this.ErrorNo = nErrorNo; if (nErrorNo == DtlpChannel.GL_NOTEXIST) return 2; if (nErrorNo == DtlpChannel.GL_INVALIDCHANNEL) this.channel = null; /* channel.ErrorBox(owner, "dp1Batch", "校准最大号时发生错误\nSearch() style=PREV_RECORD error"); * */ strError = "校准最大号时发生错误\nSearch() style=PREV_RECORD error: \r\n" + channel.GetErrorDescription(); goto ERROR1; } /// Package package = new Package(); package.LoadPackage(baPackage, channel.GetPathEncoding(strPath)); nRet = package.Parse(PackageFormat.Binary); if (nRet == -1) { strError = "Package::Parse(PackageFormat.Binary) error"; Debug.Assert(false, strError); goto ERROR1; } strPath = package.GetFirstPath(); nRet = GetCtlNoFromPath(strPath, out strMaxNumber); if (nRet == -1) { strError = "GetCtlNoFromPath() error ..."; Debug.Assert(false, strError); goto ERROR1; } // 2007/8/18 if (strVersion == "0.9") strMaxNumber = strMaxNumber.PadLeft(7, '0'); // 7位 else strMaxNumber = strMaxNumber.PadLeft(10, '0'); // 10位 if (Convert.ToInt64(m_strStartNumber) <= Convert.ToInt64(m_strEndNumber)) { if (Convert.ToInt64(m_strEndNumber) > Convert.ToInt64(strMaxNumber)) { m_strEndNumber = strMaxNumber; bChanged = true; } } else { if (Convert.ToInt64(m_strStartNumber) > Convert.ToInt64(strMaxNumber)) { m_strStartNumber = strMaxNumber; bChanged = true; } } // 校准最小号 //REDO2: strPath = m_strDBPath; strPath += "/ctlno/0000000000"; // - nRet = channel.Search(strPath, style | DtlpChannel.NEXT_RECORD, out baPackage); if (nRet <= 0) { nErrorNo = channel.GetLastErrno(); this.ErrorNo = nErrorNo; if (nErrorNo == DtlpChannel.GL_NOTEXIST) return 2; if (nErrorNo == DtlpChannel.GL_INVALIDCHANNEL) this.channel = null; /* channel.ErrorBox(owner, "Batch", "校准最小号时发生错误\nSearch() style=NEXT_RECORD error"); * */ strError = "校准最小号时发生错误\nSearch() style=NEXT_RECORD error: \r\n" + channel.GetErrorDescription(); goto ERROR1; } /// package.LoadPackage(baPackage, channel.GetPathEncoding(strPath)); nRet = package.Parse(PackageFormat.Binary); if (nRet == -1) { strError = "Package::Parse(PackageFormat.Binary) error"; Debug.Assert(false, strError); goto ERROR1; } strPath = package.GetFirstPath(); nRet = GetCtlNoFromPath(strPath, out strMinNumber); if (nRet == -1) { strError = "GetCtlNoFromPath() error ..."; Debug.Assert(false, strError); goto ERROR1; } // 2007/8/18 if (strVersion == "0.9") strMinNumber = strMinNumber.PadLeft(7, '0'); // 7位 else strMinNumber = strMinNumber.PadLeft(10, '0'); // 10位 if (Convert.ToInt64(m_strStartNumber) <= Convert.ToInt64(m_strEndNumber)) { if (Convert.ToInt64(m_strStartNumber) < Convert.ToInt64(strMinNumber)) { m_strStartNumber = strMinNumber; bChanged = true; } } else { if (Convert.ToInt64(m_strEndNumber) < Convert.ToInt64(strMinNumber)) { m_strEndNumber = strMinNumber; bChanged = true; } } if (bChanged == true) return 1; else return 0; ERROR1: return -1; }
// 得到下一条记录 // return: // -1 出错 // 0 继续 // 1 到达末尾(超过m_strEndNumber) // 2 没有找到记录 public int NextRecord(ref int nRecCount, out string strError) { strError = ""; string strPath; string strNumber; string strNextNumber; byte[] baPackage = null; int nSearchStyle = DtlpChannel.XX_STYLE; int nRet; int nErrorNo; int nDirStyle = 0; // 方向风格 byte[] baMARC = null; if (this.channel == null) this.channel = this.Channels.CreateChannel(0); Debug.Assert(m_strStartNumber != "", "m_strStartNumber值不能为空"); Debug.Assert(m_strEndNumber != "", "m_strEndNumber值不能为空"); // 首次进入本函数 if (nRecCount == -1) { strNumber = m_strStartNumber; nDirStyle = 0; nRecCount = 0; } else { strNumber = m_strNextNumber; if (Convert.ToInt64(m_strStartNumber) <= Convert.ToInt64(m_strEndNumber)) { nDirStyle = DtlpChannel.NEXT_RECORD; if (Convert.ToInt64(strNumber) >= Convert.ToInt64(m_strEndNumber)) return 1; // 结束 } else { nDirStyle = DtlpChannel.PREV_RECORD; if (Convert.ToInt64(strNumber) <= Convert.ToInt64(m_strEndNumber)) return 1; // 结束 } } strPath = m_strDBPath; strPath += "/ctlno/"; strPath += strNumber; // REDO: nRet = channel.Search(strPath, nSearchStyle | nDirStyle, out baPackage); if (nRet == -1) { nErrorNo = channel.GetLastErrno(); if (nErrorNo == DtlpChannel.GL_NOTLOGIN) { // 重新登录的事情,已经被Search()接管了 } else { if (nErrorNo == DtlpChannel.GL_NOTEXIST) { // 增量号码 Int64 n64Number = Convert.ToInt64(strNumber); string strVersion; // GetDTLPVersion(m_strDBPath, strVersion); // 可以将库名再去除,效果更好 strVersion = "0.9"; if (n64Number+1<9999999 && strVersion == "0.9") { //strNumber.Format(_T("%I0764d"), n64Number+1); // 确保7位数字 strNumber = String.Format("{0:D7}", n64Number+1); // "{0,7:D}" BUG!!! 左边实际上是空格 2009/2/26 } else { // strNumber.Format(_T("%I64d"), n64Number+1); strNumber = String.Format("{0:D7}", n64Number + 1); // "{0,7:D}" BUG!!! 左边实际上是空格 2009/2/26 } m_strCurNumber = strNumber; goto NOTFOUND; } this.ErrorNo = nErrorNo; if (nErrorNo == DtlpChannel.GL_INVALIDCHANNEL) this.channel = null; // 得到字符串即可 /* channel.ErrorBox(owner, "DtlpIO", "检索发生错误\nSearch() error"); * */ strError = "检索发生错误\nSearch() error: \r\n" + channel.GetErrorDescription(); goto ERROR1; } m_strPath = strPath; goto ERROR1; } /// Package package = new Package(); package.LoadPackage(baPackage, channel.GetPathEncoding(strPath)); nRet = package.Parse(PackageFormat.Binary); if (nRet == -1) { Debug.Assert(false, "Package::Parse() error"); strError = "Package::Parse() error"; goto ERROR1; } nRet = package.GetFirstBin(out baMARC); if (nRet == -1 || nRet == 0) { Debug.Assert(false, "Package::GetFirstBin() error"); strError = "Package::GetFirstBin() error"; goto ERROR1; } if (baMARC.Length >= 9) { Array.Copy(baMARC, 0, m_baTimeStamp, 0, 9); byte [] baBody = new byte[baMARC.Length - 9]; Array.Copy(baMARC, 9, baBody, 0, baMARC.Length - 9); baMARC = baBody; //baMARC.RemoveAt(0, 9); // 时间戳 } else { // 记录有问题,放入一个空记录? } // ---????????? 编写一个在byte[]末尾追加东西的函数? // baMARC = ByteArray.Add(baMARC, (byte)0); // baMARC.Add(0); // baMARC.Add(0); m_strRecord = channel.GetPathEncoding(strPath).GetString(baMARC); strPath = package.GetFirstPath(); nRet = GetCtlNoFromPath(strPath, out strNextNumber); if (nRet == -1) { Debug.Assert(false, "GetCtlNoFromPath() return error ..."); strError = "GetCtlNoFromPath() error ..."; goto ERROR1; } m_strNextNumber = strNextNumber; if (nRecCount == 0) // 首次 m_strCurNumber = strNumber; else m_strCurNumber = strNextNumber; m_strPath = strPath; // nRecCount ++; return 0; ERROR1: return -1; NOTFOUND: return 2; }
// 加入命中路径list void AddToPathList(Package package, ref List<string> list) { for (int i = 0; i < package.Count; i++) { Cell cell = (Cell)package[i]; string strShortPath = Global.ModifyDtlpRecPath(cell.Path, ""); list.Add(strShortPath); } }
// 获得浏览记录内容 // parameters: // strPath 记录路径。应当为完全形态 int GetOneBrowseRecord( string strPath, out string[] cols, out string strError) { strError = ""; cols = null; int nRet = 0; int nStyle = DtlpChannel.JH_STYLE; // 获得简化记录 byte[] baPackage; nRet = this.DtlpChannel.Search(strPath, nStyle, out baPackage); if (nRet == -1) { strError = "Search() path '" + strPath + "' 时发生错误: " + this.DtlpChannel.GetErrorString(); goto ERROR1; } Package package = new Package(); package.LoadPackage(baPackage, this.DtlpChannel.GetPathEncoding(strPath)); nRet = package.Parse(PackageFormat.String); if (nRet == -1) { strError = "Package::Parse() error"; goto ERROR1; } string strContent = package.GetFirstContent(); if (String.IsNullOrEmpty(strContent) == false) { cols = strContent.Split(new char[] { '\t' }); } return 0; ERROR1: return -1; }
int m_nInSearching = 0; // 表示this.DtlpChannel是否被占用 /* 发生未捕获的界面线程异常: Type: System.ObjectDisposedException Message: 无法访问已释放的对象。 对象名:“System.Net.Sockets.NetworkStream”。 Stack: 在 System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult) 在 DigitalPlatform.DTLP.HostEntry.RecvTcpPackage(Byte[]& baPackage, Int32& nLen, Int32& nErrorNo) 在 DigitalPlatform.DTLP.DtlpChannel.API_Search(String strPath, Int32 lStyle, Byte[]& baResult) 在 DigitalPlatform.DTLP.DtlpChannel.Search(String strPath, Int32 lStyle, Byte[]& baResult) 在 dp2Catalog.DtlpSearchForm.GetOneBrowseRecord(String strPath, String[]& cols, String& strError) 在 dp2Catalog.DtlpSearchForm.FillBrowseList(Package package, String& strError) 在 dp2Catalog.DtlpSearchForm.DoSearch() 在 dp2Catalog.MainForm.toolButton_search_Click(Object sender, EventArgs e) 在 System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e) 在 System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e) 在 System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea) 在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) 在 System.Windows.Forms.Control.WndProc(Message& m) 在 System.Windows.Forms.ToolStrip.WndProc(Message& m) 在 System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) * */ // 检索 public int DoSearch() { string strError = ""; int nRet = 0; this._processing++; try { byte[] baNext = null; int nStyle = DtlpChannel.CTRLNO_STYLE; // nStyle |= Channel.JH_STYLE; // 获得简化记录 string strPath = ""; if ((this.dtlpResDirControl1.SelectedMask & DtlpChannel.TypeStdbase) != 0) { this.strCurrentTargetPath = this.textBox_resPath.Text + "//"; } else { this.strCurrentTargetPath = this.textBox_resPath.Text + "/"; } this.strCurrentQueryWord = this.textBox_queryWord.Text; strPath = this.strCurrentTargetPath + this.strCurrentQueryWord; this.listView_browse.Items.Clear(); EnableControls(false); stop.OnStop += new StopEventHandler(this.DoStop); stop.SetMessage("开始检索 ..."); stop.BeginLoop(); this.Update(); this.MainForm.Update(); this.m_nInSearching++; /* this.listView_browse.ListViewItemSorter = null; // 暂时屏蔽排序能力 * */ try { int nDupCount = 0; this.listView_browse.Focus(); // 便于Excape中断 bool bFirst = true; // 第一次检索 while (true) { Application.DoEvents(); // 出让界面控制权 if (stop != null) { if (stop.State != 0) { strError = "用户中断"; goto ERROR1; } } Encoding encoding = this.DtlpChannel.GetPathEncoding(strPath); this.CurrentEncoding = encoding; // 记忆下来 byte[] baPackage; if (bFirst == true) { stop.SetMessage(listView_browse.Items.Count.ToString() + " 去重:" + nDupCount.ToString() + " " + "正在检索 " + strPath); nRet = this.DtlpChannel.Search(strPath, nStyle, out baPackage); } else { stop.SetMessage(listView_browse.Items.Count.ToString() + " 去重:" + nDupCount.ToString() + " " + "正在检索 " + strPath + " " + encoding.GetString(baNext)); nRet = this.DtlpChannel.Search(strPath, baNext, nStyle, out baPackage); } if (nRet == -1) { int errorcode = this.DtlpChannel.GetLastErrno(); if (errorcode == DtlpChannel.GL_NOTEXIST) { /* if (bFirst == true) break; * */ break; } strError = "检索出错:\r\n" + "检索式: " + strPath + "\r\n" + "错误码: " + errorcode + "\r\n" + "错误信息: " + this.DtlpChannel.GetErrorString(errorcode) + "\r\n"; goto ERROR1; } bFirst = false; Package package = new Package(); package.LoadPackage(baPackage, encoding/*this.Channel.GetPathEncoding(strPath)*/); // nRet = package.Parse(PackageFormat.String); nRet = package.Parse(PackageFormat.String); if (nRet == -1) { strError = "Package::Parse() error"; goto ERROR1; } /// nRet = FillBrowseList(package, out strError); if (nRet == -1) goto ERROR1; nDupCount += nRet; if (package.ContinueString != "") { nStyle |= DtlpChannel.CONT_RECORD; baNext = package.ContinueBytes; } else { break; } } this.textBox_resultInfo.Text = "命中记录 " + this.listView_browse.Items.Count.ToString() + " 条"; } finally { this.m_nInSearching--; try { stop.EndLoop(); stop.OnStop -= new StopEventHandler(this.DoStop); stop.Initial(""); EnableControls(true); /* // 提供排序能力 this.listView_browse.ListViewItemSorter = new ListViewBrowseItemComparer(); * */ } catch { } } if (this.listView_browse.Items.Count > 0) this.listView_browse.Focus(); else this.textBox_queryWord.Focus(); return 0; } finally { this._processing--; } ERROR1: try // 防止最后退出时报错 { this.textBox_resultInfo.Text = "命中记录 " + this.listView_browse.Items.Count.ToString() + " 条"; this.textBox_resultInfo.Text += "\r\n" + strError; MessageBox.Show(this, strError); this.textBox_queryWord.Focus(); } catch { } return -1; }
// 针对一个检索词的检索 int DoOneSearch( string strDatabasePath, string strFromName, string strWord, string strWeight, string strSearchStyle, int nThreshold, out string strError) { strError = ""; int nRet = 0; byte[] baNext = null; int nStyle = DtlpChannel.CTRLNO_STYLE; if (strSearchStyle.ToLower() == "exact") nStyle |= DtlpChannel.EXACT_RECORD; string strPath = ""; strPath = strDatabasePath + "/" + strFromName.Replace('$', (char)31) + "/" + strWord; // int nDupCount = 0; List<string> path_list = new List<string>(); bool bFirst = true; // 第一次检索 while (true) { Application.DoEvents(); // 出让界面控制权 if (stop != null) { if (stop.State != 0) { strError = "用户中断"; goto ERROR1; } } Encoding encoding = this.DtlpChannel.GetPathEncoding(strPath); byte[] baPackage; if (bFirst == true) { nRet = this.DtlpChannel.Search(strPath, nStyle, out baPackage); } else { nRet = this.DtlpChannel.Search(strPath, baNext, nStyle, out baPackage); } if (nRet == -1) { int errorcode = this.DtlpChannel.GetLastErrno(); if (errorcode == DtlpChannel.GL_NOTEXIST) { break; } strError = this.DtlpChannel.GetErrorString(); goto ERROR1; } bFirst = false; Package package = new Package(); package.LoadPackage(baPackage, encoding); nRet = package.Parse(PackageFormat.String); if (nRet == -1) { strError = "Package::Parse() error"; goto ERROR1; } // TODO: 检索索引号先进入一个内存结构,去重以后,再合并进入listview AddToPathList(package, ref path_list); if (package.ContinueString != "") { nStyle |= DtlpChannel.CONT_RECORD; baNext = package.ContinueBytes; } else { break; } } // 排序去重 path_list.Sort(); Global.RemoveDup(ref path_list); nRet = FillBrowseList(path_list, strWeight, nThreshold, out strError); if (nRet == -1) goto ERROR1; return 0; ERROR1: return -1; }
// 获得一条MARC记录 // 注:如果this.DtlpChannel被占用,启动启用新的通道 // TODO: 尚未处理启用新通道时启用新Stop的课题 // parameters: // strPath 记录路径。格式为"localhost/中文图书/ctlno/1" // strDirection 方向。为 prev/next/current之一。current可以缺省。 // strOutputPath [out]返回的实际路径。格式和strPath相同。 // return: // -1 error 包括not found // 0 found // 1 为诊断记录 int InternalGetOneRecord( string strStyle, string strPath, string strDirection, out string strMARC, out string strOutputPath, out string strOutStyle, out byte[] baTimestamp, out DigitalPlatform.Z3950.Record record, out Encoding currrentEncoding, out string strError) { strMARC = ""; record = null; strError = ""; currrentEncoding = this.CurrentEncoding; baTimestamp = null; strOutStyle = "marc"; strOutputPath = ""; // TODO: 需要参考dp1batch看获得outputpath的方法 if (strStyle != "marc") { strError = "DtlpSearchForm只支持获取MARC格式记录"; return -1; } int nRet = 0; int nStyle = DtlpChannel.XX_STYLE; // 获得详细记录 if (strDirection == "prev") nStyle |= DtlpChannel.PREV_RECORD; else if (strDirection == "next") nStyle |= DtlpChannel.NEXT_RECORD; /* // 将路径转换为内核可以接受的正规形态 string strPath = DigitalPlatform.DTLP.Global.ModifyDtlpRecPath(strPath, "ctlno"); * */ Stop temp_stop = this.stop; DtlpChannel channel = null; bool bNewChannel = false; if (this.m_nInSearching == 0) channel = this.DtlpChannel; else { channel = this.DtlpChannels.CreateChannel(0); bNewChannel = true; temp_stop = new Stop(); temp_stop.Tag = channel; temp_stop.Register(MainForm.stopManager, true); // 和容器关联 temp_stop.OnStop += new StopEventHandler(this.DoNewStop); temp_stop.Initial("正在初始化浏览器组件 ..."); temp_stop.BeginLoop(); } byte[] baPackage = null; Encoding encoding = null; try { nRet = channel.Search(strPath, nStyle, out baPackage); if (nRet == -1) { int errorcode = channel.GetLastErrno(); if (errorcode == DtlpChannel.GL_NOTEXIST && (strDirection == "prev" || strDirection == "next")) { if (strDirection == "prev") strError = "到头"; else if (strDirection == "next") strError = "到尾"; goto ERROR1; } strError = "检索出错:\r\n" + "检索式: " + strPath + "\r\n" + "错误码: " + errorcode + "\r\n" + "错误信息: " + channel.GetErrorString(errorcode) + "\r\n"; goto ERROR1; } encoding = channel.GetPathEncoding(strPath); } finally { if (bNewChannel == true) { temp_stop.EndLoop(); temp_stop.OnStop -= new StopEventHandler(this.DoNewStop); temp_stop.Initial(""); this.DtlpChannels.DestroyChannel(channel); channel = null; temp_stop.Unregister(); // 和容器关联 temp_stop = null; } } Package package = new Package(); package.LoadPackage(baPackage, encoding); nRet = package.Parse(PackageFormat.Binary); if (nRet == -1) { strError = "Package::Parse() error"; goto ERROR1; } strOutputPath = package.GetFirstPath(); byte[] content = null; nRet = package.GetFirstBin(out content); if (nRet == -1) { strError = "Package::GetFirstBin() error"; goto ERROR1; } if (content == null || content.Length < 9) { strError = "content length < 9"; goto ERROR1; } baTimestamp = new byte[9]; Array.Copy(content, baTimestamp, 9); byte[] marc = new byte[content.Length - 9]; Array.Copy(content, 9, marc, 0, content.Length - 9); // strMARC = this.CurrentEncoding.GetString(marc); strMARC = encoding.GetString(marc); // 去掉最后若干连续的29字符或者0字符 // 2008/3/11 int nDelta = 0; for (int i = strMARC.Length - 1; i > 24; i--) { char ch = strMARC[i]; if (ch == 0 || ch == 29) nDelta++; else break; } if (nDelta > 0) strMARC = strMARC.Substring(0, strMARC.Length - nDelta); // 自动识别MARC格式 string strOutMarcSyntax = ""; // 探测记录的MARC格式 unimarc / usmarc / reader // return: // 0 没有探测出来。strMarcSyntax为空 // 1 探测出来了 nRet = MarcUtil.DetectMarcSyntax(strMARC, out strOutMarcSyntax); if (strOutMarcSyntax == "") strOutMarcSyntax = "unimarc"; record = new DigitalPlatform.Z3950.Record(); if (strOutMarcSyntax == "unimarc" || strOutMarcSyntax == "") record.m_strSyntaxOID = "1.2.840.10003.5.1"; else if (strOutMarcSyntax == "usmarc") record.m_strSyntaxOID = "1.2.840.10003.5.10"; else if (strOutMarcSyntax == "dt1000reader") record.m_strSyntaxOID = "1.2.840.10003.5.dt1000reader"; else { /* strError = "未知的MARC syntax '" + strOutMarcSyntax + "'"; goto ERROR1; * */ // TODO: 可以出现菜单选择 } return 0; ERROR1: return -1; }
// return: // 本次重复的记录数 int FillBrowseList(Package package, out string strError) { strError = ""; int nDupCount = 0; // 处理每条记录 for (int i = 0; i < package.Count; i++) { Application.DoEvents(); // 出让界面控制权 if (stop != null) { if (stop.State != 0) { strError = "用户中断"; return -1; } } Cell cell = (Cell)package[i]; // 查重 string strPath = DigitalPlatform.DTLP.Global.ModifyDtlpRecPath(cell.Path, ""); if (DetectDup(strPath) == true) { nDupCount++; continue; } ListViewItem item = new ListViewItem(); item.Text = strPath; string[] cols = null; int nRet = GetOneBrowseRecord( cell.Path, out cols, out strError); if (nRet == -1) { item.SubItems.Add(strError); goto CONTINUE; } if (cols != null) { // 确保列标题数量足够 ListViewUtil.EnsureColumns(this.listView_browse, cols.Length, 200); for (int j = 0; j < cols.Length; j++) { item.SubItems.Add(cols[j]); } } CONTINUE: this.listView_browse.Items.Add(item); // this.listView_browse.UpdateItem(this.listView_browse.Items.Count - 1); } return nDupCount; }
// strStart, // 起始路径, ""表示根 Package GetOneLevelDirPackage(string strStart) { int nRet; byte [] baPackage = null; // bool bSetDefault = false; // 表示是否使用过缺省帐户 //bool bFirstLogin = true; Package package = new Package(); // CWaitCursor cursor; if (Channel == null) { Channel = channelarray.CreateChannel(0); } Debug.Assert(Channel != null, "channel尚未初始化"); Cursor.Current = Cursors.WaitCursor; if (Stop != null) { Stop.OnStop += new StopEventHandler(this.DoStop); Stop.SetMessage("正在列目录 '" + strStart + "' ..."); Stop.BeginLoop(); } try { nRet = Channel.Dir(strStart, out baPackage); } finally { if (Stop != null) { Stop.EndLoop(); Stop.OnStop -= new StopEventHandler(this.DoStop); Stop.Initial(""); } Cursor.Current = Cursors.Default; } if (nRet == -1) { Channel.ErrorBox(this, "restree", "列目录发生错误"); goto ERROR1; } package.LoadPackage(baPackage, Channel.GetPathEncoding(strStart)); package.Parse(PackageFormat.String); return package; ERROR1: return null; }
// strStart, // 起始路径, ""表示根 Package GetOneLevelDirPackage(string strStart, out string strError) { strError = ""; int nRet; byte[] baPackage = null; // bool bSetDefault = false; // 表示是否使用过缺省帐户 //bool bFirstLogin = true; Package package = new Package(); // CWaitCursor cursor; if (this.DtlpChannel == null) { this.DtlpChannel = this.DtlpChannelArray.CreateChannel(0); } Debug.Assert(this.DtlpChannel != null, "channel尚未初始化"); Cursor.Current = Cursors.WaitCursor; nRet = this.DtlpChannel.Dir(strStart, out baPackage); Cursor.Current = Cursors.Default; if (nRet == -1) { strError = this.DtlpChannel.GetErrorDescription(); goto ERROR1; } package.LoadPackage(baPackage, this.DtlpChannel.GetPathEncoding(strStart)); package.Parse(PackageFormat.String); return package; ERROR1: return null; }
// 获得日志记录 // 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(""); } }