//--------------------------------- Public methods ------------------------------------------------- public ICommand GetCommand(string pFullRequest) { var _commandAndVersion = UdpMessageParser.GetCommandNameAndVersion(pFullRequest); ICommand _cmdInstance; switch (_commandAndVersion) { case RbrApi.OnGetNextSequence: _cmdInstance = (ICommand) new OnGetNextSequence(dispatcher); break; case RbrApi.OnGetCallStats: _cmdInstance = (ICommand) new OnGetCallStats(dispatcher); break; case LoggerAPI.SetLogSeverity: _cmdInstance = new SetLogSeverity(TimokLogger.Instance); break; case LoggerAPI.GetLogSeverity: _cmdInstance = new GetLogSeverity(TimokLogger.Instance); break; default: throw (new ApplicationException("CommandFactory: Unknown command: " + pFullRequest)); } _cmdInstance.APIName = APIName; _cmdInstance.FullRequest = pFullRequest; _cmdInstance.NameAndVersion = _commandAndVersion; return(_cmdInstance); }
//-------------------------------------- Private -------------------------------------------------- private bool dispatcher(string pCmd) { try { // Create a command factory and call it to create correct CommandMessage instance: ICommand _cmd = commandFactory.GetInstance(UdpMessageParser.GetCommandNameAndVersion(pCmd)); _cmd.Sequence = UdpMessageParser.GetSequence(pCmd); _cmd.Parameters = UdpMessageParser.GetInParameters(pCmd); //Process command: _cmd.Execute(); return(_cmd.Result); } catch (Exception _ex) { T.LogCritical("Exception: " + Utils.GetFullExceptionInfo(_ex)); } return(false); }
public ICommand GetCommand(string pFullRequest) { string _commandAndVersion = UdpMessageParser.GetCommandNameAndVersion(pFullRequest); ICommand _cmdInstance; switch (_commandAndVersion) { case LoggerAPI.SetLogSeverity: _cmdInstance = new SetLogSeverity(logger); break; case LoggerAPI.GetLogSeverity: _cmdInstance = new GetLogSeverity(logger); break; default: throw (new ApplicationException("Unknown command: " + _commandAndVersion)); } _cmdInstance.APIName = apiName; _cmdInstance.FullRequest = pFullRequest; _cmdInstance.NameAndVersion = _commandAndVersion; return(_cmdInstance); }