Beispiel #1
0
        public static void Merge(this MangaObject mangaObject, IEnumerable <MangaObject> list)
        {
            if (list.Count() > 0)
            {
                // Name
                if (String.IsNullOrWhiteSpace(mangaObject.Name))
                {
                    MangaObject FoD_Obj = list.FirstOrDefault(mO => !String.IsNullOrWhiteSpace(mO.Name));
                    if (FoD_Obj != null)
                    {
                        mangaObject.Name = FoD_Obj.Name;
                    }
                }

                // Released
                if (mangaObject.Released.Equals(DateTime.MinValue))
                {
                    MangaObject FoD_Obj = list.FirstOrDefault(mO => mO.Released > DateTime.MinValue);
                    if (FoD_Obj != null)
                    {
                        mangaObject.Released = FoD_Obj.Released;
                    }
                }

                // Rating
                if (mangaObject.Rating < 0)
                {
                    MangaObject FoD_Obj = list.FirstOrDefault(mO => mO.Rating >= 0);
                    if (FoD_Obj != null)
                    {
                        mangaObject.Rating = FoD_Obj.Rating;
                    }
                }

                // Description
                if (String.IsNullOrWhiteSpace(mangaObject.Description))
                {
                    MangaObject FoD_Obj = list.FirstOrDefault(mO => !String.IsNullOrWhiteSpace(mO.Description));
                    if (FoD_Obj != null)
                    {
                        mangaObject.Description = FoD_Obj.Description;
                    }
                }

                // MangaType & PageFlowDirection
                if (mangaObject.MangaType == Enums.MangaObjectType.Unknown)
                {
                    MangaObject FoD_Obj = list.FirstOrDefault(mO => mO.MangaType != Enums.MangaObjectType.Unknown);
                    if (FoD_Obj != null)
                    {
                        mangaObject.MangaType         = FoD_Obj.MangaType;
                        mangaObject.PageFlowDirection = FoD_Obj.PageFlowDirection;
                    }
                }

                // Locations
                foreach (List <LocationObject> Locations in (from MangaObject obj in list where obj != null select obj.Locations))
                {
                    foreach (LocationObject Location in Locations)
                    {
                        if (!mangaObject.Locations.Any(o => o.ExtensionName == Location.ExtensionName))
                        {
                            mangaObject.Locations.Add(Location);
                        }
                        else
                        {
                            // Update existing location url
                            Int32 idx = mangaObject.Locations.FindIndex(o => o.ExtensionName == Location.ExtensionName);
                            mangaObject.Locations.RemoveAt(idx);
                            mangaObject.Locations.Insert(idx, Location);
                        }
                    }
                }

                // DatabaseLocations
                foreach (List <LocationObject> DatabaseLocations in (from MangaObject obj in list where obj != null select obj.DatabaseLocations))
                {
                    foreach (LocationObject DatabaseLocation in DatabaseLocations)
                    {
                        if (!mangaObject.DatabaseLocations.Any(o => o.ExtensionName == DatabaseLocation.ExtensionName))
                        {
                            mangaObject.DatabaseLocations.Add(DatabaseLocation);
                        }
                    }
                }

                // Artists
                foreach (List <String> Artists in (from MangaObject obj in list where obj != null select obj.Artists))
                {
                    foreach (String Artist in Artists)
                    {
                        if (Artist != null &&
                            !mangaObject.Artists.Any(o => o.ToLower() == Artist.ToLower()))
                        {
                            mangaObject.Artists.Add(Artist);
                        }
                    }
                }

                // Authors
                foreach (List <String> Authors in (from MangaObject obj in list where obj != null select obj.Authors))
                {
                    foreach (String Author in Authors)
                    {
                        if (Author != null &&
                            !mangaObject.Authors.Any(o => o.ToLower() == Author.ToLower()))
                        {
                            mangaObject.Authors.Add(Author);
                        }
                    }
                }

                // Covers
                foreach (List <LocationObject> Covers in (from MangaObject obj in list where obj != null select obj.CoverLocations))
                {
                    foreach (LocationObject Cover in Covers)
                    {
                        if (Cover != null &&
                            !mangaObject.CoverLocations.Any(o => Equals(o.Url, Cover.Url)))
                        {
                            mangaObject.CoverLocations.Add(Cover);
                        }
                    }
                }
                mangaObject.CoverLocations.RemoveAll(c => String.IsNullOrWhiteSpace(c.Url));

                // AlternateNames
                foreach (String Name in (from MangaObject obj in list where obj != null select obj.Name))
                {
                    if (!mangaObject.AlternateNames.Any(o => o.ToLower() == Name.ToLower()) && Name != null)
                    {
                        mangaObject.AlternateNames.Add(Name);
                    }
                }
                foreach (List <String> AlternateNames in (from MangaObject obj in list where obj != null select obj.AlternateNames))
                {
                    foreach (String AlternateName in AlternateNames)
                    {
                        if (AlternateName != null && !mangaObject.AlternateNames.Any(o => o.ToLower() == AlternateName.ToLower()))
                        {
                            mangaObject.AlternateNames.Add(AlternateName);
                        }
                    }
                }

                // Genres
                foreach (List <String> Genres in (from MangaObject obj in list where obj != null select obj.Genres))
                {
                    foreach (String Genre in Genres)
                    {
                        if (Genre != null && !mangaObject.Genres.Any(o => o.ToLower() == Genre.ToLower()))
                        {
                            mangaObject.Genres.Add(Genre);
                        }
                    }
                }

                // Chapters
                foreach (List <ChapterObject> Chapters in (from MangaObject obj in list where obj != null select obj.Chapters))
                {
                    foreach (ChapterObject Chapter in Chapters)
                    {
                        if (Chapter != null)
                        {
                            ChapterObject chapterObject = mangaObject.Chapters.FirstOrDefault(o =>
                            {
                                if (!Int32.Equals(o.Chapter, Chapter.Chapter))
                                {
                                    return(false);
                                }
                                if (!Int32.Equals(o.SubChapter, Chapter.SubChapter))
                                {
                                    return(false);
                                }
                                return(true);
                            });
                            if (ChapterObject.Equals(chapterObject, null))
                            {
                                mangaObject.Chapters.Add(Chapter);
                            }
                            else
                            {
                                chapterObject.Merge(Chapter);
                            }
                        }
                    }
                }

                mangaObject.SortChapters();
            }
        }
Beispiel #2
0
        public static void AttachDatabase(this MangaObject value, DatabaseObject databaseObject, Boolean databaseAsMaster = false, Boolean preferDatabaseDescription = false)
        {
            if (databaseAsMaster)
            {
                if (!String.IsNullOrWhiteSpace(value.Name) &&
                    !value.AlternateNames.Any(o => o.ToLower() == value.Name.ToLower()))
                {
                    value.AlternateNames.Add(value.Name);
                }
                value.Name = databaseObject.Name;
            }
            else if (!String.IsNullOrWhiteSpace(databaseObject.Name) &&
                     !value.AlternateNames.Any(o => o.ToLower() == databaseObject.Name.ToLower()))
            {
                value.AlternateNames.Add(databaseObject.Name);
            }
            // AlternateNames
            foreach (String AlternateName in databaseObject.AlternateNames)
            {
                if (!String.IsNullOrWhiteSpace(AlternateName) &&
                    !value.AlternateNames.Any(o => o.ToLower() == AlternateName.ToLower()))
                {
                    value.AlternateNames.Add(AlternateName);
                }
            }

            // Description
            // Prefer database description if longer.
            if (databaseAsMaster || preferDatabaseDescription ||
                String.IsNullOrWhiteSpace(value.Description) ||
                value.Description.Length < databaseObject.Description.Length)
            {
                if (!String.IsNullOrWhiteSpace(databaseObject.Description))
                {
                    value.Description = databaseObject.Description;
                }
            }

            // Genres
            foreach (String Genre in databaseObject.Genres)
            {
                if (!String.IsNullOrWhiteSpace(Genre) &&
                    !value.Genres.Any(o => o.ToLower() == Genre.ToLower()))
                {
                    value.Genres.Add(Genre);
                }
            }

            // DatabaseLocations
            // value.DatabaseLocations = databaseObject.Locations;
            foreach (LocationObject DatabaseLocation in databaseObject.Locations)
            {
                if (!value.DatabaseLocations.Any(o => o.ExtensionName == DatabaseLocation.ExtensionName))
                {
                    value.DatabaseLocations.Add(DatabaseLocation);
                }
            }

            // Covers
            foreach (LocationObject Cover in databaseObject.Covers)
            {
                if (!String.IsNullOrWhiteSpace(Cover.Url) &&
                    !value.CoverLocations.Any(o => Equals(o.Url, Cover.Url)))
                {
                    value.CoverLocations.Insert(0, Cover);
                }
            }

            // Released
            if (value.Released.Equals(DateTime.MinValue) && databaseObject.ReleaseYear > 0)
            {
                value.Released = new DateTime(databaseObject.ReleaseYear, 1, 1);
            }
        }
Beispiel #3
0
        public static DatabaseObject Merge(IEnumerable <DatabaseObject> list)
        {
            if (list == null || list.Count() == 0)
            {
                return(null);
            }
            DatabaseObject databaseObject = list.First();

            if (list.Count() > 1)
            {
                databaseObject.ReleaseYear = (Int32)Math.Round((from DatabaseObject obj in list select obj.ReleaseYear).Average());

                // Locations
                foreach (List <LocationObject> Locations in (from DatabaseObject obj in list.Skip(1) where obj != null select obj.Locations))
                {
                    foreach (LocationObject Location in Locations)
                    {
                        if (!databaseObject.Locations.Any(o => o.ExtensionName == Location.ExtensionName))
                        {
                            databaseObject.Locations.Add(Location);
                        }
                    }
                }

                // Covers
                foreach (List <LocationObject> Covers in (from DatabaseObject obj in list.Skip(1) where obj != null select obj.Covers))
                {
                    foreach (LocationObject Cover in Covers)
                    {
                        if (!databaseObject.Covers.Any(o => o == Cover))
                        {
                            databaseObject.Covers.Add(Cover);
                        }
                    }
                }

                // AlternateNames
                foreach (String Name in (from DatabaseObject obj in list.Skip(1) where obj != null select obj.Name))
                {
                    if (!databaseObject.AlternateNames.Any(o => o.ToLower() == Name.ToLower()))
                    {
                        databaseObject.AlternateNames.Add(Name);
                    }
                }
                foreach (List <String> AlternateNames in (from DatabaseObject obj in list.Skip(1) select obj.AlternateNames))
                {
                    foreach (String AlternateName in AlternateNames)
                    {
                        if (!databaseObject.AlternateNames.Any(o => o.ToLower() == AlternateName.ToLower()))
                        {
                            databaseObject.AlternateNames.Add(AlternateName);
                        }
                    }
                }

                // Staff
                foreach (List <String> Staff in (from DatabaseObject obj in list.Skip(1) where obj != null select obj.Staff))
                {
                    foreach (String Person in Staff)
                    {
                        if (!databaseObject.Staff.Any(o => o.ToLower() == Person.ToLower()))
                        {
                            databaseObject.Staff.Add(Person);
                        }
                    }
                }

                // Genres
                foreach (List <String> Genres in (from DatabaseObject obj in list.Skip(1) where obj != null select obj.Genres))
                {
                    foreach (String Genre in Genres)
                    {
                        if (!databaseObject.Genres.Any(o => o.ToLower() == Genre.ToLower()))
                        {
                            databaseObject.Genres.Add(Genre);
                        }
                    }
                }
            }
            return(databaseObject);
        }