Ejemplo n.º 1
0
        private static void CheckNullability(KeyValueToken token)
        {
            if (!token.Name.EndsWith("?"))
            {
                return;
            }


            token.Name     = token.Name.Replace("?", "");
            token.Nullable = true;
        }
Ejemplo n.º 2
0
        private static void CheckCapturability(KeyValueToken token)
        {
            //Token name must have the @ marker to be automatically-interpretable
            if (!token.Name.StartsWith("@"))
            {
                return;
            }

            //Remove automatic-interpretation marker
            token.Name       = token.Name.Substring(1);
            token.Capturable = true;
        }
Ejemplo n.º 3
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.º 4
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);
        }
Ejemplo n.º 5
0
        public static List <KeyValueToken> Scan(String template)
        {
            Regex                regex           = new Regex(MATCH_TOKENS_EXPRESSION, RegexOptions.IgnoreCase);
            MatchCollection      matchCollection = regex.Matches(template);
            List <KeyValueToken> tokens          = new List <KeyValueToken>();

            int scanIndex = 0;

            foreach (Match m in matchCollection)
            {
                KeyValueToken token = new KeyValueToken();
                token.ArgumentIndex = scanIndex;
                token.TokenText     = m.Value;

                Group keywordParser    = m.Groups["KeywordParse"];
                Group parser           = m.Groups["Parser"];
                Group keywordFormatter = m.Groups["KeywordFormat"];
                Group formatter        = m.Groups["Formatter"];
                Group keyword          = m.Groups["Keyword"];

                if (keywordParser.Success)
                {
                    //keyword with parser
                    token.Name   = keywordParser.Value;
                    token.Parser = parser.Value;
                }
                else if (keywordFormatter.Success)
                {
                    //keyword with formatter
                    token.Name      = keywordFormatter.Value;
                    token.Formatter = formatter.Value;
                }
                else
                {
                    //Plain keyword
                    token.Name = keyword.Value;
                }

                CheckCapturability(token);
                CheckNullability(token);
                tokens.Add(token);
                scanIndex++;
            }

            return(tokens);
        }
Ejemplo n.º 6
0
        public object Get(string name)
        {
            Object value = null;

            if (_tokens.ContainsKey(name))
            {
                KeyValueToken token = null;
                _tokens.TryGetValue(name, out token);
                token.Container = _context.Container;
                value           = token.GetValue(this);
            }
            else if (_values.ContainsKey(name))
            {
                _values.TryGetValue(name, out value);
            }


            return(value);
        }
Ejemplo n.º 7
0
 public void Set(KeyValueToken token)
 {
     _tokens.Add(token.Name, token);
 }