int DoSearch(out string strError) { strError = ""; /* * string strServerName = ""; * * strServerName = this.textBox_serverName.Text; * * if (String.IsNullOrEmpty(strServerName) == true) * { * // 如果servername text为空,则从发起路径中获得servername * strServerName = GetServerName(this.RecordPath); * if (String.IsNullOrEmpty(strServerName) == true) * { * strError = "在没有指定服务器名的情况下,必须指定发起路径"; * return -1; * } * }*/ string strProjectName = ""; if (this.comboBox_projectName.Text == "" || this.comboBox_projectName.Text == "{default}" || this.comboBox_projectName.Text == "<default>" || this.comboBox_projectName.Text == "<默认>") { // 获得和一个来源路径相关的缺省查重方案 string strDatabasePath = ""; strProjectName = GetDefaultProjectName(this.RecordPath, out strDatabasePath); if (String.IsNullOrEmpty(strProjectName) == true) { strError = "没有定义和发起数据库 '" + strDatabasePath + "' 关联的缺省查重方案,因此无法进行查重..."; return(-1); } this.comboBox_projectName.Text = strProjectName; // 将实际用到的查重方案名显示出来 } else { strProjectName = this.comboBox_projectName.Text; } this.m_nodeProject = this.dom.DocumentElement.SelectSingleNode("//project[@name='" + strProjectName + "']"); if (this.m_nodeProject == null) { strError = "没有定义名字为 '" + strProjectName + "' 的查重方案"; return(-1); } stop.OnStop += new StopEventHandler(this.DoStop); stop.SetMessage("开始检索 ..."); stop.BeginLoop(); this.Update(); this.EnableControls(false); this.EventFinish.Reset(); this.m_bInSearch = true; try { this.ClearDupState(true); this.listView_browse.Items.Clear(); // 列出<project>元素下的所有<database>元素 XmlNodeList databases = this.m_nodeProject.SelectNodes("database"); for (int i = 0; i < databases.Count; i++) { XmlNode nodeDatabase = databases[i]; int nRet = DoOneDatabase( nodeDatabase, out strError); if (nRet == -1) { return(-1); } } // 排序 { ColumnSortStyle sortStyle = ColumnSortStyle.RightAlign; this.SortColumns.SetFirstColumn(1, sortStyle, this.listView_browse.Columns, true); this.SortColumns[0].Asc = false; // 大的在前 this.SortColumns.RefreshColumnDisplay(this.listView_browse.Columns); // 排序 this.listView_browse.ListViewItemSorter = new SortColumnsComparer(this.SortColumns); this.listView_browse.ListViewItemSorter = null; } // 显示查重状态 this.SetDupState(); } finally { this.EventFinish.Set(); this.m_bInSearch = false; stop.EndLoop(); stop.OnStop -= new StopEventHandler(this.DoStop); stop.Initial(""); EnableControls(true); } // 命中数 return(this.listView_browse.Items.Count); }
// 下载资源,保存到备份文件 static int WriteResToBackupFile( IWin32Window owner, RmsChannel channel, DigitalPlatform.Stop stop, Stream outputfile, string strXmlRecPath, string[] res_ids, out string strError) { strError = ""; long lRet; for (int i = 0; i < res_ids.Length; i++) { if (owner != null) { Application.DoEvents(); // 出让界面控制权 } if (stop != null && stop.State != 0) { if (owner != null) { DialogResult result = MessageBox.Show(owner, "确实要中断当前批处理操作?", "导出数据", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (result == DialogResult.Yes) { strError = "用户中断"; return(-1); } else { stop.Continue(); } } else { strError = "用户中断"; return(-1); } } string strID = res_ids[i].Trim(); if (string.IsNullOrEmpty(strID)) { continue; } string strResPath = strXmlRecPath + "/object/" + strID; string strMetaData; if (stop != null) { stop.SetMessage("正在下载 " + strResPath); } byte[] baOutputTimeStamp = null; string strOutputPath; REDO_GETRES: lRet = channel.GetRes(strResPath, (Stream)null, // 故意不获取资源体 stop, "metadata,timestamp,outputpath", null, out strMetaData, // 但是要获得metadata out baOutputTimeStamp, out strOutputPath, out strError); if (lRet == -1) { if (channel.OriginErrorCode == rmsws_localhost.ErrorCodeValue.NotFoundObjectFile) { continue; // TODO: 返回警告信息 } if (owner != null) { // TODO: 允许重试 DialogResult redo_result = MessageBox.Show(owner, "获取记录 '" + strResPath + "' 时出现错误: " + strError + "\r\n\r\n重试,还是中断当前批处理操作?\r\n(Retry 重试;Cancel 中断批处理)", "导出数据", MessageBoxButtons.RetryCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); if (redo_result == DialogResult.Cancel) { return(-1); } goto REDO_GETRES; } else { return(-1); } } long lResStart = 0; // 写res的头。 // 如果不能预先确知整个res的长度,可以用随便一个lTotalLength值调用本函数, // 但是需要记忆下函数所返回的lStart,最后调用EndWriteResToBackupFile()。 // 如果能预先确知整个res的长度,则最后不必调用EndWriteResToBackupFile() long lRet0 = Backup.BeginWriteResToBackupFile( outputfile, 0, // 未知 out lResStart); byte[] timestamp = baOutputTimeStamp; ResPath respath = new ResPath(); respath.Url = channel.Url; respath.Path = strOutputPath; // strResPath; // strMetaData还要加入资源id? StringUtil.ChangeMetaData(ref strMetaData, strID, null, null, null, respath.FullPath, ByteArray.GetHexTimeStampString(baOutputTimeStamp)); lRet = Backup.WriteResMetadataToBackupFile(outputfile, strMetaData); if (lRet == -1) { return(-1); } long lBodyStart = 0; // 写res body的头。 // 如果不能预先确知body的长度,可以用随便一个lBodyLength值调用本函数, // 但是需要记忆下函数所返回的lBodyStart,最后调用EndWriteResBodyToBackupFile()。 // 如果能预先确知body的长度,则最后不必调用EndWriteResBodyToBackupFile() lRet = Backup.BeginWriteResBodyToBackupFile( outputfile, 0, // 未知 out lBodyStart); if (lRet == -1) { return(-1); } if (stop != null) { stop.SetMessage("正在下载 " + strResPath + " 的数据体"); } REDO_GETRES_1: lRet = channel.GetRes(strResPath, outputfile, stop, "content,data,timestamp", //"content,data,timestamp" timestamp, out strMetaData, out baOutputTimeStamp, out strOutputPath, out strError); if (lRet == -1) { if (channel.ErrorCode == ChannelErrorCode.EmptyRecord || channel.ErrorCode == ChannelErrorCode.NotFoundObjectFile) // 2017/7/13 { // 空记录 } else { if (owner != null) { // TODO: 允许重试 DialogResult redo_result = MessageBox.Show(owner, "获取记录 '" + strResPath + "' 时出现错误: " + strError + "\r\n\r\n重试,还是中断当前批处理操作?\r\n(Retry 重试;Cancel 中断批处理)", "导出数据", MessageBoxButtons.RetryCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); if (redo_result == DialogResult.Cancel) { return(-1); } goto REDO_GETRES_1; } else { return(-1); } } } long lBodyLength = outputfile.Position - lBodyStart - 8; // res body收尾 lRet = Backup.EndWriteResBodyToBackupFile( outputfile, lBodyLength, lBodyStart); if (lRet == -1) { return(-1); } long lTotalLength = outputfile.Position - lResStart - 8; lRet = Backup.EndWriteResToBackupFile( outputfile, lTotalLength, lResStart); if (lRet == -1) { return(-1); } } return(0); }