Ejemplo n.º 1
0
        /// <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);
        }
Ejemplo n.º 2
0
    /// <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;
    }
Ejemplo n.º 3
0
 /// <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 );
 }
Ejemplo n.º 4
0
 /// <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));
 }