private static bool DoTask(WebPosition.PersistStruct persistStruct)
 {
     using (ExtendedWebBrowser browser = new ExtendedWebBrowser())
       {
     try
     {
       browser.Navigate(persistStruct.Url);
       for (int i = 0; i < 30; i++)
     System.Windows.Forms.Application.DoEvents();
       do
       {
     System.Windows.Forms.Application.DoEvents();
       } while (browser.IsBusy);
     }
     catch (Exception exc)
     {
       TraceHlp2.WriteException(exc);
       return false;
     }
     if (browser.Document != null && browser.Document.Body != null && browser.Document.Body.Parent != null)
     {
       lock (dataCache)
       {
     dataCache[persistStruct] = browser.Document.Body.Parent.OuterHtml;
     return true;
       }
     }
     else
       return false;
       }
 }
Пример #2
0
    public BrowserPage(WebPosition position)
    {
      this.innerPosition = position;
      InitializeComponent();
      //this.TabsContextMenu.Tag = this;

      highlighter = new HtmlElementsHighlighter(this.Browser);
      string style = "FILTER: progid:DXImageTransform.Microsoft.Alpha(opacity=30);BACKGROUND-COLOR: #ff0000";
      highlighter.Links[style] = GetSelectedElements;
    }
Пример #3
0
 public static WebDocument Load(WebPosition position)
 {
     string content = AsyncLoader.Instance.Load(position);
     using( ExtendedWebBrowser browser = new ExtendedWebBrowser())
     {
       	    browser.DocumentText = content;
       	    browser.IsWebBrowserContextMenuEnabled = false;
       	    // WARNING!! this can cause problems when certificate approval needed!
       	    browser.ScriptErrorsSuppressed = true;
     System.Windows.Forms.Application.DoEvents();
       	    while (browser.IsBusy)
       	      System.Windows.Forms.Application.DoEvents();
       	    return new WebDocument(DOMTreeToXml(browser.Document));
     }
 }
 public static string GetDocumentCode(WebPosition position)
 {
     bool shouldRequest = false;
       lock (dataCache)
       {
     shouldRequest = !dataCache.ContainsKey(position.Persist);
     if (shouldRequest)
       dataCache[position.Persist] = string.Empty;
       }
       if (shouldRequest)
       {
     lock (workQueue)
     {
       workQueue.Enqueue(position.Persist);
       Monitor.Pulse(workQueue);
     }
       }
       lock (dataCache)
     return dataCache[position.Persist];
 }
 public void SetUp()
 {
     filename = Path.GetFullPath("document.html");
     if(File.Exists(filename))
       File.Delete(filename);
       testPosition = WebPosition.Parse(filename);
 }
Пример #6
0
 public RequestState(WebPosition.PersistStruct pos, WebRequest request)
 {
     this.Request = request;
     this.Position = pos;
 }
Пример #7
0
        private static void StartGetting(WebPosition.PersistStruct position)
        {
            try
              {
            WebRequest request = WebRequest.Create(position.Url);
            request.Proxy = DefaultProxy;
            //if (!proxySaved)
            //{
            //  Uri yandex = new Uri("http://www.yandex.ru");
            //  IWebProxy p = request.Proxy;
            //  Type type = p.GetType();
            //  System.Reflection.PropertyInfo prop = type.GetProperty("WebProxy", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
            //  WebProxy proxy = prop.GetValue(p, null) as WebProxy;
            //  if (proxy != null)
            //  {
            //    TraceHlp2.AddMessage("Url: {0}", proxy.Address);
            //    TraceHlp2.AddMessage(string.Join("; ", proxy.BypassList));
            //    TraceHlp2.AddMessage("BypassProxyOnLocal: {0}", proxy.BypassProxyOnLocal);
            //    TraceHlp2.AddMessage("UseDefaultCredentials: {0}", proxy.UseDefaultCredentials);
            //    TraceHlp2.AddMessage("Credentials: {0}", proxy.Credentials);
            //  }
            //  TraceHlp2.AddMessage("Bypassed {0}", p.IsBypassed(yandex));
            //  TraceHlp2.AddMessage("Yandex :{0}", p.GetProxy(yandex));
            //  TraceHlp2.AddMessage("Credentails :{0}", p.Credentials);
            //  proxySaved = true;
            //}
            ////request.Proxy = Proxy;
            //Console.WriteLine(request.Proxy);

            request.BeginGetResponse(new AsyncCallback(CallBack), new RequestState(position, request));
              }
              catch (Exception exc)
              {
            lock (requestsDict)
              requestsDict.Remove(position);
            TraceHlp2.WriteException(exc);
              }
        }
Пример #8
0
 internal static string GetDocumentCode(WebPosition position)
 {
     lock (dataDict)
       {
     if (dataDict.ContainsKey(position.Persist))
       return dataDict[position.Persist];
       }
       lock (requestsDict)
       {
     if (!requestsDict.ContainsKey(position.Persist))
     {
       requestsDict[position.Persist] = true;
       StartGetting(position.Persist);
     }
     return "";
       }
 }
Пример #9
0
 private void StartGetting(WebPosition.PersistStruct position)
 {
     try
       {
     WebRequest request = WebRequest.Create(position.Url);
     request.Proxy = DefaultProxy;
     request.BeginGetResponse(new AsyncCallback(CallBack), new RequestState(position, request));
       }
       catch (Exception exc)
       {
     lock (requestsDict)
       requestsDict.Remove(position);
     TraceHlp2.WriteException(exc);
       }
 }
Пример #10
0
 public string Load(WebPosition position)
 {
     try
       {
     WebRequest request = WebRequest.Create(position.Url);
     request.Proxy = DefaultProxy;
     using(WebResponse response = request.GetResponse())
     {
       return ReadResponse(response);
     }
       }
       catch(Exception exc)
       {
     throw new Exception("Could not process request to "
                     + position.Url.ToString(),
                     exc);
       }
 }
Пример #11
0
 public void Set(WebPosition source)
 {
     this.Persist = source.Persist;
 }
Пример #12
0
 public static PersistStruct GetPersist(WebPosition pos)
 {
     return pos.Persist;
 }