cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From purplecabb...@apache.org
Subject [1/2] git commit: Remove unwanted slashes and handle Exceptions
Date Tue, 26 Aug 2014 21:20:19 GMT
Repository: cordova-wp8
Updated Branches:
  refs/heads/master d20237c4f -> f49433754


Remove unwanted slashes and handle Exceptions


Project: http://git-wip-us.apache.org/repos/asf/cordova-wp8/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-wp8/commit/8829719b
Tree: http://git-wip-us.apache.org/repos/asf/cordova-wp8/tree/8829719b
Diff: http://git-wip-us.apache.org/repos/asf/cordova-wp8/diff/8829719b

Branch: refs/heads/master
Commit: 8829719bbbca1e92670f4576f7baa5e6e4701b9a
Parents: 0cd48c8
Author: Martin Gonzalez <martin.c.glez.glez@gmail.com>
Authored: Tue Aug 19 13:15:43 2014 -0500
Committer: Martin Gonzalez <martin.c.glez.glez@gmail.com>
Committed: Tue Aug 19 13:15:43 2014 -0500

----------------------------------------------------------------------
 wp8/template/cordovalib/XHRHelper.cs | 53 ++++++++++++++++++++-----------
 1 file changed, 34 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/8829719b/wp8/template/cordovalib/XHRHelper.cs
----------------------------------------------------------------------
diff --git a/wp8/template/cordovalib/XHRHelper.cs b/wp8/template/cordovalib/XHRHelper.cs
index b6573a3..fa7b617 100644
--- a/wp8/template/cordovalib/XHRHelper.cs
+++ b/wp8/template/cordovalib/XHRHelper.cs
@@ -228,7 +228,10 @@ namespace WPCordovaClassLib.CordovaLib
                     var alias = this;
 
                     var root = window.location.href.split('#')[0];   // remove hash
-                    var basePath = root.substr(0,root.lastIndexOf('/')) + '/';
+                    
+                    var rootPath = root.substr(0,root.lastIndexOf('/')) + '/';
+                    // Removing unwanted slashes after x-wmapp0 from the basePath, URI cannot
process x-wmapp0: /www or //www
+                    var basePath = rootPath.replace(/:\/+/gi, ':');
 
                     //console.log( 'Stripping protocol if present and removing leading /
characters' );
                     var resolvedUrl =
@@ -285,38 +288,50 @@ namespace WPCordovaClassLib.CordovaLib
                 string url = reqStr[1];
 
                 Uri uri = new Uri(url, UriKind.RelativeOrAbsolute);
-
-                using (IsolatedStorageFile isoFile = IsolatedStorageFile.GetUserStoreForApplication())
+                try
                 {
-                    if (isoFile.FileExists(uri.AbsolutePath))
+                    using (IsolatedStorageFile isoFile = IsolatedStorageFile.GetUserStoreForApplication())
                     {
-                        using (TextReader reader = new StreamReader(isoFile.OpenFile(uri.AbsolutePath,
FileMode.Open, FileAccess.Read)))
+                        if (isoFile.FileExists(uri.AbsolutePath))
                         {
-                            string text = reader.ReadToEnd();
-                            Browser.InvokeScript("__onXHRLocalCallback", new string[] { "200",
text, reqId });
-                            return true;
+                            using (TextReader reader = new StreamReader(isoFile.OpenFile(uri.AbsolutePath,
FileMode.Open, FileAccess.Read)))
+                            {
+                                string text = reader.ReadToEnd();
+                                Browser.InvokeScript("__onXHRLocalCallback", new string[]
{ "200", text, reqId });
+                                return true;
+                            }
                         }
                     }
                 }
+                catch (Exception ex)
+                {
+                    Debug.WriteLine("ERROR: Exception in HandleCommand: " + ex);
+                }
 
                 Uri relUri = new Uri(uri.AbsolutePath, UriKind.Relative);
 
                 var resource = Application.GetResourceStream(relUri);
-
-                if (resource == null)
-                {
-                    // 404 ?
-                    Browser.InvokeScript("__onXHRLocalCallback", new string[] { "404", null,
reqId });
-                    return true;
-                }
-                else
+                try
                 {
-                    using (StreamReader streamReader = new StreamReader(resource.Stream))
+                    if (resource == null)
                     {
-                        string text = streamReader.ReadToEnd();
-                        Browser.InvokeScript("__onXHRLocalCallback", new string[] { "200",
text, reqId });
+                        // 404 ?
+                        Browser.InvokeScript("__onXHRLocalCallback", new string[] { "404",
null, reqId });
                         return true;
                     }
+                    else
+                    {
+                        using (StreamReader streamReader = new StreamReader(resource.Stream))
+                        {
+                            string text = streamReader.ReadToEnd();
+                            Browser.InvokeScript("__onXHRLocalCallback", new string[] { "200",
text, reqId });
+                            return true;
+                        }
+                    }
+                }
+                catch (Exception ex)
+                {
+                    Debug.WriteLine("ERROR: Exception in HandleCommand: " + ex);
                 }
             }
 


Mime
View raw message