Exemple #1
0
        public async Task UploadTestTumblrs()
        {
            var uriFactory         = new UriFactory();
            var tableEntityFactory = new TableEntityFactory(uriFactory);

            var uploadBlobCommand   = new UploadBlobFromStreamCommand();
            var generateSCommand    = new ResizeCommand(ResizeCommand.ScalingType.CropScaling, 128);
            var generateMCommand    = new ResizeCommand(ResizeCommand.ScalingType.CropScaling, 300);
            var generateLCommand    = new ResizeCommand(ResizeCommand.ScalingType.FitScaling, 1280);
            var createTumblrCommand = new CreateTumblrCommand
            {
                UriFactory         = uriFactory,
                TableEntityFactory = tableEntityFactory
            };
            var createTableEntitiesCommand = new CreateTableEntitiesCommand();
            var command = new WriteTumblrCommand(
                _azureStorage, uploadBlobCommand,
                generateLCommand, generateMCommand, generateSCommand,
                createTumblrCommand,
                createTableEntitiesCommand);

            foreach (var testImage in GetTestImages())
            {
                using (Stream stream = File.OpenRead(testImage))
                {
                    // upload
                    dynamic pTumblr = new ExpandoObject();

                    // Blob
                    pTumblr.Container = await _azureStorage.GetContainerReferenceAsync(LvConstants.ContainerNameOfImage);

                    pTumblr.Stream   = stream;
                    pTumblr.BlobName = Path.GetFileName(testImage);

                    // Create Tumblr
                    pTumblr.PartitionKey = LvConstants.MediaTypeOfImage;
                    pTumblr.TumblrText   = new TumblrText
                    {
                        Text     = "你也曾当过笨蛋,也曾试着当瞎子当聋子的去信任一个人,你也知道世界上最可悲的就是自我欺骗,但是人笨过傻过瞎过就够了,你更要懂得爱自己,而不是一直重蹈覆辙,还自以为多痴情。",
                        Category = TumblrCategory.C2
                    };

                    // Table
                    pTumblr.Table = await _azureStorage.GetTableReferenceAsync(LvConstants.TableNameOfTumblr);

                    // Execute
                    await command.ExecuteAsync(pTumblr);

                    // Create Tumblr End
                }
            }
        }
Exemple #2
0
        public async Task ExecuteAsync(dynamic p)
        {
            Stream original = p.Stream;

            await _uploadBlobCommand.ExecuteAsync(p);

            p.MediaUri = p.BlobUri;

            p.Stream = original;
            await _generateLCommand.ExecuteAsync(p);

            p.Container = await _azureStorage.GetContainerReferenceAsync(LvConstants.ContainerNameOfLargeImage);

            await _uploadBlobCommand.ExecuteAsync(p);

            p.MediaLargeUri = p.BlobUri;

            p.Stream = original;
            await _generateMCommand.ExecuteAsync(p);

            p.Container = await _azureStorage.GetContainerReferenceAsync(LvConstants.ContainerNameOfMediumImage);

            await _uploadBlobCommand.ExecuteAsync(p);

            p.MediaMediumUri = p.BlobUri;

            p.Stream = original;
            await _generateSCommand.ExecuteAsync(p);

            p.Container = await _azureStorage.GetContainerReferenceAsync(LvConstants.ContainerNameOfSmallImage);

            await _uploadBlobCommand.ExecuteAsync(p);

            p.MediaSmallUri = p.BlobUri;

            await _createTumblrCommand.ExecuteAsync(p);

            await _createTableEntitiesCommand.ExecuteAsync(p);
        }
Exemple #3
0
 public async Task <CloudBlobContainer> GetContainerReferenceAsync(string containerName)
 {
     return(await _cache.Get(_cacheKeyFactory.CreateKey(RegionOfBlob, containerName),
                             async() => await _azureStorage.GetContainerReferenceAsync(containerName)));
 }