WPF设计考虑使用WebBrowser控件 [英] WPF Design Considerations Using WebBrowser Control

查看:120
本文介绍了WPF设计考虑使用WebBrowser控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要建立一个程序,让我从一个系统中不同的触发点被击中跟踪。

I have to build a program that will allow me to track from a system different trigger points being hit.

当触发已另一个系统调用Web服务中命中,这个Web服务将记录到数据库中的以下内容:

When a trigger has been hit within another system a web service is called, this web service will log to a database the following:


  1. 联盟ID

  2. 触发标识

  3. 参考code

我的程序是读取这些数据,并调用到分支机构的网站呼吁子公司跟踪。

My program is to read this data and invoke a call to affiliates websites for affiliate tracking.

唯一麻烦的是,这些网站不提供任何好的Web服务或形式后,它通过跟踪像素(从某种程序自己的服务器上创建的映像)或JavaScript完成的。​​

The only trouble is, these sites do not offer any nice web service or form post, it is done via tracking pixels (images created from some kind of process on their server) or javascript.

所以,我一直在这个试图得到它的工作,我能想到这样做的唯一方法是通过使用web浏览器控制一个WPF或WinForms应用程序玩耍。

So I have been playing around with this trying to get it working, and the only way I can think of doing it is via a WPF or WinForms application using the "WebBrowser" control.

于是我简单地得到设置了数据库,并为每个触发的结果捕获获得需要的子公司跟踪图像code或JavaScript code,然后做与参考号码predefined键替代,子公司IDS等。

So I simply get the results set out of the database and for each trigger captured get the required affiliate tracking image code or javascript code and then do replacements on predefined keys with the reference numbers, affiliate ids, etc.

在这里我担心的,是因为WebBrowser控件是异步之前我问了Web浏览器加载另一个跟踪code段可能无法处理JavaScript或图像请求。

My concern here, is as the WebBrowser control is asynchronous it may not process the javascript or image request before I ask the web browser to load another tracking code snippet.

List<TRACKING_TRANSACTIONS> trackingTransactions = affiliateContext.TRACKING_TRANSACTIONS.Where(at => at.EFFECTIVE_DATE <= DateTime.Now && at.PROCESSED_DATE == null ).ToList();

foreach (TRACKING_TRANSACTIONS transaction in trackingTransactions)
{

    if (transaction != null)
    {
        AFFILIATE_TRIGGERS affiliateTrigger = affiliateContext.AFFILIATE_TRIGGERS.SingleOrDefault(at => at.AFFILIATE_ID == transaction.AFFILIATE_ID && at.TRIGGER_ID == transaction.TRIGGER_ID);

        if (affiliateTrigger != null)
        {
            //do replacements
            string trackingCode = ReplaceStringValues(affiliateTrigger.TRACKING_CODE, transaction);

            RunWebBrowserTrackingCode(trackingCode);//ConfigurationManager.AppSettings["WebsiteUrl"] + "?trackingTransactionId=" + transaction.TRACKING_TRANSACTION_ID.ToString());        
            Thread.Sleep(2000);

            transaction.PROCESSED_DATE = DateTime.Now;

            affiliateContext.SaveChanges();
        }
    }


}

到Web浏览器的调用的位置

The calls to the web browser are here

void RunWebBrowserTrackingCode(string trackingCode)
{

    if (!webBrowser.Dispatcher.CheckAccess())
    {
        webBrowser.Dispatcher.Invoke(
        System.Windows.Threading.DispatcherPriority.Normal,
            new Action(
            delegate()
            {
                webBrowser.NavigateToString(trackingCode);
            }
        ));
    }
    else
    {
        webBrowser.NavigateToString(trackingCode);
    }
}

我最关心的是,使用 Thread.sleep代码(2000); 键,使得程序只需等待是这样做的错误的方式。

My main concern is that using Thread.Sleep(2000); and making the program just wait is the wrong way of doing it.

任何人都可以提出一个更好的办法?难道我连这个攻克这里使用正确的技术?

Can anyone suggest a better way? Have I even tackled this using the right technologies here??

推荐答案

看一看的DocumentCompleted事件:

Take a look at the DocumentCompleted Event:

<一个href=\"http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.ondocumentcompleted.aspx\" rel=\"nofollow\">http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.ondocumentcompleted.aspx

这篇关于WPF设计考虑使用WebBrowser控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆