コード例 #1
0
 private static void RenderChilds(IHtmlContainer container, TextWriter writer, params IHtmlAdapter[] adapter)
 {
     foreach (var node in container.Nodes())
     {
         Render(node, writer, adapter);
     }
 }
コード例 #2
0
 /// <summary>
 /// 构建 HtmlDomChangedEventArgs 对象
 /// </summary>
 /// <param name="node">发生变化的节点</param>
 /// <param name="container">节点所属的容器</param>
 /// <param name="action">节点所发生的操作</param>
 public HtmlDomChangedEventArgs(IHtmlNode node, IHtmlContainer container, HtmlDomChangedAction action)
 {
     IsAttributeChanged = false;
     Node      = node;
     Container = container;
     Action    = action;
 }
コード例 #3
0
ファイル: BindingContext.cs プロジェクト: toddfsy/Jumony
        /// <summary>
        /// 后序遍历所有元素用于绑定
        /// </summary>
        /// <param name="container">根元素</param>
        /// <returns></returns>
        private static IEnumerable <IHtmlElement> PostOrderTraverse(IHtmlContainer container)
        {
            var elementList = new List <IHtmlElement>();

            PostOrderTraverse(container, elementList);
            return(elementList);
        }
コード例 #4
0
      /// <exception cref="ArgumentNullException"><paramref name="catalog"/> is <see langword="null" />.</exception>
      public void SetContext(IHtmlContainer catalog)
      {
         if (catalog == null)
            throw new ArgumentNullException("catalog");

         _catalog = catalog;
      }
コード例 #5
0
ファイル: HtmlRange.cs プロジェクト: neo2018/Jumony
        public HtmlRange( IHtmlNode node1, IHtmlNode node2, bool inclusiveNode1, bool inclusiveNode2 )
        {
            if ( node1 == null )
            throw new ArgumentNullException( "node1" );

              if ( node2 == null )
            throw new ArgumentNullException( "node2" );

              container = node1.Container;

              if ( container == null || !container.Equals( node2.Container ) || node1.Equals( node2 ) )
            throw new InvalidOperationException();

              if ( node1.NodesIndexOfSelf() <= node2.NodesIndexOfSelf() )
              {
            beginNode = node1;
            endNode = node2;
            inclusiveBegin = inclusiveNode1;
            inclusiveEnd = inclusiveNode2;
              }
              else
              {
            beginNode = node2;
            endNode = node1;
            inclusiveBegin = inclusiveNode2;
            inclusiveEnd = inclusiveNode1;
              }
        }
コード例 #6
0
        /// <summary>
        /// 添加元素的副本
        /// </summary>
        /// <param name="container">要添加副本的容器</param>
        /// <param name="index">要添加的位置</param>
        /// <param name="element">要创作副本的元素</param>
        /// <returns>添加后的元素</returns>
        public static IHtmlElement AddCopy(this IHtmlContainer container, int index, IHtmlElement element)
        {
            if (container == null)
            {
                throw new ArgumentNullException("container");
            }

            if (element == null)
            {
                throw new ArgumentNullException("element");
            }


            var _element = container.AddElement(index, element.Name);

            foreach (var attribute in element.Attributes())
            {
                _element.AddAttribute(attribute.Name, attribute.AttributeValue);
            }


            foreach (var node in element.Nodes())
            {
                AddCopy(_element, node);
            }


            return(_element);
        }
コード例 #7
0
        /// <summary>
        /// 从当前容器按照 CSS 选择器搜索符合要求的元素
        /// </summary>
        /// <param name="container">要搜索子代元素的容器</param>
        /// <param name="expression">CSS 选择器</param>
        /// <returns>搜索到的符合要求的元素</returns>
        public static IEnumerable <IHtmlElement> Find(this IHtmlContainer container, string expression)
        {
            if (container == null)
            {
                throw new ArgumentNullException("container");
            }

            if (expression == null)
            {
                throw new ArgumentNullException("expression");
            }


            try
            {
                var selector = CssParser.Create(container, expression);
                return(selector.Filter(container.Descendants()));
            }
            catch (Exception e)
            {
                if (e.Data != null && !e.Data.Contains("selector expression"))
                {
                    e.Data["selector expression"] = expression;
                }

                throw;
            }
        }
コード例 #8
0
        /// <summary>
        /// 对容器创建索引管理器
        /// </summary>
        /// <param name="container">要创建索引的容器</param>
        public IndexManager(IHtmlContainer container)
        {
            Container = container;

            Initialize();
            Rebuild();
        }
コード例 #9
0
ファイル: HtmlRange.cs プロジェクト: qaz734913414/Topawes
        public HtmlRange(IHtmlNode node1, IHtmlNode node2, bool inclusiveNode1, bool inclusiveNode2)
        {
            if (node1 == null)
            {
                throw new ArgumentNullException("node1");
            }

            if (node2 == null)
            {
                throw new ArgumentNullException("node2");
            }


            container = node1.Container;

            if (container == null || !container.Equals(node2.Container) || node1.Equals(node2))
            {
                throw new InvalidOperationException();
            }

            if (node1.NodesIndexOfSelf() <= node2.NodesIndexOfSelf())
            {
                beginNode      = node1;
                endNode        = node2;
                inclusiveBegin = inclusiveNode1;
                inclusiveEnd   = inclusiveNode2;
            }
            else
            {
                beginNode      = node2;
                endNode        = node1;
                inclusiveBegin = inclusiveNode2;
                inclusiveEnd   = inclusiveNode1;
            }
        }
コード例 #10
0
ファイル: PartialView.cs プロジェクト: wangscript007/roycms
        /// <summary>
        /// 部分视图主处理流程
        /// </summary>
        protected override void ProcessMain()
        {
            if (Container == null)
            {
                HttpContext.Trace.Write("Jumony for MVC - PartialView", "Begin LoadContainer");
                Container = LoadContainer();
                HttpContext.Trace.Write("Jumony for MVC - PartialView", "End LoadContainer");
            }


            HttpContext.Trace.Write("Jumony for MVC - PartialView", "Begin ProcessContaner");
            ProcessContainer();
            HttpContext.Trace.Write("Jumony for MVC - PartialView", "End ProcessContaner");


            HttpContext.Trace.Write("Jumony for MVC - PartialView", "Begin ProcessActionLinks");
            ProcessActionUrls(Container);
            HttpContext.Trace.Write("Jumony for MVC - PartialView", "End ProcessActionLinks");

            if (VirtualPath != null)//若不是内嵌部分视图,则应当进行 URL 转换。
            {
                HttpContext.Trace.Write("Jumony for MVC - PartialView", "Begin ResolveUri");
                ResolveUri(Container);
                HttpContext.Trace.Write("Jumony for MVC - PartialView", "End ResolveUri");
            }
        }
コード例 #11
0
      /// <exception cref="ArgumentNullException"><paramref name="catalog"/> is <see langword="null" />.</exception>
      public PluralsightNodeSelector(IHtmlContainer catalog)
      {
         if(catalog == null)
            throw new ArgumentNullException("catalog");

         _catalog = catalog;
      }
コード例 #12
0
        /// <summary>
        /// 从当前容器按照 CSS 选择器搜索符合要求的最后一个元素,若不存在任何符合要求的元素,则抛出异常。
        /// </summary>
        /// <param name="container">要搜索子代元素的容器</param>
        /// <param name="expression">CSS选择器</param>
        /// <returns>搜索到的符合要求的最后一个元素</returns>
        public static IHtmlElement FindLast(this IHtmlContainer container, string expression)
        {
            if (container == null)
            {
                throw new ArgumentNullException("container");
            }

            if (expression == null)
            {
                throw new ArgumentNullException("expression");
            }



            IHtmlElement result;

            result = container.Find(expression).LastOrDefault();

            if (result == null)
            {
                throw new InvalidOperationException(string.Format("未找到符合选择器 \"{0}\" 的元素。", expression));
            }

            return(result);
        }
コード例 #13
0
ファイル: ViewBase.cs プロジェクト: wangscript007/roycms
 /// <summary>
 /// 转换容器中所有 URI 与当前请求匹配。
 /// </summary>
 /// <param name="container">确定要转换 URI 范围的容器</param>
 protected virtual void ResolveUri(IHtmlContainer container)
 {
     foreach (var attribute in container.Descendants().SelectMany(e => e.Attributes()).Where(a => HtmlSpecification.IsUriValue(a)).ToArray())
     {
         ResolveUri(attribute);
     }
 }
コード例 #14
0
        /// <summary>
        /// 从当前容器按照 CSS 选择器搜索符合要求的唯一元素,如果有多个元素符合要求,则会引发异常。
        /// </summary>
        /// <param name="container">要搜索子代元素的容器</param>
        /// <param name="expression">CSS选择器</param>
        /// <returns>搜索到的符合要求的唯一元素</returns>
        public static IHtmlElement FindSingle(this IHtmlContainer container, string expression)
        {
            if (container == null)
            {
                throw new ArgumentNullException("container");
            }

            if (expression == null)
            {
                throw new ArgumentNullException("expression");
            }

            try
            {
                return(Find(container, expression).Single());
            }
            catch (InvalidOperationException e)
            {
                throw new InvalidOperationException(string.Format("未找到符合选择器 \"{0}\" 的元素或结果集不唯一", expression), e);
            }
            catch (Exception e)
            {
                if (e.Data != null && !e.Data.Contains("Ivony.Html.CssQuery.Expression"))
                {
                    e.Data["selector expression"] = expression;
                }

                throw;
            }
        }
コード例 #15
0
 /// <summary>
 /// 渲染所有的子节点
 /// </summary>
 /// <param name="container">要渲染子节点的容器</param>
 /// <param name="context">渲染上下文</param>
 public static void RenderChilds(this IHtmlContainer container, IHtmlRenderContext context)
 {
     foreach (var node in container.Nodes())
     {
         Render(node, context);
     }
 }
コード例 #16
0
ファイル: CssSelector.cs プロジェクト: wangscript007/roycms
        /// <summary>
        /// 执行CSS选择器搜索
        /// </summary>
        /// <param name="expression">CSS选择器表达式</param>
        /// <param name="scope">CSS选择器和搜索范畴</param>
        /// <returns>搜索结果</returns>
        public static IEnumerable <IHtmlElement> Search(string expression, IHtmlContainer scope)
        {
            if (expression == null)
            {
                throw new ArgumentNullException("expression");
            }

            if (scope == null)
            {
                throw new ArgumentNullException("scope");
            }


            try
            {
                var selector = Create(expression, scope);
                return(selector.Filter(scope.Descendants()));
            }
            catch (Exception e)
            {
                if (e.Data != null && !e.Data.Contains("selector expression"))
                {
                    e.Data["selector expression"] = expression;
                }

                throw;
            }
        }
コード例 #17
0
ファイル: CssSelector.cs プロジェクト: wangscript007/roycms
        /// <summary>
        /// 创建一个 CSS 选择器
        /// </summary>
        /// <param name="expression">选择器表达式</param>
        /// <param name="scope">范畴限定</param>
        /// <returns>选择器</returns>
        public static ICssSelector Create(string expression, IHtmlContainer scope)
        {
            if (expression == null)
            {
                throw new ArgumentNullException("expression");
            }


            ICssSelector[] selectors;

            if (_selectorCache.ContainsKey(expression))
            {
                selectors = _selectorCache[expression];
            }

            else
            {
                var match = cssSelectorRegex.Match(expression);

                if (!match.Success)
                {
                    throw new FormatException("无法识别的CSS选择器");
                }

                selectors = match.Groups["selector"].Captures.Cast <Capture>().Select(c => CssCasecadingSelector.Create(c.Value)).ToArray();
            }

            lock ( _cacheSync )
            {
                _selectorCache[expression] = selectors;
            }


            return(new CssMultipleSelector(selectors.Select(s => CssCasecadingSelector.Create(s, scope)).ToArray()));
        }
コード例 #18
0
ファイル: DomModifier.cs プロジェクト: ajayumi/Jumony
    public IHtmlElement AddElement( IHtmlContainer container, int index, string name )
    {
      var element = _document.CreateElement( name );
      AddNode( container, index, element );

      return element.AsElement();
    }
コード例 #19
0
        /// <summary>
        /// 从当前容器按照 CSS 选择器搜索符合要求的唯一元素,如果有多个元素符合要求,则会引发异常。
        /// </summary>
        /// <param name="container">要搜索子代元素的容器</param>
        /// <param name="expression">CSS选择器</param>
        /// <returns>搜索到的符合要求的唯一元素</returns>
        public static IHtmlElement FindSingle(this IHtmlContainer container, string expression)
        {
            if (container == null)
            {
                throw new ArgumentNullException("container");
            }

            if (expression == null)
            {
                throw new ArgumentNullException("expression");
            }


            IHtmlElement result;

            try
            {
                result = container.Find(expression).SingleOrDefault();
            }
            catch (InvalidOperationException e)
            {
                throw new InvalidOperationException(string.Format("符合选择器 \"{0}\" 的元素不唯一", expression), e);
            }

            if (result == null)
            {
                throw new InvalidOperationException(string.Format("未找到符合选择器 \"{0}\" 的元素。", expression));
            }

            return(result);
        }
コード例 #20
0
ファイル: DomModifier.cs プロジェクト: zpzgone/Jumony
        public IHtmlTextNode AddTextNode(IHtmlContainer container, int index, string htmlText)
        {
            var node = _document.CreateTextNode(htmlText);

            AddNode(container, index, node);

            return(node.AsTextNode());
        }
コード例 #21
0
ファイル: LegacyDomExtensions.cs プロジェクト: zpzgone/Jumony
        /// <summary>
        /// 将容器所有内容创建为文档碎片
        /// </summary>
        /// <param name="factory">用于创建节点的创造器</param>
        /// <param name="container">包含内容的容器</param>
        /// <returns>文档碎片</returns>
        public static HtmlFragment MakeFragment(this IHtmlNodeFactory factory, IHtmlContainer container)
        {
            var fragment = new HtmlFragment(factory);

            fragment.AddCopies(container.Nodes());

            return(fragment);
        }
コード例 #22
0
ファイル: jQuery.cs プロジェクト: toddfsy/Jumony
        /// <summary>
        /// 创建 jQuery 对象
        /// </summary>
        /// <param name="selector">选择器</param>
        /// <param name="scope">范畴限定</param>
        public jQuery(string selector, IHtmlContainer scope)
        {
            _selectorExpression = selector;
            _scope = scope;

            _selector = CssParser.Create(scope, selector);
            _elements = _selector.Filter(_scope.Descendants());
        }
コード例 #23
0
ファイル: DomModifier.cs プロジェクト: zpzgone/Jumony
        public IHtmlComment AddComment(IHtmlContainer container, int index, string comment)
        {
            var node = _document.CreateComment(comment);

            AddNode(container, index, node);

            return(node.AsComment());
        }
コード例 #24
0
ファイル: DomModifier.cs プロジェクト: ajayumi/Jumony
    public IHtmlTextNode AddTextNode( IHtmlContainer container, int index, string htmlText )
    {
      var node = _document.CreateTextNode( htmlText );

      AddNode( container, index, node );

      return node.AsTextNode();
    }
コード例 #25
0
ファイル: DomModifier.cs プロジェクト: zpzgone/Jumony
        public IHtmlElement AddElement(IHtmlContainer container, int index, string name)
        {
            var element = _document.CreateElement(name);

            AddNode(container, index, element);

            return(element.AsElement());
        }
コード例 #26
0
            /// <summary>
            /// 创建范畴限定选择器实例
            /// </summary>
            /// <param name="scope"></param>
            public CssScopeRestrictionSelector(IHtmlContainer scope)
            {
                if (scope == null)
                {
                    throw new ArgumentNullException("scope");
                }

                _scope = scope;
            }
コード例 #27
0
        /// <summary>
        /// 从当前容器按照 CSS 选择器搜索符合要求的元素
        /// </summary>
        /// <param name="container">要搜索子代元素的容器</param>
        /// <param name="expression">CSS 选择器</param>
        /// <param name="action">要对元素执行的操作</param>
        /// <returns>搜索到的符合要求的元素</returns>
        public static IEnumerable <IHtmlElement> Find(this IHtmlContainer container, string expression, Action <IHtmlElement> action)
        {
            if (action == null)
            {
                throw new ArgumentNullException("action");
            }

            return(container.Find(expression).ForAll(action));
        }
コード例 #28
0
        /// <summary>
        /// 获取所有元素,并做处理
        /// </summary>
        /// <param name="container">要获取子元素的容器</param>
        /// <param name="action">要对子元素进行的操作</param>
        /// <returns>容器的子元素</returns>
        public static IEnumerable <IHtmlElement> Elements(IHtmlContainer container, Action <IHtmlElement> action)
        {
            if (action == null)
            {
                throw new ArgumentNullException("action");
            }

            return(container.Elements().ForAll(action));
        }
コード例 #29
0
        /// <summary>
        /// 获取符合条件的子代元素,并作相应处理
        /// </summary>
        /// <param name="container">要获取子代元素的容器对象</param>
        /// <param name="selector">用于筛选子代元素的选择器</param>
        /// <param name="action">要对子代元素执行的操作</param>
        /// <returns>符合选择器的容器的所有子代元素</returns>
        /// <remarks>与Find方法不同的是,Descendants方法的选择器会无限上溯,即当判断父代约束时,会无限上溯到文档根。而Find方法只会上溯到自身的子节点</remarks>
        public static IEnumerable <IHtmlElement> Descendants(IHtmlContainer container, string selector, Action <IHtmlElement> action)
        {
            if (action == null)
            {
                throw new ArgumentNullException("action");
            }

            return(container.Descendants(selector).ForAll(action));
        }
コード例 #30
0
        /// <summary>
        /// 获取所有的子代节点,并作相应处理
        /// </summary>
        /// <param name="container">要获取子代元素的容器对象</param>
        /// <param name="action">要对子代元素执行的操作</param>
        /// <returns>容器所有的子代节点</returns>
        public static IEnumerable <IHtmlNode> DescendantNodes(IHtmlContainer container, Action <IHtmlNode> action)
        {
            if (action == null)
            {
                throw new ArgumentNullException("action");
            }

            return(container.DescendantNodes().ForAll(action));
        }
コード例 #31
0
        /// <exception cref="ArgumentNullException"><paramref name="catalog"/> is <see langword="null" />.</exception>
        public PluralsightNodeSelector(IHtmlContainer catalog)
        {
            if (catalog == null)
            {
                throw new ArgumentNullException("catalog");
            }

            _catalog = catalog;
        }
コード例 #32
0
ファイル: BindingContext.cs プロジェクト: ajayumi/Jumony
 private void SetDataContext( IHtmlContainer element, object dataContext )
 {
   _dataContextStack.Push(
     new DataContextStackItem()
     {
       DataContainer = element,
       DataContext = dataContext
     } );
 }
コード例 #33
0
        /// <exception cref="ArgumentNullException"><paramref name="catalog"/> is <see langword="null" />.</exception>
        public void SetContext(IHtmlContainer catalog)
        {
            if (catalog == null)
            {
                throw new ArgumentNullException("catalog");
            }

            _catalog = catalog;
        }
コード例 #34
0
 private void SetDataContext(IHtmlContainer element, object dataContext)
 {
     _dataContextStack.Push(
         new DataContextStackItem()
     {
         DataContainer = element,
         DataContext   = dataContext
     });
 }
コード例 #35
0
ファイル: DomProvider.cs プロジェクト: ajayumi/Jumony
    internal static IDomContainer EnsureDomContainer( IHtmlContainer container )
    {
      var domContainer = container as IDomContainer;

      if ( domContainer == null )
        throw new NotSupportedException( "只能向指定类型容器添加节点" );

      return domContainer;
    }
コード例 #36
0
ファイル: DomModifier.cs プロジェクト: ajayumi/Jumony
    public IHtmlComment AddComment( IHtmlContainer container, int index, string comment )
    {
      var node = _document.CreateComment( comment );

      AddNode( container, index, node );

      return node.AsComment();

    }
コード例 #37
0
        /// <summary>
        /// 从当前容器按照 CSS 选择器搜索符合要求的元素
        /// </summary>
        /// <param name="container">要搜索子代元素的容器</param>
        /// <param name="expression">CSS 选择器</param>
        /// <returns>搜索到的符合要求的元素</returns>
        public static IEnumerable <IHtmlElement> Find(this IHtmlContainer container, string expression)
        {
            if (container == null)
            {
                throw new ArgumentNullException("container");
            }

            return(CssSelector.Search(expression, container));
        }
コード例 #38
0
        /// <summary>
        /// 获取所有子元素
        /// </summary>
        /// <param name="container">要获取子元素的容器</param>
        /// <returns>容器的所有子元素</returns>
        public static IEnumerable <IHtmlElement> Elements(this IHtmlContainer container)
        {
            if (container == null)
            {
                throw new ArgumentNullException("container");
            }

            return(container.Nodes().OfType <IHtmlElement>());
        }
コード例 #39
0
ファイル: DomModifier.cs プロジェクト: ajayumi/Jumony
    private HAP.HtmlNode AddNode( IHtmlContainer container, int index, HAP.HtmlNode node )
    {
      var containerNode = container.RawObject as HAP.HtmlNode;

      if ( containerNode == null )
        throw new InvalidOperationException();

      containerNode.ChildNodes.Insert( index, node );

      return node;
    }
コード例 #40
0
ファイル: DomModifier.cs プロジェクト: ajayumi/Jumony
    /// <summary>
    /// 在容器指定位置添加一个文本节点
    /// </summary>
    /// <param name="container">要添加元素的容器</param>
    /// <param name="index">要添加文本节点的位置</param>
    /// <param name="htmlText">添加的 HTML 文本</param>
    /// <returns>添加好的文本节点</returns>
    public IHtmlTextNode AddTextNode( IHtmlContainer container, int index, string htmlText )
    {
      lock ( _sync )
      {
        unchecked { _version++; }

        var textNode = DomProvider.EnsureDomContainer( container ).InsertNode( index, new DomTextNode( htmlText ) );

        OnDomChanged( this, new HtmlDomChangedEventArgs( textNode, container, HtmlDomChangedAction.Add ) );

        return textNode;
      }
    }
コード例 #41
0
ファイル: DomModifier.cs プロジェクト: ajayumi/Jumony
    /// <summary>
    /// 在容器指定位置添加一个元素
    /// </summary>
    /// <param name="container">要添加元素的容器</param>
    /// <param name="index">要添加元素的位置</param>
    /// <param name="name">添加元素的名称</param>
    /// <returns>添加好的元素</returns>
    public IHtmlElement AddElement( IHtmlContainer container, int index, string name )
    {
      lock ( _sync )
      {
        unchecked { _version++; }

        var element = DomProvider.EnsureDomContainer( container ).InsertNode( index, new DomElement( name, null ) );

        OnDomChanged( this, new HtmlDomChangedEventArgs( element, container, HtmlDomChangedAction.Add ) );

        return element;
      }
    }
コード例 #42
0
ファイル: HtmlNodeFactory.cs プロジェクト: ajayumi/Jumony
      public IHtmlNode Into( IHtmlContainer container, int index )
      {
        if ( container == null )
          throw new ArgumentNullException( "container" );

        var containerAdapter = container as HtmlContainerAdapter;
        if ( containerAdapter == null )
          throw new InvalidOperationException();


        containerAdapter.Node.ChildNodes.Insert( index, Node );

        return Node.AsNode();
      }
コード例 #43
0
        /// <summary>
        /// 在容器末尾增加一个文本节点
        /// </summary>
        /// <param name="modifier">DOM 结构修改器</param>
        /// <param name="container">要添加节点的容器</param>
        /// <param name="htmlText">HTML文本</param>
        /// <returns>添加的文本节点</returns>
        public static IHtmlTextNode AddTextNode( this IHtmlDomModifier modifier, IHtmlContainer container, string htmlText )
        {
            if ( modifier == null )
            throw new ArgumentNullException( "modifier" );

              if ( container == null )
            throw new ArgumentNullException( "container" );

              if ( htmlText == null )
            throw new ArgumentNullException( "htmlText" );

              lock ( container.SyncRoot )
              {
            return modifier.AddTextNode( container, container.Nodes().Count(), htmlText );
              }
        }
コード例 #44
0
        /// <summary>
        /// 在容器末尾增加一个元素
        /// </summary>
        /// <param name="modifier">DOM 结构修改器</param>
        /// <param name="container">要添加元素的容器</param>
        /// <param name="elementName">元素名</param>
        /// <returns>添加的元素</returns>
        public static IHtmlElement AddElement( this IHtmlDomModifier modifier, IHtmlContainer container, string elementName )
        {
            if ( modifier == null )
            throw new ArgumentNullException( "modifier" );

              if ( container == null )
            throw new ArgumentNullException( "container" );

              if ( elementName == null )
            throw new ArgumentNullException( "elementName" );

              lock ( container.SyncRoot )
              {
            return modifier.AddElement( container, container.Nodes().Count(), elementName );
              }
        }
コード例 #45
0
        /// <summary>
        /// 在容器末尾增加一个注释节点
        /// </summary>
        /// <param name="modifier">DOM 结构修改器</param>
        /// <param name="container">要添加注释的容器</param>
        /// <param name="comment">HTML注释</param>
        /// <returns>添加的注释节点</returns>
        public static IHtmlComment AddComment( this IHtmlDomModifier modifier, IHtmlContainer container, string comment )
        {
            if ( modifier == null )
            throw new ArgumentNullException( "modifier" );

              if ( container == null )
            throw new ArgumentNullException( "container" );

              if ( comment == null )
            throw new ArgumentNullException( "comment" );

              lock ( container.SyncRoot )
              {
            return modifier.AddComment( container, container.Nodes().Count(), comment );
              }
        }
コード例 #46
0
ファイル: HtmlRequestContext.cs プロジェクト: ajayumi/Jumony
    /// <summary>
    /// 创建 HtmlRequestContext 实例
    /// </summary>
    /// <param name="httpContext">当前 HTTP 请求上下文</param>
    /// <param name="virtualPath">当前处理的文档的虚拟路径</param>
    /// <param name="scope">当前要处理的 HTML 文档范围</param>
    public HtmlRequestContext( HttpContextBase httpContext, string virtualPath, IHtmlContainer scope )
    {

      if ( httpContext == null )
        throw new ArgumentNullException( "httpContext" );

      if ( virtualPath == null )
        throw new ArgumentNullException( "virtualPath" );

      if ( scope == null )
        throw new ArgumentException( "scope" );


      HttpContext = httpContext;
      VirtualPath = virtualPath;
      Scope = scope;
    }
コード例 #47
0
ファイル: HtmlDomDependency.cs プロジェクト: ajayumi/Jumony
    /// <summary>
    /// 创建一个 DOM 依赖项,当 DOM 结构发生更改时将会被标记为已过时。
    /// </summary>
    /// <param name="scope">要监视 DOM 修改的范围</param>
    /// <param name="inclusive">是否监视自身的修改</param>
    /// <param name="dependency">创建的依赖项</param>
    /// <returns>是否成功</returns>
    public static bool TryCreateDependency( IHtmlContainer scope, bool inclusive, out HtmlDomDependency dependency )
    {
      dependency = null;
      if ( scope == null )
        throw new ArgumentNullException( "container" );

      var notifier = scope.Document.DomModifier as INotifyDomChanged;
      if ( notifier == null )
        return false;

      if ( inclusive && !( scope is IHtmlNode ) )
        return false;


      dependency = new HtmlDomDependency();

      dependency.Notifier = notifier;
      dependency.ChangedDetermine = e =>
        {
          if ( e.Container.Equals( scope ) )
            return true;

          if ( inclusive && e.Node.Equals( scope ) )
            return true;

          var container = e.Container as IHtmlNode;

          if ( container != null && container.IsDescendantOf( scope ) )
            return true;

          return false;

        };

      dependency.Notifier.HtmlDomChanged += dependency.Handler;

      return true;
    }
コード例 #48
0
    /// <summary>
    /// 发现容器中所有可能是控件的元素并包装成控件返回
    /// </summary>
    /// <param name="form">控件所属的表单</param>
    /// <param name="container">要搜索的容器</param>
    /// <returns>找到的控件</returns>
    protected virtual IEnumerable<IFormControl> DiscoveryControls( HtmlForm form, IHtmlContainer container )
    {

      //UNDONE 没有检查 name 是否包含特殊字符

      foreach ( var element in container.Elements() )
      {
        if ( inputTextSelector.IsEligible( element ) )
          yield return new HtmlInputText( form, element );

        else if ( textareaSelector.IsEligible( element ) )
          yield return new HtmlTextArea( form, element );

        else if ( selectControlSelector.IsEligible( element ) )
          yield return new HtmlSelect( form, element );

        else
        {
          foreach ( var control in DiscoveryControls( form, element ) )
            yield return control;
        }
      }

    }
コード例 #49
0
 public ContainerRestrict( IHtmlContainer container )
 {
     RestrictContainer = container;
 }
コード例 #50
0
ファイル: DomModifier.cs プロジェクト: ajayumi/Jumony
 internal void OnFragmentInto( DomFragment fragment, IHtmlContainer targetContainer, DomNode node )
 {
   OnDomChanged( this, new HtmlDomChangedEventArgs( node, fragment, HtmlDomChangedAction.Remove ) );
   OnDomChanged( this, new HtmlDomChangedEventArgs( node, targetContainer, HtmlDomChangedAction.Add ) );
 }
コード例 #51
0
ファイル: DomModifier.cs プロジェクト: ajayumi/Jumony
    /// <summary>
    /// 在容器指定位置添加一个特殊节点
    /// </summary>
    /// <param name="container">要添加特殊节点的容器</param>
    /// <param name="index">要添加特殊节点的位置</param>
    /// <param name="html">添加特殊节点的 HTML</param>
    /// <returns>添加好的特殊节点</returns>
    public IHtmlSpecial AddSpecial( IHtmlContainer container, int index, string html )
    {
      lock ( _sync )
      {
        unchecked { _version++; }

        var specialNode = DomProvider.EnsureDomContainer( container ).InsertNode( index, new DomSpecial( html ) );

        //UNDONE 未确定special node具体是什么

        OnDomChanged( this, new HtmlDomChangedEventArgs( specialNode, container, HtmlDomChangedAction.Add ) );

        return specialNode;
      }
    }
コード例 #52
0
ファイル: CssSelectorTest.cs プロジェクト: ajayumi/Jumony
 private void SelectorAssert( IHtmlContainer container, string selector, Predicate<IEnumerable<IHtmlElement>> assert )
 {
   Assert.IsTrue( assert( container.Find( selector ) ), string.Format( "选择器 \"{0}\" 有问题", selector ) );
 }
コード例 #53
0
 /// <summary>
 /// 构建 HtmlDomChangedEventArgs 对象
 /// </summary>
 /// <param name="node">发生变化的节点</param>
 /// <param name="container">节点所属的容器</param>
 /// <param name="action">节点所发生的操作</param>
 public HtmlDomChangedEventArgs( IHtmlNode node, IHtmlContainer container, HtmlDomChangedAction action )
 {
     IsAttributeChanged = false;
       Node = node;
       Container = container;
       Action = action;
 }
コード例 #54
0
ファイル: ViewBase.cs プロジェクト: ajayumi/Jumony
 /// <summary>
 /// 实现处理和渲染逻辑
 /// </summary>
 /// <param name="scope">要渲染的范畴</param>
 /// <returns>渲染后的字符串</returns>
 protected abstract string RenderCore( IHtmlContainer scope );
コード例 #55
0
ファイル: JumonyView.cs プロジェクト: ajayumi/Jumony
    /// <summary>
    /// 渲染 HTML 内容。
    /// </summary>
    /// <returns></returns>
    protected virtual string RenderContent( IHtmlContainer scope, bool partialMode, IHtmlRenderAdapter[] adapters )
    {


      var document = scope as IHtmlDocument;
      if ( document == null )
      {
        var writer = new StringWriter();

        foreach ( var node in scope.Nodes() )
          node.Render( writer, adapters );

        return writer.ToString();
      }

      else
        return document.Render( adapters );

    }
コード例 #56
0
ファイル: HtmlDomDependency.cs プロジェクト: ajayumi/Jumony
 /// <summary>
 /// 创建一个 DOM 依赖项,当 DOM 结构发生更改时将会被标记为已过时。
 /// </summary>
 /// <param name="scope">要监视 DOM 修改的范围</param>
 /// <param name="dependency">创建的依赖项</param>
 /// <returns>是否成功</returns>
 public static bool TryCreateDependency( IHtmlContainer scope, out HtmlDomDependency dependency )
 {
   return TryCreateDependency( scope, false, out dependency );
 }
コード例 #57
0
            private static void BuildChildNodesStatement( IHtmlContainer container, CodeVariableReferenceExpression containerVariable, CodeStatementCollection statements )
            {
                var providerVariable = new CodeVariableReferenceExpression( "provider" );
                var attributesVariable = new CodeVariableReferenceExpression( "attributes" );

                foreach ( var node in container.Nodes() )
                {

                  var textNode = node as IHtmlTextNode;
                  if ( textNode != null )
                statements.Add( new CodeMethodInvokeExpression( providerVariable, "AddTextNode", containerVariable, new CodePrimitiveExpression( textNode.HtmlText ) ) );

                  var comment = node as IHtmlComment;
                  if ( comment != null )
                statements.Add( new CodeMethodInvokeExpression( providerVariable, "AddComment", containerVariable, new CodePrimitiveExpression( comment.Comment ) ) );

                  var element = node as IHtmlElement;

                  if ( element != null )
                  {
                var elementId = "element_" + Guid.NewGuid().ToString( "n" );

                statements.Add( new CodeCommentStatement( ContentExtensions.GenerateTagHtml( element, false ) ) );

                statements.Add( new CodeAssignStatement( attributesVariable, new CodeObjectCreateExpression( typeof( Dictionary<string, string> ) ) ) );

                foreach ( var attribute in element.Attributes() )
                  statements.Add( new CodeMethodInvokeExpression( attributesVariable, "Add", new CodePrimitiveExpression( attribute.Name ), new CodePrimitiveExpression( attribute.AttributeValue ) ) );

                statements.Add( new CodeVariableDeclarationStatement( typeof( IHtmlElement ), elementId, new CodeMethodInvokeExpression( providerVariable, "AddElement", containerVariable, new CodePrimitiveExpression( element.Name ), attributesVariable ) ) );

                var elementVariable = new CodeVariableReferenceExpression( elementId );

                BuildChildNodesStatement( element, elementVariable, statements );

                  }
                }
            }
コード例 #58
0
ファイル: JumonyMasterView.cs プロジェクト: ajayumi/Jumony
 /// <summary>
 /// 重写此方法以屏蔽直接渲染母板视图
 /// </summary>
 protected sealed override string RenderCore( IHtmlContainer scope )
 {
   throw new NotSupportedException( "母板页不能当作视图生成" );
 }
コード例 #59
0
ファイル: DomModifier.cs プロジェクト: ajayumi/Jumony
 public IHtmlSpecial AddSpecial( IHtmlContainer container, int index, string html )
 {
   throw new NotSupportedException();
 }
コード例 #60
0
ファイル: JumonyView.cs プロジェクト: ajayumi/Jumony
    /// <summary>
    /// 处理和渲染指定 HTML 范畴
    /// </summary>
    /// <param name="scope">要处理和渲染的范畴</param>
    /// <returns>渲染结果</returns>
    protected override string RenderCore( IHtmlContainer scope )
    {

      HttpContext.Trace.Write( "Jumony View", "Begin GetViewHandler" );
      var handler = GetHandler( VirtualPath );
      HttpContext.Trace.Write( "Jumony View", "End GetViewHandler" );

      HttpContext.Trace.Write( "Jumony View", "Begin Process" );
      OnPreProcess();
      ProcessScope( handler );
      OnPostProcess();
      HttpContext.Trace.Write( "Jumony View", "End Process" );

      HttpContext.Trace.Write( "Jumony View", "Begin DataBind" );
      Scope.DataBind( ViewContext.ViewData, HtmlBinding.ElementBinders, HtmlBinding.ExpressionBinders, new ActionUrlBinder( Url, Scope.Document.HtmlSpecification ) );
      HttpContext.Trace.Write( "Jumony View", "End DataBind" );


      Scope.Find( "form[postback]" )
        .SetAttribute( "action", RawViewContext.HttpContext.Request.RawUrl )
        .SetAttribute( "method", "post" )
        .RemoveAttribute( "postback" );



      AddGeneratorMetaData();

      RenderAdapters = GetRenderAdapters( handler );

      string result;

      if ( MasterView != null )
      {
        HttpContext.Trace.Write( "Jumony View", "Begin Initialize Master" );
        MasterView.Initialize( ViewContext );
        HttpContext.Trace.Write( "Jumony View", "End Initialize Master" );


        var jumonyMaster = MasterView as JumonyMasterView;
        if ( jumonyMaster != null )
        {
          HttpContext.Trace.Write( "Jumony View", "Begin Process Jumony Master View" );
          ProcessMaster( jumonyMaster );
          HttpContext.Trace.Write( "Jumony View", "Begin Process Jumony Master View" );
        }

        HttpContext.Trace.Write( "Jumony View", "Begin Render" );
        OnPreRender();
        result = MasterView.Render( this );
        OnPostRender();
        HttpContext.Trace.Write( "Jumony View", "End Render" );
      }
      else
      {
        HttpContext.Trace.Write( "Jumony View", "Begin Render" );
        OnPreRender();
        result = RenderContent( RenderAdapters.ToArray() );
        OnPostRender();
        HttpContext.Trace.Write( "Jumony View", "End Render" );
      }


      var disposable = handler as IDisposable;
      if ( disposable != null )
        disposable.Dispose();

      return result;
    }