public GameRepository(ZanyContext ctx) : base(ctx) { genreRepo = new GenreRepository(ctx); mediaRepo = new MediaRepository(ctx); platformRepo = new PlatformRepository(ctx); }
public QuoteRepository(ZanyContext ctx) : base(ctx) { gameRepo = new GameRepository(ctx); mediaRepo = new MediaRepository(ctx); zanyRepo = new ZanyRepository(ctx); }
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); }
public ZanyRepository(ZanyContext ctx) : base(ctx) { }
public GenreRepository(ZanyContext ctx) : base() { this.context = ctx; }
public GenreRepository() : base() { this.context = new ZanyContext(); }
public PlatformRepository(ZanyContext ctx) : base() { this.context = ctx; }
public PlatformRepository() : base() { this.context = new ZanyContext(); }
public RepositoryBase(ZanyContext ctx) { context = ctx; }
public RepositoryBase() { context = new ZanyContext(); }
private Game MigrateTitleImage(Game game, DirectoryInfo gameDir, ZanyContext ctx) { FileInfo titleFile = null; List<FileInfo> files = gameDir.GetFiles().ToList(); titleFile = files.Where(x => x.Name.Contains("title")) .FirstOrDefault(); if (titleFile == null) { titleFile = files.Where(x => x.Name.Contains("logo")) .FirstOrDefault(); } CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["StorageConnection"].ConnectionString); CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); CloudBlobContainer imageContainer = blobClient.GetContainerReference("media"); imageContainer.CreateIfNotExists(); BlobContainerPermissions permissions = new BlobContainerPermissions(); permissions.PublicAccess = BlobContainerPublicAccessType.Container; imageContainer.SetPermissions(permissions); string blockBlobRef = game.ShortName + "/" + "title" + titleFile.Extension; CloudBlockBlob blockBlob = imageContainer.GetBlockBlobReference(blockBlobRef); using (var fileStream = System.IO.File.OpenRead(titleFile.FullName)) { blockBlob.UploadFromStream(fileStream); } this.IntializeGameData(game, ctx); MediaItem gameTitleItem = new MediaItem(); gameTitleItem.MediaType = MediaTypes.Image; gameTitleItem.FileUrl = blockBlob.Uri.ToString(); game.TitleMediaItem = ctx.MediaItems.Add(gameTitleItem); return game; }
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; }
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(); }
private Game IntializeGameData(Game game, ZanyContext ctx) { if (_region == null) { _region = ctx.Regions.FirstOrDefault(); } game.Region = _region; return game; }
public MediaRepository(ZanyContext context) { this.InitializeCloudConnection(); this.context = context; }