Ejemplo n.º 1
0
        public ExecutionResult ExecuteCommand(string command, Object contextCreationParam)
        {
            try
            {
                String            arguments   = null;
                IServiceInfo      serviceInfo = _serviceIdentifier.IdentifyService(command, out arguments);
                IExecutionContext context     = _contextFactory.CreateContext(serviceInfo, contextCreationParam);
                context.Service   = serviceInfo;
                context.Arguments = arguments;
                context.Container = this;

                MethodInfo serviceMethodInfo = null;
                Object     invocationTarget  = null;
                serviceMethodInfo = GetServiceMethodInfo(serviceInfo.Id, out invocationTarget);

                //TODO: Throw MissingServiceMethodException

                IList <KeyValueToken> tokens = KeyValueToken.Scan(serviceInfo.ArgumentsMapping);

                //Initialize context for current Thread
                BaseContextualized.Initialize(context);

                foreach (KeyValueToken token in tokens)
                {
                    token.Container = this;
                    context.KeyValues.Set(token);
                }

                //Put the argument values in the context
                context.KeyValues.InitializeTokens(context);

                //This variable will if the service method invokes IExecutionContext.Exit
                String exitMessage = null;

                //Call Capturers
                if (HandleCapturables(tokens, context, out exitMessage))
                {
                    ExecuteService(context, serviceMethodInfo, invocationTarget, out exitMessage);
                }

                return(GetResult(serviceInfo, context, exitMessage));
            }catch (ContainerException ex) {
                throw ex;
            }catch (Exception ex)
            {
                throw new ContainerException("An Unexpected Exception was thrown during the command execution", ex, command);
            }finally{
                BaseContextualized.Clean();
            }
        }
Ejemplo n.º 2
0
        public string Apply(string target)
        {
            String result = target;

            IList <KeyValueToken> tokens = KeyValueToken.Scan(result);

            foreach (KeyValueToken token in tokens)
            {
                token.Container = _context.Container;
                result          = token.ApplyValue(this, result);
            }

            return(result);
        }