コード例 #1
0
ファイル: TableRepository.cs プロジェクト: robzelt/ASC
        /// <summary>
        /// This implementation uses Wintellect Azure Table library to overcome the limitation of 32KB for string attributes.
        /// The ARM template data is now stored as bytes and Wintellect library is used to automatically split and join the byte array based on pre-defined number of splits.
        /// Refer <see cref="TemplateEntity"/> for implementation details
        /// </summary>
        public async Task <TemplateViewModel> GetTemplate(string templateName)
        {
            var table = await TableUtil.GetTableReference(Tables.Products);

            var azTable = new AzureTable(table);

            var dynamicTemplateEntity = await TemplateEntity.FindAsync(azTable, partitionKey, templateName);

            var templateViewModel = new TemplateEntity(azTable, dynamicTemplateEntity);

            return(TemplateEntity.MapToViewModel(templateViewModel));
        }
コード例 #2
0
ファイル: TableRepository.cs プロジェクト: robzelt/ASC
        /// <summary>
        /// This implementation uses Wintellect Azure Table library to overcome the limitation of 32KB for string attributes.
        /// The ARM template data is now stored as bytes and Wintellect library is used to automatically split and join the byte array based on pre-defined number of splits.
        /// Refer <see cref="TemplateEntity"/> for implementation details
        /// </summary>
        public async Task DeleteTemplate(string rowKey)
        {
            var table = await TableUtil.GetTableReference(Tables.Products);

            var azTable = new AzureTable(table);

            var templateEntity = new TemplateEntity(azTable);

            templateEntity.RowKey       = rowKey;
            templateEntity.PartitionKey = partitionKey;
            templateEntity.ETag         = "*";

            await templateEntity.DeleteAsync();
        }
コード例 #3
0
        public static TemplateEntity MapFromViewModel(TemplateViewModel template, AzureTable azTable)
        {
            var templateEntity = new TemplateEntity(azTable);

            templateEntity.PartitionKey = template.PartitionKey;
            templateEntity.RowKey       = template.RowKey;

            templateEntity.TemplateData      = string.Empty;
            templateEntity.Name              = template.Name;
            templateEntity.Description       = template.Description;
            templateEntity.ProductImagePath  = template.ProductImagePath;
            templateEntity.ProductPrice      = template.ProductPrice;
            templateEntity.IsPublished       = template.IsPublished;
            templateEntity.TemplateDataBytes = GetTemplateBytes(template.TemplateData);
            return(templateEntity);
        }
コード例 #4
0
ファイル: TableRepository.cs プロジェクト: robzelt/ASC
        /// <summary>
        /// This implementation uses Wintellect Azure Table library to overcome the limitation of 32KB for string attributes.
        /// The ARM template data is now stored as bytes and Wintellect library is used to automatically split and join the byte array based on pre-defined number of splits.
        /// Refer <see cref="TemplateEntity"/> for implementation details
        /// </summary>
        public async Task <TemplateViewModel> SaveTemplate(TemplateViewModel template)
        {
            template.PartitionKey     = partitionKey;
            template.ProductImagePath = await SaveProductImageAsBlob(template.ProductImage);

            template.ProductImage = null; //Null out the base64 data

            var table = await TableUtil.GetTableReference(Tables.Products);

            var azTable = new AzureTable(table);

            var templateEntity = TemplateEntity.MapFromViewModel(template, azTable);

            var tableResult = await templateEntity.InsertOrReplaceAsync();

            var templateViewModel = TemplateEntity.MapToViewModel((TemplateEntity)tableResult.Result);

            return(templateViewModel);
        }
コード例 #5
0
ファイル: TableRepository.cs プロジェクト: robzelt/ASC
        /// <summary>
        /// This implementation uses Wintellect Azure Table library to overcome the limitation of 32KB for string attributes.
        /// The ARM template data is now stored as bytes and Wintellect library is used to automatically split and join the byte array based on pre-defined number of splits.
        /// Refer <see cref="TemplateEntity"/> for implementation details
        /// </summary>
        public async Task <List <TemplateViewModel> > GetTemplates()
        {
            var query = new TableQuery();

            query.FilterString = new TableFilterBuilder <TemplateEntity>()
                                 .And(te => te.PartitionKey, CompareOp.EQ, partitionKey);

            var table = await TableUtil.GetTableReference(Tables.Products);

            var azTable = new AzureTable(table);

            var dynamicTemplateEntities = table.ExecuteQuery(query);
            var templateList            = new List <TemplateViewModel>();

            foreach (var entity in dynamicTemplateEntities)
            {
                var templateEntity = new TemplateEntity(azTable, entity);
                templateList.Add(TemplateEntity.MapToViewModel(templateEntity));
            }

            return(templateList);
        }
コード例 #6
0
        public static TemplateViewModel MapToViewModel(TemplateEntity template)
        {
            var templateEntity = new TemplateViewModel();

            templateEntity.PartitionKey     = template.PartitionKey;
            templateEntity.RowKey           = template.RowKey;
            templateEntity.Name             = template.Name;
            templateEntity.Description      = template.Description;
            templateEntity.ProductImagePath = template.ProductImagePath;
            templateEntity.ProductPrice     = template.ProductPrice;
            templateEntity.IsPublished      = template.IsPublished;
            templateEntity.TemplateData     = GetTemplateDataString(template.TemplateDataBytes);

            //Code from backward compatility. In new approach, template data is stored as bytes.
            //But there might be old templates, where templatedata is still stored as string.
            if (string.IsNullOrEmpty(templateEntity.TemplateData))
            {
                templateEntity.TemplateData = template.TemplateData;
            }

            return(templateEntity);
        }