예제 #1
0
        public ActionResult Index()
        {
            HomeViewModel model = null;

            if (Directory.Exists(SOURCEROOTDIR))
            {
                classicRoot = new DirectoryInfo(SOURCEROOTDIR);
                gameDirectories = classicRoot.GetDirectories().ToList();

                model = new HomeViewModel();
                model.successfulTransfers = new List<Game>();
                model.failedTransfers = new List<Game>();

                gameDirectories.RemoveAt(0);

                this.InitCloudVariables();
                using (ZanyContext ctx = new ZanyContext()) // change to LiveDatabaseConnection for publish
                {
                    foreach (var directory in gameDirectories)
                    {
                        try
                        {
                            this.MigrateGame(directory.FullName, ctx);
                            model.successfulTransfers.Add(new Game() { Title = directory.Name });
                        }
                        catch (Exception ex)
                        {
                            model.failedTransfers.Add(new Game() { Title = directory.Name });
                        }
                    }
                }
            }
            else
            {
                throw new DirectoryNotFoundException("Directory does not exist");
            }

            return View(model);
        }
예제 #2
0
        private HomeViewModel MigrateGames()
        {
            HomeViewModel model = new HomeViewModel();
            model.successfulTransfers = new List<Game>();
            model.failedTransfers = new List<Game>();

            Game currentGame = null;

            using (ZanyContext ctx = new ZanyContext())
            {
                foreach (var item in gameDirectories)
                {
                    currentGame = new Game();

                    currentGame.Title = item.Name;
                    currentGame.ShortName = item.Name;

                    try
                    {
                        currentGame = this.MigrateTitleImage(currentGame, item, ctx);
                        ctx.Games.Add(currentGame);
                        ctx.SaveChanges();

                        model.successfulTransfers.Add(currentGame);
                    }
                    catch (Exception ex)
                    {
                        model.failedTransfers.Add(currentGame);
                    }
                }

                ctx.SaveChanges();

            }

            return model;
        }