Exemplo n.º 1
0
        public void TestSankakuTagParser()
        {
            string target = @"../../../DanbooruDownloader3.test/TestXml/sankakutagspage.htm";
            var    data   = File.ReadAllText(target);
            var    parser = new SankakuComplexParser();

            var result = parser.parseTagsPage(data, 1);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Tag.Length == 50, "Count: " + result.Tag.Length);

            List <DanbooruTag> newTagList = new List <DanbooruTag>();

            target = @"../../../DanbooruDownloader3.test/TestXml/sankakutagspage-invalid.htm";
            data   = File.ReadAllText(target);
            parser = new SankakuComplexParser();

            result = parser.parseTagsPage(data, 1);
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Tag.Length == 50, "Count: " + result.Tag.Length);

            var filename = "dummy.xml";

            DanbooruTagsDao.Save(filename, result.Tag.ToList());
            DanbooruTagsDao dao = new DanbooruTagsDao(filename);
        }
        private List <DanbooruTag> CombineLoopTag(int lastPage)
        {
            // construct the tag list from each xml
            List <DanbooruTag> newTagList = new List <DanbooruTag>();

            for (int i = 1; i < lastPage; ++i)
            {
                Program.Logger.Debug("[Download Tags] Merging Page: " + i);
                lblStatus.Text = "Status: Merging Page: " + i + ", this might take some times.";
                lblStatus.Invalidate();
                lblStatus.Update();
                lblStatus.Refresh();
                Application.DoEvents();

                string tempName = TAGS_FILENAME + "." + i + ".!tmp";

                DanbooruTagCollection tempTag;
                if (isSankaku)
                {
                    SankakuComplexParser parser = new SankakuComplexParser();
                    tempTag = parser.parseTagsPage(File.ReadAllText(tempName), i);
                }
                else
                {
                    tempTag = new DanbooruTagsDao(tempName).Tags;
                }
                if (tempTag != null && tempTag.Tag != null)
                {
                    newTagList.AddRange(tempTag.Tag);
                }
            }

            for (int i = 1; i < lastPage; ++i)
            {
                string tempName = TAGS_FILENAME + "." + i + ".!tmp";
                File.Delete(tempName);
            }

            return(newTagList);
        }