public async Task <MDesign_BlockCollection> GetBlockCollectionAsync(int previewSize) { using var log = BeginFunction(nameof(DesignMicroService), nameof(GetBlockCollectionAsync)); try { using var ctx = QuiltContextFactory.Create(); var allTags = await ctx.Tags.Where(r => r.TagTypeCode == TagTypeCodes.Block).OrderBy(r => r.Value).Select(r => r.Value).ToArrayAsync().ConfigureAwait(false); var blockList = new List <MDesign_Block>(); var provider = new DatabaseBlockComponentProvider(QuiltContextFactory); foreach (var entry in provider.GetComponents(BlockComponent.TypeName, Constants.DefaultComponentCategory).OrderBy(r => r.Category).ThenBy(r => r.Name)) { var blockComponent = (BlockComponent)entry.Component; var data = Create.MDesign_Block(blockComponent, entry.Tags, previewSize); blockList.Add(data); } var result = new MDesign_BlockCollection() { Blocks = blockList, AllTags = allTags }; log.Result(result); return(result); } catch (Exception ex) { log.Exception(ex); throw; } }
public async Task <byte[]> GetBlockThumbnailAsync(string blockId, int thumbnailSize) { using var log = BeginFunction(nameof(DesignMicroService), nameof(GetBlockThumbnailAsync), blockId, thumbnailSize); try { await Task.CompletedTask; var provider = new DatabaseBlockComponentProvider(QuiltContextFactory); var entry = provider.GetComponent(BlockComponent.TypeName, Constants.DefaultComponentCategory, blockId); var node = entry.Component.Expand(true); var blockDimension = new Dimension(1, DimensionUnits.Inch); var thumbnailDimension = new Dimension(thumbnailSize, DimensionUnits.Pixel); var scale = new DimensionScale(1, DimensionUnits.Inch, thumbnailSize, DimensionUnits.Pixel); var pageLayoutNode = new PageLayoutNode(blockDimension * scale, blockDimension * scale); pageLayoutNode.LayoutSites[0].Node = node; pageLayoutNode.UpdateBounds(PathOrientation.CreateDefault(), scale); var renderer = new DesignRenderer(); using var image = renderer.CreateBitmap(node, DimensionScale.CreateIdentity(DimensionUnits.Pixel), false); using var ms = new MemoryStream(); image.Save(ms, ImageFormat.Png); var result = ms.ToArray(); log.Result(result); return(result); } catch (Exception ex) { log.Exception(ex); throw; } }