예제 #1
0
        private void Browser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            WebBrowser2 browser = sender as WebBrowser2;
            // 查询当前Url是否已有填报线程。
            FillBase findFill = GetFiller(e.Url);

            if (findFill == null)
            {
                if (CanFill(e.Url))
                { //若当前Url可填报且线程尚未创建,则创建一个新线程。
                    FillBase fill = CreateFillInner(e.Url, browser);
                    if (fill != null)
                    {
                        _currentFill = fill;
                    }
                }
                else
                {
                    OnDocumentCompleted(browser, e);
                    return;
                }
            }
            else
            {
                // 若当前填报线程已结束,则创建一个新的线程执行填报。
                if (findFill.FillState == FillState.End || findFill.FillState == FillState.Exception || findFill.FillState == FillState.Abort)
                {
                    findFill.Dispose();
                    findFill = CreateFillInner(e.Url, browser);
                }
                _currentFill = findFill;
            }
            if (browser.IsBusy == false && _currentFill != null && _currentFill.Browser == browser && !browser.IsDisposed)
            {
                _currentFill.FillIndexes = _fillIndexes;
                if (_currentFill.FillState == FillState.Suspended || _currentFill.FillState == FillState.Waiting ||
                    _currentFill.FillState == FillState.Running)
                {
                    if (CanFill(e.Url))
                    {
                        _currentFill.UpdateDocument(e.Url);
                    }
                    else
                    {
                        _currentFill.UpdateDocument();
                    }
                    _currentFill.Resume();
                }
                else if (_currentFill.FillState == FillState.New)
                {
                    _currentFill.BeginFill();
                }
            }
            OnDocumentCompleted(browser, e);
        }
예제 #2
0
        public override void BeginFill()
        {
            _fillTable.Clear();
            _uris = this.GetUris();
            _data = base.DataProvider.ProvideData(null) as Hashtable;
            // 获取数据转换器
            converter = this.DataProvider.GetConverter() as WebValueConverter;
            // 从配置文件中获取是否进行数据转换
            if (FileHelper.GetIsUseConverter(this.Version, this.FillType))
            {
                converter.DataFilePath = string.IsNullOrEmpty(base.DataProvider.DataSourceFile) ? "" : System.IO.Directory.GetParent(base.DataProvider.DataSourceFile).FullName;
                string converterFile = FileHelper.GetConverterFile(this.FillType);
                _data = converter.Convert(converterFile, this.FillType, _data);
            }
            _browser.Invoke((Action)(() =>
            {
                // 监听浏览器事件,确定填报线程的执行顺序。
                _browser.Navigating += Browser_Navigating;
                _browser.DocumentCompleted += Browser_DocumentCompleted;
                _browser.NewWindow3 += Browser_NewWindow3;
                _openedBrowser.Add(_browser);

                if (_browser.IsBusy == false && _browser.Document != null)
                {
                    HtmlDocument doc = FindFillDocument(_browser.Document);
                    if (doc == null || CanFill(doc.Url) == false)
                    {
                        return;
                    }
                    _currentFill = CreateFillInner(doc.Url, _browser);
                    _currentFill.FillIndexes = _fillIndexes;
                    if (_currentFill != null)
                    {
                        _currentFill.BeginFill();
                    }
                }
            }));
        }