Example #1
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;
        }
Example #2
0
        private void MigrateGame(string sourceDir, ZanyContext ctx)
        {
            DirectoryInfo gameDirectory = new DirectoryInfo(sourceDir);

            // create game entity
            Game game       = new Game();
            game.Title      = gameDirectory.Name;
            game.ShortName  = gameDirectory.Name;
            game            = this.IntializeGameData(game, ctx);

            // get file
            FileInfo fileInfo = this.GetTitleFile(gameDirectory);

            // add title media item
            string titleMediaUri = this.UploadMediaFile(fileInfo, "title", game.Title);
            MediaItem mediaItem = new MediaItem();
            mediaItem.MediaType = MediaTypes.Image;
            mediaItem.FileUrl = titleMediaUri;

            // get quotes
            List<Quote> gameQuotes = this.GetGameQuotes(gameDirectory, fileInfo, game.Title);

            // add entities
            game.TitleMediaItem = ctx.MediaItems.Add(mediaItem);
            foreach (var quote in gameQuotes)
            {
                game.Quotes.Add(quote);
            }
            ctx.Games.Add(game);

            // save context
            ctx.SaveChanges();
        }