Esempio n. 1
0
        private StyleManager( IHtmlElement element )
        {
            if ( element == null )
            throw new ArgumentNullException( "element" );

              _element = element;
        }
Esempio n. 2
0
        /// <summary>
        /// 尝试生成元素开始标签的HTML形式
        /// </summary>
        /// <param name="element">要生成HTML的元素</param>
        /// <param name="selfClosed">指示是否应产生自结束符号</param>
        /// <returns></returns>
        public static string GenerateTagHtml( IHtmlElement element, bool selfClosed )
        {
            if ( element == null )
            throw new ArgumentNullException( "element" );

              var builder = new StringBuilder( 20 );

              builder.Append( "<" );
              builder.Append( element.Name );

              foreach ( var attribute in element.Attributes() )
              {
            builder.Append( " " );
            builder.Append( attribute.Name );
            if ( attribute.AttributeValue != null )
            {
              var specification = element.Document.HtmlSpecification;

              if ( ( specification.IsUriValue( attribute ) || specification.IsScriptValue( attribute ) ) && !attribute.AttributeValue.Contains( '"' ) )
            builder.Append( "=\"" ).Append( attribute.AttributeValue ).Append( "\"" );
              else
            builder.Append( "=\"" ).Append( HtmlEncoding.HtmlAttributeEncode( attribute.AttributeValue ) ).Append( "\"" );
            }
              }

              if ( selfClosed )
            builder.Append( " /" );

              builder.Append( ">" );
              return builder.ToString();
        }
Esempio n. 3
0
    /// <summary>
    /// 创建一个 HTML 表单对象
    /// </summary>
    /// <param name="element">表单元素</param>
    /// <param name="configuration">表单配置</param>
    /// <param name="provider">表单控件提供程序</param>
    public HtmlForm( IHtmlElement element, FormConfiguration configuration = null, IFormProvider provider = null )
    {

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

      var document = element.Document;

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


      var modifier = document.DomModifier as ISynchronizedDomModifier;
      if ( modifier == null )
        throw new InvalidOperationException();


      SyncRoot = modifier.SyncRoot;
      
      _element = element;

      Configuration = configuration ?? new FormConfiguration();
      Provider = provider ?? new StandardFormProvider();


      RefreshForm();
    }
Esempio n. 4
0
 public IEnumerable<IHtmlElement> Apply(IEnumerable<IHtmlElement> elems, IHtmlElement root = null) {
     var result = new List<IHtmlElement>();
     foreach (var elem in elems) {
         if (this.Check(elem,root)!=null) result.Add(elem);
     }
     return result;
 }
Esempio n. 5
0
    /// <summary>
    /// 检查元素是否符合选择器要求(此方法会自动缓存结果)
    /// </summary>
    /// <param name="element">要检查的元素</param>
    /// <returns>是否符合选择器的要求</returns>
    public virtual bool IsEligible( IHtmlElement element )
    {
      if ( element == null )
        return false;

      var cacheContainer = element.Document as IVersionCacheContainer;
      if ( cacheContainer == null )
        return IsEligibleCore( element );


      lock ( cacheContainer.SyncRoot )
      {
        var cache = cacheContainer.CurrenctVersionCache[this] as Dictionary<IHtmlElement, bool>;

        if ( cache != null )
        {

          bool result;
          if ( cache.TryGetValue( element, out result ) )
            return result;
        }

        else
          cacheContainer.CurrenctVersionCache[this] = cache = new Dictionary<IHtmlElement, bool>();

        return cache[element] = IsEligibleCore( element );

      }
    }
Esempio n. 6
0
        public TableEntity(IHtmlElement tableElement)
        {
            var head = tableElement.FindFirst("thead");
            this.THead = new THeadEntity(head);

            var headTrList = head.Find("tr");
            foreach (var tr in headTrList)
            {
                var trEntity = new TrEntity(tr);
                var tdList = tr.Find("td").ToList();
                foreach (var td in tdList)
                {
                    trEntity.TdList.Add(new TdEntity(td) { Text = td.InnerText() });
                }
                this.THead.TrList.Add(trEntity);
            }
            var body = tableElement.FindFirst("tbody");
            this.TBody = new TBodyEntity(body);

            var bodyTrList = body.Find("tr");
            foreach (var tr in bodyTrList)
            {
                var trEntity = new TrEntity(tr);
                var tdList = tr.Find("td").ToList();
                foreach (var td in tdList)
                {
                    trEntity.TdList.Add(new TdEntity(td) { Text = td.InnerText() });
                }
                this.TBody.TrList.Add(trEntity);
            }
        }
Esempio n. 7
0
 public static ApiPagedResult<List<ProductItem>> GetProductItemList(IHtmlElement stockTable, int page = 1)
 {
     var result = new ApiPagedResult<List<ProductItem>>();
     var tableEntity = new TableEntity(stockTable);
     if (tableEntity.TBody.TrList.Count == 1 && tableEntity.TBody.TrList[0].TrElement.InnerHtml().IndexOf("没有符合条件的结果") != -1)
     {
         result.HasMore = false;
         result.Data = new List<ProductItem>();
     }
     else
     {
         var list = tableEntity.TBody.TrList.Select(x => x.GetProductItem()).ToList();
         var nextUrl = stockTable.Container.Find("a.page-next");
         if (nextUrl.Any())
         {
             var pageNext = UrlHelper.GetIntValue(nextUrl.First().Attribute("href").AttributeValue, "page");
             result.HasMore = pageNext > page;
         }
         else
         {
             result.HasMore = false;
         }
         result.Data = list;
     }
     tableEntity.Dispose();
     return result;
 }
Esempio n. 8
0
    internal FormButtonGroupItem( FormButtonGroup groupControl, IHtmlElement element )
      : base( groupControl )
    {

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

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

      if ( !element.Name.EqualsIgnoreCase( "input" ) )
        throw new InvalidOperationException();

      if ( !element.Attribute( "name" ).Value().EqualsIgnoreCase( groupControl.Name ) )
        throw new InvalidOperationException();

      var type = element.Attribute( "type" ).Value();

      if ( type.EqualsIgnoreCase( "radio" ) )
        ButtonType = FormGroupButtonType.RadioButton;

      else if ( type.EqualsIgnoreCase( "checkbox" ) )
        ButtonType = FormGroupButtonType.RadioButton;

      else
        throw new InvalidOperationException();

      Element = element;
    }
        public void Count_of_empty_collection_should_be_0()
        {
            var elements = new IHtmlElement[] { };
            var collection = new HtmlCollection(elements);

            Assert.That(collection.Count, Is.EqualTo(0));
        }
Esempio n. 10
0
 public void BindData( IHtmlElement element, object data )
 {
     if ( IsComplexData( data.GetType() ) )
     BindComplexData( element, data );
       else
     BindSimpleData( element, data );
 }
Esempio n. 11
0
 protected virtual void ApplyAdorners(IHtmlElement cell)
 {
     foreach (var adorner in Adorners)
     {
         adorner.ApplyTo(cell);
     }
 }
Esempio n. 12
0
 public override IHtmlElement Check(IHtmlElement elem, IHtmlElement root = null)
 {
     if (elem == root) return null;
     if (AscendantFilters.Count == 0) throw new ArgumentException("Ascendant Filter is required.");
     var at = AscendantFilters.Count-1;
    
     
     var filter = AscendantFilters[at];
     if (filter.Check(elem, root) == null || --at<0) return null;
     filter = AscendantFilters[at];
     var p = elem.ParentNode;
     while (p != null)
     {
         
         var checkResult = filter.Check(p,root);
         if (checkResult != null) {
             
             if (--at < 0) return elem;
             p = checkResult.ParentNode;
             continue;
         }
         if (p == root) break;
         p = p.ParentNode;  
           
     }
     return null;
 }
Esempio n. 13
0
        /// <summary>
        /// 检查元素是否符合选择器
        /// </summary>
        /// <param name="element">要检验的元素</param>
        /// <returns>是否符合选择器</returns>
        public virtual bool IsEligible( IHtmlElement element )
        {
            if ( element == null )
            return false;

              return IsEligible( LeftSelector, element );
        }
Esempio n. 14
0
    internal HtmlListItem( IHtmlElement element )
    {
      if ( !element.Name.EqualsIgnoreCase( "li" ) )
        throw new FormatException( "HTML 文档格式不正确,列表元素只能包含 li 元素" );

      _element = element;
    }
Esempio n. 15
0
        /// <summary>
        /// 检查元素是否符合指定选择器要求,并缓存结果于元素当前文档版本
        /// </summary>
        /// <param name="selector">选择器</param>
        /// <param name="element">元素</param>
        /// <returns>是否符合选择器要求</returns>
        public static bool IsEligibleBuffered( this ICssSelector selector, IHtmlElement element )
        {
            if ( selector == null )
            throw new ArgumentNullException( "selector" );

              if ( element == null )
            return selector.IsEligible( element );

              var cacheContainer = element.Document as IVersionCacheContainer;
              if ( cacheContainer == null )
            return selector.IsEligible( element );

              lock ( cacheContainer.SyncRoot )
              {
            var cache = cacheContainer.CurrenctVersionCache[selector] as Dictionary<IHtmlElement, bool>;

            if ( cache != null )
            {

              bool result;
              if ( cache.TryGetValue( element, out result ) )
            return result;
            }

            else
              cacheContainer.CurrenctVersionCache[selector] = cache = new Dictionary<IHtmlElement, bool>();

            return cache[element] = selector.IsEligible( element );

              }
        }
Esempio n. 16
0
        public HtmlMeta( IHtmlElement element )
        {
            if ( !element.Name.EqualsIgnoreCase( "meta" ) )
            throw new InvalidOperationException();

              Element = element;
        }
Esempio n. 17
0
    internal RouteValueDictionary GetRouteValues( IHtmlElement element, bool clearRouteAttributes )
    {

      var routeValues = new RouteValueDictionary();

      var inherits = element.Attribute( "inherits" ).Value();

      if ( inherits != null )
      {

        var inheritsKeys = GetInheritsKeys( inherits );

        foreach ( var key in inheritsKeys )
          routeValues.Add( key, RequestContext.RouteData.Values[key] );

      }


      if ( !MvcEnvironment.Configuration.DisableUnderscorePrefix )
        CustomRouteValues( element, "_", routeValues, clearRouteAttributes );
      
      CustomRouteValues( element, "route-", routeValues, clearRouteAttributes );

      return routeValues;
    }
    bool ISelector.IsEligible( IHtmlElement element )
    {
      if ( element == null )
        return false;

      return _elements.Contains( element );
    }
Esempio n. 19
0
    internal FormButtonGroup( HtmlForm form, string name, IHtmlElement[] buttonElements )
      : base( form )
    {
      _name = name;
      ButtonItems = buttonElements.Select( element => CreateGroupItem( element ) ).ToArray();

      _allowMultiple = ButtonItems.Any( item => item.ButtonType == FormGroupButtonType.CheckBox );
    }
Esempio n. 20
0
    /// <summary>
    /// 派生类调用此构造函数初始化 FormTextControl 实例
    /// </summary>
    /// <param name="form">所属表单</param>
    /// <param name="element">定义文本控件的元素</param>
    protected FormTextControl( HtmlForm form, IHtmlElement element )
      : base( form )
    {

      Element = element;
      MaxLength = GetMaxLength();

    }
Esempio n. 21
0
    protected override bool IsEligible( ISelector leftSelector, IHtmlElement element )
    {
      var restrict = leftSelector as ContainerRestrict;
      if ( restrict != null )
        return restrict.RestrictContainer.Nodes().Contains( element );

      return leftSelector.IsEligibleBuffered( element.Parent() );
    }
Esempio n. 22
0
 private void AddStyleReferences( IHtmlElement headElement, string[] styleFiles )
 {
   foreach ( var path in styleFiles )
     headElement.AddElement( "link" )
       .SetAttribute( "rel", "stylesheet" )
       .SetAttribute( "type", "text/css" )
       .SetAttribute( "href", path );
 }
Esempio n. 23
0
    internal HtmlSelect( HtmlForm form, IHtmlElement element )
      : base( form )
    {

      Element = element;
      options = element.Find( "option" ).Select( e => new HtmlOption( this, e ) ).ToArray();

    }
Esempio n. 24
0
 public override IHtmlElement Check(IHtmlElement elem, IHtmlElement root = null)
 {
     foreach (var filter in Filters) {
         var result = filter.Check(elem,root);
         if (result == null) return null;
     }
     return elem;
 }
Esempio n. 25
0
        public HtmlTextArea( HtmlForm form, IHtmlElement element )
        {
            if ( !element.Name.EqualsIgnoreCase( "textarea" ) )
            throw new InvalidOperationException( "只有 <textarea> 元素才能转换为 HtmlTextArea 对象" );

              _form = form;
              _element = element;
        }
Esempio n. 26
0
    /// <summary>
    /// 对元素进行数据绑定
    /// </summary>
    /// <param name="element">要进行数据绑定的元素</param>
    protected virtual void DataBind( IHtmlElement element, BindingContext context )
    {
      var bindings = FindBindings( element ).OrderBy( b => b.Priority );

      context.Enter( element );
      bindings.ForAll( b => b.DataBind( context ) );
      element.Elements().ForAll( e => DataBind( e, context ) );
      context.Exit( element );
    }
Esempio n. 27
0
    public AttributeAdapter( object attribute, IHtmlElement element )
    {
      _attribute = attribute as IHTMLDOMAttribute;
      _attribute2 = attribute as IHTMLDOMAttribute2;

      _element = element;

      _raw = attribute;
    }
Esempio n. 28
0
        private void BindSimpleData( IHtmlElement element, object data )
        {
            var htmlContent = data as IHtmlContent;

              if ( htmlContent != null )
            element.InnerHtml( htmlContent.ToHtmlString() );
              else
            element.InnerText( data.ToString() );
        }
Esempio n. 29
0
            public override IHtmlElement Check(IHtmlElement elem, IHtmlElement root = null)
            {
                foreach (var filter in this.Filters) {
                    var next = filter.Check(elem, root);
                    return next != null ? elem : null;
                }
                return null;

            }
Esempio n. 30
0
        public void Count_of_collection_with_one_element_should_be_1()
        {
            var elements = new IHtmlElement[] {
                new HtmlElement()
            };
            var collection = new HtmlCollection(elements);

            Assert.That(collection.Count, Is.EqualTo(1));
        }
Esempio n. 31
0
 private StyleClassManager(IHtmlElement element)
 {
     _element = element;
 }
Esempio n. 32
0
 public override Boolean IsAppendingData(IHtmlElement submitter)
 {
     return(Object.ReferenceEquals(submitter, Input));
 }
Esempio n. 33
0
 public LinkExternalLogin(HttpClient client, IHtmlDocument externalLoginsDocument, DefaultUIContext context)
     : base(client, externalLoginsDocument, context)
 {
     _linkLoginForm   = HtmlAssert.HasForm($"#link-login-form", externalLoginsDocument);
     _linkLoginButton = HtmlAssert.HasElement($"#link-login-button-Contoso", externalLoginsDocument);
 }
Esempio n. 34
0
 internal static void BindData(IHtmlElement element, object p)
 {
     throw new NotImplementedException();
 }
Esempio n. 35
0
 public TBodyEntity(IHtmlElement tbodyElement)
 {
     this.TBodyElement = tbodyElement;
 }
Esempio n. 36
0
 public void AddOption(IHtmlOptionsGroupElement element, IHtmlElement before = null)
 {
     Options.Add(element, before);
 }
        /// <summary>
        /// 从当前容器按照 CSS 选择器搜索符合要求的最后一个元素,若不存在任何符合要求的元素,则返回 defaultElement 或者 null 。
        /// </summary>
        /// <param name="container">要搜索子代元素的容器</param>
        /// <param name="expression">CSS选择器</param>
        /// <param name="defaultElement">(可选)找不到符合要求的元素时应返回的元素,若不提供则返回 null</param>
        /// <returns>搜索到的符合要求的最后一个元素</returns>
        public static IHtmlElement FindLastOrDefault(this IHtmlContainer container, string expression, IHtmlElement defaultElement = null)
        {
            if (container == null)
            {
                throw new ArgumentNullException("container");
            }

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


            return(container.Find(expression).LastOrDefault() ?? defaultElement);
        }
        /// <summary>
        /// 从当前容器按照 CSS 选择器搜索符合要求的唯一元素,如果有多个元素符合要求,则会引发异常,如果没有符合要求的元素,则返回 defaultElement 或者 null 。
        /// </summary>
        /// <param name="container">要搜索子代元素的容器</param>
        /// <param name="expression">CSS选择器</param>
        /// <param name="defaultElement">(可选)找不到符合要求的元素时应返回的元素,若不提供则返回 null</param>
        /// <returns>搜索到的符合要求的唯一元素</returns>
        public static IHtmlElement FindSingleOrDefault(this IHtmlContainer container, string expression, IHtmlElement defaultElement = null)
        {
            if (container == null)
            {
                throw new ArgumentNullException("container");
            }

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


            try
            {
                return(container.Find(expression).SingleOrDefault() ?? defaultElement);
            }
            catch (InvalidOperationException e)
            {
                throw new InvalidOperationException(string.Format("符合选择器 \"{0}\" 的元素不唯一", expression), e);
            }
        }
Esempio n. 39
0
 public HtmlBuilder(string rootName)
 {
     this.rootName = rootName;
     rootElement   = new HtmlElement(rootName);
 }
Esempio n. 40
0
 public void Clear()
 {
     rootElement = new HtmlElement(rootName);
 }
Esempio n. 41
0
 /// <summary>
 /// Sanitizes the specified parsed HTML body fragment.
 /// If the document has not been parsed with CSS support then all styles will be removed.
 /// </summary>
 /// <param name="document">The parsed HTML document.</param>
 /// <param name="context">The node within which to sanitize.</param>
 /// <param name="baseUrl">The base URL relative URLs are resolved against. No resolution if empty.</param>
 /// <returns>The sanitized HTML document.</returns>
 public IHtmlDocument SanitizeDom(IHtmlDocument document, IHtmlElement context = null, string baseUrl = "")
 {
     DoSanitize(document, context ?? (IParentNode)document, baseUrl);
     return(document);
 }
Esempio n. 42
0
 public static string GetN_value(IHtmlElement item, string str)
 {
     return(item.Exists(str) ? item.FindFirst(str).InnerText().Trim() : string.Empty);
 }
Esempio n. 43
0
        public IHtmlElementsCollection ParseElements(int startIndex, int endIndex)
        {
            IHtmlElementsCollection elements = new HtmlElementsCollection();

            // get all matches in current range
            List <Match> startTagMatchesInCurrentRange     = _startTagsMathes.Where(x => x.Index >= startIndex && x.Index < endIndex).ToList();
            List <Match> pairStartTagMatchesInCurrentRange = _pairStartTagsMathes.Where(x => x.Index >= startIndex && x.Index < endIndex).ToList();
            List <Match> endTagMatchesInCurrentRange       = _endTagsMathes.Where(x => x.Index > startIndex && x.Index < endIndex).ToList();

            try
            {
                // get root start tags in current range
                List <Match> rootStartTagMatches = startTagMatchesInCurrentRange
                                                   .Where(currentStartTag =>
                                                          pairStartTagMatchesInCurrentRange
                                                          .Count(startTag => startTag.Index < currentStartTag.Index) == endTagMatchesInCurrentRange.Count(endTag => endTag.Index <= currentStartTag.Index)
                                                          )
                                                   .ToList();
                // get root end tags in current range
                List <Match> rootEndTagMatches = endTagMatchesInCurrentRange
                                                 .Where(currentEndTag =>
                                                        pairStartTagMatchesInCurrentRange
                                                        .Count(startTag => startTag.Index < currentEndTag.Index) == endTagMatchesInCurrentRange.Count(endTag2 => endTag2.Index <= currentEndTag.Index)
                                                        )
                                                 .ToList();

                // create IHtmlElement for every start tag match and add to collection
                foreach (Match startTagMatch in rootStartTagMatches)
                {
                    // get tag name
                    string tagName = _htmlHelper.ExtractTagNameFromStartTag(startTagMatch.Value);

                    // parse attributes
                    HtmlAttributesCollection attributes = ParseAttributes(startTagMatch.Value);

                    // if tag is self closing
                    if (_htmlHelper.IsSelfClosingHtmlTag(tagName))
                    {
                        // create elements factory
                        IHtmlSelfClosingTagElementFactory htmlElementsFactory;
                        switch (tagName.ToLower())
                        {
                        case "!doctype":
                            htmlElementsFactory = new HtmlDoctypeElementFactory();
                            break;

                        default:
                            htmlElementsFactory = new HtmlSelfClosingTagElementFactory(tagName);
                            break;
                        }

                        // create element
                        IHtmlElement element = htmlElementsFactory.Create(attributes, _encodedHtml, this);
                        // add
                        elements.Add(element);
                    }
                    // when tag have pair tags
                    else
                    {
                        // create elements factory
                        IHtmlPairTagsElementFactory htmlElementsFactory;
                        switch (tagName.ToLower())
                        {
                        case "noscript":
                            htmlElementsFactory = new HtmlNoScriptElementFactory();
                            break;

                        case "script":
                            htmlElementsFactory = new HtmlScriptElementFactory();
                            break;

                        case "style":
                            htmlElementsFactory = new HtmlStyleElementFactory();
                            break;

                        case "code":
                            htmlElementsFactory = new HtmlCodeElementFactory();
                            break;

                        default:
                            htmlElementsFactory = new HtmlNodeElementFactory(tagName);
                            break;
                        }

                        // find start content index
                        int startContentIndex = startTagMatch.Index + startTagMatch.Value.Length;

                        // find cloing tang on current star tag
                        Match endTagMatch = rootEndTagMatches.FirstOrDefault(x => x.Index > startTagMatch.Index);
                        // in html may have tags which should have end tag but he is not defined, in this case just skip him as set end index to be end index on current start tag
                        int endContentIndex = startTagMatch.Index + startTagMatch.Value.Length;
                        if (endTagMatch != null)
                        {
                            endContentIndex = endTagMatch.Index;
                        }

                        // create element
                        IHtmlElement element = htmlElementsFactory.Create(attributes, _encodedHtml, startContentIndex, endContentIndex, this);

                        // add
                        elements.Add(element);
                    }
                }
            }
            catch (Exception ex)
            {
                return(elements);
            }

            return(elements);
        }
 public void Add(IHtmlElement element)
 {
     _childrens.Add(element);
 }
Esempio n. 45
0
 public static TBehavior WrapAs <TBehavior>(this IHtmlElement element) where TBehavior : IBehavior, new()
 {
     return(new TBehavior {
         WrappedElement = element
     });
 }
Esempio n. 46
0
 internal HtmlInputText(HtmlForm form, IHtmlElement element)
     : base(form, element)
 {
     var value = element.Attribute("value").Value() ?? "";
 }
Esempio n. 47
0
 /// <summary>
 /// 派生类实现此方法检查元素是否符合选择器要求
 /// </summary>
 /// <param name="element"></param>
 /// <returns></returns>
 protected abstract bool IsEligibleCore(IHtmlElement element);
Esempio n. 48
0
 public DecoratorElement(IHtmlElement htmlElement)
 {
     _htmlElement = htmlElement;
 }
Esempio n. 49
0
 private IHtmlElement FindTarget(IHtmlElement element, string name)
 {
     throw new NotImplementedException();
 }
Esempio n. 50
0
 public LinkDecorator(IHtmlElement htmlElement, Uri url)
     : base(htmlElement)
 {
     _url = url;
 }
Esempio n. 51
0
 protected override bool IsEligibleCore(IHtmlElement element)
 {
     return(_selector.IsEligible(element));
 }
Esempio n. 52
0
 public static int GetInt_value(IHtmlElement item, string str)
 {
     return(item.Exists(str) ? Convert.ToInt32(item.FindFirst(str).InnerText().Trim().Replace("图", "")) : 0);
 }
Esempio n. 53
0
 public BoldDecorator(IHtmlElement htmlElement)
     : base(htmlElement)
 {
 }
Esempio n. 54
0
 protected override bool IsInPage()
 {
     _node = _node ?? (IHtmlElement)Document.Body.QuerySelector("body > div");
     return(_node.QuerySelector("div:nth-child(1) > div > h2")?.TextContent == "Process GreenFlow::StepCScreen");
 }
Esempio n. 55
0
 public Division(IHtmlElement element)
     : base("", "", ElementNames.Dvision, "")
 {
     AddElement(element);
 }
Esempio n. 56
0
        /// <summary>
        /// 渲染部分视图(重写此方法以实现自定义输出 partial 元素)
        /// </summary>
        /// <param name="partialElement">partial 元素</param>
        /// <returns></returns>
        protected virtual string RenderPartial(IHtmlElement partialElement)
        {
            var action  = partialElement.Attribute("action").Value();
            var view    = partialElement.Attribute("view").Value();
            var path    = partialElement.Attribute("path").Value();
            var handler = partialElement.Attribute("handler").Value();
            var name    = partialElement.Attribute("name").Value();

            if (!_partialExecutors.IsNullOrEmpty() && name != null)
            {
                var executor = _partialExecutors.FirstOrDefault(e => e.Name.EqualsIgnoreCase(name));
                if (executor != null)
                {
                    var wrapper = ViewHandler as IHandlerWrapper;
                    if (wrapper != null)
                    {
                        return(executor.Execute(wrapper.Handler, partialElement));
                    }
                    else
                    {
                        return(executor.Execute(ViewHandler, partialElement));
                    }
                }
            }


            var helper = MakeHelper();


            try
            {
                if (action != null)//Action 部分视图
                {
                    var routeValues = Url.GetRouteValues(partialElement);

                    return(RenderAction(partialElement, action, partialElement.Attribute("controller").Value(), routeValues));
                }

                else if (view != null)
                {
                    return(RenderPartial(partialElement, view));
                }

                else if (path != null)
                {
                    if (!VirtualPathUtility.IsAppRelative(path))
                    {
                        throw new FormatException("path 只能使用应用程序根相对路径,即以 \"~/\" 开头的路径,调用 VirtualPathUtility.ToAppRelative 方法或使用 HttpRequest.AppRelativeCurrentExecutionFilePath 属性获取");
                    }

                    var content = HtmlProviders.LoadContent(path);
                    if (content != null)
                    {
                        return(content.Content);
                    }
                }
            }
            catch (ThreadAbortException)
            {
            }
            catch //若渲染时发生错误
            {
                if (MvcEnvironment.Configuration.IgnorePartialRenderException || partialElement.Attribute("ignoreError") != null)
                {
                    return("<!--parital view render failed-->");
                }
                else
                {
                    throw;
                }
            }

            throw new NotSupportedException("无法处理的partial标签:" + ContentExtensions.GenerateTagHtml(partialElement, false));
        }
Esempio n. 57
0
 private string RenderAction(IHtmlElement partialElement, string actionName, string controllerName, System.Web.Routing.RouteValueDictionary routeValues)
 {
     return(MakeHelper().Action(actionName, controllerName, routeValues).ToString());
 }
Esempio n. 58
0
 private string RenderPartial(IHtmlElement partialElement, string viewName)
 {
     return(MakeHelper().Partial(viewName).ToString());
 }
Esempio n. 59
0
 protected override bool IsInPage()
 {
     _node = _node ?? (IHtmlElement)Document.Body.QuerySelector("body > div");
     return(_node.QuerySelector("div > div > h2")?.TextContent == "BlueFlow::Process Completed");
 }
Esempio n. 60
0
 public TdEntity(IHtmlElement tdElement)
 {
     this.TdElement = tdElement;
 }