Exemplo n.º 1
0
        // 获得名称对照表
        // parameters:
        //      keyname_table   keyname --> 当前语言的名称
        public static int GetKeyNameTable(
            OpacApplication app,
            string strFilterFileName,
            List <NodeInfo> nodeinfos,
            string strLang,
            out Hashtable keyname_table,
            out string strError)
        {
            strError = "";
            int nRet = 0;

            keyname_table = new Hashtable();

            FilterHost host = new FilterHost();

            LoanFilterDocument filter = null;

            nRet = app.PrepareMarcFilter(
                host,
                strFilterFileName,
                out filter,
                out strError);
            if (nRet == -1)
            {
                goto ERROR1;
            }

            try
            {
                nRet = BuildKeyNameTable(
                    filter,
                    nodeinfos,
                    strLang,
                    out keyname_table,
                    out strError);
                if (nRet == -1)
                {
                    goto ERROR1;
                }
            }
            catch (Exception ex)
            {
                strError = "GetKeyNameTable() error: " + ExceptionUtil.GetDebugText(ex);
                return(-1);
            }
            finally
            {
                // 归还对象
                app.Filters.SetFilter(strFilterFileName, filter);
            }

            return(0);

ERROR1:
            return(-1);
        }
Exemplo n.º 2
0
        // 将种记录数据从XML格式转换为HTML格式
        public int ConvertBiblioXmlToHtml(
            string strFilterFileName,
            string strBiblioXml,
            string strRecPath,
            out string strBiblio,
            out KeyValueCollection result_params,
            out string strError)
        {
            strBiblio     = "";
            strError      = "";
            result_params = null;

            OpacApplication app = this;

            FilterHost host = new FilterHost();

            host.RecPath      = strRecPath;
            host.App          = this;
            host.ResultParams = new KeyValueCollection();

            // 如果必要,转换为MARC格式,调用filter

            string strOutMarcSyntax = "";
            string strMarc          = "";
            // 将MARCXML格式的xml记录转换为marc机内格式字符串
            // parameters:
            //		bWarning	==true, 警告后继续转换,不严格对待错误; = false, 非常严格对待错误,遇到错误后不继续转换
            //		strMarcSyntax	指示marc语法,如果=="",则自动识别
            //		strOutMarcSyntax	out参数,返回marc,如果strMarcSyntax == "",返回找到marc语法,否则返回与输入参数strMarcSyntax相同的值
            int nRet = MarcUtil.Xml2Marc(strBiblioXml,
                                         true,
                                         "", // this.CurMarcSyntax,
                                         out strOutMarcSyntax,
                                         out strMarc,
                                         out strError);

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

            LoanFilterDocument filter = null;

            nRet = app.PrepareMarcFilter(
                host,
                strFilterFileName,
                out filter,
                out strError);
            if (nRet == -1)
            {
                goto ERROR1;
            }

            try
            {
                nRet = filter.DoRecord(null,
                                       strMarc,
                                       0,
                                       out strError);
                if (nRet == -1)
                {
                    goto ERROR1;
                }

                strBiblio     = host.ResultString;
                result_params = host.ResultParams;
            }
            catch (Exception ex)
            {
                strError = "filter.DoRecord error: " + ExceptionUtil.GetDebugText(ex);
                return(-1);
            }
            finally
            {
                // 归还对象
                filter.FilterHost = null;  // 2016/1/23
                app.Filters.SetFilter(strFilterFileName, filter);
            }

            return(0);

ERROR1:
            return(-1);
        }
Exemplo n.º 3
0
        // TODO: 如何中断长操作?
        // parameters:
        //      strFacetDefXml   分面特性定义XML片断
        //      nMaxRecords     处理的最多记录数。如果 == -1,表示不限制
        public static int DoFilter(
            OpacApplication app,
            LibraryChannel channel,
            string strResultsetName,
            string strFilterFileName,
            int nMaxRecords,
            SetProgress setprogress,
            ref Hashtable result_table,
            out long lOuputHitCount,
            // out string strFacetDefXml,
            out string strError)
        {
            strError       = "";
            lOuputHitCount = 0;
            long lRet = 0;
            int  nRet = 0;

            // strFacetDefXml = "";

            if (result_table == null)
            {
                result_table = new Hashtable();
            }

            FilterHost host = new FilterHost();

            LoanFilterDocument filter = null;

            nRet = app.PrepareMarcFilter(
                host,
                strFilterFileName,
                out filter,
                out strError);
            if (nRet == -1)
            {
                goto ERROR1;
            }

            try
            {
                /*
                 * XmlNode node = filter.Dom.DocumentElement.SelectSingleNode("facetDef");
                 * if (node != null)
                 * {
                 *  strFacetDefXml = node.OuterXml;
                 * }
                 * */

                long lStart = 0;

                // int nCount = 0;
                for (; ;)
                {
                    Record[] records = null;
                    // return:
                    //      -1  出错
                    //      >=0 结果集内记录的总数(注意,并不是本批返回的记录数)
                    lRet = channel.GetSearchResult(
                        null,
                        "#" + strResultsetName,
                        lStart,
                        100,
                        "id,xml",
                        "zh",
                        out records,
                        out strError);
                    if (lRet == -1)
                    {
                        return(-1);
                    }

                    lOuputHitCount = lRet;
                    long lCount = lRet;

                    if (nMaxRecords != -1)
                    {
                        lCount = Math.Min(lCount, nMaxRecords);
                    }

                    if (setprogress != null)
                    {
                        setprogress(lCount, lStart);
                    }

                    foreach (Record record in records)
                    {
                        // 2014/12/21
                        if (string.IsNullOrEmpty(record.RecordBody.Xml) == true)
                        {
                            continue;
                        }

                        // 如果必要,转换为MARC格式,调用filter
                        string strOutMarcSyntax = "";
                        string strMarc          = "";
                        // 将MARCXML格式的xml记录转换为marc机内格式字符串
                        // parameters:
                        //		bWarning	==true, 警告后继续转换,不严格对待错误; = false, 非常严格对待错误,遇到错误后不继续转换
                        //		strMarcSyntax	指示marc语法,如果=="",则自动识别
                        //		strOutMarcSyntax	out参数,返回marc,如果strMarcSyntax == "",返回找到marc语法,否则返回与输入参数strMarcSyntax相同的值
                        nRet = MarcUtil.Xml2Marc(record.RecordBody.Xml,
                                                 true,
                                                 "", // this.CurMarcSyntax,
                                                 out strOutMarcSyntax,
                                                 out strMarc,
                                                 out strError);
                        if (nRet == -1)
                        {
                            strError = "转换书目记录 " + record.Path + " 的 XML 格式到 MARC 时出错: " + strError;
                            goto ERROR1;
                        }

                        host.RecPath      = record.Path;
                        host.App          = app;
                        host.ResultParams = new KeyValueCollection();

                        nRet = filter.DoRecord(null,
                                               strMarc,
                                               strOutMarcSyntax,
                                               0,
                                               out strError);
                        if (nRet == -1)
                        {
                            goto ERROR1;
                        }

                        nRet = AddItems(ref result_table,
                                        host.ResultParams,
                                        record.Path,
                                        out strError);
                        if (nRet == -1)
                        {
                            return(-1);
                        }
                    }

                    if (records.Length <= 0  // < 100
                        )
                    {
                        break;
                    }

                    lStart += records.Length;
                    // nCount += records.Length;

                    if (lStart >= lCount)
                    {
                        if (setprogress != null)
                        {
                            setprogress(lCount, lCount);
                        }

                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                strError = "filter.DoRecord error: " + ExceptionUtil.GetDebugText(ex);
                return(-1);
            }
            finally
            {
                // 归还对象
                filter.FilterHost = null;   // 2016/1/23
                app.Filters.SetFilter(strFilterFileName, filter);
            }

            return(0);

ERROR1:
            return(-1);
        }