Parse() 공개 메소드

public Parse ( string data, DanbooruDownloader3.Entity.DanbooruSearchParam searchParam ) : BindingList
data string
searchParam DanbooruDownloader3.Entity.DanbooruSearchParam
리턴 BindingList
예제 #1
0
        /// <summary>
        /// parse xml/json list stream and close it.
        /// </summary>
        /// <param name="input"></param>
        /// <param name="option"></param>
        public DanbooruPostDao(Stream input, DanbooruPostDaoOption option)
        {
            string rawData = "";
            this.Option = option;
            try
            {
                using (StreamReader reader = new StreamReader(input))
                {
                    rawData = reader.ReadToEnd();
                }
                this.Option = option;
                switch (option.Provider.Preferred)
                {
                    case PreferredMethod.Xml:
                        ReadXML(rawData, option);
                        break;

                    case PreferredMethod.Json:
                        ReadJSON(rawData, option);
                        break;

                    case PreferredMethod.Html:
                        DanbooruSearchParam param = new DanbooruSearchParam()
                        {
                            Provider = option.Provider,
                            Tag = option.SearchTags,
                            Option = option
                        };
                        if (option.Provider.BoardType == BoardType.Danbooru)
                        {
                            SankakuComplexParser parser = new SankakuComplexParser();
                            posts = parser.Parse(rawData, param);
                        }
                        else if (option.Provider.BoardType == BoardType.Gelbooru)
                        {
                            GelbooruHtmlParser parser = new GelbooruHtmlParser();
                            posts = parser.Parse(rawData, param);
                        }
                        else
                        {
                            throw new NotImplementedException("No HTML Parser for: " + option.Provider.Name);
                        }
                        break;
                }
            }
            catch (Exception)
            {
                Helper.DumpRawData(rawData, Option.Provider, option.Query);
                throw;
            }
        }
예제 #2
0
        public void TestSankakuParser()
        {
            DanbooruProviderDao pd = DanbooruProviderDao.GetInstance();
            string target = @"../../../DanbooruDownloader3.test/TestXml/sankaku_paging.htm";
            var data = File.ReadAllText(target);
            var query = new DanbooruSearchParam();
            query.Provider = pd.Read(sourceProvider).Where(x => x.Name == "Sankaku Complex").First();
            query.Tag = "";
            query.OrderBy = "score";

            var parser = new SankakuComplexParser();

            var result = parser.Parse(data, query);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Count == 20, "Count: " + result.Count);
            Assert.IsTrue(result[0].Id == "1929657", "Id: " + result[0].Id);
            Assert.IsTrue(result[0].Provider.Name == "Sankaku Complex", "Provider: " + result[0].Provider.Name);
            Assert.IsTrue(result[0].SearchTags == "", "SearchTags: " + result[0].SearchTags);
            Assert.IsTrue(result[0].Query == "tags=order:score", "Query: " + result[0].Query);

            Assert.IsTrue(result[0].Tags == "fate_(series) code_geass fate/zero gilgamesh kotomine_kirei 3boys androgynous armlet blonde bracelet brown_hair clamp_(style) cross cross_necklace earrings enkidu_(fate/strange_fake) fate/strange_fake green_eyes green_hair hand_on_own_face jewelry long_hair multiple_boys necklace parody red_eyes ruchi style_parody toga", "Tags: " + result[0].Tags);
            Assert.IsTrue(result[0].PreviewUrl == "http://c2.sankakustatic.com/data/preview/85/f5/85f54efd7fea7ba91b20ca09ad5823c7.jpg", "PreviewUrl: " + result[0].PreviewUrl);
            Assert.IsTrue(result[0].PreviewHeight == 144, "PreviewHeight: " + result[0].PreviewHeight);
            Assert.IsTrue(result[0].PreviewWidth == 150, "PreviewWidth: " + result[0].PreviewWidth);
            Assert.IsTrue(result[0].Score == "0.0", "Score: " + result[0].Score);
            Assert.IsTrue(result[0].Rating == "s", "Rating: " + result[0].Rating);
        }