You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by pu...@apache.org on 2014/01/17 00:01:55 UTC
[6/6] git commit: Apply the same changes to wp7
Apply the same changes to wp7
Project: http://git-wip-us.apache.org/repos/asf/cordova-wp8/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-wp8/commit/7ac24bfb
Tree: http://git-wip-us.apache.org/repos/asf/cordova-wp8/tree/7ac24bfb
Diff: http://git-wip-us.apache.org/repos/asf/cordova-wp8/diff/7ac24bfb
Branch: refs/heads/master
Commit: 7ac24bfb0417a97cdb6a3f596f7f172e3a79cc5d
Parents: 3fba012
Author: Jesse MacFadyen <pu...@gmail.com>
Authored: Thu Jan 16 14:58:00 2014 -0800
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Thu Jan 16 14:58:00 2014 -0800
----------------------------------------------------------------------
wp7/template/cordovalib/CommandFactory.cs | 24 ++++++++++++++++++----
wp7/template/cordovalib/ConfigHandler.cs | 18 +++++++++++++---
wp7/template/cordovalib/CordovaCommandCall.cs | 4 +++-
wp7/template/cordovalib/NativeExecution.cs | 4 ++--
4 files changed, 40 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/7ac24bfb/wp7/template/cordovalib/CommandFactory.cs
----------------------------------------------------------------------
diff --git a/wp7/template/cordovalib/CommandFactory.cs b/wp7/template/cordovalib/CommandFactory.cs
index 893ce80..4bd5a09 100644
--- a/wp7/template/cordovalib/CommandFactory.cs
+++ b/wp7/template/cordovalib/CommandFactory.cs
@@ -30,7 +30,7 @@ using System.Diagnostics;
namespace WPCordovaClassLib.Cordova
{
/// <summary>
- /// Provides functionality to create phone gap command by name.
+ /// Provides functionality to create Cordova command by name.
/// </summary>
public static class CommandFactory
{
@@ -52,7 +52,10 @@ namespace WPCordovaClassLib.Cordova
/// </summary>
/// <param name="service">Command class name, for example Device or Notification</param>
/// <returns>Command class instance or null</returns>
- public static BaseCommand CreateByServiceName(string service)
+ /// alias can be used as a namespace which is resolved + service
+ /// or it can be the fully qualified classname
+ /// or the classname in the current assembly
+ public static BaseCommand CreateByServiceName(string service, string alias="")
{
if (string.IsNullOrEmpty(service))
@@ -62,9 +65,23 @@ namespace WPCordovaClassLib.Cordova
if (!commandMap.ContainsKey(service))
{
-
Type t = Type.GetType(BaseCommandNamespacePrefix + service);
+ if (t == null && !string.IsNullOrEmpty(alias))
+ {
+ t = Type.GetType(alias);
+
+ if (t == null)
+ {
+ t = Type.GetType(BaseCommandNamespacePrefix + alias);
+ }
+
+ if (t == null)
+ {
+ t = Type.GetType(alias + "." + service);
+ }
+ }
+
// custom plugin could be defined in own namespace and assembly
if (t == null)
{
@@ -85,7 +102,6 @@ namespace WPCordovaClassLib.Cordova
break;
}
}
-
}
// unknown command, still didn't find it
http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/7ac24bfb/wp7/template/cordovalib/ConfigHandler.cs
----------------------------------------------------------------------
diff --git a/wp7/template/cordovalib/ConfigHandler.cs b/wp7/template/cordovalib/ConfigHandler.cs
index 10d118a..1fb7525 100644
--- a/wp7/template/cordovalib/ConfigHandler.cs
+++ b/wp7/template/cordovalib/ConfigHandler.cs
@@ -15,13 +15,15 @@ namespace WPCordovaClassLib.CordovaLib
{
public class PluginConfig
{
- public PluginConfig(string name, bool autoLoad = false)
+ public PluginConfig(string name, bool autoLoad = false, string className = "")
{
Name = name;
isAutoLoad = autoLoad;
+ ClassName = className;
}
public string Name;
public bool isAutoLoad;
+ public string ClassName;
}
protected Dictionary<string, PluginConfig> AllowedPlugins;
@@ -174,6 +176,16 @@ namespace WPCordovaClassLib.CordovaLib
}
}
+ public string GetNamespaceForCommand(string key)
+ {
+ if(AllowedPlugins.Keys.Contains(key))
+ {
+ return AllowedPlugins[key].Name;
+ }
+
+ return "";
+ }
+
public bool IsPluginAllowed(string key)
{
return AllowAllPlugins || AllowedPlugins.Keys.Contains(key);
@@ -187,7 +199,7 @@ namespace WPCordovaClassLib.CordovaLib
foreach (var feature in features)
{
- var name = feature.Attribute("name");
+ string name = (string)feature.Attribute("name");
var values = from results in feature.Descendants()
where results.Name.LocalName == "param" && ((string)results.Attribute("name") == "wp-package")
select results;
@@ -199,7 +211,7 @@ namespace WPCordovaClassLib.CordovaLib
Debug.WriteLine("Adding feature.value=" + key);
var onload = value.Attribute("onload");
PluginConfig pConfig = new PluginConfig(key, onload != null && onload.Value == "true");
- AllowedPlugins[key] = pConfig;
+ AllowedPlugins[name] = pConfig;
}
}
}
http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/7ac24bfb/wp7/template/cordovalib/CordovaCommandCall.cs
----------------------------------------------------------------------
diff --git a/wp7/template/cordovalib/CordovaCommandCall.cs b/wp7/template/cordovalib/CordovaCommandCall.cs
index a8851fd..7b9ee0c 100644
--- a/wp7/template/cordovalib/CordovaCommandCall.cs
+++ b/wp7/template/cordovalib/CordovaCommandCall.cs
@@ -36,6 +36,7 @@ namespace WPCordovaClassLib.Cordova
public String Action { get; private set; }
public String CallbackId { get; private set; }
public String Args { get; private set; }
+ public String Namespace { get; set; }
/// <summary>
/// Retrieves command call parameters and creates wrapper for them
@@ -60,6 +61,7 @@ namespace WPCordovaClassLib.Cordova
commandCallParameters.Service = split[0];
commandCallParameters.Action = split[1];
commandCallParameters.CallbackId = split[2];
+ commandCallParameters.Namespace = String.Empty;
try
{
@@ -74,7 +76,7 @@ namespace WPCordovaClassLib.Cordova
}
catch (Exception)
{
- return null;
+ return null;
}
// sanity check for illegal names
// was failing with ::
http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/7ac24bfb/wp7/template/cordovalib/NativeExecution.cs
----------------------------------------------------------------------
diff --git a/wp7/template/cordovalib/NativeExecution.cs b/wp7/template/cordovalib/NativeExecution.cs
index c8ec1bd..e8bda8f 100644
--- a/wp7/template/cordovalib/NativeExecution.cs
+++ b/wp7/template/cordovalib/NativeExecution.cs
@@ -85,7 +85,7 @@ namespace WPCordovaClassLib.Cordova
try
{
- BaseCommand bc = CommandFactory.CreateByServiceName(commandCallParams.Service);
+ BaseCommand bc = CommandFactory.CreateByServiceName(commandCallParams.Service, commandCallParams.Namespace);
if (bc == null)
{
@@ -119,7 +119,7 @@ namespace WPCordovaClassLib.Cordova
{
try
{
- bc.InvokeMethodNamed(commandCallParams.CallbackId,commandCallParams.Action, commandCallParams.Args);
+ bc.InvokeMethodNamed(commandCallParams.CallbackId, commandCallParams.Action, commandCallParams.Args);
}
catch (Exception ex)
{