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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/RomCheater.Core/IWebBrowserProvider.cs	2013/06/17 11:47:23	696
+++ trunk/RomCheater.Core/IWebBrowserProvider.cs	2013/06/19 21:20:22	740
@@ -3,6 +3,7 @@
 using System.Linq;
 using System.Text;
 using System.Windows.Forms;
+using RomCheater.Logging;
 
 namespace RomCheater.Core
 {
@@ -11,73 +12,99 @@
         IWebBrowserInterface GetProvider();
     }
     public interface IWebBrowserInterface
-    {
-        //WebBrowser Provider { get; }
+    {        
         void Navigate(string urlString);    
         void Navigate(Uri url);
-        //void Navigate(string urlString, bool newWindow);
-        //void Navigate(string urlString, string targetFrameName);
-        //void Navigate(Uri url, bool newWindow);
-        //void Navigate(Uri url, string targetFrameName);        
-        //void Navigate(string urlString, string targetFrameName, byte[] postData, string additionalHeaders);
-        //void Navigate(Uri url, string targetFrameName, byte[] postData, string additionalHeaders);
-
     }
 
-    //public class WebBrowserProvider : IWebBrowserProvider
-    //{
-    //    public WebBrowserProvider(IWebBrowserInterface provider)
-    //    {
-    //        _provider = provider;
-    //    }
-
-    //    #region IWebBrowserProvider Members
-    //    private IWebBrowserInterface _provider;
-    //    public IWebBrowserInterface GetProvider()
-    //    {
-    //        return _provider;
-    //    }
-    //    #endregion
-    //}
-
-    public class EmptyWebBrowserProvider : BaseWebBrowserProvider, IWebBrowserInterface
+    internal class EmptyWebBrowserProvider : IWebBrowserInterface, IWebBrowserProvider
     {
-        public EmptyWebBrowserProvider() :base()
+        private WebBrowserProvider BackingProvider;
+        public EmptyWebBrowserProvider() : base() { this.BackingProvider = new WebBrowserProvider(this); }
+        //public IWebBrowserInterface Provider
+        //{
+        //    get { return this.BackingProvider; }
+        //}
+
+        #region IWebBrowserInterface Members
+
+        public void Navigate(string urlString) { logger.Debug.WriteLine("called::NavigateInternal(string urlString)::{0}", urlString); System.Diagnostics.Process.Start(urlString); }
+        public void Navigate(Uri url) { logger.Debug.WriteLine("called::NavigateInternal(Uri url)::{0}", url.ToString()); Navigate(url.ToString()); }
+        #endregion
+
+        public IWebBrowserInterface GetProvider()
         {
+            return this.BackingProvider.GetProvider();
         }
     }
 
     public class WebBrowserProvider : BaseWebBrowserProvider, IWebBrowserInterface
     {
-        public WebBrowserProvider() : this(new WebBrowser()) { }
-        public WebBrowserProvider(IWebBrowserInterface provider) { }
-        public WebBrowserProvider(WebBrowser provider)
-            : base(provider)
-        {
-        }
+        public static IWebBrowserProvider DefaultProvider { get { return WebBrowserProvider.EmptyProvider; } }
+        public static IWebBrowserProvider EmptyProvider { get { return WebBrowserProvider.Empty; } }
+        public static IWebBrowserProvider Empty { get { return new EmptyWebBrowserProvider(); } }
+        protected WebBrowserProvider() : this(new EmptyWebBrowserProvider()) { }
+        public WebBrowserProvider(IWebBrowserInterface provider) : base(provider) { }
+        //#region IWebBrowserInterface Members
+        //public virtual void Navigate(string urlString) { base.Navigate(urlString); }
+        //public virtual void Navigate(Uri url) { base.Navigate(url); }
+        //#endregion
     }
 
-    public class BaseWebBrowserProvider : IWebBrowserInterface, IWebBrowserProvider
+    public abstract class BaseWebBrowserProvider : IWebBrowserInterface, IWebBrowserProvider
     {
-        
-        public BaseWebBrowserProvider() : this(new WebBrowser()) { }
-        protected BaseWebBrowserProvider(WebBrowser provider)
+
+        public BaseWebBrowserProvider() { }
+        protected BaseWebBrowserProvider(IWebBrowserInterface provider)
         {
             this.Provider = provider;
         }
         #region IWebBrowserInterface Members
-        private WebBrowser _Provider;
-        public WebBrowser Provider { get { return _Provider; } protected set { _Provider = value; } }
+        private IWebBrowserInterface _Provider;
+        public IWebBrowserInterface Provider { get { return _Provider; } protected set { _Provider = value; } }
 
         #region Extensions to WebBrowser provider
-        public void Navigate(string urlString) { this.Provider.Navigate(urlString); }
-        public void Navigate(Uri url) { this.Provider.Navigate(url); }
-        //public void Navigate(string urlString, bool newWindow) { this.Provider.Navigate(urlString, newWindow); }
-        //public void Navigate(string urlString, string targetFrameName) { this.Provider.Navigate(urlString, targetFrameName); }
-        //public void Navigate(Uri url, bool newWindow) { this.Provider.Navigate(url, newWindow); }
-        //public void Navigate(Uri url, string targetFrameName) { this.Provider.Navigate(url, targetFrameName); }
-        //public void Navigate(string urlString, string targetFrameName, byte[] postData, string additionalHeaders) { this.Provider.Navigate(urlString, targetFrameName, postData, additionalHeaders); }
-        //public void Navigate(Uri url, string targetFrameName, byte[] postData, string additionalHeaders) { this.Provider.Navigate(url, targetFrameName, postData, additionalHeaders); }
+        public void Navigate(string urlString) { logger.Debug.WriteLine("called::Navigate(string urlString)::{0}", urlString); NavigateInternal(urlString); }
+        public void Navigate(Uri url) { logger.Debug.WriteLine("called::Navigate(Uri url)::{0}", url.ToString()); NavigateInternal(url.ToString()); }  
+
+        private void NavigateInternal(string url)
+        {
+            logger.Debug.WriteLine("called::NavigateInternal(string url)::{0}", url);
+            try
+            {
+                try
+                {
+                    Uri uri = new Uri(url);
+                    this.Provider.Navigate(uri);
+                }
+                catch (UriFormatException)
+                {
+                    try
+                    {
+                        UriBuilder builder = new UriBuilder(url);
+                        var proto = builder.Uri.Scheme;
+                        this.Provider.Navigate(builder.Uri);
+                    }
+                    catch (Exception ex)
+                    {
+                        throw ex;
+                    }
+                }
+            }
+            catch (UriFormatException ex)
+            {
+                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);
+                logger.Error.WriteLine("Unable to navigate to url: '{0}'", url);
+                logger.VerboseError.WriteLine(ex.ToString());
+            }
+            catch (Exception ex)
+            {
+                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);
+                logger.Error.WriteLine("Unable to navigate to url: '{0}'", url);
+                logger.VerboseError.WriteLine(ex.ToString());
+            }
+        }
+
         #endregion
         #endregion
 

 

  ViewVC Help
Powered by ViewVC 1.1.22