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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 812 - (show annotations) (download)
Tue Apr 15 14:52:10 2014 UTC (6 years, 6 months ago) by william
File size: 4936 byte(s)
+ update logging to use Enterpise.Logging -- more work is still needed

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

  ViewVC Help
Powered by ViewVC 1.1.22