示例#1
0
        // 装载XML记录
        public int LoadRecord(ISearchForm searchform,
                              int index,
                              bool bForceFullElementSet = false)
        {
            string strError = "";
            string strMARC  = "";

            this.LinkedSearchForm = searchform;
            this.SavePath         = "";

            DigitalPlatform.OldZ3950.Record record = null;
            Encoding currentEncoding = null;

            this.CurrentRecord = null;

            byte[]    baTimestamp = null;
            string    strSavePath = "";
            string    strOutStyle = "";
            LoginInfo logininfo   = null;
            long      lVersion    = 0;

            string strXmlFragment = "";

            string strParameters = "hilight_browse_line";

            if (bForceFullElementSet == true)
            {
                strParameters += ",force_full";
            }

            int nRet = searchform.GetOneRecord(
                "xml",
                index,         // 即将废止
                "index:" + index.ToString(),
                strParameters, // true,
                out strSavePath,
                out strMARC,
                out strXmlFragment,
                out strOutStyle,
                out baTimestamp,
                out lVersion,
                out record,
                out currentEncoding,
                out logininfo,
                out strError);

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


            this.LoginInfo = logininfo;

            this.CurrentTimestamp = baTimestamp;
            this.SavePath         = strSavePath;
            this.CurrentEncoding  = currentEncoding;


            // 替换单个0x0a
            strMARC = strMARC.Replace("\r", "");
            strMARC = strMARC.Replace("\n", "\r\n");

            // 装入XML编辑器
            // this.textBox_xml.Text = strMARC;
            this.PlainText = strMARC;   // 能自动缩进
            this.textBox_xml.Select(0, 0);

            // 装入XML只读Web控件
            {
                string strTempFileName = MainForm.DataDir + "\\xml.xml";

                // SUTRS
                if (record.m_strSyntaxOID == "1.2.840.10003.5.101")
                {
                    strTempFileName = MainForm.DataDir + "\\xml.txt";
                }

                using (Stream stream = File.Create(strTempFileName))
                {
                    // 写入xml内容
                    byte[] buffer = Encoding.UTF8.GetBytes(strMARC);
                    stream.Write(buffer, 0, buffer.Length);
                }

                this.webBrowser_xml.Navigate(strTempFileName);
            }

            this.CurrentRecord = record;
            if (this.CurrentRecord != null && this.DisplayOriginPage == true)
            {
                // 装入二进制编辑器
                this.binaryEditor_originData.SetData(
                    this.CurrentRecord.m_baRecord);

                // 装入原始文本
                nRet = this.SetOriginText(this.CurrentRecord.m_baRecord,
                                          this.CurrentEncoding,
                                          out strError);
                if (nRet == -1)
                {
                    this.textBox_originData.Text = strError;
                }

                // 数据库名
                this.textBox_originDatabaseName.Text = this.CurrentRecord.m_strDBName;

                // record syntax OID
                this.textBox_originMarcSyntaxOID.Text = this.CurrentRecord.m_strSyntaxOID;
            }

            // 构造路径
            string strPath = searchform.CurrentProtocol + ":"
                             + searchform.CurrentResultsetPath
                             + "/" + (index + 1).ToString();

            this.textBox_tempRecPath.Text = strPath;
            this.textBox_xml.Focus();
            return(0);

ERROR1:
            MessageBox.Show(this, strError);
            return(-1);
        }
示例#2
0
        // 获得一条MARC/XML记录
        // return:
        //      -1  error 包括not found
        //      0   found
        //      1   为诊断记录
        public int GetOneRecord(
            string strStyle,
            int nTest,
            string strPathParam,
            string strParameters,   // bool bHilightBrowseLine,
            out string strSavePath,
            out string strRecord,
            out string strXmlFragment,
            out string strOutStyle,
            out byte[] baTimestamp,
            out long lVersion,
            out DigitalPlatform.OldZ3950.Record record,
            out Encoding currrentEncoding,
            out LoginInfo logininfo,
            out string strError)
        {
            strXmlFragment   = "";
            strRecord        = "";
            record           = null;
            strError         = "";
            currrentEncoding = this.CurrentEncoding;
            baTimestamp      = null;
            strSavePath      = "";
            strOutStyle      = "marc";
            logininfo        = new LoginInfo();
            lVersion         = 0;

            // 防止重入
            if (m_bInSearch == true)
            {
                strError = "当前窗口正在被一个未结束的长操作使用,无法获得记录。请稍后再试。";
                return(-1);
            }

            if (strStyle != "marc" && strStyle != "xml")
            {
                strError = "DupForm只支持获取MARC格式记录和xml格式记录,不支持 '" + strStyle + "' 格式的记录";
                return(-1);
            }
            int nRet = 0;

            int    index        = -1;
            string strPath      = "";
            string strDirection = "";

            nRet = Global.ParsePathParam(strPathParam,
                                         out index,
                                         out strPath,
                                         out strDirection,
                                         out strError);
            if (nRet == -1)
            {
                return(-1);
            }

            if (index == -1)
            {
                strError = "暂时不支持没有 index 的用法";
                return(-1);
            }

            bool bHilightBrowseLine = StringUtil.IsInList("hilight_browse_line", strParameters);

            if (index >= this.listView_browse.Items.Count)
            {
                strError = "越过结果集尾部";
                return(-1);
            }
            ListViewItem curItem = this.listView_browse.Items[index];

            if (bHilightBrowseLine == true)
            {
                // 修改listview中事项的选定状态
                for (int i = 0; i < this.listView_browse.SelectedItems.Count; i++)
                {
                    this.listView_browse.SelectedItems[i].Selected = false;
                }

                curItem.Selected = true;
                curItem.EnsureVisible();
            }

            string strPurePath   = curItem.Text;
            string strServerName = this.LibraryServerName;

            strPath = strPurePath + "@" + this.LibraryServerName;

            strSavePath = this.CurrentProtocol + ":" + strPath;

            // 拉上一个dp2检索窗,好办事
            dp2SearchForm dp2_searchform = this.GetDp2SearchForm();

            if (dp2_searchform == null)
            {
                strError = "没有打开的dp2检索窗,无法GetOneRecordSyntax()";
                return(-1);
            }

            // 获得server url
            string strServerUrl = dp2_searchform.GetServerUrl(strServerName);

            if (strServerUrl == null)
            {
                strError = "没有找到服务器名 '" + strServerName + "' 对应的URL";
                return(-1);
            }

            this.Channel = this.Channels.GetChannel(strServerUrl);

            stop.OnStop += new StopEventHandler(this.DoStop);
            stop.Initial("正在初始化浏览器组件 ...");
            stop.BeginLoop();

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

            try
            {
                stop.SetMessage("正在装入书目记录 " + strPath + " ...");

                string[] formats = null;
                formats    = new string[1];
                formats[0] = "xml";

                string[] results = null;

                long lRet = Channel.GetBiblioInfos(
                    stop,
                    strPurePath,
                    "",
                    formats,
                    out results,
                    out baTimestamp,
                    out strError);
                if (lRet == 0)
                {
                    strError = "路径为 '" + strPath + "' 的书目记录没有找到 ...";
                    goto ERROR1;   // not found
                }

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

                // this.BiblioTimestamp = baTimestamp;

                if (results == null)
                {
                    strError = "results == null";
                    goto ERROR1;
                }
                if (results.Length != formats.Length)
                {
                    strError = "result.Length != formats.Length";
                    goto ERROR1;
                }

                string strXml = results[0];

                if (strStyle == "marc")
                {
                    string strMarcSyntax    = "";
                    string strOutMarcSyntax = "";
                    // 从数据记录中获得MARC格式
                    nRet = MarcUtil.Xml2Marc(strXml,
                                             true,
                                             strMarcSyntax,
                                             out strOutMarcSyntax,
                                             out strRecord,
                                             out strError);
                    if (nRet == -1)
                    {
                        strError = "XML转换到MARC记录时出错: " + strError;
                        goto ERROR1;
                    }


                    // 获得书目以外的其它XML片断
                    nRet = dp2SearchForm.GetXmlFragment(strXml,
                                                        out strXmlFragment,
                                                        out strError);
                    if (nRet == -1)
                    {
                        goto ERROR1;
                    }
                }
                else
                {
                    strRecord   = strXml;
                    strOutStyle = strStyle;
                }
            }
            finally
            {
                stop.EndLoop();
                stop.OnStop -= new StopEventHandler(this.DoStop);
                stop.Initial("");
            }
            return(0);

ERROR1:
            return(-1);
        }