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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 699 - (show annotations) (download)
Mon Jun 17 12:40:47 2013 UTC (7 years, 4 months ago) by william
File size: 3455 byte(s)
+ work out passing around the webbrowser through the config plugin

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 public EmptyWebBrowserProvider() :base()
23 {
24 }
25 }
26
27 public class WebBrowserProvider : BaseWebBrowserProvider, IWebBrowserInterface
28 {
29 public WebBrowserProvider() { }
30 //public WebBrowserProvider(IWebBrowserInterface provider) { }
31 public WebBrowserProvider(IWebBrowserInterface provider)
32 : base(provider)
33 {
34 }
35 }
36
37 public abstract class BaseWebBrowserProvider : IWebBrowserInterface, IWebBrowserProvider
38 {
39
40 public BaseWebBrowserProvider() { }
41 protected BaseWebBrowserProvider(IWebBrowserInterface provider)
42 {
43 this.Provider = provider;
44 }
45 #region IWebBrowserInterface Members
46 private IWebBrowserInterface _Provider;
47 public IWebBrowserInterface Provider { get { return _Provider; } protected set { _Provider = value; } }
48
49 #region Extensions to WebBrowser provider
50 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 try
58 {
59 Uri uri = new Uri(url);
60 this.Provider.Navigate(uri);
61 }
62 catch (UriFormatException)
63 {
64 try
65 {
66 UriBuilder builder = new UriBuilder(url);
67 var proto = builder.Uri.Scheme;
68 this.Provider.Navigate(builder.Uri);
69 }
70 catch (Exception ex)
71 {
72 throw ex;
73 }
74 }
75 }
76 catch (UriFormatException ex)
77 {
78 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);
79 logger.Error.WriteLine("Unable to navigate to url: '{0}'", url);
80 logger.VerboseError.WriteLine(ex.ToString());
81 }
82 catch (Exception ex)
83 {
84 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);
85 logger.Error.WriteLine("Unable to navigate to url: '{0}'", url);
86 logger.VerboseError.WriteLine(ex.ToString());
87 }
88 }
89
90 #endregion
91 #endregion
92
93 #region IWebBrowserProvider Members
94 public IWebBrowserInterface GetProvider() { return (IWebBrowserInterface)this; }
95 #endregion
96 }
97
98 }

  ViewVC Help
Powered by ViewVC 1.1.22