Exemple #1
0
        private static void ProcessPersonList(Dao.Title title, List <OMLEngine.Person> updatedList, PeopleRole role)
        {
            IEnumerable <string> originals = from a in title.People
                                             where a.Role == (byte)role
                                             select a.MetaData.FullName;

            List <string> added   = new List <string>(updatedList.Where(t => !originals.Contains(t.full_name)).Select(t => t.full_name));
            List <string> removed = new List <string>(originals.Where(t => !updatedList.Select(r => r.full_name).Contains(t)));

            // remove ones no longer used
            foreach (string remove in removed)
            {
                Dao.Person person = title.People.SingleOrDefault(p => p.MetaData.FullName == remove && p.Role == (byte)role);

                if (person != null)
                {
                    title.People.Remove(person);
                }
            }

            // add the new ones
            foreach (string add in added)
            {
                if (!string.IsNullOrEmpty(add))
                {
                    AddActorToTitle(title, add, null, role);
                }
            }
        }
Exemple #2
0
        private static void AddActorToTitle(Dao.Title title, string actor, string role, PeopleRole type)
        {
            if (actor.Length > 255)
            {
                throw new FormatException("Actor must be 255 characters or less.");
            }
            if (role != null && role.Length > 255)
            {
                throw new FormatException("Role must be 255 characters or less.");
            }

            if (string.IsNullOrEmpty(actor))
            {
                return;
            }

            Dao.BioData bioData = Dao.TitleCollectionDao.GetPersonBioDataByName(actor);

            if (bioData == null)
            {
                bioData          = new OMLEngine.Dao.BioData();
                bioData.FullName = actor;
                Dao.DBContext.Instance.BioDatas.InsertOnSubmit(bioData);
                Dao.DBContext.Instance.SubmitChanges();
            }

            Dao.Person person = new OMLEngine.Dao.Person();
            person.MetaData      = bioData;
            person.CharacterName = role;
            person.Role          = (byte)type;
            title.People.Add(person);
        }
Exemple #3
0
        /// <summary>
        /// Adds a genre to a title
        /// </summary>
        /// <param name="title"></param>
        /// <param name="genre"></param>
        private static void AddGenreToTitle(Dao.Title title, string genre)
        {
            if (string.IsNullOrEmpty(genre))
            {
                return;
            }

            // see if the genre exists
            Dao.GenreMetaData meta = Dao.TitleCollectionDao.GetGenreMetaDataByName(genre);

            if (meta == null)
            {
                meta      = new OMLEngine.Dao.GenreMetaData();
                meta.Name = genre;

                // save the genre
                Dao.DBContext.Instance.GenreMetaDatas.InsertOnSubmit(meta);
            }

            title.Genres.Add(new Dao.Genre {
                MetaData = meta
            });
        }
Exemple #4
0
        public static void UpdateCollectionsForTitle(Dao.Title title)
        {
            if (title.UpdatedActors != null)
            {
                IEnumerable <string> originalActors = from a in title.People
                                                      where a.Role == (byte)PeopleRole.Actor
                                                      select a.MetaData.FullName;

                List <string> added   = new List <string>(title.UpdatedActors.Where(t => !originalActors.Contains(t.PersonName)).Select(t => t.PersonName));
                List <string> removed = new List <string>(originalActors.Where(t => !title.UpdatedActors.Select(r => r.PersonName).Contains(t)));

                // remove ones no longer used
                foreach (string remove in removed)
                {
                    Dao.Person person = title.People.SingleOrDefault(p => p.MetaData.FullName == remove && p.Role == (byte)PeopleRole.Actor);

                    if (person != null)
                    {
                        title.People.Remove(person);
                    }
                }

                Dictionary <string, string> actorLookup = new Dictionary <string, string>();
                title.UpdatedActors.ForEach(t => actorLookup.Add(t.PersonName, t.RoleName));

                // add the new ones
                foreach (string add in added)
                {
                    AddActorToTitle(title, add, actorLookup[add], PeopleRole.Actor);
                }
            }

            if (title.UpdatedDirectors != null)
            {
                ProcessPersonList(title, title.UpdatedDirectors, PeopleRole.Director);
            }

            if (title.UpdatedWriters != null)
            {
                ProcessPersonList(title, title.UpdatedWriters, PeopleRole.Writer);
            }

            if (title.UpdatedProducers != null)
            {
                ProcessPersonList(title, title.UpdatedProducers, PeopleRole.Producers);
            }

            // if the genres were modified see how they've changed
            if (title.UpdatedGenres != null)
            {
                // see if there are any genres to add

                // grab all the original genres
                IEnumerable <string> originalGenres = from g in title.Genres
                                                      select g.MetaData.Name;

                List <string> added   = new List <string>(title.UpdatedGenres.Where(t => !originalGenres.Contains(t)));
                List <string> removed = new List <string>(originalGenres.Where(t => !title.UpdatedGenres.Contains(t)));

                // remove ones no longer used
                foreach (string remove in removed)
                {
                    Dao.Genre genre = title.Genres.SingleOrDefault(g => g.MetaData.Name == remove);

                    if (genre != null)
                    {
                        title.Genres.Remove(genre);
                    }
                }

                // add the new ones
                foreach (string add in added)
                {
                    AddGenreToTitle(title, add);
                }
            }

            if (title.UpdatedTags != null)
            {
                IEnumerable <string> originalTags = from t in title.Tags
                                                    select t.Name;

                List <string> added   = new List <string>(title.UpdatedTags.Where(t => !originalTags.Contains(t)));
                List <string> removed = new List <string>(originalTags.Where(t => !title.UpdatedTags.Contains(t)));

                foreach (string remove in removed)
                {
                    Dao.Tag tag = title.Tags.SingleOrDefault(t => t.Name == remove);

                    if (tag != null)
                    {
                        title.Tags.Remove(tag);
                    }
                }

                foreach (string add in added)
                {
                    Dao.Tag daoTag = new OMLEngine.Dao.Tag();
                    daoTag.TitleId = title.Id;
                    daoTag.Name    = add;

                    title.Tags.Add(daoTag);
                }
            }
        }