示例#1
0
        /// <summary>
        /// Maps a single page block data model to a concrete
        /// display model.
        /// </summary>
        /// <param name="typeName">The block type name e.g. 'PlainText', 'RawHtml'.</param>
        /// <param name="pageBlock">The version data to get the serialized model from.</param>
        /// <param name="publishStatus">
        /// The publish status of the parent page or custom entity
        /// being mapped. This is provided so dependent entities can use
        /// the same publish status.
        /// </param>
        /// <param name="executionContext">
        /// The execution context from the caller which can be used in
        /// any child queries to ensure any elevated permissions are
        /// passed down the chain of execution.
        /// </param>
        /// <returns>Mapped display model.</returns>
        public virtual async Task <IPageBlockTypeDisplayModel> MapDisplayModelAsync(
            string typeName,
            IEntityVersionPageBlock pageBlock,
            PublishStatusQuery publishStatus,
            IExecutionContext executionContext
            )
        {
            var mapped = await MapDisplayModelAsync(
                typeName,
                new IEntityVersionPageBlock[] { pageBlock },
                publishStatus,
                executionContext
                );

            var id = pageBlock.GetVersionBlockId();

            if (mapped.ContainsKey(id))
            {
                return(mapped[id]);
            }

            return(null);
        }
示例#2
0
        /// <summary>
        /// Locates and returns the correct templates for a block if it a custom template
        /// assigned, otherwise null is returned.
        /// </summary>
        /// <param name="pageBlock">An unmapped database block to locate the template for.</param>
        /// <param name="blockType">The block type associated with the block in which to look for the template.</param>
        public PageBlockTypeTemplateSummary GetCustomTemplate(IEntityVersionPageBlock pageBlock, PageBlockTypeSummary blockType)
        {
            if (pageBlock == null)
            {
                throw new ArgumentNullException(nameof(pageBlock));
            }
            if (blockType == null)
            {
                throw new ArgumentNullException(nameof(blockType));
            }

            if (!pageBlock.PageBlockTypeTemplateId.HasValue)
            {
                return(null);
            }

            var template = blockType
                           .Templates
                           .FirstOrDefault(t => t.PageBlockTypeTemplateId == pageBlock.PageBlockTypeTemplateId);

            Debug.Assert(template != null, string.Format("The block template with id {0} could not be found for {1} {2}", pageBlock.PageBlockTypeTemplateId, pageBlock.GetType().Name, pageBlock.GetVersionBlockId()));

            return(template);
        }
示例#3
0
        /// <summary>
        /// Locates and returns the correct templates for a block if it a custom template
        /// assigned, otherwise null is returned.
        /// </summary>
        /// <param name="pageBlock">An unmapped database block to locate the template for.</param>
        /// <param name="blockType">The block type associated with the block in which to look for the template.</param>
        public PageBlockTypeTemplateSummary GetCustomTemplate(IEntityVersionPageBlock pageBlock, PageBlockTypeSummary blockType)
        {
            if (pageBlock == null)
            {
                throw new ArgumentNullException(nameof(pageBlock));
            }
            if (blockType == null)
            {
                throw new ArgumentNullException(nameof(blockType));
            }

            if (!pageBlock.PageBlockTypeTemplateId.HasValue)
            {
                return(null);
            }

            var template = blockType
                           .Templates
                           .FirstOrDefault(t => t.PageBlockTypeTemplateId == pageBlock.PageBlockTypeTemplateId);

            if (template == null)
            {
                _logger.LogDebug("The block template with id {PageBlockTypeTemplateId} could not be found for {PageBlockType} {VersionBlockId}", pageBlock.PageBlockTypeTemplateId, pageBlock.GetType().Name, pageBlock.GetVersionBlockId());
            }

            return(template);
        }