Пример #1
0
        static void Main(string[] args)
        {
            try
            {
                var gameService = new GameService();

                var gameIds = Filesystem.GetGameIds();

                using (var db = new DatabaseContext())
                {
                    foreach (var existingGame in db.Games)
                    {
                        db.Remove(existingGame);
                    }

                    foreach (var existingDisc in db.Discs)
                    {
                        db.Remove(existingDisc);
                    }

                    db.SaveChanges();

                    var infos = gameIds.Select(id => gameService.GetGameInfo(id));

                    foreach (var info in infos)
                    {
                        var game = new Game()
                        {
                            Id        = info.Id,
                            Title     = info.Title,
                            Publisher = info.Publisher,
                            Year      = info.Year,
                            Players   = info.Players
                        };

                        game.Discs = info.DiscIds.Select((discId, index) => new Disc()
                        {
                            GameId = info.Id, DiscNumber = index + 1, DiscBasename = discId
                        }).ToList();

                        db.Add(game);

                        Console.WriteLine($"Added game [{game.Id}] {game.Title} to the database");
                    }

                    db.SaveChanges();

                    Console.WriteLine($"Successfully inserted {gameIds.Count} games");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.ReadLine();
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            var gameService = new GameService();

            var gameIds = Filesystem.GetGameIds();

            using (var db = new DatabaseContext())
            {
                foreach (var existingGame in db.Games)
                {
                    db.Remove(existingGame);
                }

                foreach (var existingDisc in db.Discs)
                {
                    db.Remove(existingDisc);
                }

                db.SaveChanges();

                foreach (var id in gameIds)
                {
                    var gameInfo = gameService.GetGameInfo(id);

                    var game = new Game()
                    {
                        Id        = id,
                        Title     = gameInfo.Title,
                        Publisher = gameInfo.Publisher,
                        Year      = gameInfo.Year,
                        Players   = gameInfo.Players
                    };

                    var i = 1;

                    foreach (var discId in gameInfo.DiscIds)
                    {
                        var disc = new Disc()
                        {
                            GameId       = id,
                            DiscNumber   = i,
                            DiscBasename = discId
                        };

                        i++;

                        db.Add(disc);
                    }

                    db.Add(game);
                }

                db.SaveChanges();
            }
        }
Пример #3
0
        static void SyncGames(DatabaseContext db, IConfigurationRoot configuration)
        {
            try
            {
                var gameService = new GameService(configuration);

                var gameIds = Filesystem.GetGameIds(configuration["GamesPath"]);


                foreach (var existingGame in db.Games)
                {
                    db.Remove(existingGame);
                }

                foreach (var existingDisc in db.Discs)
                {
                    db.Remove(existingDisc);
                }

                db.SaveChanges();

                var infos = new List <GameInfo>();

                foreach (var id in gameIds)
                {
                    try
                    {
                        infos.Add(gameService.GetGameInfo(id));
                        Console.WriteLine("");
                    }
                    catch
                    {
                    }
                }

                foreach (var info in infos)
                {
                    var game = new Game()
                    {
                        Id        = info.Id,
                        Title     = info.Title,
                        Publisher = info.Publisher,
                        Year      = info.Year,
                        Players   = info.Players
                    };

                    game.Discs = info.DiscIds.Select((discId, index) => new Disc()
                    {
                        GameId = info.Id, DiscNumber = index + 1, DiscBasename = discId
                    }).ToList();

                    db.Add(game);

                    Console.WriteLine($"Added game [{game.Id}] {game.Title} to the database");
                }

                try
                {
                    db.SaveChanges();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.InnerException);
                }

                Console.WriteLine($"Successfully inserted {gameIds.Count} games");
            }
            catch (Exception e)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(e.Message);
                Console.ResetColor();
                Console.ReadLine();
            }
        }
Пример #4
0
        static void Main(string[] args)
        {
            var gameService = new GameService();

            var gameIds = Filesystem.GetGameIds();

            using (var db = new DatabaseContext())
            {
                foreach (var existingGame in db.Games)
                {
                    db.Remove(existingGame);
                }

                foreach (var existingDisc in db.Discs)
                {
                    db.Remove(existingDisc);
                }

                db.SaveChanges();

                foreach (var id in gameIds)
                {
                    var gameInfo = gameService.GetGameInfo(id);

                    var game = new Game()
                    {
                        Id        = id,
                        Title     = gameInfo.Title,
                        Publisher = gameInfo.Publisher,
                        Year      = gameInfo.Year,
                        Players   = gameInfo.Players
                    };

                    var i = 1;

                    foreach (var discId in gameInfo.DiscIds)
                    {
                        var disc = new Disc()
                        {
                            GameId       = id,
                            DiscNumber   = i,
                            DiscBasename = discId
                        };

                        i++;

                        db.Add(disc);
                    }

                    db.Add(game);
                }

                db.SaveChanges();

                // Generate mounting script
                var executingDirectory = Utilities.Filesystem.GetExecutingDirectory();

                using (TextWriter mountScript = new StreamWriter($"{executingDirectory}\\..\\System\\MountGames.sh"))
                {
                    mountScript.NewLine = "\n";

                    foreach (var id in gameIds)
                    {
                        mountScript.WriteLine($"mount -o bind /media/Games/{id} /gaadata/{id}");
                    }
                }
            }
        }