示例#1
0
        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;
        }
示例#2
0
        private List<Quote> GetGameQuotes(DirectoryInfo dir, FileInfo titleFile, string gameName)
        {
            List<Quote> retval = new List<Quote>();

            var files = dir.GetFiles()
                                .Where(x => x.FullName.Equals(titleFile.FullName) == false)
                                .Where(x => x.Extension.Equals(".png") || x.Extension.Equals(".jpg") || x.Extension.Equals(".gif"));

            for (int i = 0; i < files.Count(); i++)
            {
                var quote = new Quote();
                string mediaUri = this.UploadMediaFile(files.ElementAt(i), gameName + "_quote" + i, gameName);
                var quoteItem = new MediaItem() { MediaType = MediaTypes.Image, FileUrl = mediaUri };
                quote.MediaItems.Add(quoteItem);

                // init the quote
                quote.ContributorId = 1;

                retval.Add(quote);
            }

            return retval;
        }
示例#3
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();
        }