/[RomCheater]/trunk/RomCheater.Core/IWebBrowserProvider.cs
ViewVC logotype

Annotation of /trunk/RomCheater.Core/IWebBrowserProvider.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 697 - (hide annotations) (download)
Mon Jun 17 12:03:50 2013 UTC (7 years, 4 months ago) by william
File size: 2496 byte(s)

1 william 696 using System;
2     using System.Collections.Generic;
3     using System.Linq;
4     using System.Text;
5     using System.Windows.Forms;
6 william 697 using RomCheater.Logging;
7 william 696
8     namespace RomCheater.Core
9     {
10     public interface IWebBrowserProvider
11     {
12     IWebBrowserInterface GetProvider();
13     }
14     public interface IWebBrowserInterface
15 william 697 {
16 william 696 void Navigate(string urlString);
17     void Navigate(Uri url);
18     }
19    
20     public class EmptyWebBrowserProvider : BaseWebBrowserProvider, IWebBrowserInterface
21     {
22     public EmptyWebBrowserProvider() :base()
23     {
24     }
25     }
26    
27     public class WebBrowserProvider : BaseWebBrowserProvider, IWebBrowserInterface
28     {
29     public WebBrowserProvider() : this(new WebBrowser()) { }
30     public WebBrowserProvider(IWebBrowserInterface provider) { }
31     public WebBrowserProvider(WebBrowser provider)
32     : base(provider)
33     {
34     }
35     }
36    
37     public class BaseWebBrowserProvider : IWebBrowserInterface, IWebBrowserProvider
38     {
39    
40     public BaseWebBrowserProvider() : this(new WebBrowser()) { }
41     protected BaseWebBrowserProvider(WebBrowser provider)
42     {
43     this.Provider = provider;
44     }
45     #region IWebBrowserInterface Members
46     private WebBrowser _Provider;
47     public WebBrowser Provider { get { return _Provider; } protected set { _Provider = value; } }
48    
49     #region Extensions to WebBrowser provider
50 william 697 public void Navigate(string urlString) { NavigateInternal(urlString); }
51     public void Navigate(Uri url) { NavigateInternal(url.ToString()); }
52    
53     private void NavigateInternal(string url)
54     {
55     try
56     {
57     Uri uri = new Uri(url);
58     this.Provider.Navigate(uri);
59     }
60     catch (UriFormatException ex)
61     {
62     MessageBox.Show(string.Format("Could not navigate to url: '{0}'", url), string.Format("A Uri Format Exception Occurred in '{0}'", this.GetType().Name), MessageBoxButtons.OK, MessageBoxIcon.Error);
63     logger.Error.WriteLine("Unable to navigate to url: '{0}'", url);
64     logger.VerboseError.WriteLine(ex.ToString());
65     }
66     }
67    
68 william 696 #endregion
69     #endregion
70    
71     #region IWebBrowserProvider Members
72     public IWebBrowserInterface GetProvider() { return (IWebBrowserInterface)this; }
73     #endregion
74     }
75    
76     }

  ViewVC Help
Powered by ViewVC 1.1.22