|
using System;
using System.Collections.Generic;
using System.Text;
using System.ServiceModel;
using System.Reflection;
namespace Robotics.Coordinator
{
/// <summary>
/// WCF server object
/// </summary>
public class CoordinatorServiceType : ICoordinator
{
static readonly private Type[] types = null;
static CoordinatorServiceType()
{
types = Assembly.GetExecutingAssembly().GetTypes();
}
/// <summary>
/// Implement [OperationContract] ICoordinator.Command()
///
/// </summary>
public object Command(string commandName, object commandData)
{
IDssCommand dssCommand = null;
Type commandType = GetCommandTypeByName(commandName);
if (null != commandType)
dssCommand = Activator.CreateInstance(commandType) as IDssCommand;
return (null != dssCommand)
? dssCommand.DoCommand(commandData)
: string.Format("{0}: Command \"{0}\" is not implemented in DSS Coordinator.", commandName);
}
private Type GetCommandTypeByName(string commandName)
{
Type commandType = null;
foreach (Type type in types)
if (type.Name.ToLower() == commandName.ToLower())
{
try
{
commandType = type;
break;
}
catch
{
}
}
return commandType;
}
}
[ServiceContract]
public interface ICoordinator
{
[OperationContract]
object Command(string commandName, object commandData);
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here