Example #1
0
        private void updateLocalData(MangaAnimeItems locals, MangaAnimeItems remote, ref int added, ref int updated)
        {
            foreach (MangaAnimeItem remoteItem in remote.Values)
            {
                if (!locals.ContainsKey(remoteItem.id))
                {
                    locals.Add(remoteItem.id, remoteItem);
                    added++;
                    continue;
                }

                bool           changed   = false;
                MangaAnimeItem localItem = locals[remoteItem.id];
                if (!localItem.EqualsImageUrl(remoteItem))
                {
                    localItem.url = remoteItem.url;
                    changed       = true;
                }

                if (localItem.name != remoteItem.name)
                {
                    localItem.name = remoteItem.name;
                    changed        = true;
                }

                if (changed)
                {
                    updated++;
                }
            }
        }
Example #2
0
        public ImageUpdater()
        {
            Stopwatch sw = Stopwatch.StartNew();

            sw.Start();

            Task anime = new Task(() =>
            {
                Task local  = new Task(getLocalAnimeData);
                Task remote = new Task(getRemoteAnimeData);
                local.Start();
                remote.Start();
                local.Wait();
                remote.Wait();

                //update anime
                updateAnimeDataInLocal();
                saveAnimeToCss();
            });
            Task manga = new Task(() =>
            {
                Task local  = new Task(getLocalMangaData);
                Task remote = new Task(getRemoteMangaData);
                local.Start();
                remote.Start();
                local.Wait();
                remote.Wait();

                //update manga
                updateMangaDataInLocal();
                saveMangaToCss();
            });

            anime.Start();
            manga.Start();
            anime.Wait();
            manga.Wait();

            //statistic count
            //Console.WriteLine("Anime remote count: " + animeRemote.Count());
            //Console.WriteLine("Anime local count: " + animeLocal.Count());
            //Console.WriteLine("Manga remote count: " + mangaRemote.Count());
            //Console.WriteLine("Mnime local count: " + mangaLocal.Count());


            //statistic added/removed
            //Console.WriteLine("Anime added : {0}", animeAdded);
            //Console.WriteLine("Anime updated : {0}", animeUpdated);
            //Console.WriteLine("Manga added : {0}", mangaAdded);
            //Console.WriteLine("Manga updated : {0}", mangaUpdated);
            sw.Stop();
            Console.WriteLine("App work: {0}ms.", sw.Elapsed.TotalMilliseconds);
            animeLocal = animeRemote = mangaLocal = mangaRemote = null;
            GC.Collect();
            GC.WaitForPendingFinalizers();

            Thread.Sleep(7 * 1000);
        }
Example #3
0
        private void getLocalMangaData()
        {
            //Console.WriteLine("Load manga local data.");
            Stopwatch sw = Stopwatch.StartNew();

            try
            {
                using (StreamReader reader = new StreamReader(Settings.Instance.getMangaFilePath()))
                {
                    mangaLocal = parseCssFile(reader);
                }
            }
            catch (IOException ioex)
            {
                Console.WriteLine("test " + ioex.ToString());
            }
            sw.Stop();
            Console.WriteLine("Manga local data loaded: {0}ms.", sw.Elapsed.TotalMilliseconds);
        }
Example #4
0
        private MangaAnimeItems parseCssFile(StreamReader reader)
        {
            MangaAnimeItems list = new MangaAnimeItems();
            string          line;

            while ((line = reader.ReadLine()) != null)
            {
                Regex regexId   = new Regex(@"#more([0-9]+)");
                Regex regexUrl  = new Regex(@"url\((.*)\);");
                Regex regexName = new Regex(@"(\/\*.*\*\/)");
                Match matchId   = regexId.Match(line);
                Match matchUrl  = regexUrl.Match(line);
                Match matchName = regexName.Match(line);
                if (!matchId.Success || !matchUrl.Success || !matchName.Success)
                {
                    continue;
                }

                int            id   = Int32.Parse(matchId.Groups[1].Value);
                MangaAnimeItem item = null;
                if (list.ContainsKey(id))
                {
                    item = list[id];
                }
                else
                {
                    item = new MangaAnimeItem();
                    list.Add(id, item);
                }

                item.id   = id;
                item.url  = matchUrl.Groups[1].Value;
                item.name = matchName.Groups[1].Value.Substring(3).TrimEnd('/').TrimEnd('*').TrimEnd(' ');
            }
            return(list);
        }