Esempio n. 1
0
 protected virtual void OnFillerStateChanged(FillBase fill)
 {
     if (fill.FillState == FillState.End)
     {
         Uri url = null;
         try
         {
             url = new Uri(this.EndPageUri);
         }
         catch (Exception)
         {
             this.EndFill();
             WebFillManager.ShowMessageBox(string.Format("填报类型{0}的EndFillPageUri的url地址不正确!", base.FillType), "错误",
                                           MessageBoxButtons.OK, MessageBoxIcon.Information);
             return;
         }
         if (fill.CurrentUrl.AbsolutePath == url.AbsolutePath)
         {
             OnFinished(EventArgs.Empty);
             WebFillManager.ShowMessageBox("填报已完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
             this.EndFill();
         }
     }
     else if (fill.FillState == FillState.Exception)
     {
         if (fill.Exception != null)
         {
             LogHelper.Write(fill.Exception);
         }
     }
 }
Esempio n. 2
0
 protected override void OnFillerStateChanged(FillBase fill)
 {
     if (fill.FillState == FillState.Exception)
     {
         WebFillManager.ShowMessageBox(string.Format("填报过程发生错误,异常信息:{0}", fill.Exception.Message), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
     base.OnFillerStateChanged(fill);
 }
Esempio n. 3
0
 private void Browser_NewWindow3(object sender, WebBrowserNavigatingEventArgs e)
 {
     if (_currentFill != null)
     {
         _currentFill.Reset(); // 有新的页面打开时挂起当前填报线程。
         _fillIndexes = _currentFill.FillIndexes == null ? _fillIndexes : _currentFill.FillIndexes;
         _currentFill = null;
     }
     OnBrowserNewWindow3((WebBrowser2)sender, e);
 }
Esempio n. 4
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);
        }
Esempio n. 5
0
        private void OnFillStateChanged(object sender, EventArgs e)
        {
            FillBase fill = sender as FillBase;

            if (fill != null)
            {
                OnFillerStateChanged(fill);
                if (fill.FillState == FillState.End || fill.FillState == FillState.Abort || fill.FillState == FillState.Exception)
                {
                    OnEndPageFill(new WebBrowserDocumentCompletedEventArgs(fill.CurrentUrl));
                    fill.FillStateChanged -= OnFillStateChanged;
                }
            }
        }
Esempio n. 6
0
 protected override void OnFillerStateChanged(FillBase fill)
 {
     if (fill.FillState == FillState.End)
     {
         Uri url = null;
         try
         {
             url = new Uri(this.EndPageUri);
         }
         catch (Exception)
         {
             this.EndFill();
             WebFillManager.ShowMessageBox(string.Format("填报类型{0}的EndFillPageUri的url地址不正确!", base.FillType), "错误", MessageBoxButtons.OK, MessageBoxIcon.Information);
             return;
         }
     }
 }
Esempio n. 7
0
 private void Browser_Navigating(object sender, WebBrowserNavigatingEventArgs e)
 {
     WebBrowserUtils.WinApi.NativeApi.DeleteUrlCacheEntry(e.Url.OriginalString);
     if (_currentFill != null)
     {
         // 在导航到任何网页时挂起当前的填报线程。
         if (_currentFill != null)
         {
             _currentFill.Reset();
         }
         _fillIndexes = _currentFill.FillIndexes == null ? _fillIndexes : _currentFill.FillIndexes;
         // 将当前填报线程正在进行填报的值存储到CurrentValue,以便在打开文件对话框中填入。
         _currentFillValue = _currentFill.CurrentFillValue;
         if (CanFill(e.Url))
         {
             _currentFill = null;
         }
     }
     OnBrowserNavigating((WebBrowser2)sender, e);
 }
Esempio n. 8
0
        private void Browser_Disposed(object sender, EventArgs e)
        {
            WebBrowser2 browser = sender as WebBrowser2;

            if (browser != null)
            {
                DetachWebBrowser(browser); // 浏览器被关闭时停止监听其事件,并继续主WebBrowser中的填报线程。
            }
            _currentFill = null;
            _openedBrowser.Remove(browser);
            HtmlDocument doc = FindFillDocument(_openedBrowser[_openedBrowser.Count - 1].Document);

            if (doc != null)
            {
                FillBase findFill = GetFiller(doc.Url);
                if (findFill != null)
                {
                    _currentFill = findFill;
                }
            }
            this.OnBrowserDisposed(browser);
        }
Esempio n. 9
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();
                    }
                }
            }));
        }
Esempio n. 10
0
 public override void EndFill()
 {
     _browser.Navigating        -= Browser_Navigating;
     _browser.DocumentCompleted -= Browser_DocumentCompleted;
     _browser.NewWindow3        -= Browser_NewWindow3;
     foreach (var item in _openedBrowser)
     {
         this.DetachWebBrowser(item);
     }
     if (_currentFill != null)
     {
         _currentFill.Reset();
         _currentFill = null;
     }
     this.DataProvider.Clean();
     foreach (FillBase item in _fillTable.Values)
     {
         if (item != null)
         {
             item.EndFill();
         }
     }
     _fillTable.Clear();
 }
Esempio n. 11
0
        protected FillBase CreateFillInner(Uri url, WebBrowser2 browser)
        {
            string uri = url.AbsolutePath;

            if (string.IsNullOrEmpty(uri))
            {
                return(null);
            }
            UrlParameter parameter = _uris[uri] as UrlParameter;
            string       key       = parameter == null ? null : parameter.LabelName;

            if (key == null)
            {
                return(null);
            }
            FillBase fill = CreateFill(url, browser);

            if (fill != null)
            {
                if (_fillTable.Contains(key))
                {
                    _fillTable[key] = fill;
                }
                else
                {
                    _fillTable.Add(key, fill);
                }
                fill.DataTable         = _data;
                fill.RulePath          = RuleFilePath;
                fill.FillVersion       = this.Version;
                fill.FillRecords       = this._records;
                fill.DataProvider      = this.DataProvider;
                fill.FillStateChanged += new EventHandler(OnFillStateChanged);
            }
            return(fill);
        }