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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 740 - (hide annotations) (download)
Wed Jun 19 21:20:22 2013 UTC (7 years, 10 months ago) by william
File size: 4925 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 william 738 internal class EmptyWebBrowserProvider : IWebBrowserInterface, IWebBrowserProvider
21 william 696 {
22 william 738 private WebBrowserProvider BackingProvider;
23     public EmptyWebBrowserProvider() : base() { this.BackingProvider = new WebBrowserProvider(this); }
24     //public IWebBrowserInterface Provider
25     //{
26     // get { return this.BackingProvider; }
27     //}
28 william 733
29     #region IWebBrowserInterface Members
30 william 738
31 william 740 public void Navigate(string urlString) { logger.Debug.WriteLine("called::NavigateInternal(string urlString)::{0}", urlString); System.Diagnostics.Process.Start(urlString); }
32     public void Navigate(Uri url) { logger.Debug.WriteLine("called::NavigateInternal(Uri url)::{0}", url.ToString()); Navigate(url.ToString()); }
33 william 738 #endregion
34    
35     public IWebBrowserInterface GetProvider()
36 william 733 {
37 william 738 return this.BackingProvider.GetProvider();
38 william 733 }
39 william 696 }
40    
41     public class WebBrowserProvider : BaseWebBrowserProvider, IWebBrowserInterface
42     {
43 william 738 public static IWebBrowserProvider DefaultProvider { get { return WebBrowserProvider.EmptyProvider; } }
44     public static IWebBrowserProvider EmptyProvider { get { return WebBrowserProvider.Empty; } }
45     public static IWebBrowserProvider Empty { get { return new EmptyWebBrowserProvider(); } }
46     protected WebBrowserProvider() : this(new EmptyWebBrowserProvider()) { }
47     public WebBrowserProvider(IWebBrowserInterface provider) : base(provider) { }
48     //#region IWebBrowserInterface Members
49     //public virtual void Navigate(string urlString) { base.Navigate(urlString); }
50     //public virtual void Navigate(Uri url) { base.Navigate(url); }
51     //#endregion
52 william 696 }
53    
54 william 699 public abstract class BaseWebBrowserProvider : IWebBrowserInterface, IWebBrowserProvider
55 william 696 {
56 william 699
57     public BaseWebBrowserProvider() { }
58     protected BaseWebBrowserProvider(IWebBrowserInterface provider)
59 william 696 {
60     this.Provider = provider;
61     }
62     #region IWebBrowserInterface Members
63 william 699 private IWebBrowserInterface _Provider;
64     public IWebBrowserInterface Provider { get { return _Provider; } protected set { _Provider = value; } }
65 william 696
66     #region Extensions to WebBrowser provider
67 william 740 public void Navigate(string urlString) { logger.Debug.WriteLine("called::Navigate(string urlString)::{0}", urlString); NavigateInternal(urlString); }
68     public void Navigate(Uri url) { logger.Debug.WriteLine("called::Navigate(Uri url)::{0}", url.ToString()); NavigateInternal(url.ToString()); }
69 william 697
70     private void NavigateInternal(string url)
71     {
72 william 740 logger.Debug.WriteLine("called::NavigateInternal(string url)::{0}", url);
73 william 697 try
74     {
75 william 698 try
76     {
77     Uri uri = new Uri(url);
78     this.Provider.Navigate(uri);
79     }
80     catch (UriFormatException)
81     {
82     try
83     {
84     UriBuilder builder = new UriBuilder(url);
85     var proto = builder.Uri.Scheme;
86     this.Provider.Navigate(builder.Uri);
87     }
88     catch (Exception ex)
89     {
90     throw ex;
91     }
92     }
93 william 697 }
94     catch (UriFormatException ex)
95     {
96     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);
97     logger.Error.WriteLine("Unable to navigate to url: '{0}'", url);
98     logger.VerboseError.WriteLine(ex.ToString());
99     }
100 william 698 catch (Exception ex)
101     {
102     MessageBox.Show(string.Format("Could not navigate to url: '{0}'", url), string.Format("An {0} Exception Occurred in '{1}'",ex.GetType().Name, this.GetType().Name), MessageBoxButtons.OK, MessageBoxIcon.Error);
103     logger.Error.WriteLine("Unable to navigate to url: '{0}'", url);
104     logger.VerboseError.WriteLine(ex.ToString());
105     }
106 william 697 }
107    
108 william 696 #endregion
109     #endregion
110    
111     #region IWebBrowserProvider Members
112     public IWebBrowserInterface GetProvider() { return (IWebBrowserInterface)this; }
113     #endregion
114     }
115    
116     }

  ViewVC Help
Powered by ViewVC 1.1.22