Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
CommandFactory.CreateByServiceName takes new optional string value wh…
…ich can be the fully qualified class name, or just an alias class name to prevent ambiguity
  • Loading branch information
purplecabbage committed Jan 16, 2014
1 parent 4265d0a commit af80474988f1eee61684c3ee9f37b96d9aa398a6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
@@ -52,7 +52,10 @@ public static class CommandFactory
/// </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,18 @@ public static BaseCommand CreateByServiceName(string service)

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(alias + "." + service);
}
}

// custom plugin could be defined in own namespace and assembly
if (t == null)
{
@@ -85,7 +97,6 @@ public static BaseCommand CreateByServiceName(string service)
break;
}
}

}

// unknown command, still didn't find it
@@ -85,7 +85,7 @@ public void ProcessCommand(CordovaCommandCall commandCallParams)

try
{
BaseCommand bc = CommandFactory.CreateByServiceName(commandCallParams.Service);
BaseCommand bc = CommandFactory.CreateByServiceName(commandCallParams.Service, commandCallParams.Namespace);

if (bc == null)
{
@@ -119,7 +119,7 @@ public void ProcessCommand(CordovaCommandCall commandCallParams)
{
try
{
bc.InvokeMethodNamed(commandCallParams.CallbackId,commandCallParams.Action, commandCallParams.Args);
bc.InvokeMethodNamed(commandCallParams.CallbackId, commandCallParams.Action, commandCallParams.Args);
}
catch (Exception ex)
{

0 comments on commit af80474

Please sign in to comment.