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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 733 - (show annotations) (download)
Wed Jun 19 15:32:53 2013 UTC (7 years, 4 months ago) by william
File size: 4429 byte(s)
+ if no web browser provider is defined, return an EmptyProvider which uses the default system browser

1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Windows.Forms;
6 using RomCheater.Logging;
7
8 namespace RomCheater.Core
9 {
10 public interface IWebBrowserProvider
11 {
12 IWebBrowserInterface GetProvider();
13 }
14 public interface IWebBrowserInterface
15 {
16 void Navigate(string urlString);
17 void Navigate(Uri url);
18 }
19
20 public class EmptyWebBrowserProvider : BaseWebBrowserProvider, IWebBrowserInterface
21 {
22 private WebBrowserProvider BackingProvider = new WebBrowserProvider();
23 public EmptyWebBrowserProvider()
24 : base()
25 {
26 this.BackingProvider = new WebBrowserProvider(this);
27 }
28 public IWebBrowserInterface Provider
29 {
30 get { return this.BackingProvider; }
31 }
32
33 #region IWebBrowserInterface Members
34 public void Navigate(string urlString)
35 {
36 ////this.Provider.Navigate(urlString);
37 //this.webBrowser.Navigate(urlString);
38 System.Diagnostics.Process.Start(urlString);
39 }
40 public void Navigate(Uri url) { Navigate(url.ToString()); }
41 #endregion
42 }
43
44 public class WebBrowserProvider : BaseWebBrowserProvider, IWebBrowserInterface
45 {
46 public static IWebBrowserInterface DefaultProvider { get { return WebBrowserProvider.EmptyProvider; } }
47 public static IWebBrowserInterface EmptyProvider { get { return WebBrowserProvider.Empty; } }
48 public static IWebBrowserInterface Empty { get { return new EmptyWebBrowserProvider(); } }
49 public WebBrowserProvider() { }
50 //public WebBrowserProvider(IWebBrowserInterface provider) { }
51 public WebBrowserProvider(IWebBrowserInterface provider)
52 : base(provider)
53 {
54 }
55 }
56
57 public abstract class BaseWebBrowserProvider : IWebBrowserInterface, IWebBrowserProvider
58 {
59
60 public BaseWebBrowserProvider() { }
61 protected BaseWebBrowserProvider(IWebBrowserInterface provider)
62 {
63 this.Provider = provider;
64 }
65 #region IWebBrowserInterface Members
66 private IWebBrowserInterface _Provider;
67 public IWebBrowserInterface Provider { get { return _Provider; } protected set { _Provider = value; } }
68
69 #region Extensions to WebBrowser provider
70 public void Navigate(string urlString) { NavigateInternal(urlString); }
71 public void Navigate(Uri url) { NavigateInternal(url.ToString()); }
72
73 private void NavigateInternal(string url)
74 {
75 try
76 {
77 try
78 {
79 Uri uri = new Uri(url);
80 this.Provider.Navigate(uri);
81 }
82 catch (UriFormatException)
83 {
84 try
85 {
86 UriBuilder builder = new UriBuilder(url);
87 var proto = builder.Uri.Scheme;
88 this.Provider.Navigate(builder.Uri);
89 }
90 catch (Exception ex)
91 {
92 throw ex;
93 }
94 }
95 }
96 catch (UriFormatException ex)
97 {
98 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);
99 logger.Error.WriteLine("Unable to navigate to url: '{0}'", url);
100 logger.VerboseError.WriteLine(ex.ToString());
101 }
102 catch (Exception ex)
103 {
104 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);
105 logger.Error.WriteLine("Unable to navigate to url: '{0}'", url);
106 logger.VerboseError.WriteLine(ex.ToString());
107 }
108 }
109
110 #endregion
111 #endregion
112
113 #region IWebBrowserProvider Members
114 public IWebBrowserInterface GetProvider() { return (IWebBrowserInterface)this; }
115 #endregion
116 }
117
118 }

  ViewVC Help
Powered by ViewVC 1.1.22