Esempio n. 1
0
 /// <summary>
 /// Creates a new ChapterViewModel
 /// </summary>
 /// <param name="manga">Manga</param>
 /// <param name="chapter">Chapter to wrap</param>
 /// <param name="task">Mangas task</param>
 public ChapterViewModel(Manga manga, Chapter chapter, MangasTask task)
 {
     chapter_ = chapter;
     chapter_.Read += OnChapterRead;
     manga_ = manga;
     task_ = task;
 }
Esempio n. 2
0
        /// <summary>
        /// Creates a new MangaViewModel
        /// </summary>
        /// <param name="factory">Chapter factory</param>
        /// <param name="manga">Manga to wrap</param>
        /// <param name="task">Mangas task</param>
        public MangaViewModel(IChapterViewModelFactory factory, Manga manga, MangasTask task)
        {
            DisplayName = manga.Name;

            chapters_ = new List<ChapterViewModel>();
            factory_ = factory;
            manga_ = manga;
            manga_.NewChapter += OnMangaNewChapter;
            task_ = task;

            foreach (var chapter in manga_.Chapters)
                chapters_.Add(factory_.Create(manga_, chapter, task_));
        }
Esempio n. 3
0
        /// <summary>
        /// Displays the delete confirmation dialog for the given manga
        /// </summary>
        /// <param name="manga">Manga</param>
        /// <returns>If the user pressed yes</returns>
        public bool DeleteManga(Manga manga)
        {
            bool confirm = false;
            var dialog = delete_manga_.Create(manga);
            var result = manager_.ShowDialog(dialog);

            if (result.HasValue && result.Value)
            {
                confirm = true;
            }

            delete_manga_.Release(dialog);

            return confirm;
        }
Esempio n. 4
0
        /// <summary>
        /// Displays the add manga dialog
        /// </summary>
        /// <returns>Created manga, or null</returns>
        public Manga AddManga()
        {
            Manga manga = null;

            var dialog = add_manga_.Create();
            var result = manager_.ShowDialog(dialog);

            if (result.HasValue && result.Value)
            {
                manga = new Manga();
                manga.Name = dialog.MangaName;
                manga.Link = dialog.MangaLink;
            }

            add_manga_.Release(dialog);

            return manga;
        }
Esempio n. 5
0
        /// <summary>
        /// Creates a new DeleteMangaViewModel
        /// </summary>
        /// <param name="manga"></param>
        public DeleteMangaViewModel(Manga manga)
        {
            DisplayName = "MeliMelo - Delete Manga";

            manga_ = manga;
        }
Esempio n. 6
0
 /// <summary>
 /// Removes the given manga from the list
 /// </summary>
 /// <param name="manga">Manga to remove</param>
 public void Remove(Manga manga)
 {
     repository_.Remove(manga);
     Save();
 }
Esempio n. 7
0
 /// <summary>
 /// Adds the given manga to the list
 /// </summary>
 /// <param name="manga">Manga to add</param>
 public void Add(Manga manga)
 {
     repository_.Add(manga);
     Save();
 }
Esempio n. 8
0
        /// <summary>
        /// Updates the given manga
        /// </summary>
        /// <param name="manga">Manga to update</param>
        /// <returns>If the manga was updated or not</returns>
        private async Task UpdateManga(Manga manga)
        {
            try
            {
                string data = await HttpHelper.Get(manga.Link);

                if (!string.IsNullOrEmpty(data))
                {
                    var document = XDocument.Parse(data);

                    var items = document.Root.Element("channel").Elements("item");

                    foreach (var item in items)
                    {
                        string description_item = item.Element("description").Value;
                        string link_item = item.Element("link").Value;
                        string title_item = item.Element("title").Value;

                        var description = parser_.ParseDescription(description_item);
                        float? number = parser_.ParseChapterNumber(title_item);

                        // We assume the link never changes (Since we don't have an uuid or something
                        // like that. Thanks MangaFox)
                        var chapter = manga.Chapters.FirstOrDefault(c => c.Link == link_item);

                        // Create a new chapter
                        if (chapter == null)
                        {
                            chapter = new Chapter();

                            chapter.Description = description.Item1;
                            chapter.Team = description.Item2;
                            chapter.Link = link_item;
                            chapter.Number = number;
                            chapter.Title = title_item;

                            manga.Add(chapter);
                        }
                        // Update data
                        else
                        {
                            chapter.Description = description.Item1;
                            chapter.Team = description.Item2;
                            chapter.Number = number;
                            chapter.Title = title_item;
                        }
                    }
                }

                log_.Info("Update", "Successfully updated the manga \"" + manga.Name + "\"");
            }
            catch (Exception e)
            {
                log_.Error("Update", "Could not update the manga \"" + manga.Name + "\": "
                    + e.Message);
            }
        }