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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

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     public class EmptyWebBrowserProvider : BaseWebBrowserProvider, IWebBrowserInterface
21     {
22     public EmptyWebBrowserProvider() :base()
23     {
24     }
25     }
26    
27     public class WebBrowserProvider : BaseWebBrowserProvider, IWebBrowserInterface
28     {
29 william 699 public WebBrowserProvider() { }
30     //public WebBrowserProvider(IWebBrowserInterface provider) { }
31     public WebBrowserProvider(IWebBrowserInterface provider)
32 william 696 : base(provider)
33     {
34     }
35     }
36    
37 william 699 public abstract class BaseWebBrowserProvider : IWebBrowserInterface, IWebBrowserProvider
38 william 696 {
39 william 699
40     public BaseWebBrowserProvider() { }
41     protected BaseWebBrowserProvider(IWebBrowserInterface provider)
42 william 696 {
43     this.Provider = provider;
44     }
45     #region IWebBrowserInterface Members
46 william 699 private IWebBrowserInterface _Provider;
47     public IWebBrowserInterface Provider { get { return _Provider; } protected set { _Provider = value; } }
48 william 696
49     #region Extensions to WebBrowser provider
50 william 697 public void Navigate(string urlString) { NavigateInternal(urlString); }
51 william 699 public void Navigate(Uri url) { NavigateInternal(url.ToString()); }
52 william 697
53     private void NavigateInternal(string url)
54     {
55     try
56     {
57 william 698 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 william 697 }
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 william 698 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 william 697 }
89    
90 william 696 #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