Exemple #1
0
        /// <summary>
        /// Creates a whole new game record in the DB. Used when no hash, filename, or title match was found in the DB.
        /// </summary>
        /// <param name="gameDetails">Details of the unknown game.</param>
        /// <param name="hash">Hash of the unknown game.</param>
        /// <param name="filename">Filename of the unknown game.</param>
        void UnknownGame(GameDetails gameDetails, ISession session)
        {
            Service.Log.Info("Creating completely new game records");

            // create new details. We know that a new game, hash, filename, title and their match tables need to be created.
            // the other details might already have records (assigned to another game in error possibly)
            Game game = new Game();

            session.Save(game);

            Hash newHash = new Hash();

            newHash.hash = gameDetails.Hash;
            session.Save(newHash);

            HashMatch hashMatch = new HashMatch();

            hashMatch.hash = newHash;
            hashMatch.game = game;
            session.Save(hashMatch);

            Filename newFilename = new Filename();

            newFilename.filename = gameDetails.Filename;
            session.Save(newFilename);

            FilenameMatch filenameMatch = new FilenameMatch();

            filenameMatch.filename = newFilename;
            filenameMatch.game     = game;
            session.Save(filenameMatch);

            Title newTitle = new Title();

            newTitle.title = gameDetails.Title;
            session.Save(newTitle);

            TitleMatch titleMatch = new TitleMatch();

            titleMatch.title = newTitle;
            titleMatch.game  = game;
            session.Save(titleMatch);

            // now add the other game details to our new game.
            // we check if there is an instance of each game detail first, and if there is
            // we create a match to our new game. If there isnt an instance of the game detail
            // already in our db, then we create one and match that to our game.

            // Year
            Service.Log.Info("Checking if year already exists in DB");
            // There can only be one result
            var yearResult = session.CreateCriteria <Year>()
                             .Add(Restrictions.Eq("year", gameDetails.YearMade))
                             .List <Year>();

            YearMatch yearMatch = new YearMatch();
            Year      year;

            if (yearResult.Count > 0) // an instance was found
            {
                Service.Log.Info("Year already existed in DB");
                year = yearResult[0];
            }
            else // no instance was found
            {
                Service.Log.Info("Year did not exist in DB. Creating year");
                year      = new Year();
                year.year = gameDetails.YearMade;
                session.Save(year);
            }

            Service.Log.Info("Creating match for year to game");
            yearMatch.game = game;
            yearMatch.year = year;
            session.Save(yearMatch);

            //Manual
            var manualResult = session.CreateCriteria <Manual>()
                               .Add(Restrictions.Eq("manual", gameDetails.Manual))
                               .List <Manual>();

            ManualMatch manualMatch = new ManualMatch();
            Manual      manual;

            if (manualResult.Count > 0) // an instance in the db was found
            {
                manual = manualResult[0];
            }
            else
            {
                manual        = new Manual();
                manual.manual = gameDetails.Manual;
                session.Save(manual);
            }

            manualMatch.game   = game;
            manualMatch.manual = manual;
            session.Save(manualMatch);

            //Genre
            var genreResult = session.CreateCriteria <Genre>()
                              .Add(Restrictions.Eq("genre", gameDetails.Genre))
                              .List <Genre>();

            GenreMatch genreMatch = new GenreMatch();
            Genre      genre;

            if (genreResult.Count > 0) // an instance in the db was found
            {
                genre = genreResult[0];
            }
            else
            {
                genre       = new Genre();
                genre.genre = gameDetails.Genre;
                session.Save(genre);
            }

            genreMatch.game  = game;
            genreMatch.genre = genre;
            session.Save(genreMatch);

            //Grade
            var gradeResult = session.CreateCriteria <Grade>()
                              .Add(Restrictions.Eq("grade", gameDetails.Grade))
                              .List <Grade>();

            GradeMatch gradeMatch = new GradeMatch();
            Grade      grade;

            if (gradeResult.Count > 0) // an instance in the db was found
            {
                grade = gradeResult[0];
            }
            else
            {
                grade       = new Grade();
                grade.grade = gameDetails.Grade;
                session.Save(grade);
            }

            gradeMatch.game  = game;
            gradeMatch.grade = grade;
            session.Save(gradeMatch);

            // Description
            var descriptionResult = session.CreateCriteria <Description>()
                                    .Add(Restrictions.Eq("description", gameDetails.Description))
                                    .List <Description>();

            DescriptionMatch descriptionMatch = new DescriptionMatch();
            Description      description;

            if (descriptionResult.Count > 0) // an instance in the db was found
            {
                description = descriptionResult[0];
            }
            else
            {
                description             = new Description();
                description.description = gameDetails.Description;
                session.Save(description);
            }

            descriptionMatch.game        = game;
            descriptionMatch.description = description;
            session.Save(descriptionMatch);

            //ImageBack
            var ImageBackResult = session.CreateCriteria <ImageBack>()
                                  .Add(Restrictions.Eq("url", gameDetails.ImageBack))
                                  .List <ImageBack>();

            ImageBackMatch ImageBackMatch = new ImageBackMatch();
            ImageBack      ImageBack;

            if (ImageBackResult.Count > 0) // an instance in the db was found
            {
                ImageBack = ImageBackResult[0];
            }
            else
            {
                ImageBack     = new ImageBack();
                ImageBack.url = gameDetails.ImageBack;
                session.Save(ImageBack);
            }

            ImageBackMatch.game      = game;
            ImageBackMatch.ImageBack = ImageBack;
            session.Save(ImageBackMatch);

            //ImageFront
            var ImageFrontResult = session.CreateCriteria <ImageFront>()
                                   .Add(Restrictions.Eq("url", gameDetails.ImageFront))
                                   .List <ImageFront>();

            ImageFrontMatch ImageFrontMatch = new ImageFrontMatch();
            ImageFront      ImageFront;

            if (ImageFrontResult.Count > 0) // an instance in the db was found
            {
                ImageFront = ImageFrontResult[0];
            }
            else
            {
                ImageFront     = new ImageFront();
                ImageFront.url = gameDetails.ImageFront;
                session.Save(ImageFront);
            }

            ImageFrontMatch.game       = game;
            ImageFrontMatch.ImageFront = ImageFront;
            session.Save(ImageFrontMatch);

            //ImageTitleScreen
            var ImageTitleScreenResult = session.CreateCriteria <ImageTitleScreen>()
                                         .Add(Restrictions.Eq("url", gameDetails.ImageTitleScreen))
                                         .List <ImageTitleScreen>();

            ImageTitleScreenMatch ImageTitleScreenMatch = new ImageTitleScreenMatch();
            ImageTitleScreen      ImageTitleScreen;

            if (ImageTitleScreenResult.Count > 0) // an instance in the db was found
            {
                ImageTitleScreen = ImageTitleScreenResult[0];
            }
            else
            {
                ImageTitleScreen     = new ImageTitleScreen();
                ImageTitleScreen.url = gameDetails.ImageTitleScreen;
                session.Save(ImageTitleScreen);
            }

            ImageTitleScreenMatch.game             = game;
            ImageTitleScreenMatch.ImageTitleScreen = ImageTitleScreen;
            session.Save(ImageTitleScreenMatch);

            //ImageIngame
            var ImageIngameResult = session.CreateCriteria <ImageIngame>()
                                    .Add(Restrictions.Eq("url", gameDetails.ImageIngame))
                                    .List <ImageIngame>();

            ImageIngameMatch ImageIngameMatch = new ImageIngameMatch();
            ImageIngame      ImageIngame;

            if (ImageIngameResult.Count > 0) // an instance in the db was found
            {
                ImageIngame = ImageIngameResult[0];
            }
            else
            {
                ImageIngame     = new ImageIngame();
                ImageIngame.url = gameDetails.ImageIngame;
                session.Save(ImageIngame);
            }

            ImageIngameMatch.game        = game;
            ImageIngameMatch.ImageIngame = ImageIngame;
            session.Save(ImageIngameMatch);

            //ImageFanart
            var ImageFanartResult = session.CreateCriteria <ImageFanart>()
                                    .Add(Restrictions.Eq("url", gameDetails.ImageFanart))
                                    .List <ImageFanart>();

            ImageFanartMatch ImageFanartMatch = new ImageFanartMatch();
            ImageFanart      ImageFanart;

            if (ImageFanartResult.Count > 0) // an instance in the db was found
            {
                ImageFanart = ImageFanartResult[0];
            }
            else
            {
                ImageFanart     = new ImageFanart();
                ImageFanart.url = gameDetails.ImageFanart;
                session.Save(ImageFanart);
            }

            ImageFanartMatch.game        = game;
            ImageFanartMatch.ImageFanart = ImageFanart;
            session.Save(ImageFanartMatch);


            session.Flush();
        }
Exemple #2
0
        /// <summary>
        /// Creates a whole new game record in the DB. Used when no hash, filename, or title match was found in the DB.
        /// </summary>
        /// <param name="gameDetails">Details of the unknown game.</param>
        /// <param name="hash">Hash of the unknown game.</param>
        /// <param name="filename">Filename of the unknown game.</param>
        void UnknownGame(GameDetails gameDetails, ISession session)
        {
            Service.Log.Info("Creating completely new game records");

            // create new details. We know that a new game, hash, filename, title and their match tables need to be created.
            // the other details might already have records (assigned to another game in error possibly)
            Game game = new Game();
            session.Save(game);

            Hash newHash = new Hash();
            newHash.hash = gameDetails.Hash;
            session.Save(newHash);

            HashMatch hashMatch = new HashMatch();
            hashMatch.hash = newHash;
            hashMatch.game = game;
            session.Save(hashMatch);

            Filename newFilename = new Filename();
            newFilename.filename = gameDetails.Filename;
            session.Save(newFilename);

            FilenameMatch filenameMatch = new FilenameMatch();
            filenameMatch.filename = newFilename;
            filenameMatch.game = game;
            session.Save(filenameMatch);

            Title newTitle = new Title();
            newTitle.title = gameDetails.Title;
            session.Save(newTitle);

            TitleMatch titleMatch = new TitleMatch();
            titleMatch.title = newTitle;
            titleMatch.game = game;
            session.Save(titleMatch);

            // now add the other game details to our new game.
            // we check if there is an instance of each game detail first, and if there is
            // we create a match to our new game. If there isnt an instance of the game detail
            // already in our db, then we create one and match that to our game.

            // Year
            Service.Log.Info("Checking if year already exists in DB");
            // There can only be one result
            var yearResult = session.CreateCriteria<Year>()
                .Add(Restrictions.Eq("year", gameDetails.YearMade))
                .List<Year>();

            YearMatch yearMatch = new YearMatch();
            Year year;
            if (yearResult.Count > 0) // an instance was found
            {
                Service.Log.Info("Year already existed in DB");
                year = yearResult[0];
            }
            else // no instance was found
            {
                Service.Log.Info("Year did not exist in DB. Creating year");
                year = new Year();
                year.year = gameDetails.YearMade;
                session.Save(year);
            }

            Service.Log.Info("Creating match for year to game");
            yearMatch.game = game;
            yearMatch.year = year;
            session.Save(yearMatch);

            //Manual
            var manualResult = session.CreateCriteria<Manual>()
                .Add(Restrictions.Eq("manual", gameDetails.Manual))
                .List<Manual>();

            ManualMatch manualMatch = new ManualMatch();
            Manual manual;
            if (manualResult.Count > 0) // an instance in the db was found
                manual = manualResult[0];
            else
            {
                manual = new Manual();
                manual.manual = gameDetails.Manual;
                session.Save(manual);
            }

            manualMatch.game = game;
            manualMatch.manual = manual;
            session.Save(manualMatch);

            //Genre
            var genreResult = session.CreateCriteria<Genre>()
                .Add(Restrictions.Eq("genre", gameDetails.Genre))
                .List<Genre>();

            GenreMatch genreMatch = new GenreMatch();
            Genre genre;
            if (genreResult.Count > 0) // an instance in the db was found
                genre = genreResult[0];
            else
            {
                genre = new Genre();
                genre.genre = gameDetails.Genre;
                session.Save(genre);
            }

            genreMatch.game = game;
            genreMatch.genre = genre;
            session.Save(genreMatch);

            //Grade
            var gradeResult = session.CreateCriteria<Grade>()
                .Add(Restrictions.Eq("grade", gameDetails.Grade))
                .List<Grade>();

            GradeMatch gradeMatch = new GradeMatch();
            Grade grade;
            if (gradeResult.Count > 0) // an instance in the db was found
                grade = gradeResult[0];
            else
            {
                grade = new Grade();
                grade.grade = gameDetails.Grade;
                session.Save(grade);
            }

            gradeMatch.game = game;
            gradeMatch.grade = grade;
            session.Save(gradeMatch);

            // Description
            var descriptionResult = session.CreateCriteria<Description>()
                .Add(Restrictions.Eq("description", gameDetails.Description))
                .List<Description>();

            DescriptionMatch descriptionMatch = new DescriptionMatch();
            Description description;
            if (descriptionResult.Count > 0) // an instance in the db was found
                description = descriptionResult[0];
            else
            {
                description = new Description();
                description.description = gameDetails.Description;
                session.Save(description);
            }

            descriptionMatch.game = game;
            descriptionMatch.description = description;
            session.Save(descriptionMatch);

            //ImageBack
            var ImageBackResult = session.CreateCriteria<ImageBack>()
                .Add(Restrictions.Eq("url", gameDetails.ImageBack))
                .List<ImageBack>();

            ImageBackMatch ImageBackMatch = new ImageBackMatch();
            ImageBack ImageBack;
            if (ImageBackResult.Count > 0) // an instance in the db was found
                ImageBack = ImageBackResult[0];
            else
            {
                ImageBack = new ImageBack();
                ImageBack.url = gameDetails.ImageBack;
                session.Save(ImageBack);
            }

            ImageBackMatch.game = game;
            ImageBackMatch.ImageBack = ImageBack;
            session.Save(ImageBackMatch);

            //ImageFront
            var ImageFrontResult = session.CreateCriteria<ImageFront>()
                .Add(Restrictions.Eq("url", gameDetails.ImageFront))
                .List<ImageFront>();

            ImageFrontMatch ImageFrontMatch = new ImageFrontMatch();
            ImageFront ImageFront;
            if (ImageFrontResult.Count > 0) // an instance in the db was found
                ImageFront = ImageFrontResult[0];
            else
            {
                ImageFront = new ImageFront();
                ImageFront.url = gameDetails.ImageFront;
                session.Save(ImageFront);
            }

            ImageFrontMatch.game = game;
            ImageFrontMatch.ImageFront = ImageFront;
            session.Save(ImageFrontMatch);

            //ImageTitleScreen
            var ImageTitleScreenResult = session.CreateCriteria<ImageTitleScreen>()
                .Add(Restrictions.Eq("url", gameDetails.ImageTitleScreen))
                .List<ImageTitleScreen>();

            ImageTitleScreenMatch ImageTitleScreenMatch = new ImageTitleScreenMatch();
            ImageTitleScreen ImageTitleScreen;
            if (ImageTitleScreenResult.Count > 0) // an instance in the db was found
                ImageTitleScreen = ImageTitleScreenResult[0];
            else
            {
                ImageTitleScreen = new ImageTitleScreen();
                ImageTitleScreen.url = gameDetails.ImageTitleScreen;
                session.Save(ImageTitleScreen);
            }

            ImageTitleScreenMatch.game = game;
            ImageTitleScreenMatch.ImageTitleScreen = ImageTitleScreen;
            session.Save(ImageTitleScreenMatch);

            //ImageIngame
            var ImageIngameResult = session.CreateCriteria<ImageIngame>()
                .Add(Restrictions.Eq("url", gameDetails.ImageIngame))
                .List<ImageIngame>();

            ImageIngameMatch ImageIngameMatch = new ImageIngameMatch();
            ImageIngame ImageIngame;
            if (ImageIngameResult.Count > 0) // an instance in the db was found
                ImageIngame = ImageIngameResult[0];
            else
            {
                ImageIngame = new ImageIngame();
                ImageIngame.url = gameDetails.ImageIngame;
                session.Save(ImageIngame);
            }

            ImageIngameMatch.game = game;
            ImageIngameMatch.ImageIngame = ImageIngame;
            session.Save(ImageIngameMatch);

            //ImageFanart
            var ImageFanartResult = session.CreateCriteria<ImageFanart>()
                .Add(Restrictions.Eq("url", gameDetails.ImageFanart))
                .List<ImageFanart>();

            ImageFanartMatch ImageFanartMatch = new ImageFanartMatch();
            ImageFanart ImageFanart;
            if (ImageFanartResult.Count > 0) // an instance in the db was found
                ImageFanart = ImageFanartResult[0];
            else
            {
                ImageFanart = new ImageFanart();
                ImageFanart.url = gameDetails.ImageFanart;
                session.Save(ImageFanart);
            }

            ImageFanartMatch.game = game;
            ImageFanartMatch.ImageFanart = ImageFanart;
            session.Save(ImageFanartMatch);


            session.Flush();
        }
Exemple #3
0
        /// <summary>
        /// Takes new game details for a game we already have in the DB.
        /// It correctly puts the details in the right tables and increases counter when needed.
        /// </summary>
        /// <param name="DBgame">The object representing the game in the DB</param>
        /// <param name="newGameDetails">The new details for the game to be put into the DB</param>
        /// /// <param name="session">The session to the Database</param>
        void NewGameDetails(Game DBgame, GameDetails newGameDetails, ISession session)
        {
            Service.Log.Info("Adding new details to existing game");
            bool found = false;

            // Check Title
            if (!string.IsNullOrEmpty(newGameDetails.Title))
            {
                found = false;
                foreach (TitleMatch titleMatch in DBgame.titleMatches)
                {
                    if (titleMatch.title.title == newGameDetails.Title)
                    {
                        titleMatch.count++;
                        session.Update(titleMatch);
                        found = true;
                    }
                }
                if (!found)
                {
                    Title title = new Title();
                    title.title = newGameDetails.Title;
                    session.Save(title);

                    TitleMatch titleMatch = new TitleMatch();
                    titleMatch.title = title;
                    titleMatch.game  = DBgame;
                    session.Save(titleMatch);
                }
            }

            // Check Year
            if (!string.IsNullOrEmpty(newGameDetails.YearMade))
            {
                found = false;
                foreach (YearMatch yearMatch in DBgame.yearMatches)
                {
                    if (yearMatch.year.year == newGameDetails.YearMade)
                    {
                        yearMatch.count++;
                        session.Update(yearMatch);
                        found = true;
                    }
                }
                if (!found)
                {
                    Year year = new Year();
                    year.year = newGameDetails.YearMade;
                    session.Save(year);

                    YearMatch yearMatch = new YearMatch();
                    yearMatch.year = year;
                    yearMatch.game = DBgame;
                    session.Save(yearMatch);
                }
            }

            // check filename
            if (!string.IsNullOrEmpty(newGameDetails.Filename))
            {
                found = false;
                foreach (FilenameMatch filenameMatch in DBgame.filenameMatches)
                {
                    if (filenameMatch.filename.filename == newGameDetails.Filename)
                    {
                        filenameMatch.count++;
                        session.Update(filenameMatch);
                        found = true;
                    }
                }
                if (!found)
                {
                    Filename newFilename = new Filename();
                    newFilename.filename = newGameDetails.Filename;
                    session.Save(newFilename);

                    FilenameMatch filenameMatch = new FilenameMatch();
                    filenameMatch.filename = newFilename;
                    filenameMatch.game     = DBgame;
                    session.Save(filenameMatch);
                }
            }

            // check genre
            if (!string.IsNullOrEmpty(newGameDetails.Genre))
            {
                found = false;
                foreach (GenreMatch genreMatch in DBgame.genreMatches)
                {
                    if (genreMatch.genre.genre == newGameDetails.Genre)
                    {
                        genreMatch.count++;
                        session.Update(genreMatch);
                        found = true;
                    }
                }
                if (!found)
                {
                    Genre genre = new Genre();
                    genre.genre = newGameDetails.Genre;
                    session.Save(genre);

                    GenreMatch genreMatch = new GenreMatch();
                    genreMatch.genre = genre;
                    genreMatch.game  = DBgame;
                    session.Save(genreMatch);
                }
            }

            //check Grade
            if (!string.IsNullOrEmpty(newGameDetails.Grade))
            {
                found = false;
                foreach (GradeMatch gradeMatch in DBgame.gradeMatches)
                {
                    if (gradeMatch.grade.grade == newGameDetails.Grade)
                    {
                        gradeMatch.count++;
                        session.Update(gradeMatch);
                        found = true;
                    }
                }
                if (!found)
                {
                    Grade grade = new Grade();
                    grade.grade = newGameDetails.Grade;
                    session.Save(grade);

                    GradeMatch gradeMatch = new GradeMatch();
                    gradeMatch.grade = grade;
                    gradeMatch.game  = DBgame;
                    session.Save(gradeMatch);
                }
            }

            //check Description
            if (!string.IsNullOrEmpty(newGameDetails.Description))
            {
                found = false;
                foreach (DescriptionMatch descriptionMatch in DBgame.descriptionMatches)
                {
                    if (descriptionMatch.description.description == newGameDetails.Description)
                    {
                        descriptionMatch.count++;
                        session.Update(descriptionMatch);
                        found = true;
                    }
                }
                if (!found)
                {
                    Description description = new Description();
                    description.description = newGameDetails.Description;
                    session.Save(description);

                    DescriptionMatch descriptionMatch = new DescriptionMatch();
                    descriptionMatch.description = description;
                    descriptionMatch.game        = DBgame;
                    session.Save(descriptionMatch);
                }
            }

            // check hash
            if (!string.IsNullOrEmpty(newGameDetails.Hash))
            {
                found = false;
                foreach (HashMatch hashMatch in DBgame.hashMatches)
                {
                    if (hashMatch.hash.hash == newGameDetails.Hash)
                    {
                        hashMatch.count++;
                        session.Update(hashMatch);
                        found = true;
                    }
                }
                if (!found)
                {
                    Hash newHash = new Hash();
                    newHash.hash = newGameDetails.Hash;
                    session.Save(newHash);

                    HashMatch hashMatch = new HashMatch();
                    hashMatch.hash = newHash;
                    hashMatch.game = DBgame;
                    session.Save(hashMatch);
                }
            }

            // check manual
            if (!string.IsNullOrEmpty(newGameDetails.Manual))
            {
                found = false;
                foreach (ManualMatch manualMatch in DBgame.manualMatches)
                {
                    if (manualMatch.manual.manual == newGameDetails.Manual)
                    {
                        manualMatch.count++;
                        session.Update(manualMatch);
                        found = true;
                    }
                }
                if (!found)
                {
                    Manual manual = new Manual();
                    manual.manual = newGameDetails.Manual;
                    session.Save(manual);

                    ManualMatch manualMatch = new ManualMatch();
                    manualMatch.manual = manual;
                    manualMatch.game   = DBgame;
                    session.Save(manualMatch);
                }
            }

            // check ImageBack
            if (!string.IsNullOrEmpty(newGameDetails.ImageBack))
            {
                found = false;
                foreach (ImageBackMatch ImageBackMatch in DBgame.ImageBackMatches)
                {
                    if (ImageBackMatch.ImageBack.url == newGameDetails.ImageBack)
                    {
                        ImageBackMatch.count++;
                        session.Update(ImageBackMatch);
                        found = true;
                    }
                }
                if (!found)
                {
                    ImageBack ImageBack = new ImageBack();
                    ImageBack.url = newGameDetails.ImageBack;
                    session.Save(ImageBack);

                    ImageBackMatch ImageBackMatch = new ImageBackMatch();
                    ImageBackMatch.ImageBack = ImageBack;
                    ImageBackMatch.game      = DBgame;
                    session.Save(ImageBackMatch);
                }
            }

            // check ImageFront
            if (!string.IsNullOrEmpty(newGameDetails.ImageFront))
            {
                found = false;
                foreach (ImageFrontMatch ImageFrontMatch in DBgame.ImageFrontMatches)
                {
                    if (ImageFrontMatch.ImageFront.url == newGameDetails.ImageFront)
                    {
                        ImageFrontMatch.count++;
                        session.Update(ImageFrontMatch);
                        found = true;
                    }
                }
                if (!found)
                {
                    ImageFront ImageFront = new ImageFront();
                    ImageFront.url = newGameDetails.ImageFront;
                    session.Save(ImageFront);

                    ImageFrontMatch ImageFrontMatch = new ImageFrontMatch();
                    ImageFrontMatch.ImageFront = ImageFront;
                    ImageFrontMatch.game       = DBgame;
                    session.Save(ImageFrontMatch);
                }
            }

            // check ImageFanart
            if (!string.IsNullOrEmpty(newGameDetails.ImageFanart))
            {
                found = false;
                foreach (ImageFanartMatch ImageFanartMatch in DBgame.ImageFanartMatches)
                {
                    if (ImageFanartMatch.ImageFanart.url == newGameDetails.ImageFanart)
                    {
                        ImageFanartMatch.count++;
                        session.Update(ImageFanartMatch);
                        found = true;
                    }
                }
                if (!found)
                {
                    ImageFanart ImageFanart = new ImageFanart();
                    ImageFanart.url = newGameDetails.ImageFanart;
                    session.Save(ImageFanart);

                    ImageFanartMatch ImageFanartMatch = new ImageFanartMatch();
                    ImageFanartMatch.ImageFanart = ImageFanart;
                    ImageFanartMatch.game        = DBgame;
                    session.Save(ImageFanartMatch);
                }
            }

            //check ImageIngame
            if (!string.IsNullOrEmpty(newGameDetails.ImageIngame))
            {
                found = false;
                foreach (ImageIngameMatch ImageIngameMatch in DBgame.ImageIngameMatches)
                {
                    if (ImageIngameMatch.ImageIngame.url == newGameDetails.ImageIngame)
                    {
                        ImageIngameMatch.count++;
                        session.Update(ImageIngameMatch);
                        found = true;
                    }
                }
                if (!found)
                {
                    ImageIngame ImageIngame = new ImageIngame();
                    ImageIngame.url = newGameDetails.ImageIngame;
                    session.Save(ImageIngame);

                    ImageIngameMatch ImageIngameMatch = new ImageIngameMatch();
                    ImageIngameMatch.ImageIngame = ImageIngame;
                    ImageIngameMatch.game        = DBgame;
                    session.Save(ImageIngameMatch);
                }
            }

            // check ImageTitleScreen
            if (!string.IsNullOrEmpty(newGameDetails.ImageTitleScreen))
            {
                found = false;
                foreach (ImageTitleScreenMatch ImageTitleScreenMatch in DBgame.ImageTitleScreenMatches)
                {
                    if (ImageTitleScreenMatch.ImageTitleScreen.url == newGameDetails.ImageTitleScreen)
                    {
                        ImageTitleScreenMatch.count++;
                        session.Update(ImageTitleScreenMatch);
                        found = true;
                    }
                }
                if (!found)
                {
                    ImageTitleScreen ImageTitleScreen = new ImageTitleScreen();
                    ImageTitleScreen.url = newGameDetails.ImageTitleScreen;
                    session.Save(ImageTitleScreen);

                    ImageTitleScreenMatch ImageTitleScreenMatch = new ImageTitleScreenMatch();
                    ImageTitleScreenMatch.ImageTitleScreen = ImageTitleScreen;
                    ImageTitleScreenMatch.game             = DBgame;
                    session.Save(ImageTitleScreenMatch);
                }
            }

            session.Flush();
        }
Exemple #4
0
        /// <summary>
        /// Takes new game details for a game we already have in the DB.
        /// It correctly puts the details in the right tables and increases counter when needed.
        /// </summary>
        /// <param name="DBgame">The object representing the game in the DB</param>
        /// <param name="newGameDetails">The new details for the game to be put into the DB</param>
        /// /// <param name="session">The session to the Database</param>
        void NewGameDetails(Game DBgame, GameDetails newGameDetails, ISession session)
        {
            Service.Log.Info("Adding new details to existing game");
            bool found = false;
            // Check Title
            if (!string.IsNullOrEmpty(newGameDetails.Title))
            {
                found = false;
                foreach (TitleMatch titleMatch in DBgame.titleMatches)
                {
                    if (titleMatch.title.title == newGameDetails.Title)
                    {
                        titleMatch.count++;
                        session.Update(titleMatch);
                        found = true;
                    }
                }
                if (!found)
                {
                    Title title = new Title();
                    title.title = newGameDetails.Title;
                    session.Save(title);

                    TitleMatch titleMatch = new TitleMatch();
                    titleMatch.title = title;
                    titleMatch.game = DBgame;
                    session.Save(titleMatch);
                }
            }

            // Check Year
            if (!string.IsNullOrEmpty(newGameDetails.YearMade))
            {
                found = false;
                foreach (YearMatch yearMatch in DBgame.yearMatches)
                {
                    if (yearMatch.year.year == newGameDetails.YearMade)
                    {
                        yearMatch.count++;
                        session.Update(yearMatch);
                        found = true;
                    }
                }
                if (!found)
                {
                    Year year = new Year();
                    year.year = newGameDetails.YearMade;
                    session.Save(year);

                    YearMatch yearMatch = new YearMatch();
                    yearMatch.year = year;
                    yearMatch.game = DBgame;
                    session.Save(yearMatch);
                }
            }

            // check filename
            if (!string.IsNullOrEmpty(newGameDetails.Filename))
            {
                found = false;
                foreach (FilenameMatch filenameMatch in DBgame.filenameMatches)
                {
                    if (filenameMatch.filename.filename == newGameDetails.Filename)
                    {
                        filenameMatch.count++;
                        session.Update(filenameMatch);
                        found = true;
                    }
                }
                if (!found)
                {
                    Filename newFilename = new Filename();
                    newFilename.filename = newGameDetails.Filename;
                    session.Save(newFilename);

                    FilenameMatch filenameMatch = new FilenameMatch();
                    filenameMatch.filename = newFilename;
                    filenameMatch.game = DBgame;
                    session.Save(filenameMatch);
                }
            }

            // check genre
            if (!string.IsNullOrEmpty(newGameDetails.Genre))
            {
                found = false;
                foreach (GenreMatch genreMatch in DBgame.genreMatches)
                {
                    if (genreMatch.genre.genre == newGameDetails.Genre)
                    {
                        genreMatch.count++;
                        session.Update(genreMatch);
                        found = true;
                    }
                }
                if (!found)
                {
                    Genre genre = new Genre();
                    genre.genre = newGameDetails.Genre;
                    session.Save(genre);

                    GenreMatch genreMatch = new GenreMatch();
                    genreMatch.genre = genre;
                    genreMatch.game = DBgame;
                    session.Save(genreMatch);
                }
            }

            //check Grade
            if (!string.IsNullOrEmpty(newGameDetails.Grade))
            {
                found = false;
                foreach (GradeMatch gradeMatch in DBgame.gradeMatches)
                {
                    if (gradeMatch.grade.grade == newGameDetails.Grade)
                    {
                        gradeMatch.count++;
                        session.Update(gradeMatch);
                        found = true;
                    }
                }
                if (!found)
                {
                    Grade grade = new Grade();
                    grade.grade = newGameDetails.Grade;
                    session.Save(grade);

                    GradeMatch gradeMatch = new GradeMatch();
                    gradeMatch.grade = grade;
                    gradeMatch.game = DBgame;
                    session.Save(gradeMatch);
                }
            }

            //check Description
            if (!string.IsNullOrEmpty(newGameDetails.Description))
            {
                found = false;
                foreach (DescriptionMatch descriptionMatch in DBgame.descriptionMatches)
                {
                    if (descriptionMatch.description.description == newGameDetails.Description)
                    {
                        descriptionMatch.count++;
                        session.Update(descriptionMatch);
                        found = true;
                    }
                }
                if (!found)
                {
                    Description description = new Description();
                    description.description = newGameDetails.Description;
                    session.Save(description);

                    DescriptionMatch descriptionMatch = new DescriptionMatch();
                    descriptionMatch.description = description;
                    descriptionMatch.game = DBgame;
                    session.Save(descriptionMatch);
                }
            }

            // check hash
            if (!string.IsNullOrEmpty(newGameDetails.Hash))
            {
                found = false;
                foreach (HashMatch hashMatch in DBgame.hashMatches)
                {
                    if (hashMatch.hash.hash == newGameDetails.Hash)
                    {
                        hashMatch.count++;
                        session.Update(hashMatch);
                        found = true;
                    }
                }
                if (!found)
                {
                    Hash newHash = new Hash();
                    newHash.hash = newGameDetails.Hash;
                    session.Save(newHash);

                    HashMatch hashMatch = new HashMatch();
                    hashMatch.hash = newHash;
                    hashMatch.game = DBgame;
                    session.Save(hashMatch);
                }
            }

            // check manual
            if (!string.IsNullOrEmpty(newGameDetails.Manual))
            {
                found = false;
                foreach (ManualMatch manualMatch in DBgame.manualMatches)
                {
                    if (manualMatch.manual.manual == newGameDetails.Manual)
                    {
                        manualMatch.count++;
                        session.Update(manualMatch);
                        found = true;
                    }
                }
                if (!found)
                {
                    Manual manual = new Manual();
                    manual.manual = newGameDetails.Manual;
                    session.Save(manual);

                    ManualMatch manualMatch = new ManualMatch();
                    manualMatch.manual = manual;
                    manualMatch.game = DBgame;
                    session.Save(manualMatch);
                }
            }
            
            // check ImageBack
            if (!string.IsNullOrEmpty(newGameDetails.ImageBack))
            {
                found = false;
                foreach (ImageBackMatch ImageBackMatch in DBgame.ImageBackMatches)
                {
                    if (ImageBackMatch.ImageBack.url == newGameDetails.ImageBack)
                    {
                        ImageBackMatch.count++;
                        session.Update(ImageBackMatch);
                        found = true;
                    }
                }
                if (!found)
                {
                    ImageBack ImageBack = new ImageBack();
                    ImageBack.url = newGameDetails.ImageBack;
                    session.Save(ImageBack);

                    ImageBackMatch ImageBackMatch = new ImageBackMatch();
                    ImageBackMatch.ImageBack = ImageBack;
                    ImageBackMatch.game = DBgame;
                    session.Save(ImageBackMatch);
                }
            }

            // check ImageFront
            if (!string.IsNullOrEmpty(newGameDetails.ImageFront))
            {
                found = false;
                foreach (ImageFrontMatch ImageFrontMatch in DBgame.ImageFrontMatches)
                {
                    if (ImageFrontMatch.ImageFront.url == newGameDetails.ImageFront)
                    {
                        ImageFrontMatch.count++;
                        session.Update(ImageFrontMatch);
                        found = true;
                    }
                }
                if (!found)
                {
                    ImageFront ImageFront = new ImageFront();
                    ImageFront.url = newGameDetails.ImageFront;
                    session.Save(ImageFront);

                    ImageFrontMatch ImageFrontMatch = new ImageFrontMatch();
                    ImageFrontMatch.ImageFront = ImageFront;
                    ImageFrontMatch.game = DBgame;
                    session.Save(ImageFrontMatch);
                }
            }

            // check ImageFanart
            if (!string.IsNullOrEmpty(newGameDetails.ImageFanart))
            {
                found = false;
                foreach (ImageFanartMatch ImageFanartMatch in DBgame.ImageFanartMatches)
                {
                    if (ImageFanartMatch.ImageFanart.url == newGameDetails.ImageFanart)
                    {
                        ImageFanartMatch.count++;
                        session.Update(ImageFanartMatch);
                        found = true;
                    }
                }
                if (!found)
                {
                    ImageFanart ImageFanart = new ImageFanart();
                    ImageFanart.url = newGameDetails.ImageFanart;
                    session.Save(ImageFanart);

                    ImageFanartMatch ImageFanartMatch = new ImageFanartMatch();
                    ImageFanartMatch.ImageFanart = ImageFanart;
                    ImageFanartMatch.game = DBgame;
                    session.Save(ImageFanartMatch);
                }
            }

            //check ImageIngame
            if (!string.IsNullOrEmpty(newGameDetails.ImageIngame))
            {
                found = false;
                foreach (ImageIngameMatch ImageIngameMatch in DBgame.ImageIngameMatches)
                {
                    if (ImageIngameMatch.ImageIngame.url == newGameDetails.ImageIngame)
                    {
                        ImageIngameMatch.count++;
                        session.Update(ImageIngameMatch);
                        found = true;
                    }
                }
                if (!found)
                {
                    ImageIngame ImageIngame = new ImageIngame();
                    ImageIngame.url = newGameDetails.ImageIngame;
                    session.Save(ImageIngame);

                    ImageIngameMatch ImageIngameMatch = new ImageIngameMatch();
                    ImageIngameMatch.ImageIngame = ImageIngame;
                    ImageIngameMatch.game = DBgame;
                    session.Save(ImageIngameMatch);
                }
            }

            // check ImageTitleScreen
            if (!string.IsNullOrEmpty(newGameDetails.ImageTitleScreen))
            {
                found = false;
                foreach (ImageTitleScreenMatch ImageTitleScreenMatch in DBgame.ImageTitleScreenMatches)
                {
                    if (ImageTitleScreenMatch.ImageTitleScreen.url == newGameDetails.ImageTitleScreen)
                    {
                        ImageTitleScreenMatch.count++;
                        session.Update(ImageTitleScreenMatch);
                        found = true;
                    }
                }
                if (!found)
                {
                    ImageTitleScreen ImageTitleScreen = new ImageTitleScreen();
                    ImageTitleScreen.url = newGameDetails.ImageTitleScreen;
                    session.Save(ImageTitleScreen);

                    ImageTitleScreenMatch ImageTitleScreenMatch = new ImageTitleScreenMatch();
                    ImageTitleScreenMatch.ImageTitleScreen = ImageTitleScreen;
                    ImageTitleScreenMatch.game = DBgame;
                    session.Save(ImageTitleScreenMatch);
                }
            }

            session.Flush();
        }