예제 #1
0
        private static string ParseImpl(PageInfo pageInfo, ContextInfo contextInfo, ListInfo listInfo)
        {
            var parsedContent = string.Empty;

            var type = listInfo.Others.Get(AttributeType);

            if (string.IsNullOrEmpty(type))
            {
                type = BackgroundContentAttribute.ImageUrl;
            }

            var         contextType = EContextType.Each;
            IEnumerable dataSource  = null;

            if (StringUtils.EqualsIgnoreCase(type, TypePhoto))
            {
                contextType = EContextType.Photo;
                dataSource  = StlDataUtility.GetPhotosDataSource(pageInfo.PublishmentSystemInfo, contextInfo.ContentId, listInfo.StartNum, listInfo.TotalNum);
            }
            else
            {
                var contentInfo = contextInfo.ContentInfo;
                if (contentInfo != null)
                {
                    var eachList = new List <string>();

                    if (!string.IsNullOrEmpty(contentInfo.GetExtendedAttribute(type)))
                    {
                        eachList.Add(contentInfo.GetExtendedAttribute(type));
                    }

                    var extendAttributeName = ContentAttribute.GetExtendAttributeName(type);
                    var extendValues        = contentInfo.GetExtendedAttribute(extendAttributeName);
                    if (!string.IsNullOrEmpty(extendValues))
                    {
                        foreach (var extendValue in TranslateUtils.StringCollectionToStringList(extendValues))
                        {
                            eachList.Add(extendValue);
                        }
                    }

                    if (listInfo.StartNum > 1 || listInfo.TotalNum > 0)
                    {
                        if (listInfo.StartNum > 1)
                        {
                            var count = listInfo.StartNum - 1;
                            if (count > eachList.Count)
                            {
                                count = eachList.Count;
                            }
                            eachList.RemoveRange(0, count);
                        }

                        if (listInfo.TotalNum > 0)
                        {
                            if (listInfo.TotalNum < eachList.Count)
                            {
                                eachList.RemoveRange(listInfo.TotalNum, eachList.Count - listInfo.TotalNum);
                            }
                        }
                    }

                    dataSource = eachList;
                }
            }

            if (listInfo.Layout == ELayout.None)
            {
                var rptContents = new Repeater
                {
                    ItemTemplate =
                        new RepeaterTemplate(listInfo.ItemTemplate, listInfo.SelectedItems,
                                             listInfo.SelectedValues, listInfo.SeparatorRepeatTemplate, listInfo.SeparatorRepeat,
                                             pageInfo, contextType, contextInfo)
                };

                if (!string.IsNullOrEmpty(listInfo.HeaderTemplate))
                {
                    rptContents.HeaderTemplate = new SeparatorTemplate(listInfo.HeaderTemplate);
                }
                if (!string.IsNullOrEmpty(listInfo.FooterTemplate))
                {
                    rptContents.FooterTemplate = new SeparatorTemplate(listInfo.FooterTemplate);
                }
                if (!string.IsNullOrEmpty(listInfo.SeparatorTemplate))
                {
                    rptContents.SeparatorTemplate = new SeparatorTemplate(listInfo.SeparatorTemplate);
                }
                if (!string.IsNullOrEmpty(listInfo.AlternatingItemTemplate))
                {
                    rptContents.AlternatingItemTemplate = new RepeaterTemplate(listInfo.AlternatingItemTemplate, listInfo.SelectedItems, listInfo.SelectedValues, listInfo.SeparatorRepeatTemplate, listInfo.SeparatorRepeat, pageInfo, contextType, contextInfo);
                }

                rptContents.DataSource = dataSource;

                rptContents.DataBind();

                if (rptContents.Items.Count > 0)
                {
                    parsedContent = ControlUtils.GetControlRenderHtml(rptContents);
                }
            }
            else
            {
                var pdlContents = new ParsedDataList();

                TemplateUtility.PutListInfoToMyDataList(pdlContents, listInfo);

                pdlContents.ItemTemplate = new DataListTemplate(listInfo.ItemTemplate, listInfo.SelectedItems, listInfo.SelectedValues, listInfo.SeparatorRepeatTemplate, listInfo.SeparatorRepeat, pageInfo, contextType, contextInfo);
                if (!string.IsNullOrEmpty(listInfo.HeaderTemplate))
                {
                    pdlContents.HeaderTemplate = new SeparatorTemplate(listInfo.HeaderTemplate);
                }
                if (!string.IsNullOrEmpty(listInfo.FooterTemplate))
                {
                    pdlContents.FooterTemplate = new SeparatorTemplate(listInfo.FooterTemplate);
                }
                if (!string.IsNullOrEmpty(listInfo.SeparatorTemplate))
                {
                    pdlContents.SeparatorTemplate = new SeparatorTemplate(listInfo.SeparatorTemplate);
                }
                if (!string.IsNullOrEmpty(listInfo.AlternatingItemTemplate))
                {
                    pdlContents.AlternatingItemTemplate = new DataListTemplate(listInfo.AlternatingItemTemplate, listInfo.SelectedItems, listInfo.SelectedValues, listInfo.SeparatorRepeatTemplate, listInfo.SeparatorRepeat, pageInfo, contextType, contextInfo);
                }

                pdlContents.DataSource = dataSource;

                pdlContents.DataBind();

                if (pdlContents.Items.Count > 0)
                {
                    parsedContent = ControlUtils.GetControlRenderHtml(pdlContents);
                }
            }

            return(parsedContent);
        }
예제 #2
0
파일: StlEach.cs 프로젝트: ylqiu/cms-2
        private static string ParseImpl(PageInfo pageInfo, XmlNode node, ContextInfo contextInfo, ContentsDisplayInfo displayInfo)
        {
            var parsedContent = string.Empty;

            var type = displayInfo.OtherAttributes[Attribute_Type];

            if (string.IsNullOrEmpty(type))
            {
                type = BackgroundContentAttribute.ImageUrl;
            }
            var value     = displayInfo.OtherAttributes[Attribute_Value];
            var onPreLoad = displayInfo.OtherAttributes[Attribute_OnPreLoad];
            var onLoaded  = displayInfo.OtherAttributes[Attribute_OnLoaded];

            var         contextType = EContextType.Each;
            IEnumerable dataSource  = null;

            if (StringUtils.EqualsIgnoreCase(type, Type_Photo))
            {
                contextType = EContextType.Photo;
                dataSource  = StlDataUtility.GetPhotosDataSource(pageInfo.PublishmentSystemInfo, contextInfo.ContentID, displayInfo.StartNum, displayInfo.TotalNum);
            }
            else if (StringUtils.EqualsIgnoreCase(type, Type_Property))
            {
                if (contextInfo.ContextType == EContextType.Undefined)
                {
                    contextInfo.ContextType = EContextType.Content;
                }
                contextType = contextInfo.ContextType;
                dataSource  = StlDataUtility.GetPropertysDataSource(pageInfo.PublishmentSystemInfo, contextInfo.ContentInfo, contextType, value, displayInfo.StartNum, displayInfo.TotalNum);
            }
            else if (StringUtils.EqualsIgnoreCase(type, Type_Template))
            {
                var builder = new StringBuilder(node.InnerXml);
                StlParserManager.ParseInnerContent(builder, pageInfo, contextInfo);

                return($@"
<%for(i = 0; i < {value}.length; i ++) {{
    item = {value}[i]; %>
    {builder}
<%}}%>
");
            }
            else
            {
                var contentInfo = contextInfo.ContentInfo;
                if (contentInfo != null)
                {
                    var eachList = new List <string>();

                    if (!string.IsNullOrEmpty(contentInfo.GetExtendedAttribute(type)))
                    {
                        eachList.Add(contentInfo.GetExtendedAttribute(type));
                    }

                    var extendAttributeName = ContentAttribute.GetExtendAttributeName(type);
                    var extendValues        = contentInfo.GetExtendedAttribute(extendAttributeName);
                    if (!string.IsNullOrEmpty(extendValues))
                    {
                        foreach (string extendValue in TranslateUtils.StringCollectionToStringList(extendValues))
                        {
                            eachList.Add(extendValue);
                        }
                    }

                    if (displayInfo.StartNum > 1 || displayInfo.TotalNum > 0)
                    {
                        if (displayInfo.StartNum > 1)
                        {
                            var count = displayInfo.StartNum - 1;
                            if (count > eachList.Count)
                            {
                                count = eachList.Count;
                            }
                            eachList.RemoveRange(0, count);
                        }

                        if (displayInfo.TotalNum > 0)
                        {
                            if (displayInfo.TotalNum < eachList.Count)
                            {
                                eachList.RemoveRange(displayInfo.TotalNum, eachList.Count - displayInfo.TotalNum);
                            }
                        }
                    }

                    dataSource = eachList;
                }
            }

            if (displayInfo.Layout == ELayout.None)
            {
                var rptContents = new Repeater();

                rptContents.ItemTemplate = new RepeaterTemplate(displayInfo.ItemTemplate, displayInfo.SelectedItems, displayInfo.SelectedValues, displayInfo.SeparatorRepeatTemplate, displayInfo.SeparatorRepeat, pageInfo, contextType, contextInfo);
                if (!string.IsNullOrEmpty(displayInfo.HeaderTemplate))
                {
                    rptContents.HeaderTemplate = new SeparatorTemplate(displayInfo.HeaderTemplate);
                }
                if (!string.IsNullOrEmpty(displayInfo.FooterTemplate))
                {
                    rptContents.FooterTemplate = new SeparatorTemplate(displayInfo.FooterTemplate);
                }
                if (!string.IsNullOrEmpty(displayInfo.SeparatorTemplate))
                {
                    rptContents.SeparatorTemplate = new SeparatorTemplate(displayInfo.SeparatorTemplate);
                }
                if (!string.IsNullOrEmpty(displayInfo.AlternatingItemTemplate))
                {
                    rptContents.AlternatingItemTemplate = new RepeaterTemplate(displayInfo.AlternatingItemTemplate, displayInfo.SelectedItems, displayInfo.SelectedValues, displayInfo.SeparatorRepeatTemplate, displayInfo.SeparatorRepeat, pageInfo, contextType, contextInfo);
                }

                rptContents.DataSource = dataSource;

                rptContents.DataBind();

                if (rptContents.Items.Count > 0)
                {
                    parsedContent = ControlUtils.GetControlRenderHtml(rptContents);
                }
            }
            else
            {
                var pdlContents = new ParsedDataList();

                TemplateUtility.PutContentsDisplayInfoToMyDataList(pdlContents, displayInfo);

                pdlContents.ItemTemplate = new DataListTemplate(displayInfo.ItemTemplate, displayInfo.SelectedItems, displayInfo.SelectedValues, displayInfo.SeparatorRepeatTemplate, displayInfo.SeparatorRepeat, pageInfo, contextType, contextInfo);
                if (!string.IsNullOrEmpty(displayInfo.HeaderTemplate))
                {
                    pdlContents.HeaderTemplate = new SeparatorTemplate(displayInfo.HeaderTemplate);
                }
                if (!string.IsNullOrEmpty(displayInfo.FooterTemplate))
                {
                    pdlContents.FooterTemplate = new SeparatorTemplate(displayInfo.FooterTemplate);
                }
                if (!string.IsNullOrEmpty(displayInfo.SeparatorTemplate))
                {
                    pdlContents.SeparatorTemplate = new SeparatorTemplate(displayInfo.SeparatorTemplate);
                }
                if (!string.IsNullOrEmpty(displayInfo.AlternatingItemTemplate))
                {
                    pdlContents.AlternatingItemTemplate = new DataListTemplate(displayInfo.AlternatingItemTemplate, displayInfo.SelectedItems, displayInfo.SelectedValues, displayInfo.SeparatorRepeatTemplate, displayInfo.SeparatorRepeat, pageInfo, contextType, contextInfo);
                }

                pdlContents.DataSource = dataSource;

                pdlContents.DataBind();

                if (pdlContents.Items.Count > 0)
                {
                    parsedContent = ControlUtils.GetControlRenderHtml(pdlContents);
                }
            }

            return(parsedContent);
        }