cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From purplecabb...@apache.org
Subject [2/5] wp7 commit: removing CordovaCommandResult dependency
Date Thu, 14 Mar 2013 22:30:43 GMT
removing CordovaCommandResult dependency


Project: http://git-wip-us.apache.org/repos/asf/cordova-wp7/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-wp7/commit/65443b1e
Tree: http://git-wip-us.apache.org/repos/asf/cordova-wp7/tree/65443b1e
Diff: http://git-wip-us.apache.org/repos/asf/cordova-wp7/diff/65443b1e

Branch: refs/heads/master
Commit: 65443b1e78948760e7e130ebd3c6248a07163403
Parents: aeb213b
Author: Jesse MacFadyen <purplecabbage@gmail.com>
Authored: Tue Mar 12 17:07:40 2013 -0700
Committer: Jesse MacFadyen <purplecabbage@gmail.com>
Committed: Tue Mar 12 17:07:40 2013 -0700

----------------------------------------------------------------------
 .../standalone/cordovalib/CordovaCommandCall.cs    |    2 +-
 .../standalone/cordovalib/CordovaView.xaml.cs      |   10 ++--
 templates/standalone/cordovalib/NativeExecution.cs |   57 ++++++++++-----
 templates/standalone/cordovalib/PluginResult.cs    |   30 +--------
 4 files changed, 46 insertions(+), 53 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-wp7/blob/65443b1e/templates/standalone/cordovalib/CordovaCommandCall.cs
----------------------------------------------------------------------
diff --git a/templates/standalone/cordovalib/CordovaCommandCall.cs b/templates/standalone/cordovalib/CordovaCommandCall.cs
index 084fd2c..a864fe6 100644
--- a/templates/standalone/cordovalib/CordovaCommandCall.cs
+++ b/templates/standalone/cordovalib/CordovaCommandCall.cs
@@ -64,7 +64,7 @@ namespace WPCordovaClassLib.Cordova
 
             // sanity check for illegal names
             // was failing with ::
-            // CordovaCommandResult :: 1, Device1, {"status":1,"message":"{\"name\":\"XD.....
+            // 1, Device1, {"status":1,"message":"{\"name\":\"XD.....
             if (commandCallParameters.Service.IndexOfAny(new char[] { '@', ':', ',', '!',
' ' }) > -1)
             {
                 return null;

http://git-wip-us.apache.org/repos/asf/cordova-wp7/blob/65443b1e/templates/standalone/cordovalib/CordovaView.xaml.cs
----------------------------------------------------------------------
diff --git a/templates/standalone/cordovalib/CordovaView.xaml.cs b/templates/standalone/cordovalib/CordovaView.xaml.cs
index a6c4bce..e584a1a 100644
--- a/templates/standalone/cordovalib/CordovaView.xaml.cs
+++ b/templates/standalone/cordovalib/CordovaView.xaml.cs
@@ -161,7 +161,7 @@ namespace WPCordovaClassLib
 
         void AppClosing(object sender, ClosingEventArgs e)
         {
-            Debug.WriteLine("AppClosing");
+            //Debug.WriteLine("AppClosing");
         }
 
         void AppDeactivated(object sender, DeactivatedEventArgs e)
@@ -170,7 +170,7 @@ namespace WPCordovaClassLib
 
             try
             {
-                CordovaBrowser.InvokeScript("CordovaCommandResult", new string[] { "pause"
});
+                CordovaBrowser.InvokeScript("eval", new string[] { "cordova.fireDocumentEvent('pause');"
});
             }
             catch (Exception)
             {
@@ -180,7 +180,7 @@ namespace WPCordovaClassLib
 
         void AppLaunching(object sender, LaunchingEventArgs e)
         {
-            Debug.WriteLine("INFO: AppLaunching");
+            //Debug.WriteLine("INFO: AppLaunching");
         }
 
         void AppActivated(object sender, Microsoft.Phone.Shell.ActivatedEventArgs e)
@@ -188,7 +188,7 @@ namespace WPCordovaClassLib
             Debug.WriteLine("INFO: AppActivated");
             try
             {
-                CordovaBrowser.InvokeScript("CordovaCommandResult", new string[] { "resume"
});
+                CordovaBrowser.InvokeScript("eval", new string[] { "cordova.fireDocumentEvent('resume');"
});
             }
             catch (Exception)
             {
@@ -332,7 +332,7 @@ namespace WPCordovaClassLib
             {
                 try
                 {
-                    CordovaBrowser.InvokeScript("CordovaCommandResult", new string[] { "backbutton"
});
+                    CordovaBrowser.InvokeScript("eval", new string[] { "cordova.fireDocumentEvent('backbutton');"
});
                     e.Cancel = true;
                 }
                 catch (Exception ex)

http://git-wip-us.apache.org/repos/asf/cordova-wp7/blob/65443b1e/templates/standalone/cordovalib/NativeExecution.cs
----------------------------------------------------------------------
diff --git a/templates/standalone/cordovalib/NativeExecution.cs b/templates/standalone/cordovalib/NativeExecution.cs
index 9459ffc..28dc528 100644
--- a/templates/standalone/cordovalib/NativeExecution.cs
+++ b/templates/standalone/cordovalib/NativeExecution.cs
@@ -61,15 +61,23 @@ namespace WPCordovaClassLib.Cordova
             CommandFactory.ResetAllCommands();
         }
 
+        public void AutoLoadCommand(string commandService)
+        {
+            BaseCommand bc = CommandFactory.CreateByServiceName(commandService);
+            if (bc != null)
+            {
+                bc.OnInit();
+            }
+
+        }
+
         /// <summary>
         /// Executes command and returns result back.
         /// </summary>
         /// <param name="commandCallParams">Command to execute</param>
-        
         public void ProcessCommand(CordovaCommandCall commandCallParams)
         {
 
-            
             if (commandCallParams == null)
             {
                 throw new ArgumentNullException("commandCallParams");
@@ -90,7 +98,6 @@ namespace WPCordovaClassLib.Cordova
                     this.OnCommandResult(commandCallParams.CallbackId, res);
                 };
 
-                bc.OnCommandResult -= OnCommandResultHandler;
                 bc.OnCommandResult += OnCommandResultHandler;
 
                 EventHandler<ScriptCallback> OnCustomScriptHandler = delegate(object
o, ScriptCallback script)
@@ -98,14 +105,12 @@ namespace WPCordovaClassLib.Cordova
                     this.InvokeScriptCallback(script);
                 };
 
-                bc.OnCustomScript -= OnCustomScriptHandler;
-                bc.OnCustomScript += OnCustomScriptHandler;
 
-                // TODO: alternative way is using thread pool (ThreadPool.QueueUserWorkItem)
instead of 
-                // new thread for every command call; but num threads are not sufficient
- 2 threads per CPU core
+                bc.OnCustomScript += OnCustomScriptHandler;
 
-                Thread thread = new Thread(func =>
+                ThreadStart methodInvokation = () =>
                 {
+
                     try
                     {
                         bc.InvokeMethodNamed(commandCallParams.Action, commandCallParams.Args);
@@ -122,9 +127,20 @@ namespace WPCordovaClassLib.Cordova
 
                         return;
                     }
-                });
+                };
+
+                if (true || (bc is File) || (bc is Accelerometer))
+                {
+                    // Due to some issues with the IsolatedStorage in current version of
WP8 SDK we have to run all File Api commands synchronously.
+                    // TODO: test this in WP8 RTM
+                    methodInvokation.Invoke();
+                }
+                else
+                {
+                    new Thread(methodInvokation).Start();
+                }
 
-                thread.Start();
+                    
             }
             catch (Exception ex)
             {
@@ -160,21 +176,27 @@ namespace WPCordovaClassLib.Cordova
 
             #endregion
 
-            string status = ((int)result.Result).ToString();
             string jsonResult = result.ToJSONString();
 
-            ScriptCallback scriptCallback = null;
+            string callback;
+            string args = string.Format("('{0}',{1});", callbackId, jsonResult);
 
-            if (String.IsNullOrEmpty(result.Cast))
+            if (result.Result == PluginResult.Status.NO_RESULT ||
+               result.Result == PluginResult.Status.OK)
             {
-                scriptCallback = new ScriptCallback("CordovaCommandResult", new string[]
{ status, callbackId, jsonResult });
+                callback = @"(function(callbackId,args) {
+                try { args.message = JSON.parse(args.message); } catch (ex) { }
+                cordova.callbackSuccess(callbackId,args);
+                })" + args;
             }
             else
             {
-                scriptCallback = new ScriptCallback("CordovaCommandResult", new string[]
{ status, callbackId, jsonResult, result.Cast });
+                callback = @"(function(callbackId,args) {
+                try { args.message = JSON.parse(args.message); } catch (ex) { }
+                cordova.callbackError(callbackId,args);
+                })" + args;
             }
-
-            this.InvokeScriptCallback(scriptCallback);
+            this.InvokeScriptCallback(new ScriptCallback("eval", new string[] { callback
}));
 
         }
 
@@ -197,7 +219,6 @@ namespace WPCordovaClassLib.Cordova
             //Debug.WriteLine("INFO:: About to invoke ::" + script.ScriptName + " with args
::" + script.Args[0]);
             this.webBrowser.Dispatcher.BeginInvoke((ThreadStart)delegate()
             {
-
                 try
                 {
                     //Debug.WriteLine("INFO:: InvokingScript::" + script.ScriptName + " with
args ::" + script.Args[0]);

http://git-wip-us.apache.org/repos/asf/cordova-wp7/blob/65443b1e/templates/standalone/cordovalib/PluginResult.cs
----------------------------------------------------------------------
diff --git a/templates/standalone/cordovalib/PluginResult.cs b/templates/standalone/cordovalib/PluginResult.cs
index b887bb8..e6d0c56 100644
--- a/templates/standalone/cordovalib/PluginResult.cs
+++ b/templates/standalone/cordovalib/PluginResult.cs
@@ -68,8 +68,6 @@ namespace WPCordovaClassLib.Cordova
 
         public Status Result { get; private set; }
         public string Message { get; set; }
-        public String Cast { get; private set; }
-
         public bool KeepCallback { get; set; }
 
         /// <summary>
@@ -103,21 +101,6 @@ namespace WPCordovaClassLib.Cordova
             this.Message = JSON.JsonHelper.Serialize(message);
         }
 
-        /// <summary>
-        /// Creates new instance of the PluginResult class.
-        /// </summary>
-        /// <param name="status">Execution result</param>
-        /// <param name="message">The message</param>
-        /// <param name="cast">The cast parameter</param>
-        /// 
-        [Obsolete("Don't use Cast!!", false)]
-        public PluginResult(Status status, object message, string cast)
-        {
-            this.Result = status;
-            this.Message = JSON.JsonHelper.Serialize(message);
-            this.Cast = cast;
-        }
-
         public string ToJSONString()
         {
             string res = String.Format("\"status\":{0},\"message\":{1},\"keepCallback\":{2}",
@@ -132,21 +115,10 @@ namespace WPCordovaClassLib.Cordova
 
         public string ToCallbackString(string callbackId, string successCallback, string
errorCallback)
         {
-            //return String.Format("{0}('{1}',{2});", successCallback, callbackId, this.ToJSONString());
-
             if (this.IsSuccess)
             {
                 StringBuilder buf = new StringBuilder("");
-                if (this.Cast != null)
-                {
-                    Debug.WriteLine(callbackId + "this.Cast = " + this.Cast);
-                    buf.Append("var temp = " + this.Cast + "(" + this.ToJSONString() + ");\n");
-                    buf.Append(String.Format("{0}('{1}',temp);", successCallback, callbackId));
-                }
-                else
-                {
-                    buf.Append(String.Format("{0}('{1}',{2});", successCallback, callbackId,
this.ToJSONString()));
-                }
+                buf.Append(String.Format("{0}('{1}',{2});", successCallback, callbackId,
this.ToJSONString()));
                 return buf.ToString();
             }
             else


Mime
View raw message