Exemplo n.º 1
0
        // return:
        //      -1  出错
        //      >=0 命中的记录数
        int SearchLineAmazon(RegisterLine line,
            AccountInfo account,
            out string strError)
        {
            strError = "";

            // ??? this._currentAccount = account;

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

            AmazonSearch search = new AmazonSearch();
            // search.MainForm = this.MainForm;
            search.TempFileDir = this.MainForm.UserTempDir;

            // 多行检索中的一行检索
            int nRedoCount = 0;
        REDO:
            int nRet = search.Search(
                account.ServerUrl,
                line.BiblioBarcode.Replace("-", ""),
                "ISBN",
                "[default]",
                true,
                out strError);
            if (nRet == -1)
            {
                if (search.Exception != null && search.Exception is WebException)
                {
                    WebException e = search.Exception as WebException;
                    if (e.Status == WebExceptionStatus.ProtocolError)
                    {
                        // 重做
                        if (nRedoCount < 2)
                        {
                            nRedoCount++;
                            Thread.Sleep(1000);
                            goto REDO;
                        }

#if NO
                        // 询问是否重做
                        DialogResult result = MessageBox.Show(this,
"检索 '" + strLine + "' 时发生错误:\r\n\r\n" + strError + "\r\n\r\n是否重试?\r\n\r\n(Yes: 重试; No: 跳过这一行继续检索后面的行; Cancel: 中断整个检索操作",
"AmazonSearchForm",
MessageBoxButtons.YesNoCancel,
MessageBoxIcon.Question,
MessageBoxDefaultButton.Button1);
                        if (result == System.Windows.Forms.DialogResult.Retry)
                        {
                            Thread.Sleep(1000);
                            goto REDO;
                        }
                        if (result == System.Windows.Forms.DialogResult.Cancel)
                            return -1;
                        goto CONTINUE;
#endif
                        goto ERROR1;
                    }
                }
                goto ERROR1;
            }


            nRet = search.LoadBrowseLines(appendBrowseLine,
                line,
                false,
                out strError);
            if (nRet == -1)
                goto ERROR1;
            return nRet;

            ERROR1:
            strError = "针对服务器 '" + account.ServerName + "' 检索出错: " + strError;
            line.AddBiblioBrowseLine(strError, BiblioRegisterControl.TYPE_ERROR);
            return -1;
        }
Exemplo n.º 2
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;
        }
Exemplo n.º 3
0
        void SearchLine(RegisterLine line)
        {
            string strError = "";
            int nRet = 0;

            if (this.ServersDom == null)
            {
                strError = "ServersDom 为空";
                goto ERROR1;
            }

            string strTotalError = "";

            this.Progress.OnStop += new StopEventHandler(this.DoStop);
            // this.Progress.Initial("进行一轮任务处理...");
            this.Progress.BeginLoop();
            try
            {
                int nHitCount = 0;

                line.SetBiblioSearchState("searching");
                line.BiblioSummary = "正在检索 " + line.BiblioBarcode + " ...";

                XmlNodeList servers = this.ServersDom.DocumentElement.SelectNodes("server");
                foreach (XmlElement server in servers)
                {
                    AccountInfo account = EntityRegisterBase.GetAccountInfo(server);
                    Debug.Assert(account != null, "");
                    _base.CurrentAccount = account;
#if NO
                string strName = server.GetAttribute("name");
                string strType = server.GetAttribute("type");
                string strUrl = server.GetAttribute("url");
                string strUserName = server.GetAttribute("userName");
                string strPassword = server.GetAttribute("password");
                // e.Password = this.MainForm.DecryptPasssword(e.Password);
                string strIsReader = server.GetAttribute("isReader");
#endif

                    if (account.ServerType == "dp2library")
                    {
                        nRet = SearchLineDp2library(line,
                            account,
                            out strError);
                        if (nRet == -1)
                            strTotalError += strError + "\r\n";
                        else
                            nHitCount += nRet;
                    }
                    else if (account.ServerType == "amazon")
                    {
                        nRet = SearchLineAmazon(line,
                            account,
                            out strError);
                        if (nRet == -1)
                            strTotalError += strError + "\r\n";
                        else
                            nHitCount += nRet;
                    }
                }

                line.SetBiblioSearchState(nHitCount.ToString());

                // 
                if (nHitCount == 1)
                {
                    // TODO: 如果有报错的行,是否就不要自动模拟双击了? 假如这种情况是因为红泥巴服务器持续无法访问引起的,需要有配置办法可以临时禁用这个数据源

                    // 模拟双击
                    int index = line._biblioRegister.GetFirstRecordIndex();
                    if (index == -1)
                    {
                        strError = "获得第一个浏览记录 index 时出错";
                        goto ERROR1;
                    }
                    nRet = line._biblioRegister.SelectBiblio(index,
                        out strError);
                    if (nRet == -1)
                        goto ERROR1;
                }
                else
                {
                    if (nHitCount > 1)
                        line.SetDisplayMode("select");
                    else
                    {
                        // 进入详细状态,可以新创建一条记录
                        line.AddBiblioBrowseLine(BiblioRegisterControl.TYPE_INFO,
                            "没有命中书目记录。双击本行新创建书目记录",
                            "",
                            BuildBlankBiblioInfo(line.BiblioBarcode)); 
                        line.SetDisplayMode("select");
                    }
                }
            }
            finally
            {
                this.Progress.EndLoop();
                this.Progress.OnStop -= new StopEventHandler(this.DoStop);
                // this.Progress.Initial("");
            }

            if (string.IsNullOrEmpty(strTotalError) == false)
            {
                // DisplayFloatErrorText(strTotalError);

                line._biblioRegister.BarColor = "R";   // 红色,需引起注意
                this.SetColorList();
            }
            else
            {
                line._biblioRegister.BarColor = "Y";   // 黄色表示等待选择?
                this.SetColorList();
            }
            return;
        ERROR1:
            line.SetDisplayMode("summary");
            line.SetBiblioSearchState("error");
            line.BiblioSummary = strError;
            DisplayFloatErrorText(strError);

            line._biblioRegister.BarColor = "R";   // 红色,需引起注意
            this.SetColorList();
        }