예제 #1
0
        public async Task <IElementView <HtmlElementSettings, HtmlElementContent> > ReadElementViewAsync(long tenantId, long elementId, IPageContext context)
        {
            // Get element settings
            HtmlElementSettings settings = await _elementRepository.ReadElementSettingsAsync(tenantId, elementId);

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

            // Get details of all preview images that may be displayed in the HTML content
            IEnumerable <long> blobIds = settings.BlobSets.Select(s => s.PreviewImageBlobId);
            IEnumerable <Blob> blobs   = await _storageService.ListBlobsAsync(tenantId, blobIds);

            IDictionary <long, BlobImage> blobsById = blobs.ToDictionary(b => b.BlobId, b => (BlobImage)b);

            // Construct dictionary containing details of all preview images keyed by blob set identifier
            IDictionary <long, HtmlPreviewImage> previewImagesByHtmlBlobId = settings.BlobSets
                                                                             .Where(s => blobsById.ContainsKey(s.PreviewImageBlobId))
                                                                             .Select(s => GetHtmlPreviewImageFromHtmlBlob(s, blobsById))
                                                                             .ToDictionary(i => i.BlobSetId, i => i);

            // Format HTML
            string formattedHtml = FormatHtml(settings.Html, previewImagesByHtmlBlobId);

            // Construct element content
            HtmlElementContent content = new HtmlElementContent
            {
                FormattedHtml = formattedHtml,
                Images        = previewImagesByHtmlBlobId
            };

            // Return element view
            return(new ElementView <HtmlElementSettings, HtmlElementContent>
            {
                Settings = settings,
                Content = content
            });
        }
예제 #2
0
        public async Task <IElementView <HtmlElementSettings, HtmlElementContent> > ReadElementViewAsync(long tenantId, long elementId, IPageContext context)
        {
            // Get element settings
            HtmlElementSettings settings = await GetElementSettingsAsync(tenantId, elementId);

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

            // Construct element content
            HtmlElementContent content = new HtmlElementContent
            {
                FormattedHtml = settings.Html,
                Images        = null// previewImagesByHtmlBlobId
            };

            // Return element view
            return(new ElementView <HtmlElementSettings, HtmlElementContent>
            {
                Settings = settings,
                Content = content
            });
        }