Ejemplo n.º 1
0
        /// <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;
        }
Ejemplo n.º 2
0
        public ListViewBiblioLoader(LibraryChannelCollection channels,
            dp2ServerCollection servers,
            Stop stop,
            List<ListViewItem> items,
            Hashtable cacheTable)
        {
            m_loader = new BiblioLoader();
            m_loader.Channels = channels;
            m_loader.Servers = servers;
            m_loader.Stop = stop;
            m_loader.Format = "xml";
            m_loader.GetBiblioInfoStyle = GetBiblioInfoStyle.Timestamp; // 附加信息只取得 timestamp

            this.Items = items;
            this.CacheTable = cacheTable;
        }
Ejemplo n.º 3
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 = "EntityRegisterWizard GetBiblioFromStyle() {D6B49099-CB3F-4B76-84EC-7548981B2E47} exception: " + ex.Message;
                    goto ERROR1;
                }

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

            LibraryChannel current_channel = _base.GetChannel(account.ServerUrl, account.UserName);
            current_channel.Timeout = new TimeSpan(0, 0, 15);   // 超时值为 15 秒
            // current_channel.Idle += _channel_Idle;
            lock (this._channels)
            {
                this._channels.Add(current_channel);
            }

            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(
                    current_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 = current_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.LibraryClient.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 = current_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.LibraryClient.localhost.Record searchresult in searchresults)
                    {
                        biblio_recpaths.Add(searchresult.Path);
                    }

                    {
                        // 获得书目记录
                        BiblioLoader loader = new BiblioLoader();
                        loader.Channel = current_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 = "EntityRegisterWizard {414094F8-91E3-4C94-9AD6-71804FD93B67} exception: " + ExceptionUtil.GetAutoText(ex);
                            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
            {
                lock (this._channels)
                {
                    this._channels.Remove(current_channel);
                }

                // current_channel.Idle -= _channel_Idle;
                _base.ReturnChannel(current_channel);
                current_channel = null;
                this.ClearMessage();
            }

        ERROR1:
            AddBiblioBrowseLine(strError, TYPE_ERROR, bAutoSetFocus);
            return -1;
        }
Ejemplo n.º 4
0
        // 复制书目记录
        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 = "";

                // 2015/11/25
                this.Channel.Timeout = new TimeSpan(0, 5, 0);
                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.LibraryClient.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 (; ; )
                {
                    if (this.InvokeRequired == false)
                        Application.DoEvents();	// 出让界面控制权

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

                    // 2015/11/25
                    this.Channel.Timeout = new TimeSpan(0, 0, 30);
                    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.LibraryClient.localhost.Record searchresult in searchresults)
                    {
                        // DigitalPlatform.LibraryClient.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, "");

                        // 2015/11/25
                        this.Channel.Timeout = new TimeSpan(0, 0, 30);

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

                        loader.Prompt -= new MessagePromptEventHandler(loader_Prompt);
                        loader.Prompt += new MessagePromptEventHandler(loader_Prompt);

                        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 = "ReportForm {72A00ADB-1F9F-45FA-A31E-6956569045D9} exception: " + ExceptionUtil.GetAutoText(ex);
                            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;
            }
        }