예제 #1
0
        /// <summary>
        /// Maps from a dto to an ITemplate
        /// </summary>
        /// <param name="dto"></param>
        /// <param name="axisDefinitions">
        /// This is a collection of template definitions ... either all templates, or the collection of child templates and it's parent template
        /// </param>
        /// <returns></returns>
        private ITemplate MapFromDto(TemplateDto dto, IUmbracoEntity[] axisDefinitions)
        {
            var factory  = new TemplateFactory();
            var template = factory.BuildEntity(dto, axisDefinitions, file => GetFileContent((Template)file, false));

            if (dto.NodeDto.ParentId > 0)
            {
                var masterTemplate = axisDefinitions.FirstOrDefault(x => x.Id == dto.NodeDto.ParentId);
                if (masterTemplate != null)
                {
                    template.MasterTemplateAlias = masterTemplate.Name;
                    template.MasterTemplateId    = new Lazy <int>(() => dto.NodeDto.ParentId);
                }
            }

            // get the infos (update date and virtual path) that will change only if
            // path changes - but do not get content, will get loaded only when required
            GetFileContent(template, true);

            //on initial construction we don't want to have dirty properties tracked
            // http://issues.umbraco.org/issue/U4-1946
            template.ResetDirtyProperties(false);

            return(template);
        }
예제 #2
0
        protected override ITemplate PerformGet(int id)
        {
            var sql = GetBaseQuery(false);

            sql.Where(GetBaseWhereClause(), new { Id = id });

            var dto = Database.Fetch <TemplateDto, NodeDto>(sql).FirstOrDefault();

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

            string csViewName     = string.Concat(dto.Alias, ".cshtml");
            string vbViewName     = string.Concat(dto.Alias, ".vbhtml");
            string masterpageName = string.Concat(dto.Alias, ".master");

            var factory  = new TemplateFactory();
            var template = factory.BuildEntity(dto);

            if (dto.Master.HasValue)
            {
                var masterTemplate = Get(dto.Master.Value);
                template.MasterTemplateAlias = masterTemplate.Alias;
                template.MasterTemplateId    = new Lazy <int>(() => dto.Master.Value);
            }

            if (_viewsFileSystem.FileExists(csViewName))
            {
                PopulateViewTemplate(template, csViewName);
            }
            else if (_viewsFileSystem.FileExists(vbViewName))
            {
                PopulateViewTemplate(template, vbViewName);
            }
            else
            {
                if (_masterpagesFileSystem.FileExists(masterpageName))
                {
                    PopulateMasterpageTemplate(template, masterpageName);
                }
            }

            //on initial construction we don't want to have dirty properties tracked
            // http://issues.umbraco.org/issue/U4-1946
            template.ResetDirtyProperties(false);

            return(template);
        }
예제 #3
0
        protected override ITemplate PerformGet(int id)
        {
            var sql = GetBaseQuery(false);

            sql.Where(GetBaseWhereClause(), new { Id = id });

            var dto = Database.Fetch <TemplateDto, NodeDto>(sql).FirstOrDefault();

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

            string csViewName     = string.Concat(dto.Alias, ".cshtml");
            string vbViewName     = string.Concat(dto.Alias, ".vbhtml");
            string masterpageName = string.Concat(dto.Alias, ".master");

            var factory  = new TemplateFactory();
            var template = factory.BuildEntity(dto);

            if (dto.Master.HasValue)
            {
                var masterTemplate = Get(dto.Master.Value);
                template.MasterTemplateAlias = masterTemplate.Alias;
                template.MasterTemplateId    = new Lazy <int>(() => dto.Master.Value);
            }

            if (_viewsFileSystem.FileExists(csViewName))
            {
                PopulateViewTemplate(template, csViewName);
            }
            else if (_viewsFileSystem.FileExists(vbViewName))
            {
                PopulateViewTemplate(template, vbViewName);
            }
            else
            {
                if (_masterpagesFileSystem.FileExists(masterpageName))
                {
                    PopulateMasterpageTemplate(template, masterpageName);
                }
            }

            return(template);
        }
예제 #4
0
    /// <summary>
    ///     Maps from a dto to an ITemplate
    /// </summary>
    /// <param name="dto"></param>
    /// <param name="axisDefinitions">
    ///     This is a collection of template definitions ... either all templates, or the collection of child templates and
    ///     it's parent template
    /// </param>
    /// <returns></returns>
    private ITemplate MapFromDto(TemplateDto dto, IUmbracoEntity[] axisDefinitions)
    {
        Template template = TemplateFactory.BuildEntity(_shortStringHelper, dto, axisDefinitions,
                                                        file => GetFileContent((Template)file, false));

        if (dto.NodeDto.ParentId > 0)
        {
            IUmbracoEntity?masterTemplate = axisDefinitions.FirstOrDefault(x => x.Id == dto.NodeDto.ParentId);
            if (masterTemplate != null)
            {
                template.MasterTemplateAlias = masterTemplate.Name;
                template.MasterTemplateId    = new Lazy <int>(() => dto.NodeDto.ParentId);
            }
        }

        // get the infos (update date and virtual path) that will change only if
        // path changes - but do not get content, will get loaded only when required
        GetFileContent(template, true);

        // reset dirty initial properties (U4-1946)
        template.ResetDirtyProperties(false);

        return(template);
    }