Beispiel #1
0
        // 获得图像 URL
        //
        // parameters:
        // return:
        //      name(string) --> ImageInfo 对照表
        //                  name = "SmallImage",  "MediumImage", "LargeImage"};
        public Hashtable GetImageUrls(string strXml)
        {
            Hashtable table    = null;
            string    strError = "";

            XmlDocument dom = new XmlDocument();

            dom.LoadXml(strXml);

            XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable());

            nsmgr.AddNamespace("amazon", AmazonSearch.NAMESPACE);

            int nRet = AmazonSearch.GetImageUrl(dom.DocumentElement,
                                                nsmgr,
                                                out table,
                                                out strError);

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

            return(table);

ERROR1:
            throw new Exception(strError);
        }
Beispiel #2
0
        public SearchArtistsController()
        {
            IKernel kernal           = new StandardKernel(new BindModule());
            var     amazonSearchRepo = kernal.Get <IAmazonSearchRepository>();

            _amazonSearch = new AmazonSearch(amazonSearchRepo);
        }
        public FeedController()
        {
            IKernel kernal           = new StandardKernel(new BindModule());
            var     listOfBandsRepo  = kernal.Get <IListofBandsRepo>();
            var     amazonSearchRepo = kernal.Get <IAmazonSearchRepository>();

            _service      = new ListOfBandsService(listOfBandsRepo);
            _amazonSearch = new AmazonSearch(amazonSearchRepo);
        }
Beispiel #4
0
        // 针对亚马逊服务器检索,装入一个浏览行的回调函数
        int appendBrowseLine(string strRecPath,
                             string strRecord,
                             object param,
                             bool bAutoSetFocus,
                             out string strError)
        {
            strError = "";

            XmlDocument dom = new XmlDocument();

            dom.LoadXml(strRecord);

            XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable());

            nsmgr.AddNamespace("amazon", AmazonSearch.NAMESPACE);

            List <string> cols             = null;
            string        strASIN          = "";
            string        strCoverImageUrl = "";
            int           nRet             = AmazonSearch.ParseItemXml(dom.DocumentElement,
                                                                       nsmgr,
                                                                       out strASIN,
                                                                       out strCoverImageUrl,
                                                                       out cols,
                                                                       out strError);

            if (nRet == -1)
            {
                return(-1);
            }

#if NO
            string strMARC = "";
            // 将亚马逊 XML 格式转换为 UNIMARC 格式
            nRet = AmazonSearch.AmazonXmlToUNIMARC(dom.DocumentElement,
                                                   out strMARC,
                                                   out strError);
            if (nRet == -1)
            {
                return(-1);
            }
#endif

            AmazonBiblioInfo info = new AmazonBiblioInfo();
            info.Xml        = dom.DocumentElement.OuterXml;
            info.Timestamp  = null;
            info.ASIN       = strASIN + "@" + this.ServerUrl;
            info.MarcSyntax = "amazon"; // 表示 XML 尚未转换
            info.ImageUrl   = strCoverImageUrl;
            this.AddBiblioBrowseLine(
                info.ASIN,
                StringUtil.MakePathList(cols, "\t"),
                info);

            return(0);
        }
Beispiel #5
0
        public HomeController()
        {
            IKernel kernal           = new StandardKernel(new BindModule());
            var     amazonSearchRepo = kernal.Get <IAmazonSearchRepository>();
            var     amazonItemRepo   = kernal.Get <IAmazonItemRepository>();
            var     itunesItemRepo   = kernal.Get <IItunesItemRepository>();

            _releaseSearch = new ReleaseSearch(amazonItemRepo, itunesItemRepo);
            _amazonSearch  = new AmazonSearch(amazonSearchRepo);
        }
        public void AmazonSearchFindsNothing()
        {
            IKernel kernal           = new StandardKernel(new BindModule());
            var     amazonSearchRepo = kernal.Get <IAmazonSearchRepository>();

            AmazonSearch amazonSearch = new AmazonSearch(amazonSearchRepo);
            var          results      = amazonSearch.SearchFromCommaSeparatedList("asdasdasd");

            Assert.IsTrue(results.Count == 0);
        }
        public void AmazonSearchIsNotNull()
        {
            IKernel kernal           = new StandardKernel(new BindModule());
            var     amazonSearchRepo = kernal.Get <IAmazonSearchRepository>();

            AmazonSearch amazonSearch = new AmazonSearch(amazonSearchRepo);
            var          results      = amazonSearch.SearchFromCommaSeparatedList("ride,the cure");

            Assert.IsNotNull(results);
        }
        static void Main(string[] args)
        {
            IKernel kernal           = new StandardKernel(new BindModule());
            var     amazonSearchRepo = kernal.Get <IAmazonSearchRepository>();
            var     amazonItemRepo   = kernal.Get <IAmazonItemRepository>();

            Console.WriteLine("1. Search from comma searated list.");
            Console.WriteLine("2. Search from ASIN.");
            Console.WriteLine("Please select.");
            string answer = Console.ReadLine();

            if (answer == "1")
            {
                Console.WriteLine("Type a list of bands separated by commas");
                string list         = Console.ReadLine();
                var    amazonSearch = new AmazonSearch(amazonSearchRepo);

                IList <ExtendedItem> returnObj = null;

                try
                {
                    returnObj = amazonSearch.SearchFromCommaSeparatedList(list);
                }
                catch (WebException ex)
                {
                    Console.WriteLine(ex.Message);
                }

                Console.WriteLine("Found " + returnObj.Count.ToString() + " items");

                foreach (var item in returnObj)
                {
                    Console.WriteLine(item.Artist + " - " + item.Title + " " + item.ReleaseDate.ToLongDateString());
                }

                Console.ReadLine();
            }
            else if (answer == "2")
            {
                var amazonItemRetrieve = new AmazonItemSearch(amazonItemRepo);
                Console.WriteLine("Please enter ASIN.");
                string asin        = Console.ReadLine();
                var    returnedObj = amazonItemRetrieve.GetByASIN(asin);

                Console.WriteLine(returnedObj.Artist + " - " + returnedObj.Title);
                Console.ReadLine();
            }

            string[] arg1 = { "" };
            Main(arg1);
        }
Beispiel #9
0
        //static Configuration Configuration { get; set; }

        static void Main(string[] args)
        {
            var builder       = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("passes.json");
            var Configuration = builder.Build();

            var AmazonAccessId     = Configuration["AmazonAccessId"];
            var AmazonEndPoint     = Configuration["AmazonEndPoint"];
            var AmazonAssociateTag = Configuration["AmazonAssociateTag"];
            var AmazonSecretKey    = Configuration["AmazonSecretKey"];
            var ItunesAffiliateId  = Configuration["ItunesAffiliateId"];
            var ItunesRequestUrl   = Configuration["ItunesRequestUrl"];

            var amazonSearchRepo = new AmazonSearchRepository(AmazonAccessId, AmazonEndPoint, AmazonAssociateTag, AmazonSecretKey);
            var amazonItemRepo   = new AmazonItemRepository(AmazonAccessId, AmazonEndPoint, AmazonAssociateTag, AmazonSecretKey);

            System.Console.WriteLine("1. Search from comma searated list.");
            Console.WriteLine("2. Search from ASIN.");
            Console.WriteLine("Please select.");
            string answer = Console.ReadLine();

            if (answer == "1")
            {
                Console.WriteLine("Type a list of bands separated by commas");
                string list         = Console.ReadLine();
                var    amazonSearch = new AmazonSearch(amazonSearchRepo);

                IList <ExtendedItem> returnObj = null;

                try
                {
                    returnObj = amazonSearch.SearchFromCommaSeparatedList(list);
                }
                catch (WebException ex)
                {
                    Console.WriteLine(ex.Message);
                }

                Console.WriteLine("Found " + returnObj.Count.ToString() + " items");

                foreach (var item in returnObj)
                {
                    Console.WriteLine(item.Artist + " - " + item.Title + " " + item.ReleaseDate.ToLongDateString());
                }

                Console.ReadLine();
            }
            else if (answer == "2")
            {
                var amazonItemRetrieve = new AmazonItemSearch(amazonItemRepo);
                Console.WriteLine("Please enter ASIN.");
                string asin        = Console.ReadLine();
                var    returnedObj = amazonItemRetrieve.GetByASIN(asin);

                Console.WriteLine(returnedObj.Artist + " - " + returnedObj.Title);
                Console.ReadLine();
            }

            string[] arg1 = { "" };

            Main(arg1);
        }
    // 加入封面图像 URL
    void AddCoverImageUrl()
    {
        string strError = "";
        string strISBN  = "";
        int    nRet     = 0;

        MainForm main_form = this.DetailForm.MainForm;

        strISBN = this.DetailForm.MarcEditor.Record.Fields.GetFirstSubfield("010", "a");

        if (strISBN.Trim() == "")
        {
            strError = "记录中不存在 010$a 子字段, 因此无法加入封面图片 URL";
            goto ERROR1;
        }

        nRet = main_form.LoadIsbnSplitter(true, out strError);
        if (nRet == -1)
        {
            goto ERROR1;
        }

        AmazonSearchForm dlg = new AmazonSearchForm();

        string strOutputISBN = "";

        Debug.Assert(main_form != null, "1");
        Debug.Assert(main_form.IsbnSplitter != null, "2");

        nRet = main_form.IsbnSplitter.IsbnInsertHyphen(strISBN, "force10", out strOutputISBN, out strError);
        if (nRet != -1)
        {
            string strHead  = "";
            string strOther = "";

            StringUtil.ParseTwoPart(strOutputISBN, "-", out strHead, out strOther);

            if (strHead == "7")
            {
                dlg.ServerUrl = "webservices.amazon.cn";  // 中国
            }
            else
            {
                dlg.ServerUrl = "webservices.amazon.com";  // 美国
            }
        }
        else
        {
            dlg.ServerUrl = "webservices.amazon.cn";  // 中国
        }
        MainForm.SetControlFont(dlg, this.DetailForm.Font, false);
        dlg.TempFileDir = main_form.DataDir;
        dlg.AutoSearch  = true;

        dlg.UiState = main_form.AppInfo.GetString(
            "TestForm",
            "AmazonSearchForm_uiState",
            "");
        dlg.QueryWord = strISBN;
        dlg.From      = "ISBN";

        main_form.AppInfo.LinkFormState(dlg, "TestForm_AmazonSearchForm_state");

        dlg.ShowDialog(this.DetailForm);

        main_form.AppInfo.UnlinkFormState(dlg);
        main_form.AppInfo.SetString(
            "TestForm",
            "AmazonSearchForm_uiState",
            dlg.UiState);
        if (dlg.DialogResult == DialogResult.Cancel)
        {
            return;
        }

        Hashtable table = dlg.GetImageUrls(dlg.SelectedItem.Xml);

        foreach (string name in table.Keys)
        {
            AmazonSearch.ImageInfo info = table[name] as AmazonSearch.ImageInfo;

            Field field_856 = this.DetailForm.MarcEditor.Record.Fields.Add("856",
                                                                           "4 ",
                                                                           "",
                                                                           true);

            NewSubfield(field_856, "3", "Cover image");
            NewSubfield(field_856, "u", info.Url);
            NewSubfield(field_856, "q", AmazonSearch.GetMime(info.Url));

            NewSubfield(field_856, "x", "type:FrontCover." + name + ";size:" + info.Size + ";source:Amazon:" + dlg.SelectedItem.ASIN);
        }

        return;

ERROR1:
        MessageBox.Show(this.DetailForm, strError);
    }
Beispiel #11
0
        public AmazonAutomatedTestSteps()
        {
            #region ' Fake AMAZON site data '
            List <AmazonObjectItem> list = new List <AmazonObjectItem>();
            list.Add(new AmazonObjectItem()
            {
                ID         = 1,
                Name       = "Pair of paints.",
                ObjectType = AmazonObjectType.BoysFashion,
                Price      = 50.00
            });
            list.Add(new AmazonObjectItem()
            {
                ID         = 2,
                Name       = "DELL Ultrabook",
                ObjectType = AmazonObjectType.Computers,
                Price      = 1500.00
            });
            list.Add(new AmazonObjectItem()
            {
                ID         = 3,
                Name       = "Love Story",
                ObjectType = AmazonObjectType.Books,
                Price      = 10.00
            });
            list.Add(new AmazonObjectItem()
            {
                ID         = 4,
                Name       = "Algortims and programming logic",
                ObjectType = AmazonObjectType.Books,
                Price      = 25.00
            });
            list.Add(new AmazonObjectItem()
            {
                ID         = 4,
                Name       = "Test automation design - from paper to software.",
                ObjectType = AmazonObjectType.Books,
                Price      = 173.00
            });
            list.Add(new AmazonObjectItem()
            {
                ID         = 4,
                Name       = "Techniques of Test automation - Design, build and refatctoring.",
                ObjectType = AmazonObjectType.Books,
                Price      = 189.00
            });
            list.Add(new AmazonObjectItem()
            {
                ID         = 4,
                Name       = "BDD Test automation - Build bridge bettween stackholder and developer.",
                ObjectType = AmazonObjectType.Books,
                Price      = 98.00
            });
            list.Add(new AmazonObjectItem()
            {
                ID         = 4,
                Name       = "TDD Test automation: skeptical but pratical approach.",
                ObjectType = AmazonObjectType.Books,
                Price      = 99.00
            });

            #endregion

            this._amazonSearch = new AmazonSearch()
            {
                SearchCriteriaFilter = AmazonObjectType.Books,
                SearchFor            = "Test automation",
                Url = "www.amazon.com"
            };

            this._amazonSelectedObject = new AmazonSelectedObject(this._amazonSearch, list);
        }
Beispiel #12
0
        /// <summary>
        /// 检索
        /// </summary>
        /// <param name="strError">返回出错信息</param>
        /// <returns>-1表示出错,其他命中记录的数目</returns>
        public int DoSearch(out string strError)
        {
            strError = "";

            this.ClearList();

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

            this.button_stop.Enabled   = true;
            this.button_search.Enabled = false;
            try
            {
                string strFrom = this.GetFromRight();

#if NO
                if (_search != null)
                {
                    _search.Dispose();
                }

                _search = new AmazonSearch();
                // search.MainForm = this.MainForm;
                _search.TempFileDir = this.TempFileDir;
                _search.Idle       -= new EventHandler(search_Idle);
                _search.Idle       += new EventHandler(search_Idle);
#endif
                if (_search == null)
                {
                    _search             = new AmazonSearch();
                    _search.TempFileDir = this.TempFileDir;
                    _search.Idle       -= new EventHandler(search_Idle);
                    _search.Idle       += new EventHandler(search_Idle);
                }

                // 多行检索中的一行检索
                int nRedoCount = 0;
REDO:
                int nRet = _search.Search(
                    this.ServerUrl,
                    this.textBox_queryWord.Text.Replace("-", ""),
                    strFrom,    // "ISBN",
                    "[default]",
                    true,
                    out strError);
                if (nRet == -1)
                {
                    if (_search.Exception != null && _search.Exception is WebException)
                    {
                        WebException e1 = _search.Exception as WebException;
                        if (e1.Status == WebExceptionStatus.ProtocolError)
                        {
                            // 重做
                            if (nRedoCount < this.RetryCount)
                            {
                                nRedoCount++;
                                _search.Delay();
                                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)
                            {
                                _search.Delay();
                                goto REDO;
                            }
                            if (result == System.Windows.Forms.DialogResult.Cancel)
                            {
                                return(-1);
                            }
                            goto CONTINUE;
#endif
                            strError = "nRedoCount [" + nRedoCount.ToString() + "] " + strError;
                            goto ERROR1;
                        }
                    }
                    goto ERROR1;
                }

                nRet = _search.LoadBrowseLines(appendBrowseLine,
                                               null,
                                               false,
                                               out strError);
                if (nRet == -1)
                {
                    goto ERROR1;
                }

                // 如果有命中的,自动选定第一行
                if (dpTable_items.Rows.Count > 0)
                {
                    dpTable_items.Rows[0].Select(SelectAction.On);
                }

                if (_search.HasNextBatch() == true)
                {
                    AddNextCmdLine();
                }
            }
            finally
            {
                this.button_stop.Enabled   = false;
                this.button_search.Enabled = true;
            }

            return(_search.HitCount);

ERROR1:
            strError = "针对服务器 '" + this.ServerUrl + "' 检索出错: " + strError;
            return(-1);
        }