Exemple #1
0
 static void Main()
 {
     Application.EnableVisualStyles();
     Application.SetCompatibleTextRenderingDefault(false);
     NhContext.Bootstrap();
     if (Properties.Settings.Default.FilmDirectories == null)
     {
         Properties.Settings.Default.FilmDirectories = new StringCollection();
     }
     if (Properties.Settings.Default.FilmFileFilter == null)
     {
         Properties.Settings.Default.FilmFileFilter = new StringCollection();
     }
     if (Properties.Settings.Default.FilmFileTypes == null)
     {
         Properties.Settings.Default.FilmFileTypes = new StringCollection();
     }
     Application.Run(new FRM_Main());
 }
Exemple #2
0
        public bool Execute()
        {
            var mayCommit = true;

            var nhSession = NhContext.GetSession();

            using (var tx = nhSession.BeginTransaction())
            {
                var newFilms = new List <Film>();

                foreach (var film in Films)
                {
                    var realNewFilm = new Film();
                    if (GetFilmFromCache(film.IMDBId) != null || nhSession.Query <Film>().Where(x => x.IMDBId == film.IMDBId).Any())
                    {
                        continue;
                    }
                    AddFilmToCache(film);
                    realNewFilm.FilmPath         = film.FilmPath;
                    realNewFilm.IMDBId           = film.IMDBId;
                    realNewFilm.ReleaseYear      = film.ReleaseYear;
                    realNewFilm.RunTime          = film.RunTime;
                    realNewFilm.Synopsis         = film.Synopsis;
                    realNewFilm.Title            = film.Title;
                    realNewFilm.Keywords         = film.Keywords;
                    realNewFilm.DirectorIndexing = film.DirectorIndexing;
                    realNewFilm.GenreIndexing    = film.GenreIndexing;
                    realNewFilm.CharIndexing     = film.CharIndexing;
                    realNewFilm.PersonIndexing   = film.PersonIndexing;
                    realNewFilm.PicURL           = film.PicURL;
                    realNewFilm.IMDBRating       = film.IMDBRating;

                    foreach (var person in film.Director)
                    {
                        var director = GetPersonFromCache(person.IMDBID) ??
                                       nhSession.Query <Person>().Where(x => x.IMDBID == person.IMDBID).
                                       SingleOrDefault() ?? person;
                        AddPersonToCache(director);
                        realNewFilm.Director.Add(director);
                    }

                    foreach (var person in film.Writers)
                    {
                        var writer = GetPersonFromCache(person.IMDBID) ??
                                     nhSession.Query <Person>().Where(x => x.IMDBID == person.IMDBID).
                                     SingleOrDefault() ?? person;
                        AddPersonToCache(writer);
                        realNewFilm.Writers.Add(writer);
                    }

                    foreach (var genre in film.Genre)
                    {
                        var type = GetTypeFromCache(genre.Type) ??
                                   nhSession.Query <FilmType>().Where(x => x.Type == genre.Type).
                                   SingleOrDefault() ?? genre;
                        AddTypeToCache(type);
                        realNewFilm.Genre.Add(type);
                    }

                    foreach (var role in film.Cast)
                    {
                        var actor = GetPersonFromCache(role.Person.IMDBID)
                                    ??
                                    nhSession.Query <Person>().Where(x => x.IMDBID == role.Person.IMDBID).
                                    SingleOrDefault()
                                    ?? role.Person;
                        AddPersonToCache(actor);
                        var role2 = new Role
                        {
                            Character = role.Character,
                            Person    = actor
                        };
                        realNewFilm.Cast.Add(role2);
                    }
                    newFilms.Add(realNewFilm);
                }

                var validator = new FilmValidator();
                foreach (var newFilm in newFilms)
                {
                    var results = validator.Validate(newFilm);
                    if (results.IsValid)
                    {
                        nhSession.Save(newFilm);
                    }
                    else
                    {
                        ValidationErrors.Add(newFilm.IMDBId, results.Errors);
                        mayCommit = false;
                    }
                }

                if (mayCommit)
                {
                    tx.Commit();
                }
            }
            return(mayCommit);
        }