/// <summary>
        /// Process any skills that the response from the engine might have invoked.
        /// </summary>
        /// <param name="responseStatement"></param>
        /// <returns></returns>
        public string ProcessSkills(string responseStatement)
        {
            if (responseStatement.Contains(SkillsRepository.SkillRequestToken))
            {
                int    start    = responseStatement.IndexOf("{{");
                int    end      = responseStatement.IndexOf("}}") - start + 2;
                string rawSkill = responseStatement.Substring(start, end);
                if (SkillParams.ValidateRawSkillString(rawSkill))
                {
                    SkillResult result = SkillsRepository.Instance.ExecuteSkill(new SkillParams(rawSkill));

                    if (result.Type == ResultType.Simple)
                    {
                        responseStatement = responseStatement.Replace(rawSkill, result.SimpleResult);
                    }
                    else if (result.Type == ResultType.KeyValuePairs)
                    {
                        // Response is in form of key value pairs.
                        // 1. Remove skill invocation raw skill string
                        responseStatement = responseStatement.Replace(rawSkill, string.Empty);

                        // 2. Replace response key placeholders with values
                        foreach (KeyValuePair <string, string> kv in result.KeyValues)
                        {
                            responseStatement = responseStatement.Replace("{{key:" + kv.Key + "}}", kv.Value);
                        }
                    }
                }
            }

            return(responseStatement);
        }
示例#2
0
        /// <summary>
        /// Entry point for executing the method that invokes the third party script
        /// </summary>
        /// <param name="skillParams"></param>
        /// <returns></returns>
        public static SkillResult RunScriptedSkill(SkillParams skillParams)
        {
            var scriptsPath = ConfigurationManager.AppSettings["scriptsPath"];

            if (ValidateParams(skillParams) && scriptsPath != null)
            {
                var processStartInfo = new ProcessStartInfo
                {
                    FileName  = skillParams["interpreter"],
                    Arguments = string.Concat(scriptsPath, skillParams["scriptname"], " ", skillParams["args"]),
                    RedirectStandardOutput = true,
                    UseShellExecute        = false
                };

                var process = Process.Start(processStartInfo);
                var output  = process.StandardOutput.ReadToEnd();
                process.WaitForExit();

                ScriptedSkillResponse js = JsonConvert.DeserializeObject <ScriptedSkillResponse>(output);

                // Build dictionary from key values in response
                Dictionary <string, string> dict = new Dictionary <string, string>();
                foreach (KeyValue kv in js.keyvalues)
                {
                    dict[kv.key] = kv.value;
                }

                SkillResult result = new SkillResult(dict);

                return(result);
            }

            return(new SkillResult(""));
        }
        /// <summary>
        /// Execute the skill code to perform skill action.
        /// </summary>
        /// <param name="skillParams"></param>
        /// <returns>Result from the executed skill</returns>
        public SkillResult ExecuteSkill(SkillParams skillParams)
        {
            SkillResult result = null;

            if (this.SkillsIndex.ContainsKey(skillParams.SkillName))
            {
                result = this.SkillsIndex[skillParams.SkillName].Invoke(skillParams);
            }

            return(result != null ? result : new SkillResult(string.Empty));
        }
示例#4
0
        /// <summary>
        /// Process any skills that the response from the engine might have invoked.
        /// </summary>
        /// <param name="responseStatement"></param>
        /// <returns></returns>
        public string ProcessSkills(string responseStatement)
        {
            if (responseStatement.Contains(SkillsRepository.SkillRequestToken))
            {
                int    start    = responseStatement.IndexOf("{{");
                int    end      = responseStatement.IndexOf("}}") - start + 2;
                string rawSkill = responseStatement.Substring(start, end);
                if (SkillParams.ValidateRawSkillString(rawSkill))
                {
                    SkillResult result = SkillsRepository.Instance.ExecuteSkill(new SkillParams(rawSkill));
                    responseStatement = responseStatement.Replace(rawSkill, result.SimpleResult);
                }
            }

            return(responseStatement);
        }