示例#1
0
        public XmlRpcStruct RunKeyword(string keywordName, string[] arguments)
        {
            var result = new XmlRpcStruct();

            KeywordManager.KeywordLookupResult lookupResult = default(KeywordManager.KeywordLookupResult);
            try
            {
                lookupResult = keywordManager.TryExecuteKeyword(keywordName, arguments, out var keywordResult);
                if (lookupResult == KeywordManager.KeywordLookupResult.Success)
                {
                    if (keywordResult != null)
                    {
                        result.Add(KeywordResultValue, keywordResult);
                    }
                    result.Add(KeywordResultStatus, KeywordResultPass);
                }
            }
            catch (Exception e)
            {
                result.Clear();

                result.Add(KeywordResultStatus, KeywordResultFail);
                result.Add(KeywordResultError, BuildRecursiveValueFromException(e, ex => ex.Message).StripNonSafeCharacters());
                result.Add(KeywordResultTraceback, BuildRecursiveValueFromException(e, ex => ex.StackTrace).StripNonSafeCharacters());
            }
            if (lookupResult == KeywordManager.KeywordLookupResult.KeywordNotFound)
            {
                throw new XmlRpcFaultException(1, string.Format("Keyword \"{0}\" not found", keywordName));
            }
            if (lookupResult == KeywordManager.KeywordLookupResult.ArgumentsNotMatched)
            {
                throw new XmlRpcFaultException(2, string.Format("Arguments types do not match any available keyword \"{0}\" : [{1}]", keywordName, string.Join(", ", arguments)));
            }
            return(result);
        }
示例#2
0
        public XmlRpcStruct RunKeyword(string keywordName, string[] arguments)
        {
            var result = new XmlRpcStruct();

            Keyword keyword;

            if (!keywordManager.TryGetKeyword(keywordName, out keyword))
            {
                throw new XmlRpcFaultException(1, string.Format("Keyword \"{0}\" not found", keywordName));
            }

            try
            {
                var keywordResult = keyword.Execute(arguments);
                if (keywordResult != null)
                {
                    result.Add(KeywordResultValue, keywordResult.ToString());
                }
                result.Add(KeywordResultStatus, KeywordResultPass);
            }
            catch (Exception e)
            {
                result.Clear();

                result.Add(KeywordResultStatus, KeywordResultFail);
                result.Add(KeywordResultError, BuildRecursiveErrorMessage(e));
                result.Add(KeywordResultTraceback, e.StackTrace);
            }

            return(result);
        }
示例#3
0
        public XmlRpcStruct RunKeyword(string keywordName, string[] arguments)
        {
            var result = new XmlRpcStruct();

            List <Keyword> keywords;

            if (!keywordManager.TryGetKeyword(keywordName, out keywords))
            {
                throw new XmlRpcFaultException(1, string.Format("Keyword \"{0}\" not found", keywordName));
            }

            foreach (var keyword in keywords)
            {
                object[] parsedArguments;
                if (!keyword.TryMatchArguments(arguments, out parsedArguments))
                {
                    continue;
                }

                try
                {
                    Recorder.Instance.RecordEvent(keywordName, arguments);
                    var keywordResult = keyword.Execute(parsedArguments);
                    if (keywordResult != null)
                    {
                        result.Add(KeywordResultValue, keywordResult);
                    }
                    result.Add(KeywordResultStatus, KeywordResultPass);
                }
                catch (Exception e)
                {
                    result.Clear();

                    result.Add(KeywordResultStatus, KeywordResultFail);
                    result.Add(KeywordResultError, BuildRecursiveErrorMessage(e).StripNonSafeCharacters());
                    result.Add(KeywordResultTraceback, e.StackTrace);
                }

                return(result);
            }

            throw new XmlRpcFaultException(2, string.Format("Arguments types do not match any available keyword \"{0}\" : [{1}]", keywordName, string.Join(", ", arguments)));
        }