Ejemplo n.º 1
0
        public async Task <string> GetSasForTable(string tableName)
        {
            if (String.IsNullOrEmpty(tableName))
            {
                return(null);
            }

            var table = await _azureStorage.GetTableReferenceAsync(tableName);

            if (table == null)
            {
                return(null);
            }

            var sas = table.GetSharedAccessSignature(
                new SharedAccessTablePolicy
            {
                Permissions            = SharedAccessTablePermissions.Query,
                SharedAccessExpiryTime = LvConfiguration.GetExpireTime(LvConfiguration.TokenExpireOffset)
            },
                null,  /* accessPolicyIdentifier */
                null,  /* startPartitionKey */
                null,  /* startRowKey */
                null,  /* endPartitionKey */
                null); /* endRowKey */

            return(string.Format(CultureInfo.InvariantCulture, "{0}{1}", table.Uri, sas));
        }
Ejemplo n.º 2
0
        public async Task DeleteFavoriteAsync(string userId, string partitionKey, string rowKey)
        {
            dynamic p = new ExpandoObject();

            p.Table = await _azureStorage.GetTableReferenceAsync(LvConstants.TableNameOfFavorite);

            p.UserId    = userId;
            p.RowKey    = rowKey;
            p.MediaType = partitionKey;

            await _deleteFavoriteCommand.ExecuteAsync(p);
        }
Ejemplo n.º 3
0
        public async Task <TumblrEntity> GetTumblrEntityAsync(string partitionKey, string rowKey)
        {
            dynamic p = new ExpandoObject();

            p.Table = await _azureStorage.GetTableReferenceAsync(LvConstants.TableNameOfTumblr);

            p.PartitionKey = partitionKey;
            p.RowKey       = rowKey;

            await _readEntityCommand.ExecuteAsync(p);

            return(p.Entity);
        }
Ejemplo n.º 4
0
        public async Task <CommentEntity> CreateCommentAsync(string partitionKey, PostedComment comment)
        {
            dynamic p = comment.ToExpandoObject();

            p.PartitionKey = partitionKey;
            p.Table        = await _azureStorage.GetTableReferenceAsync(LvConstants.TableNameOfComment);

            await _createCommentCommand.ExecuteAsync(p);

            return(p.Entity);
        }
Ejemplo n.º 5
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
                }
            }
        }
Ejemplo n.º 6
0
 public async Task <CloudTable> GetTableReferenceAsync(string tableName)
 {
     return(await _cache.Get(_cacheKeyFactory.CreateKey(RegionOfTable, tableName),
                             async() => await _azureStorage.GetTableReferenceAsync(tableName)));
 }