public void GetUrlGeneratorSmbc()
        {
            var smbcUrl = "http://www.smbc-comics.com/index.php?db=comics&id=614";
            var smbcUrl0 = "http://www.smbc-comics.com/comics/20061010.gif";
            var smbcUrl1 = "http://www.smbc-comics.com/comics/20061011.gif";
            var smbcUrl2 = "http://www.smbc-comics.com/comics/20061012.gif";
            var smbcParser = new ComicParser (smbcUrl);

            // get the generator object
            DateGenerator urlGen = (DateGenerator)smbcParser.GetUrlGenerator ();
            urlGen.Days = DateGenerator.EveryDay;

            // generate 10 urls, going backwards, including the original (and starting from the original)
            List<string> backUrls = urlGen.Get (-1, 10);
            // generate 10 urls, going forwards, excluding the original (and starting from the original)
            List<string> forwardUrls = urlGen.Get (0, 10);

            // each url should be the comic, directly
            // urls are sorted
            Assert.AreEqual (smbcUrl0, backUrls [0]);
            Assert.AreEqual (smbcUrl1, backUrls [1]);
            Assert.AreEqual (10, backUrls.Count ());
            Assert.AreEqual (smbcUrl1, forwardUrls [0]);
            Assert.AreEqual (smbcUrl2, forwardUrls [1]);
            Assert.AreEqual (10, forwardUrls.Count ());
        }
        public void GetDirectly()
        {
            var url = "http://comic.com/009.png";
            var parser = new ComicParser (url);
            var img0 = "http://comic.com/613.png";
            var img1 = "http://comic.com/614.png";
            var img2 = "http://comic.com/615.png";

            // get the generator object
            UrlGenerator urlGen = parser.GetUrlGenerator ();
            Assert.AreEqual ("1", urlGen.Start);

            // generate 10 urls, starting from 605
            List<string> backUrls = urlGen.Get (612, 10);
            // generate 10 urls, starting from 615
            List<string> forwardUrls = urlGen.Get (614, 10);

            // each url should be the comic, directly
            // urls are sorted
            Assert.AreEqual (10, backUrls.Count ());
            Assert.AreEqual (img0, backUrls [0]);
            Assert.AreEqual (img1, backUrls [1]);
            Assert.AreEqual (img2, backUrls [2]);
            Assert.AreEqual (10, forwardUrls.Count ());
            Assert.AreEqual (img2, forwardUrls [0]);
        }
 public void GetUrlGeneratorIrregularWebcomic()
 {
     var pageUrl = "http://www.irregularwebcomic.net/32.html";
     var comicUrl = "http://www.irregularwebcomic.net/comics/irreg0032.jpg";
     var parser = new ComicParser (pageUrl);
     var urlGen = parser.GetUrlGenerator ();
     Assert.AreEqual (comicUrl, urlGen.Comic.AbsoluteUri);
 }
        public void GetUrlGeneratorXkcd()
        {
            var xkcdUrl = "http://xkcd.com/614";
            var xkcdParser = new ComicParser (xkcdUrl);

            // get the generator object - should be the right type
            UrlGenerator urlGen = xkcdParser.GetUrlGenerator ();
            Assert.IsTrue (urlGen.ToString ().Contains ("SequentialGenerator"));
        }
        public void TryRedirectToImgSmbc()
        {
            var url = "http://www.smbc-comics.com/index.php?db=comics&id=614";
            var imgUrl = "http://www.smbc-comics.com/comics/20061011.gif";
            var parser = new ComicParser (url);
            var urlGen = parser.GetUrlGenerator ();
            Assert.AreEqual (imgUrl.Substring (10), urlGen.Comic.AbsoluteUri.Substring (10));

            parser = new ComicParser (imgUrl);
            urlGen = parser.GetUrlGenerator ();
            Assert.AreEqual (imgUrl.Substring (10), urlGen.Comic.AbsoluteUri.Substring (10));
        }
        public void TryRedirectToImgIrregularWebcomic()
        {
            var url = "http://www.irregularwebcomic.net/32.html";
            var imgUrl = "http://www.irregularwebcomic.net/comics/irreg0032.jpg";
            var parser = new ComicParser (url);
            var urlGen = parser.GetUrlGenerator ();
            Assert.AreEqual (imgUrl, urlGen.Comic.AbsoluteUri);

            parser = new ComicParser (imgUrl);
            urlGen = parser.GetUrlGenerator ();
            Assert.AreEqual (imgUrl, urlGen.Comic.AbsoluteUri);
        }
        public void CancelDownloads()
        {
            // choose target files to download
            var url = "http://www.smbc-comics.com/comics/20061001.gif";
            //			var url = "http://www.irregularwebcomic.net/55.html";
            var parser = new ComicParser (url);
            var urlGen = parser.GetUrlGenerator () as DateGenerator;
            urlGen.Days = DateGenerator.EveryDay;
            var urls = urlGen.Get (0, 20);

            foreach (var x in urls) {
                Console.WriteLine (x);
            }

            using (var repo = new Repository ()) {

                // set the gate
                AutoResetEvent auto = new AutoResetEvent (false);

                int num = 0;

                // event handler to count number of async downloads
                repo.DownloadFileCompleted += delegate(object sender, AsyncCompletedEventArgs e) {
                    num += 1;
                    // here we set the canceller
                    if (num == 5) {
                        repo.CancelDownloads ();
                        auto.Set ();
                    }
                };

                // event handler allows program to progress (in case of cancel failure)
                repo.MultipleDownloadsCompleted += delegate(object sender, EventArgs e) {
                    auto.Set ();
                };

                // begin the download and block
                repo.Download (urls);
                auto.WaitOne ();

                // check that it worked
                Assert.AreEqual (5, repo.Files.Count);
            }
        }
        private UrlGenerator SetupTask()
        {
            var comic = new ComicUri (InputUrl);

            var parser = new ComicParser (InputUrl);

            var urlGen = parser.GetUrlGenerator ();

            // in the interests of simplicity, just start from given comicå
            urlGen.Start = comic.Indices [0];

            return urlGen;
        }
        public void DownloadMany()
        {
            // choose target files to download
            var url = "http://www.smbc-comics.com/comics/20061001.gif";
            //			var url = "http://www.irregularwebcomic.net/55.html";
            var parser = new ComicParser (url);
            var urlGen = parser.GetUrlGenerator () as DateGenerator;
            urlGen.Days = DateGenerator.EveryDay;
            var urls = urlGen.Get (0, 20);

            foreach (var x in urls) {
                Console.WriteLine (x);
            }

            var numComics = urls.Where<string> (x => x != String.Empty).Count ();

            using (var repo = new Repository ()) {

                // set the gate
                AutoResetEvent auto = new AutoResetEvent (false);

                // event handler allows program to progress
                repo.MultipleDownloadsCompleted += delegate(object sender, EventArgs e) {
                    auto.Set ();
                };

                // begin the download and block
                repo.Download (urls);
            //				auto.WaitOne ();

                // check that it worked
                Assert.AreEqual (numComics, repo.Files.Count);
            }
        }
        public void GetFromPageXkcd()
        {
            var xkcdUrl = "http://xkcd.com/614";
            var xkcdParser = new ComicParser (xkcdUrl);
            var xkcdImg = "http://imgs.xkcd.com/comics/woodpecker.png";
            var xkcdImg2 = "http://imgs.xkcd.com/comics/avoidance.png";

            // get the generator object
            UrlGenerator urlGen = xkcdParser.GetUrlGenerator ();

            Assert.AreEqual ("1", urlGen.Start);

            // generate 10 urls, starting from 605
            List<string> backUrls = urlGen.Get (605, 10);
            // generate 10 urls, starting from 615
            List<string> forwardUrls = urlGen.Get (615, 10);
            // generate 10 urls, starting from 614
            List<string> incUrls = urlGen.Get (614, 10);

            // each url should be the comic, directly
            // urls are sorted

            //			foreach (var x in backUrls) {
            //				Console.WriteLine (x);
            //			}

            // Seems like this is a legitimate fail...
            // backUrls[0] is actually comic 606, expected 605
            // further investigation required
            Assert.AreEqual (10, backUrls.Count ());
            Assert.AreEqual (xkcdImg, backUrls [9]);
            Assert.AreEqual (10, forwardUrls.Count ());
            Assert.AreEqual (xkcdImg2, forwardUrls [0]);
            Assert.AreEqual (10, incUrls.Count ());
            Assert.AreEqual (xkcdImg, incUrls [0]);
            Assert.AreEqual (xkcdImg2, incUrls [1]);
        }
 public void GetFromPageIrregularWebcomic()
 {
     var url = "http://www.irregularwebcomic.net/55.html";
     var parser = new ComicParser (url);
     var urlGen = parser.GetUrlGenerator ();
     var urls = urlGen.Get (0, 20);
     Assert.AreEqual("http://www.irregularwebcomic.net/comics/irreg0001.jpg", urls[0]);
     Assert.AreEqual("http://www.irregularwebcomic.net/comics/irreg0002.jpg", urls[1]);
     Assert.AreEqual("http://www.irregularwebcomic.net/comics/irreg0003.jpg", urls[2]);
     Assert.AreEqual("http://www.irregularwebcomic.net/comics/irreg0004.jpg", urls[3]);
     Assert.AreEqual("http://www.irregularwebcomic.net/comics/irreg0005.jpg", urls[4]);
 }