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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 738 - (show annotations) (download)
Wed Jun 19 21:02:55 2013 UTC (7 years, 1 month ago) by william
File size: 4518 byte(s)
+ update WebBrowser provider - fix implementation architecture

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 internal class EmptyWebBrowserProvider : IWebBrowserInterface, IWebBrowserProvider
21 {
22 private WebBrowserProvider BackingProvider;
23 public EmptyWebBrowserProvider() : base() { this.BackingProvider = new WebBrowserProvider(this); }
24 //public IWebBrowserInterface Provider
25 //{
26 // get { return this.BackingProvider; }
27 //}
28
29 #region IWebBrowserInterface Members
30
31 public void Navigate(string urlString) { System.Diagnostics.Process.Start(urlString); }
32 public void Navigate(Uri url) { Navigate(url.ToString()); }
33 #endregion
34
35 public IWebBrowserInterface GetProvider()
36 {
37 return this.BackingProvider.GetProvider();
38 }
39 }
40
41 public class WebBrowserProvider : BaseWebBrowserProvider, IWebBrowserInterface
42 {
43 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 }
53
54 public abstract class BaseWebBrowserProvider : IWebBrowserInterface, IWebBrowserProvider
55 {
56
57 public BaseWebBrowserProvider() { }
58 protected BaseWebBrowserProvider(IWebBrowserInterface provider)
59 {
60 this.Provider = provider;
61 }
62 #region IWebBrowserInterface Members
63 private IWebBrowserInterface _Provider;
64 public IWebBrowserInterface Provider { get { return _Provider; } protected set { _Provider = value; } }
65
66 #region Extensions to WebBrowser provider
67 public void Navigate(string urlString) { NavigateInternal(urlString); }
68 public void Navigate(Uri url) { NavigateInternal(url.ToString()); }
69
70 private void NavigateInternal(string url)
71 {
72 try
73 {
74 try
75 {
76 Uri uri = new Uri(url);
77 this.Provider.Navigate(uri);
78 }
79 catch (UriFormatException)
80 {
81 try
82 {
83 UriBuilder builder = new UriBuilder(url);
84 var proto = builder.Uri.Scheme;
85 this.Provider.Navigate(builder.Uri);
86 }
87 catch (Exception ex)
88 {
89 throw ex;
90 }
91 }
92 }
93 catch (UriFormatException ex)
94 {
95 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);
96 logger.Error.WriteLine("Unable to navigate to url: '{0}'", url);
97 logger.VerboseError.WriteLine(ex.ToString());
98 }
99 catch (Exception ex)
100 {
101 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);
102 logger.Error.WriteLine("Unable to navigate to url: '{0}'", url);
103 logger.VerboseError.WriteLine(ex.ToString());
104 }
105 }
106
107 #endregion
108 #endregion
109
110 #region IWebBrowserProvider Members
111 public IWebBrowserInterface GetProvider() { return (IWebBrowserInterface)this; }
112 #endregion
113 }
114
115 }

  ViewVC Help
Powered by ViewVC 1.1.22