void DisplayMarc(string strOldMARC, string strNewMARC) { string strError = ""; string strHtml2 = ""; if (string.IsNullOrEmpty(strOldMARC) == false && string.IsNullOrEmpty(strNewMARC) == true) { strHtml2 = MarcUtil.GetHtmlOfMarc(strOldMARC, null, null, false); } else { // 创建展示两个 MARC 记录差异的 HTML 字符串 // return: // -1 出错 // 0 成功 int nRet = MarcDiff.DiffHtml( strOldMARC, null, null, strNewMARC, null, null, out strHtml2, out strError); if (nRet == -1) { } } string strHtml = "<html>" + this.MarcHtmlHead + "<body>" + strHtml2 + "</body></html>"; this.webBrowser1.Stop(); Global.SetHtmlString(this.webBrowser1, strHtml, this.TempDir, "temp_html"); }
// 测试 MarcDiff.MergeOldNew() 方法 // parameters: // strCommentCheckList 期望在 strComment 中出现的值,逗号分隔 void MarcDiff_MergeOldNew( string strUserRights, string strFieldNameList, MarcRecord old_record, MarcRecord new_record, MarcRecord target_record, string strCommentCheckList = "") { string strComment = ""; string strError = ""; int nRet = 0; string strOldMarc = old_record.Text; nRet = LibraryApplication.MaskCantGet856( strUserRights, ref strOldMarc, out strError); if (nRet == -1) { throw new Exception(strError); } // Assert.AreEqual(nRet, 1, "应当是只标记了一个 856 字段"); string strNewMarc = new_record.Text; // 对 strNewMarc 进行过滤,将那些当前用户无法读取的 856 字段删除 // 对 MARC 记录进行过滤,将那些当前用户无法读取的 856 字段删除 // return: // -1 出错 // 其他 滤除的 856 字段个数 nRet = LibraryApplication.MaskCantGet856( strUserRights, ref strNewMarc, out strError); if (nRet == -1) { throw new Exception(strError); } // Assert.AreEqual(nRet, 0, "应当没有标记任何 856 字段"); // 按照字段修改权限定义,合并新旧两个 MARC 记录 // parameters: // strDefaultOperation insert/replace/delete 之一或者逗号间隔组合 // return: // -1 出错 // 0 成功 // 1 有部分修改要求被拒绝 nRet = MarcDiff.MergeOldNew( "insert,replace,delete", strFieldNameList, strOldMarc, ref strNewMarc, out strComment, out strError); if (nRet == -1) { throw new Exception(strError); } // 检查 strNewMarc if (strNewMarc != target_record.Text) { throw new Exception("和期望的结果不符合"); } // 检查 strComment if (string.IsNullOrEmpty(strCommentCheckList) == false) { List <string> texts = StringUtil.SplitList(strCommentCheckList); foreach (string text in texts) { if (text == "{null}") { if (string.IsNullOrEmpty(strComment) == false) { throw new Exception("strComment 字符串 '" + strComment + "' 没有期望的那样为空"); } continue; } nRet = strComment.IndexOf(text); if (nRet == -1) { throw new Exception("strComment 字符串 '" + strComment + "' 中没有包含要求的片段 '" + text + "'"); } } } }
public void MarcDiff_MergeOldNew_1_1() { string strComment = ""; string strError = ""; int nRet = 0; string strUserRights = "level-1"; string strFieldNameList = "*:***-***"; // 所有字段都允许操作 MarcRecord old_record = new MarcRecord(); // 旧记录有三个 856 字段,第一个的权限禁止当前用户访问 old_record.add(new MarcField("001A1234567")); old_record.add(new MarcField('$', "2001 $atitle$fauthor")); old_record.add(new MarcField('$', "85642$3Cover image 1$uURL1$qimage/jpeg$xtype:FrontCover.SmallImage;rights:group")); old_record.add(new MarcField('$', "85642$3Cover image 2$uURL2$qimage/jpeg$xtype:FrontCover.MediumImage")); old_record.add(new MarcField('$', "85642$3Cover image 3$uURL3$qimage/jpeg$xtype:FrontCover.LargeImage")); old_record.add(new MarcField('$', "701 $aauthor")); #if NO string strOldMarc = old_record.Text; nRet = LibraryApplication.MaskCantGet856( strUserRights, ref strOldMarc, out strError); if (nRet == -1) { throw new Exception(strError); } Assert.AreEqual(nRet, 1, "应当是只标记了一个 856 字段"); #endif MarcRecord new_record = new MarcRecord(); // 新记录有两个 856 字段,相当于丢失了旧记录的第一个 856 字段,这模仿了权限不足的用户编辑修改保存的过程。 // 新记录的第一个 856 字段被修改了,增加了 $zZZZ new_record.add(new MarcField("001A1234567")); new_record.add(new MarcField('$', "2001 $atitle$fauthor")); new_record.add(new MarcField('$', "85642$3Cover image 2$uURL2$qimage/jpeg$xtype:FrontCover.MediumImage$zZZZ")); new_record.add(new MarcField('$', "85642$3Cover image 3$uURL3$qimage/jpeg$xtype:FrontCover.LargeImage")); new_record.add(new MarcField('$', "701 $aauthor")); #if NO string strNewMarc = new_record.Text; // 对 strNewMarc 进行过滤,将那些当前用户无法读取的 856 字段删除 // 对 MARC 记录进行过滤,将那些当前用户无法读取的 856 字段删除 // return: // -1 出错 // 其他 滤除的 856 字段个数 nRet = LibraryApplication.MaskCantGet856( strUserRights, ref strNewMarc, out strError); if (nRet == -1) { throw new Exception(strError); } Assert.AreEqual(nRet, 0, "应当没有标记任何 856 字段"); #endif MarcRecord target_record = new MarcRecord(); // 结果记录有三个 856 字段 // 结果记录的第二个 856 字段兑现了修改,增加了 $zZZZ。旧记录的第一个 856 字段得到了保护 target_record.add(new MarcField("001A1234567")); target_record.add(new MarcField('$', "2001 $atitle$fauthor")); target_record.add(new MarcField('$', "85642$3Cover image 1$uURL1$qimage/jpeg$xtype:FrontCover.SmallImage;rights:group")); target_record.add(new MarcField('$', "85642$3Cover image 2$uURL2$qimage/jpeg$xtype:FrontCover.MediumImage$zZZZ")); target_record.add(new MarcField('$', "85642$3Cover image 3$uURL3$qimage/jpeg$xtype:FrontCover.LargeImage")); target_record.add(new MarcField('$', "701 $aauthor")); MarcDiff_MergeOldNew( strUserRights, strFieldNameList, old_record, new_record, target_record, "{null}"); #if NO // 按照字段修改权限定义,合并新旧两个 MARC 记录 // parameters: // strDefaultOperation insert/replace/delete 之一或者逗号间隔组合 // return: // -1 出错 // 0 成功 // 1 有部分修改要求被拒绝 nRet = MarcDiff.MergeOldNew( "insert,replace,delete", strFieldNameList, strOldMarc, ref strNewMarc, out strComment, out strError); if (nRet == -1) { throw new Exception(strError); } // 检查 strNewMarc if (strNewMarc != target_record.Text) { throw new Exception("和期望的结果不符合"); } // 检查 strComment #endif }
// 显示选择的目标记录、和源记录。源记录显示在左边 void DisplaySelectedRecord(ListViewItem item) { string strError = ""; int nRet = 0; string strXmlOrigin = this.OriginXml; string strXmlTarget = ""; if (item != null) { ItemTag tag = (ItemTag)item.Tag; if (tag != null) { strXmlTarget = tag.Xml; } } string strRecPathOrigin = this.OriginRecPath; string strRecPathTarget = ""; if (item != null) { strRecPathTarget = ListViewUtil.GetItemText(item, 0); } string strOriginMARC = ""; string strOriginFragmentXml = ""; if (string.IsNullOrEmpty(strXmlOrigin) == false) { string strOutMarcSyntax = ""; // 将XML格式转换为MARC格式 // 自动从数据记录中获得MARC语法 nRet = MarcUtil.Xml2Marc(strXmlOrigin, MarcUtil.Xml2MarcStyle.Warning | MarcUtil.Xml2MarcStyle.OutputFragmentXml, "", out strOutMarcSyntax, out strOriginMARC, out strOriginFragmentXml, out strError); if (nRet == -1) { strError = "XML转换到MARC记录时出错: " + strError; goto ERROR1; } } string strTargetMARC = ""; string strTargetFragmentXml = ""; if (string.IsNullOrEmpty(strXmlTarget) == false) { string strOutMarcSyntax = ""; // 将XML格式转换为MARC格式 // 自动从数据记录中获得MARC语法 nRet = MarcUtil.Xml2Marc(strXmlTarget, MarcUtil.Xml2MarcStyle.Warning | MarcUtil.Xml2MarcStyle.OutputFragmentXml, "", out strOutMarcSyntax, out strTargetMARC, out strTargetFragmentXml, out strError); if (nRet == -1) { strError = "XML转换到MARC记录时出错: " + strError; goto ERROR1; } } else { strTargetMARC = ""; } string strHtml2 = ""; #if NO if (string.IsNullOrEmpty(strOriginMARC) == false && string.IsNullOrEmpty(strTargetMARC) == false) #endif { string strTargetTitle = "目标: " + strRecPathTarget; // 创建展示两个 MARC 记录差异的 HTML 字符串 // return: // -1 出错 // 0 成功 nRet = MarcDiff.DiffHtml( "源", strOriginMARC, strOriginFragmentXml, "", strTargetTitle, strTargetMARC, strTargetFragmentXml, "", out strHtml2, out strError); if (nRet == -1) { goto ERROR1; } } { string strHtml = "<html>" + this.MarcHtmlHead + "<body>" + strHtml2 + "</body></html>"; this.webBrowser1.Stop(); Global.SetHtmlString(this.webBrowser1, strHtml, this.TempDir, "temp_biblio_dup_html"); } return; ERROR1: { string strHtml = "<html>" + this.MarcHtmlHead + "<body>" + HttpUtility.HtmlEncode(strError) + "</body></html>"; this.webBrowser1.Stop(); Global.SetHtmlString(this.webBrowser1, strHtml, this.TempDir, "temp_biblio_dup_html"); } }
int GetXmlHtml( string strXml1, string strXml2, out string strHtml2, out string strError) { strError = ""; strHtml2 = ""; int nRet = 0; string strOldMARC = ""; string strOldFragmentXml = ""; if (string.IsNullOrEmpty(strXml1) == false) { string strOutMarcSyntax = ""; // 将XML格式转换为MARC格式 // 自动从数据记录中获得MARC语法 nRet = MarcUtil.Xml2Marc(strXml1, MarcUtil.Xml2MarcStyle.Warning | MarcUtil.Xml2MarcStyle.OutputFragmentXml, "", out strOutMarcSyntax, out strOldMARC, out strOldFragmentXml, out strError); if (nRet == -1) { strError = "XML 转换到 MARC 记录时出错: " + strError; return(-1); } } string strNewMARC = ""; string strNewFragmentXml = ""; if (string.IsNullOrEmpty(strXml2) == false) { string strOutMarcSyntax = ""; // 将XML格式转换为MARC格式 // 自动从数据记录中获得MARC语法 nRet = MarcUtil.Xml2Marc(strXml2, MarcUtil.Xml2MarcStyle.Warning | MarcUtil.Xml2MarcStyle.OutputFragmentXml, "", out strOutMarcSyntax, out strNewMARC, out strNewFragmentXml, out strError); if (nRet == -1) { strError = "XML 转换到 MARC 记录时出错: " + strError; return(-1); } } if (string.IsNullOrEmpty(strOldMARC) == false && string.IsNullOrEmpty(strNewMARC) == false) { // 创建展示两个 MARC 记录差异的 HTML 字符串 // return: // -1 出错 // 0 成功 nRet = MarcDiff.DiffHtml( _leftTitle, strOldMARC, strOldFragmentXml, "", _rightTitle, strNewMARC, strNewFragmentXml, "", out strHtml2, out strError); if (nRet == -1) { return(-1); } } else if (string.IsNullOrEmpty(strOldMARC) == false && string.IsNullOrEmpty(strNewMARC) == true) { strHtml2 = MarcUtil.GetHtmlOfMarc(strOldMARC, strOldFragmentXml, "", false); } else if (string.IsNullOrEmpty(strOldMARC) == true && string.IsNullOrEmpty(strNewMARC) == false) { strHtml2 = MarcUtil.GetHtmlOfMarc(strNewMARC, strNewFragmentXml, "", false); } return(0); }