Пример #1
0
        public void FeelLucky()
        {
            isBusy = true;
            var crawTargets = new List <XPathAnalyzer.CrawTarget>();
            var task        = TemporaryTask.AddTempTask("网页结构计算中",
                                                        HtmlDoc.SearchPropertiesSmart(CrawlItems, RootXPath, IsAttribute), crawTarget =>
            {
                crawTargets.Add(crawTarget);
                var datas        = HtmlDoc.GetDataFromXPath(crawTarget.CrawItems, IsMultiData, crawTarget.RootXPath);
                crawTarget.Datas = datas;
            }, d =>
            {
                isBusy = false;
                if (crawTargets.Count == 0)
                {
                    CrawTarget = null;
                    XLogSys.Print.Warn("没有检查到任何可选的列表页面");
                    return;
                }

                var luckModel    = new FeelLuckyModel(crawTargets, HtmlDoc);
                var view         = PluginProvider.GetObjectInstance <ICustomView>("手气不错面板") as UserControl;
                view.DataContext = luckModel;

                var name   = "手气不错";
                var window = new Window {
                    Title = name
                };
                window.WindowState = WindowState.Maximized;
                window.Content     = view;
                luckModel.SetView(view, window);
                window.Activate();
                window.ShowDialog();
                if (window.DialogResult == true)

                {
                    var crawTarget = luckModel.CurrentTarget;
                    RootXPath      = crawTarget.RootXPath;
                    CrawlItems.Clear();
                    CrawlItems.AddRange(crawTarget.CrawItems.Where(r => r.IsEnabled));
                }
            });

            SysProcessManager.CurrentProcessTasks.Add(task);
        }
Пример #2
0
        public void GreatHand()
        {
            var count              = 0;
            var crawTargets        = HtmlDoc.SearchPropertiesSmart(CrawlItems, RootXPath, IsAttribute);
            var currentCrawTargets = crawTargets.GetEnumerator();
            var result             = currentCrawTargets.MoveNext();

            if (result)
            {
                CrawTarget = currentCrawTargets.Current;
            }
            else
            {
                CrawTarget = null;
                XLogSys.Print.Warn("没有检查到任何可选的列表页面");
                return;
            }

            var crawitems     = CrawTarget.CrawItems;
            var datas         = HtmlDoc.GetDataFromXPath(crawitems, IsMultiData, CrawTarget.RootXPath);
            var propertyNames = new FreeDocument(datas.GetKeys().ToDictionary(d => d, d => (object)d));

            datas.Insert(0, propertyNames);
            var view = PluginProvider.GetObjectInstance <IDataViewer>("可编辑列表");
            var r    = view.SetCurrentView(datas);


            var name   = "手气不错_可修改第一列的属性名称";
            var window = new Window {
                Title = name
            };

            window.Content  = r;
            window.Closing += (s, e) =>
            {
                var check = MessageBox.Show("是否确认选择当前结果?【是】:确认结果,  【否】:检查下个目标,  【取消】:结束当前手气不错", "提示信息",
                                            MessageBoxButton.YesNoCancel);
                switch (check)
                {
                case MessageBoxResult.Yes:
                    foreach (var propertyName in propertyNames)
                    {
                        var item = crawitems.FirstOrDefault(d => d.Name == propertyName.Key);
                        if (item == null)
                        {
                            continue;
                        }
                        if (propertyName.Value == null)
                        {
                            continue;
                        }
                        item.Name = propertyName.Value.ToString();
                    }
                    CrawlItems.Clear();
                    RootXPath = CrawTarget.RootXPath;
                    CrawlItems.AddRange(crawitems);
                    currentCrawTargets = null;
                    break;

                case MessageBoxResult.No:
                    e.Cancel = true;
                    result   = currentCrawTargets.MoveNext();
                    count++;
                    if (result)
                    {
                        CrawTarget = currentCrawTargets.Current;
                    }
                    else
                    {
                        MessageBox.Show("已经搜索所有可能情况,搜索器已经返回开头");
                        crawTargets        = HtmlDoc.SearchPropertiesSmart(CrawlItems, RootXPath, IsAttribute);
                        currentCrawTargets = crawTargets.GetEnumerator();
                        count  = 0;
                        result = currentCrawTargets.MoveNext();
                        if (!result)
                        {
                            e.Cancel = false;
                        }
                        else
                        {
                            CrawTarget = currentCrawTargets.Current;
                        }
                    }

                    crawitems = CrawTarget.CrawItems;
                    var title = $"手气不错,第{count}次结果";
                    datas         = HtmlDoc.GetDataFromXPath(crawitems, IsMultiData, CrawTarget.RootXPath);
                    propertyNames = new FreeDocument(datas.GetKeys().ToDictionary(d => d, d => (object)d));
                    datas.Insert(0, propertyNames);
                    r = view.SetCurrentView(datas);
                    window.Content = r;
                    window.Title   = title;
                    break;

                case MessageBoxResult.Cancel:
                    return;
                }
            };


            window.ShowDialog();
        }
Пример #3
0
        public void FeelLucky()
        {
            if (string.IsNullOrEmpty(this.URLHTML))
            {
                this.VisitUrlAsync();
            }
            isBusy = true;
            var crawTargets = new List <XPathAnalyzer.CrawTarget>();
            ICollection <CrawlItem> existItems = CrawlItems;

            if (IsMultiData == ScriptWorkMode.One)
            {
                existItems = new List <CrawlItem> {
                    new CrawlItem {
                        Name = "temp", XPath = SelectXPath
                    }
                }
            }
            ;
            var task = TemporaryTask.AddTempTask("网页结构计算中",
                                                 HtmlDoc.DocumentNode.SearchPropertiesSmart(IsMultiData, existItems, RootXPath, RootFormat, IsAttribute),
                                                 crawTarget =>
            {
                crawTargets.Add(crawTarget);
                //var datas =
                //    HtmlDoc.DocumentNode.GetDataFromXPath(crawTarget.CrawItems, IsMultiData, crawTarget.RootXPath,
                //        RootFormat).ToList();
                //crawTarget.Datas = datas;
            }, d =>
            {
                isBusy = false;
                if (crawTargets.Count == 0)
                {
                    CrawTarget = null;
                    XLogSys.Print.Warn("没有检查到任何可选的列表页面");
                    return;
                }

                var luckModel    = new FeelLuckyModel(crawTargets, HtmlDoc, IsMultiData);
                var view         = PluginProvider.GetObjectInstance <ICustomView>("手气不错面板") as UserControl;
                view.DataContext = luckModel;

                var name   = "手气不错";
                var window = new Window {
                    Title = name
                };
                window.WindowState = WindowState.Maximized;
                window.Content     = view;
                luckModel.SetView(view, window);
                window.Activate();
                window.ShowDialog();
                if (window.DialogResult == true)

                {
                    var crawTarget = luckModel.CurrentTarget;
                    if (string.IsNullOrEmpty(RootXPath))
                    {
                        RootFormat = SelectorFormat.XPath;
                    }
                    RootXPath = crawTarget.RootXPath;


                    CrawlItems.AddRange(crawTarget.CrawItems.Where(r => r.IsEnabled && CrawlItems.FirstOrDefault(d2 => d2.XPath == r.XPath) == null));
                }
            });

            SysProcessManager.CurrentProcessTasks.Add(task);
        }