private async Task SetCustomModelTypeFieldsAsync(
            PageTemplateFileInfo pageTemplateFileInfo,
            string line,
            IExecutionContext executionContext
            )
        {
            // This regex find models with generic parameters and captures the last generic type
            // This could be the custom entity display model type and may have a namespace prefix
            const string CUSTOM_ENTITY_MODEL_REGEX = @"\s*@(?:inherits|model)\s+[\w+<.]*<([\w\.]+)";

            var match = Regex.Match(line, CUSTOM_ENTITY_MODEL_REGEX);

            if (match.Success)
            {
                // Try and find a matching custom entity model type.
                var modelType = _pageTemplateCustomEntityTypeMapper.Map(match.Groups[1].Value);

                if (modelType == null)
                {
                    return;
                }

                var query = new GetCustomEntityDefinitionMicroSummaryByDisplayModelTypeQuery();
                query.DisplayModelType = modelType;

                pageTemplateFileInfo.CustomEntityDefinition = await _queryExecutor.ExecuteAsync(query, executionContext);

                EntityNotFoundException.ThrowIfNull(pageTemplateFileInfo.CustomEntityDefinition, modelType);
                pageTemplateFileInfo.CustomEntityModelType = match.Groups[1].Value;

                pageTemplateFileInfo.PageType = PageType.CustomEntityDetails;
            }
        }
Пример #2
0
        /// <summary>
        /// Maps an EF PageTemplate record from the db into an PageTemplateMicroSummary
        /// object. If the db record is null then null is returned.
        /// </summary>
        /// <param name="dbPageTemplate">PageTemplate record from the database.</param>
        public virtual PageTemplateMicroSummary Map(PageTemplate dbPageTemplate)
        {
            if (dbPageTemplate == null)
            {
                return(null);
            }

            var pageTemplate = new PageTemplateMicroSummary();

            pageTemplate.CustomEntityDefinitionCode = dbPageTemplate.CustomEntityDefinitionCode;
            pageTemplate.FullPath       = dbPageTemplate.FullPath;
            pageTemplate.IsArchived     = dbPageTemplate.IsArchived;
            pageTemplate.Name           = dbPageTemplate.Name;
            pageTemplate.PageTemplateId = dbPageTemplate.PageTemplateId;

            pageTemplate.CustomEntityModelType = _pageTemplateCustomEntityTypeMapper.Map(dbPageTemplate.CustomEntityModelType);

            return(pageTemplate);
        }