コード例 #1
0
        // 针对 dp2library 服务器进行检索
        // parameters:
        //  
        // return:
        //      -1  出错
        //      >=0 命中的记录数
        int SearchLineDp2library(
            string strQueryWord,
            string strFrom,
            AccountInfo account,
            bool bAutoSetFocus,
            out string strError)
        {
            strError = "";
            int nRet = 0;

            string strFromStyle = "";

            if (string.IsNullOrEmpty(strFrom) == true)
                strFrom = "ISBN";

            if (strFrom == "书名" || strFrom == "题名")
                strFromStyle = "title";
            else if (strFrom == "作者" || strFrom == "著者" || strFrom == "责任者")
                strFromStyle = "contributor";
            else if (strFrom == "出版社" || strFrom == "出版者")
                strFromStyle = "publisher";
            else if (strFrom == "出版日期")
                strFromStyle = "publishtime";
            else if (strFrom == "主题词")
                strFromStyle = "subject";

            if (string.IsNullOrEmpty(strFromStyle) == true)
            {
                try
                {
                    strFromStyle = this.MainForm.GetBiblioFromStyle(strFrom);
                }
                catch (Exception ex)
                {
                    strError = ex.Message;
                    goto ERROR1;
                }

                if (String.IsNullOrEmpty(strFromStyle) == true)
                {
                    strError = "GetFromStyle()没有找到 '" + strFrom + "' 对应的 style 字符串";
                    goto ERROR1;
                }
            }

            _channel = _base.GetChannel(account.ServerUrl, account.UserName);
            _channel.Timeout = new TimeSpan(0, 0, 5);   // 超时值为 5 秒
            _channel.Idle += _channel_Idle;
            try
            {
                string strMatchStyle = "left";  // BiblioSearchForm.GetCurrentMatchStyle(this.comboBox_matchStyle.Text);
                if (string.IsNullOrEmpty(strQueryWord) == true)
                {
                    if (strMatchStyle == "null")
                    {
                        strQueryWord = "";

                        // 专门检索空值
                        strMatchStyle = "exact";
                    }
                    else
                    {
                        // 为了在检索词为空的时候,检索出全部的记录
                        strMatchStyle = "left";
                    }
                }
                else
                {
                    if (strMatchStyle == "null")
                    {
                        strError = "检索空值的时候,请保持检索词为空";
                        goto ERROR1;
                    }
                }

                ServerInfo server_info = null;

                //if (line != null)
                //    line.BiblioSummary = "正在获取服务器 " + account.ServerName + " 的配置信息 ...";
                this.ShowMessage("正在获取服务器 " + account.ServerName + " 的配置信息 ...", 
                    "progress", false);

                // 准备服务器信息
                nRet = _base.GetServerInfo(
                    _channel,
                    account,
                    out server_info,
                    out strError);
                if (nRet == -1)
                    goto ERROR1;    // 可以不报错 ?

                this.ShowMessage("正在针对 " + account.ServerName + " \r\n检索 " + strQueryWord + " ...",
                    "progress", false);

                string strQueryXml = "";
                long lRet = _channel.SearchBiblio(Progress,
                    server_info == null ? "<全部>" : server_info.GetBiblioDbNames(),    // "<全部>",
                    strQueryWord,   // this.textBox_queryWord.Text,
                    1000,
                    strFromStyle,
                    strMatchStyle,
                    this.Lang,
                    null,   // strResultSetName
                    "",    // strSearchStyle
                    "", // strOutputStyle
                    out strQueryXml,
                    out strError);
                if (lRet == -1)
                {
                    strError = "针对服务器 '" + account.ServerName + "' 检索出错: " + strError;
                    goto ERROR1;
                }
                if (lRet == 0)
                {
                    strError = "没有命中";
                    return 0;
                }

                // 装入浏览格式
                long lHitCount = lRet;

                long lStart = 0;
                long lCount = lHitCount;
                DigitalPlatform.CirculationClient.localhost.Record[] searchresults = null;

                string strStyle = "id";

                List<string> biblio_recpaths = new List<string>();
                // 装入浏览格式
                for (; ; )
                {
                    if (this.Progress != null && this.Progress.State != 0)
                    {
                        break;
                    }

                    lRet = _channel.GetSearchResult(
                        this.Progress,
                        null,   // strResultSetName
                        lStart,
                        lCount,
                        strStyle, // bOutputKeyCount == true ? "keycount" : "id,cols",
                        this.Lang,
                        out searchresults,
                        out strError);
                    if (lRet == -1)
                    {
                        strError = "检索共命中 " + lHitCount.ToString() + " 条,已装入 " + lStart.ToString() + " 条," + strError;
                        goto ERROR1;
                    }

                    if (lRet == 0)
                        break;

                    // 处理浏览结果

                    foreach (DigitalPlatform.CirculationClient.localhost.Record searchresult in searchresults)
                    {
                        biblio_recpaths.Add(searchresult.Path);
                    }

                    {
                        // 获得书目记录
                        BiblioLoader loader = new BiblioLoader();
                        loader.Channel = _channel;
                        loader.Stop = this.Progress;
                        loader.Format = "xml";
                        loader.GetBiblioInfoStyle = GetBiblioInfoStyle.Timestamp;
                        loader.RecPaths = biblio_recpaths;

                        try
                        {
                            int i = 0;
                            foreach (BiblioItem item in loader)
                            {
                                if (string.IsNullOrEmpty(item.ErrorInfo) == false)
                                {
                                    AddBiblioBrowseLine(
                                        TYPE_ERROR,
                                        item.RecPath,
                                        item.ErrorInfo,
                                        null,
                                        false);
                                    i++;
                                    continue;
                                }

                                string strXml = item.Content;

                                string strMarcSyntax = "";
                                string strBrowseText = "";
                                string strColumnTitles = "";
#if NO
                                string strMARC = "";
                                // 将XML格式转换为MARC格式
                                // 自动从数据记录中获得MARC语法
                                nRet = MarcUtil.Xml2Marc(strXml,    // info.OldXml,
                                    true,
                                    null,
                                    out strMarcSyntax,
                                    out strMARC,
                                    out strError);
                                if (nRet == -1)
                                {
                                    strError = "XML转换到MARC记录时出错: " + strError;
                                    goto ERROR1;
                                }

                                nRet = BuildMarcBrowseText(
                                    strMarcSyntax,
                                    strMARC,
                                    out strBrowseText,
                                    out strError);
                                if (nRet == -1)
                                {
                                    strError = "MARC记录转换到浏览格式时出错: " + strError;
                                    goto ERROR1;
                                }
#endif
                                nRet = BuildBrowseText(strXml,
            out strBrowseText,
            out strMarcSyntax,
            out strColumnTitles,
            out strError);
                                if (nRet == -1)
                                    goto ERROR1;

                                int image_index = -1;
                                if (account.IsLocalServer == false)
                                    image_index = TYPE_CLOUD;

                                RegisterBiblioInfo info = new RegisterBiblioInfo();
                                info.OldXml = strXml;   // strMARC;
                                info.Timestamp = item.Timestamp;
                                info.RecPath = item.RecPath + "@" + account.ServerName;
                                info.MarcSyntax = strMarcSyntax;
                                AddBiblioBrowseLine(
                                    image_index,    // -1,
                                    info.RecPath,
                                    strBrowseText,
                                    info,
                                    bAutoSetFocus);
                                i++;
                            }
                        }
                        catch (Exception ex)
                        {
                            strError = ex.Message;
                            goto ERROR1;
                        }

                        // lIndex += biblio_recpaths.Count;
                        biblio_recpaths.Clear();
                    }

                    lStart += searchresults.Length;
                    lCount -= searchresults.Length;

                    if (lStart >= lHitCount || lCount <= 0)
                        break;
                }

                return (int)lHitCount;
            }
            finally
            {
                _channel.Idle -= _channel_Idle;
                _base.ReturnChannel(_channel);
                _channel = null;
                this.ClearMessage();
            }

        ERROR1:
            AddBiblioBrowseLine(strError, TYPE_ERROR, bAutoSetFocus);
            return -1;
        }
コード例 #2
0
ファイル: ReportForm.cs プロジェクト: paopaofeng/dp2
        // 复制书目记录
        int BuildBiblioRecords(
            string strBiblioDbNameParam,
            long lOldCount,
            ref long lProgress,
            ref long lIndex,
            out string strError)
        {
            strError = "";
            int nRet = 0;
            lProgress += lIndex;

            using (SQLiteConnection connection = new SQLiteConnection(this._connectionString))
            {
                connection.Open();

                string strQueryXml = "";

                long lRet = this.Channel.SearchBiblio(stop,
                    strBiblioDbNameParam,
                    "", // (lIndex + 1).ToString() + "-", // 
                    -1,
                    "recid",     // "__id",
                    "left", // this.textBox_queryWord.Text == "" ? "left" : "exact",    // 原来为left 2007/10/18 changed
                    "zh",
                    null,   // strResultSetName
                    "",    // strSearchStyle
                    "", //strOutputStyle, // (bOutputKeyCount == true ? "keycount" : ""),
                    out strQueryXml,
                    out strError);
                if (lRet == -1)
                    return -1;
                if (lRet == 0)
                    return 0;

                long lHitCount = lRet;

                AdjustProgressRange(lOldCount, lHitCount);

                long lStart = lIndex;
                long lCount = lHitCount - lIndex;
                DigitalPlatform.CirculationClient.localhost.Record[] searchresults = null;

                // string strStyle = "id,cols,format:@coldef:*/barcode|*/department|*/readerType|*/name";
                string strStyle = "id";

                // 读者库名 --> 图书馆代码
                // Hashtable librarycode_table = new Hashtable();

                List<BiblioLine> lines = new List<BiblioLine>();
                List<string> biblio_recpaths = new List<string>();
                // 装入浏览格式
                for (; ; )
                {
                    Application.DoEvents();	// 出让界面控制权

                    if (stop != null && stop.State != 0)
                    {
                        strError = "检索共命中 " + lHitCount.ToString() + " 条,已装入 " + lStart.ToString() + " 条,用户中断...";
                        return -1;
                    }

                    lRet = this.Channel.GetSearchResult(
                        stop,
                        null,   // strResultSetName
                        lStart,
                        lCount,
                        strStyle, // bOutputKeyCount == true ? "keycount" : "id,cols",
                        "zh",
                        out searchresults,
                        out strError);
                    if (lRet == -1)
                    {
                        strError = "检索共命中 " + lHitCount.ToString() + " 条,已装入 " + lStart.ToString() + " 条," + strError;
                        return -1;
                    }

                    if (lRet == 0)
                    {
                        return 0;
                    }

                    // 处理浏览结果

                    foreach (DigitalPlatform.CirculationClient.localhost.Record searchresult in searchresults)
                    {
                        // DigitalPlatform.CirculationClient.localhost.Record searchresult = searchresults[i];

                        BiblioLine line = new BiblioLine();
                        line.BiblioRecPath = searchresult.Path;
                        lines.Add(line);

                        biblio_recpaths.Add(searchresult.Path);
                    }

#if NO
                    if (lines.Count >= INSERT_BATCH
                        || ((lStart + searchresults.Length >= lHitCount || lCount - searchresults.Length <= 0) && lines.Count > 0)
                        )
#endif
                    {
                        Debug.Assert(biblio_recpaths.Count == lines.Count, "");

                        // 获得书目摘要
                        BiblioLoader loader = new BiblioLoader();
                        loader.Channel = this.Channel;
                        loader.Stop = this.Progress;
                        loader.Format = "summary";
                        loader.GetBiblioInfoStyle = GetBiblioInfoStyle.None;
                        loader.RecPaths = biblio_recpaths;

                        try
                        {
                            int i = 0;
                            foreach (BiblioItem item in loader)
                            {
                                // this.Progress.SetMessage("正在加入 " + (i + 1).ToString() + "/" + targetLeft.Count.ToString() + " 个书目摘要,可能需要较长时间 ...");

                                BiblioLine line = lines[i];
                                if (string.IsNullOrEmpty(item.Content) == false)
                                {
                                    if (item.Content.Length > 4000)
                                        line.Summary = item.Content.Substring(0, 4000);
                                    else
                                        line.Summary = item.Content;
                                }

                                i++;
                            }
                        }
                        catch (Exception ex)
                        {
                            strError = ex.Message;
                            return -1;
                        }
                        biblio_recpaths.Clear();

                        // 插入一批书目记录
                        nRet = BiblioLine.AppendBiblioLines(
                            connection,
                            lines,
                            true,   // 用 false 可以在测试阶段帮助发现重叠插入问题
                            out strError);
                        if (nRet == -1)
                            return -1;

                        lIndex += lines.Count;
                        lines.Clear();
                    }

                    lStart += searchresults.Length;
                    lCount -= searchresults.Length;

                    // lIndex += searchresults.Length;
                    lProgress += searchresults.Length;
                    // stop.SetProgressValue(lProgress);
                    SetProgress(lProgress);

                    stop.SetMessage(strBiblioDbNameParam + " " + lStart.ToString() + "/" + lHitCount.ToString() + " "
                        + GetProgressTimeString(lProgress));

                    if (lStart >= lHitCount || lCount <= 0)
                        break;
                }

                if (lines.Count > 0)
                {
                    Debug.Assert(false, "");
                } 
                
                return 0;
            }
        }
コード例 #3
0
        // 针对 dp2library 服务器进行检索
        // parameters:
        //  
        // return:
        //      -1  出错
        //      >=0 命中的记录数
        int SearchLineDp2library(RegisterLine line,
            AccountInfo account,
            out string strError)
        {
            strError = "";
            int nRet = 0;

            // ??? _currentAccount = account;

            _channel = _base.GetChannel(account.ServerUrl, account.UserName);
            _channel.Timeout = new TimeSpan(0, 0, 5);   // 超时值为 5 秒
            try
            {
                string strQueryWord = line.BiblioBarcode;

                string strFromStyle = "";

                try
                {
                    strFromStyle = this.MainForm.GetBiblioFromStyle("ISBN");
                }
                catch (Exception ex)
                {
                    strError = ex.Message;
                    goto ERROR1;
                }

                if (String.IsNullOrEmpty(strFromStyle) == true)
                {
                    strError = "GetFromStyle()没有找到 '" + "ISBN" + "' 对应的style字符串";
                    goto ERROR1;
                }

                string strMatchStyle = "left";  // BiblioSearchForm.GetCurrentMatchStyle(this.comboBox_matchStyle.Text);
                if (string.IsNullOrEmpty(strQueryWord) == true)
                {
                    if (strMatchStyle == "null")
                    {
                        strQueryWord = "";

                        // 专门检索空值
                        strMatchStyle = "exact";
                    }
                    else
                    {
                        // 为了在检索词为空的时候,检索出全部的记录
                        strMatchStyle = "left";
                    }
                }
                else
                {
                    if (strMatchStyle == "null")
                    {
                        strError = "检索空值的时候,请保持检索词为空";
                        goto ERROR1;
                    }
                }

                ServerInfo server_info = null;

                if (line != null)
                    line.BiblioSummary = "正在获取服务器 " + account.ServerName + " 的配置信息 ...";

                // 准备服务器信息
                nRet = _base.GetServerInfo(
                    // line,
                    _channel,
                    account,
                    out server_info,
                    out strError);
                if (nRet == -1)
                    goto ERROR1;    // 可以不报错 ?

                line.BiblioSummary = "正在针对 "+account.ServerName+ " \r\n检索 " + line.BiblioBarcode + " ...";

                string strQueryXml = "";
                long lRet = _channel.SearchBiblio(Progress,
                    server_info == null ? "<全部>" : server_info.GetBiblioDbNames(),    // "<全部>",
                    strQueryWord,   // this.textBox_queryWord.Text,
                    1000,
                    strFromStyle,
                    strMatchStyle,
                    _base.Lang,
                    null,   // strResultSetName
                    "",    // strSearchStyle
                    "", // strOutputStyle
                    out strQueryXml,
                    out strError);
                if (lRet == -1)
                {
                    strError = "针对服务器 '"+account.ServerName+"' 检索出错: " + strError;
                    goto ERROR1;
                }

                // 装入浏览格式
                long lHitCount = lRet;

                long lStart = 0;
                long lCount = lHitCount;
                DigitalPlatform.CirculationClient.localhost.Record[] searchresults = null;

                string strStyle = "id";

                List<string> biblio_recpaths = new List<string>();
                // 装入浏览格式
                for (; ; )
                {
                    if (this.Progress != null && this.Progress.State != 0)
                    {
                        break;
                    }
                    // DoTasks();

                    lRet = _channel.GetSearchResult(
                        this.Progress,
                        null,   // strResultSetName
                        lStart,
                        lCount,
                        strStyle, // bOutputKeyCount == true ? "keycount" : "id,cols",
                        _base.Lang,
                        out searchresults,
                        out strError);
                    if (lRet == -1)
                    {
                        strError = "检索共命中 " + lHitCount.ToString() + " 条,已装入 " + lStart.ToString() + " 条," + strError;
                        goto ERROR1;
                    }

                    if (lRet == 0)
                        break;

                    // 处理浏览结果

                    foreach (DigitalPlatform.CirculationClient.localhost.Record searchresult in searchresults)
                    {
                        biblio_recpaths.Add(searchresult.Path);
                    }

                    {
                        // 获得书目摘要
                        BiblioLoader loader = new BiblioLoader();
                        loader.Channel = _channel;
                        loader.Stop = this.Progress;
                        loader.Format = "xml";
                        loader.GetBiblioInfoStyle = GetBiblioInfoStyle.Timestamp;
                        loader.RecPaths = biblio_recpaths;

                        try
                        {
                            int i = 0;
                            foreach (BiblioItem item in loader)
                            {
                                string strXml = item.Content;

                                string strMARC = "";
                                string strMarcSyntax = "";
                                // 将XML格式转换为MARC格式
                                // 自动从数据记录中获得MARC语法
                                nRet = MarcUtil.Xml2Marc(strXml,    // info.OldXml,
                                    true,
                                    null,
                                    out strMarcSyntax,
                                    out strMARC,
                                    out strError);
                                if (nRet == -1)
                                {
                                    strError = "XML转换到MARC记录时出错: " + strError;
                                    goto ERROR1;
                                }

                                string strBrowseText = "";
                                nRet = BuildMarcBrowseText(
                                    strMarcSyntax,
                                    strMARC,
                                    out strBrowseText,
                                    out strError);
                                if (nRet == -1)
                                {
                                    strError = "MARC记录转换到浏览格式时出错: " + strError;
                                    goto ERROR1;
                                }

                                RegisterBiblioInfo info = new RegisterBiblioInfo();
                                info.OldXml = strMARC;
                                info.Timestamp = item.Timestamp;
                                info.RecPath = item.RecPath + "@" + account.ServerName;
                                info.MarcSyntax = strMarcSyntax;
                                line.AddBiblioBrowseLine(
                                    -1,
                                    info.RecPath,
                                    strBrowseText,
                                    info);
                                i++;
                            }
                        }
                        catch (Exception ex)
                        {
                            strError = ex.Message;
                            goto ERROR1;
                        }


                        // lIndex += biblio_recpaths.Count;
                        biblio_recpaths.Clear();
                    }

                    lStart += searchresults.Length;
                    lCount -= searchresults.Length;

                    if (lStart >= lHitCount || lCount <= 0)
                        break;
                }


                return (int)lHitCount;

            }
            finally
            {
                _base.ReturnChannel(_channel);
                _channel = null;
            }

        ERROR1:
#if NO
            line.SetDisplayMode("summary");
            line.SetBiblioSearchState("error");
            line.BiblioSummary = strError;
#endif
            line.AddBiblioBrowseLine(strError, BiblioRegisterControl.TYPE_ERROR);

            return -1;
        }
コード例 #4
0
ファイル: BiblioSearchForm.cs プロジェクト: paopaofeng/dp2
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="channel">通讯通道</param>
        /// <param name="stop">停止对象</param>
        /// <param name="items">ListViewItem 集合</param>
        /// <param name="cacheTable">用于缓存的 Hashtable 对象</param>
        public ListViewBiblioLoader(LibraryChannel channel,
            Stop stop,
            List<ListViewItem> items,
            Hashtable cacheTable)
        {
            m_loader = new BiblioLoader();
            m_loader.Channel = channel;
            m_loader.Stop = stop;
            m_loader.Format = "xml";
            m_loader.GetBiblioInfoStyle = GetBiblioInfoStyle.Timestamp; // 附加信息只取得 timestamp
            m_loader.Prompt += new MessagePromptEventHandler(m_loader_Prompt);

            this.Items = items;
            this.CacheTable = cacheTable;
        }