Пример #1
0
        private void SetCustomModelTypeFields(PageTemplateFileInfo pageTemplateFileInfo, string line, IExecutionContext ex)
        {
            const string CUSTOM_ENTITY_MODEL_REGEX = @"CustomEntityDetailsPageViewModel<(\w+)";

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

            if (match.Success)
            {
                var modelType = _pageTemplateCustomEntityTypeMapper.Map(match.Groups[1].Value);

                if (modelType == null)
                {
                    throw new ApplicationException("ICustomEntityDisplayModel<T> of type " + match.Value + " not registered");
                }

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

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

                pageTemplateFileInfo.PageType = PageType.CustomEntityDetails;
            }
        }
        private void SetCustomModelTypeFields(PageTemplateFileInfo pageTemplateFileInfo, string line, IExecutionContext ex)
        {
            // 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 = _queryExecutor.Execute(query, ex);
                EntityNotFoundException.ThrowIfNull(pageTemplateFileInfo.CustomEntityDefinition, modelType);
                pageTemplateFileInfo.CustomEntityModelType = match.Groups[1].Value;

                pageTemplateFileInfo.PageType = PageType.CustomEntityDetails;
            }
        }
Пример #3
0
 public Type Resolve(PageTemplate source, PageTemplateMicroSummary destination, string sourceMember, Type destMember, ResolutionContext context)
 {
     return(_pageTemplateCustomEntityTypeMapper.Map(sourceMember));
 }