Пример #1
0
        private static bool HasValidPanes (Layout layout)
        {
            var hasPanes = false;
            var hasSingleContentPane = false;
            var allPanesDistinct = false;

            // layout contains some panes
            hasPanes = layout.Panes.Count > 0;

            if (hasPanes) {
                // layout contains single ContentPane
                hasSingleContentPane = layout.Panes.SingleOrDefault (p => string.Equals (p.ID, "ContentPane", StringComparison.OrdinalIgnoreCase)) != null;

                // all panes have distinct names
                allPanesDistinct = layout.Panes.Count == layout.Panes.Distinct (new PaneEqualityComparer ()).Count ();
            }

            return hasPanes && hasSingleContentPane && allPanesDistinct;
        }
Пример #2
0
        public static Layout ParseLayout (string markup)
        {
            // TODO: Add support for <div id="SomePane" runat="server" ...>...</div> markup

            const string runatServer = "runat=\"server\"";
            var layout = new Layout ();
            var prevEndPaneIndex = 0;

            // find first pane
            var paneIndex = markup.IndexOf (runatServer, StringComparison.Ordinal);
            while (paneIndex >= 0) {

                var startPaneIndex = markup.LastIndexOf ("<", paneIndex, StringComparison.Ordinal);
                var endPaneIndex = markup.IndexOf ("/>", paneIndex + runatServer.Length, StringComparison.Ordinal) + 2;
                var paneMarkup = markup.Substring (startPaneIndex, endPaneIndex - startPaneIndex);

                var pane = ParseDynamicPane (paneMarkup);
                pane.MarkupBefore = markup.Substring (prevEndPaneIndex, startPaneIndex - prevEndPaneIndex);

                prevEndPaneIndex = endPaneIndex;

                layout.Panes.Add (pane);

                if (endPaneIndex >= (markup.Length - 1)) {
                    break;
                }

                // find next pane
                paneIndex = markup.IndexOf (runatServer, prevEndPaneIndex, StringComparison.Ordinal);
            }

            if (layout.Panes.Count > 0) {
                layout.Panes [layout.Panes.Count - 1].MarkupAfter = markup.Substring (prevEndPaneIndex);
            }

            return layout;
        }