Ejemplo n.º 1
0
        public override void Run(bool runChildren)
        {
            currentDataRow = new DataRowObject();
            SetText(GetText());
            base.Run(runChildren);

            if (MustAttributes.IsNullOrEmpty() == false)
            {
                var must = MustAttributes.Split(',');
                if (currentDataRow.Attributes.Intersect(must).Count() == must.Count())
                {
                    Data.AddDataRow(this, currentDataRow);
                }
            }
            else
            {
                Data.AddDataRow(this, currentDataRow);
            }
            if (currentDataRow.IsDataNull())
            {
                if (EmptyTree != null)
                {
                    EmptyTree.SetParent(this);
                    EmptyTree.Run();
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 子を実行する。
        /// </summary>
        /// <param name="runChildren"></param>
        /// <param name="list"></param>
        protected void RunChildrenForArray <T>(bool runChildren, IEnumerable <T> list, Func <T, string> textFunc, Action <T> action)
        {
            if (runChildren)
            {
                List <TextPair <T> > dataList = list.Select(n => new TextPair <T> {
                    Text = textFunc(n), Obj = n
                }).ToList();
                if (ConvertTree != null)
                {
                    dataList = Convert <T>(dataList, textFunc).ToList();
                }
                if (Query != null)
                {
                    dataList = Query.RunQuery(dataList, this).ToList();
                }
                dataList = DoElementAt <TextPair <T> >(dataList).ToList();

                SetTexts(dataList.Select(n => n.Text));

                foreach (var item in dataList)
                {
                    this.SetText(item.Text);
                    action(item.Obj);
                    foreach (RawlerBase item2 in children)
                    {
                        item2.Run();
                        if (item2.GetBreakFlag())
                        {
                            break;
                        }
                    }
                }
                foreach (var item in children)
                {
                    item.Completed();
                }
                if (LoopEndEvent != null)
                {
                    LoopEndEvent(this, new EventArgs());
                }
                if (EmptyTree != null)
                {
                    if (list.Any() == false)
                    {
                        EmptyTree.SetParent(this);
                        EmptyTree.Run();
                    }
                }
                if (AnyTree != null)
                {
                    if (list.Any() == true)
                    {
                        AnyTree.SetParent(this);
                        AnyTree.Run();
                    }
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 子を実行する。
        /// </summary>
        /// <param name="runChildren"></param>
        /// <param name="list"></param>
        protected void RunChildrenForArray(bool runChildren, IEnumerable <string> list)
        {
            if (runChildren)
            {
                if (ConvertTree != null)
                {
                    list = Convert(list);
                }
                if (Query != null)
                {
                    list = Query.RunQuery(list, this);
                }
                list = DoElementAt <string>(list);
                SetTexts(list);

                foreach (var item in list)
                {
                    this.SetText(item);

                    foreach (RawlerBase item2 in children)
                    {
                        item2.Run();
                        if (item2.GetBreakFlag())
                        {
                            break;
                        }
                    }
                }

                if (LoopEndEvent != null)
                {
                    LoopEndEvent(this, new EventArgs());
                }
                if (EmptyTree != null)
                {
                    if (list.Any() == false)
                    {
                        EmptyTree.SetParent(this);
                        EmptyTree.Run();
                    }
                }
                if (AnyTree != null)
                {
                    if (list.Any() == true)
                    {
                        AnyTree.SetParent(this);
                        AnyTree.Run();
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public override void Run(bool runChildren)
        {
            currentDataRow = new DataRowObject();
            SetText(GetText());
            base.Run(runChildren);
            if (file == null)
            {
                file = this.GetUpperRawler <File>();
                if (file == null)
                {
                    ReportManage.ErrUpperNotFound <File>(this);
                    return;
                }
            }

            if (MustAttributes.IsNullOrEmpty() == false)
            {
                var must = MustAttributes.Split(',');
                if (currentDataRow.Attributes.Intersect(must).Count() == must.Count())
                {
                    if (SaveType == FileType.Ltsv)
                    {
                        file.WriteLine(currentDataRow.ToLtsv());
                    }
                    else
                    {
                        file.WriteLine(currentDataRow.DataDic.Select(n => n.Value.JoinText(",")).JoinText("\t"));
                    }
                }
            }
            else
            {
                if (SaveType == FileType.Ltsv)
                {
                    file.WriteLine(currentDataRow.ToLtsv());
                }
                else
                {
                    file.WriteLine(currentDataRow.DataDic.Select(n => n.Value.JoinText(",")).JoinText("\t"));
                }
            }
            if (currentDataRow.IsDataNull())
            {
                if (EmptyTree != null)
                {
                    EmptyTree.SetParent(this);
                    EmptyTree.Run();
                }
            }
        }
Ejemplo n.º 5
0
        private void NewMethod(bool runChildren)
        {
            List <RawlerLib.Web.Link> list;

            if (this.Parent is Links && ((Links)this.Parent).TargetTag == this.TargetTag)
            {
                var p = (Links)this.Parent;
                list = new List <RawlerLib.Web.Link>()
                {
                    p.currentLink
                };
            }
            else
            {
                if (string.IsNullOrEmpty(TargetTag))
                {
                    if (useAbsolutetLink)
                    {
                        list = new List <RawlerLib.Web.Link>(RawlerLib.Web.GetLinkForHTML(GetText(), GetPageUrl()));
                    }
                    else
                    {
                        list = new List <RawlerLib.Web.Link>(RawlerLib.Web.GetLinkForHTML(GetText()));
                    }
                }
                else
                {
                    if (useAbsolutetLink)
                    {
                        list = new List <RawlerLib.Web.Link>(RawlerLib.Web.GetLinkForHTML(GetText(), GetPageUrl(), TargetTag));
                    }
                    else
                    {
                        list = new List <RawlerLib.Web.Link>(RawlerLib.Web.GetLinkForHTML(GetText(), null, TargetTag));
                    }
                }
            }

            if (LabelFilter != null && LabelFilter.Length > 0)
            {
                list = new List <RawlerLib.Web.Link>(list.Where(n => n.Label.Contains(LabelFilter)));
            }
            if (UrlFilter != null && UrlFilter.Length > 0)
            {
                list = new List <RawlerLib.Web.Link>(list.Where(n => n.Url.Contains(UrlFilter)));
            }
            if (TagFilter != null && TagFilter.Length > 0)
            {
                list = new List <RawlerLib.Web.Link>(list.Where(n => n.TagWithoutUrl.Contains(TagFilter)));
            }
            if (CheckUrl)
            {
                if (useAbsolutetLink)
                {
                    list = list.Where(n => Uri.IsWellFormedUriString(n.Url, UriKind.Absolute)).ToList();
                }
                else
                {
                    list = list.Where(n => Uri.IsWellFormedUriString(n.Url, UriKind.RelativeOrAbsolute)).ToList();
                }
            }

            if (list.Count == 0 && EmptyTree != null)
            {
                EmptyTree.SetParent(this.Parent);
                EmptyTree.Run();
            }

            if (emptyReport && list.Count() == 0)
            {
                ReportManage.ErrReport(this, "対象が見つかりませんでした");
            }

            if (IsSingle == false)
            {
                RunChildrenForArray <RawlerLib.Web.Link>(runChildren, list, (n) => GetTextVisbleType(n), (n) => { currentLink = n; });
            }
            else
            {
                if (this.texts.Count() > 0)
                {
                    SetText(GetTextVisbleType(list.First()));
                    RunChildren(runChildren);
                }
            }
        }