Esempio n. 1
0
        // return:
        //      -1  出错
        //      >=0 命中的记录数
        int SearchLineAmazon(
            string strQueryWord,
            string strFrom,
            AccountInfo account,
            bool bAutoSetFocus,
            out string strError)
        {
            strError = "";

            if (strFrom == "书名" || strFrom == "题名")
                strFrom = "title";
            else if (strFrom == "作者" || strFrom == "著者" || strFrom == "责任者")
                strFrom = "author";
            else if (strFrom == "出版社" || strFrom == "出版者")
                strFrom = "publisher";
            else if (strFrom == "出版日期")
                strFrom = "pubdate";
            else if (strFrom == "主题词")
                strFrom = "subject";
            else if (strFrom == "关键词")
                strFrom = "keywords";
            else if (strFrom == "语言")
                strFrom = "language";
            else if (strFrom == "装订")
                strFrom = "binding";

/* 还可以使用:
            "ISBN",
            "EISBN",
            "ASIN"
*/

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

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

            search.Timeout = 5 * 1000;
            search.Idle += search_Idle;
            try
            {

                // 多行检索中的一行检索
                int nRedoCount = 0;
            REDO:
                int nRet = search.Search(
                    account.ServerUrl,
                    strQueryWord.Replace("-", ""),
                    strFrom,    // "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,
                    null,   // line,
                    bAutoSetFocus,
                    out strError);
                if (nRet == -1)
                    goto ERROR1;
                return nRet;
            }
            finally
            {
                search.Idle -= search_Idle;
                this.ClearMessage();
            }

        ERROR1:
            strError = "针对服务器 '" + account.ServerName + "' 检索出错: " + strError;
            AddBiblioBrowseLine(strError, TYPE_ERROR, bAutoSetFocus);
            return -1;
        }
Esempio n. 2
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;
        }