当前位置: 首页>>代码示例>>C#>>正文


C# RenderState.CopyElementChildren方法代码示例

本文整理汇总了C#中RenderState.CopyElementChildren方法的典型用法代码示例。如果您正苦于以下问题:C# RenderState.CopyElementChildren方法的具体用法?C# RenderState.CopyElementChildren怎么用?C# RenderState.CopyElementChildren使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在RenderState的用法示例。


在下文中一共展示了RenderState.CopyElementChildren方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: processScheduledElement


//.........这里部分代码省略.........
                    // Check the schedule range:
                    displayContent = (st.Engine.ViewDate >= fromDate && st.Engine.ViewDate < toDate);
                }
                else if (xr.LocalName == "content")
                {
                    if (hasElse)
                    {
                        st.Error("'content' element must come before 'else' element");
                        st.SkipElementAndChildren("content");
                        if (!xr.IsEmptyElement)
                            xr.ReadEndElement(/* "content" */);
                        continue;
                    }

                    if (hasContent)
                    {
                        st.Error("only one 'content' element may exist in cms-scheduled");
                        st.SkipElementAndChildren("content");
                        if (!xr.IsEmptyElement)
                            xr.ReadEndElement(/* "content" */);
                        continue;
                    }

                    hasContent = true;
                    if (!hasRanges)
                    {
                        st.Error("no 'range' elements found before 'content' element in cms-scheduled");
                        displayContent = false;
                    }

                    if (displayContent)
                    {
                        // Stream the inner content into the StringBuilder until we get back to the end </content> element.
                        await st.CopyElementChildren("content").ConfigureAwait(continueOnCapturedContext: false);
                        if (!xr.IsEmptyElement)
                            xr.ReadEndElement(/* "content" */);
                    }
                    else
                    {
                        // Skip the inner content entirely:
                        st.SkipElementAndChildren("content");
                        if (!xr.IsEmptyElement)
                            xr.ReadEndElement(/* "content" */);
                    }
                }
                else if (xr.LocalName == "else")
                {
                    if (!hasContent)
                    {
                        st.Error("'content' element must come before 'else' element");
                        st.SkipElementAndChildren("else");
                        if (!xr.IsEmptyElement)
                            xr.ReadEndElement(/* "else" */);
                        continue;
                    }
                    if (hasElse)
                    {
                        st.Error("only one 'else' element may exist in cms-scheduled");
                        st.SkipElementAndChildren("else");
                        if (!xr.IsEmptyElement)
                            xr.ReadEndElement(/* "else" */);
                        continue;
                    }

                    hasElse = true;
                    if (!hasRanges)
开发者ID:JamesDunne,项目名称:ivo-cms,代码行数:67,代码来源:ScheduledElementProvider.cs

示例2: processConditionalElement


//.........这里部分代码省略.........

                    case ConditionalState.ExpectingEnd:
                        st.Error("expected </cms-conditional> end element");
                        break;

                    processCondition:
                        // Parse out the condition test variables:
                        conditionVariables = new Dictionary<string, string>(StringComparer.Ordinal);
                        if (st.Reader.HasAttributes && st.Reader.MoveToFirstAttribute())
                        {
                            do
                            {
                                conditionVariables.Add(st.Reader.LocalName, st.Reader.Value);
                            } while (st.Reader.MoveToNextAttribute());

                            st.Reader.MoveToElement();
                        }

                        // Make sure we have at least one:
                        if (conditionVariables.Count == 0)
                        {
                            st.Error("expected at least one attribute for '{0}' element", st.Reader.LocalName);
                            goto errored;
                        }

                        // Make sure the branch has not already been satisfied:
                        if (satisfied)
                        {
                            // Branch has already been satisfied, skip inner contents:
                            st.SkipElementAndChildren(st.Reader.LocalName);
                            break;
                        }

                        // Run the condition test variables through the evaluator chain:
                        IConditionalEvaluator eval = evaluator;
                        EitherAndOr? lastAndOr = null;
                        
                        while (eval != null)
                        {
                            Errorable<bool> etest = await eval.EvaluateConditional(conditionVariables);
                            if (etest.HasErrors) return etest.Errors;
                            
                            bool test = etest.Value;

                            if (lastAndOr.HasValue)
                            {
                                if (lastAndOr.Value == EitherAndOr.And) condition = condition && test;
                                else condition = condition || test;
                            }
                            else
                            {
                                condition = test;
                            }

                            lastAndOr = eval.AndOr;
                            eval = eval.Next;
                        }

                        // Now either render the inner content or skip it based on the `condition` evaluated:
                        if (condition)
                        {
                            satisfied = true;
                            // Copy inner contents:
                            err = await st.CopyElementChildren(st.Reader.LocalName).ConfigureAwait(continueOnCapturedContext: false);
                            if (err.HasErrors) return err.Errors;
                        }
                        else
                        {
                            // Skip inner contents:
                            st.SkipElementAndChildren(st.Reader.LocalName);
                        }
                        break;

                    processElse:
                        if (st.Reader.HasAttributes)
                        {
                            st.Error("unexpected attributes on 'else' element");
                            goto errored;
                        }

                        if (satisfied)
                        {
                            // Skip inner contents:
                            st.SkipElementAndChildren(st.Reader.LocalName);
                            break;
                        }

                        // Copy inner contents:
                        err = await st.CopyElementChildren(st.Reader.LocalName).ConfigureAwait(continueOnCapturedContext: false);
                        if (err.HasErrors) return err.Errors;
                        break;
                }
            }
            return Errorable.NoErrors;

        errored:
            // Keep reading to the end cms-conditional element:
            while (st.Reader.Read() && st.Reader.Depth > knownDepth) { }
            return Errorable.NoErrors;
        }
开发者ID:JamesDunne,项目名称:ivo-cms,代码行数:101,代码来源:ConditionalElementProvider.cs

示例3: processImportTemplateElement


//.........这里部分代码省略.........
                    }

                    // Read the cms-template-area's id attribute:
                    if (!tst.Reader.MoveToAttribute("id"))
                    {
                        tst.Error("cms-template-area needs an 'id' attribute");
                        tst.Reader.MoveToElement();
                        tst.SkipElementAndChildren("cms-template-area");
                        return false;
                    }

                    // Assign the template's area id:
                    string tmplAreaId = tst.Reader.Value;

                    // Move to the first area if we have to:
                    if (isFirstArea)
                    {
                        if (!st.Reader.IsEmptyElement)
                        {
                            fillerAreaId = moveToNextAreaElement(st);
                        }
                        isFirstArea = false;
                    }

                    // Do the ids match?
                    if ((fillerAreaId != null) && (tmplAreaId == fillerAreaId))
                    {
                        // Skip the cms-template-area in the template:
                        tst.Reader.MoveToElement();
                        tst.SkipElementAndChildren("cms-template-area");
                        // Move the filler reader to the element node:
                        st.Reader.MoveToElement();
                        // Copy the elements:
                        await stWriter.CopyElementChildren("area");

                        // Move to the next area element, if available:
                        fillerAreaId = moveToNextAreaElement(st);
                    }
                    else
                    {
                        // Insert the default content from the template:
                        tst.Reader.MoveToElement();
                        // Recurse into children, allowing processing of embedded cms-template-areas:
                        await tst.CopyElementChildren("cms-template-area", null, processTemplateAreaElements);
                    }

                    // We handled this:
                    return false;
                });

                // Now continue on stream-copying child elements until we find a cms-template-area:
                var err = await sst.CopyElementChildren("cms-template", null, processTemplateAreaElements)
                    .ConfigureAwait(continueOnCapturedContext: false);
                if (err.HasErrors) return err.Errors;

                // We missed some <area />s in the cms-import-template:
                while (!((st.Reader.NodeType == XmlNodeType.EndElement) && (st.Reader.LocalName == "cms-import-template")) &&
                       !((st.Reader.NodeType == XmlNodeType.Element) && st.Reader.IsEmptyElement && (st.Reader.LocalName == "cms-import-template")))
                {
                    // Move to the next <area /> start element:
                    fillerAreaId = moveToNextAreaElement(st);
                    if (fillerAreaId != null)
                    {
                        st.Warning("area '{0}' unused by the template", fillerAreaId);
                        st.SkipElementAndChildren("area");
                    }
开发者ID:JamesDunne,项目名称:ivo-cms,代码行数:67,代码来源:ImportTemplateElementProvider.cs

示例4: processLinkElement

        private async Task<Errorable> processLinkElement(RenderState st)
        {
            // A 'cms-link' is translated directly into an anchor tag with the 'path' attribute
            // translated and canonicalized into an absolute 'href' attribute, per system
            // configuration. All other attributes are copied to the anchor tag as-is.

            // e.g.:
            //   <cms-link path="/absolute/path" ...>contents</cms-link>
            // becomes:
            //   <a href="/content/absolute/path" ...>contents</a>
            // if the CMS requests are "mounted" to the /content/ root URL path.

            // Either relative or absolute paths are allowed for 'path':
            //   <cms-link path="../../hello/world" target="_blank">Link text.</cms-link>
            //   <cms-link path="/hello/world" target="_blank">Link text.</cms-link>

            // Set the current element depth so we know where to read up to on error:
            int knownDepth = st.Reader.Depth;
            bool isEmpty = st.Reader.IsEmptyElement;

            if (!st.Reader.HasAttributes)
            {
                st.Error("cms-link has no attributes");
                goto errored;
            }

            bool foundPath = false;

            st.Writer.Append("<a");

            st.Reader.MoveToFirstAttribute();
            do
            {
                string value = st.Reader.Value;

                if (st.Reader.LocalName == "path")
                {
                    foundPath = true;

                    // Get the canonicalized blob path (from either absolute or relative):
                    var abspath = PathObjectModel.ParseBlobPath(value);
                    CanonicalBlobPath path = abspath.Collapse(abs => abs.Canonicalize(), rel => (st.Item.TreeBlobPath.Path.Tree + rel).Canonicalize());
                    
                    // TODO: apply the reverse-mount prefix path from the system configuration,
                    // or just toss the CanonicalBlobPath over to a provider implementation and
                    // it can give us the final absolute URL path.
                    st.Writer.AppendFormat(" href=\"{0}\"", path);
                    continue;
                }

                // Append the normal attribute:
                st.Writer.AppendFormat(" {0}={2}{1}{2}", st.Reader.LocalName, value, st.Reader.QuoteChar);
            } while (st.Reader.MoveToNextAttribute());

            // Jump back to the element node from the attributes:
            st.Reader.MoveToElement();

            if (!foundPath)
            {
                // Issue a warning and append an "href='#'" attribute:
                st.WarningSuppressComment("expected 'path' attribute on 'cms-link' element was not found");
                st.Writer.Append(" href=\"#\"");
            }

            // Self-close the <a /> if the <cms-link /> is empty:
            if (isEmpty)
            {
                st.Writer.Append(" />");
                return Errorable.NoErrors;
            }

            // Copy the inner contents and close out the </a>.
            st.Writer.Append(">");
            var err = await st.CopyElementChildren("cms-link").ConfigureAwait(continueOnCapturedContext: false);
            if (err.HasErrors) return err.Errors;
            st.Writer.Append("</a>");
            return Errorable.NoErrors;

        errored:
            // Skip to the end of the cms-link element:
            if (!isEmpty)
                while (st.Reader.Read() && st.Reader.Depth > knownDepth) { }
            return Errorable.NoErrors;
        }
开发者ID:JamesDunne,项目名称:ivo-cms,代码行数:84,代码来源:LinkElementProvider.cs


注:本文中的RenderState.CopyElementChildren方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。