コード例 #1
0
        public void TestMessageFormatterLocal()
        {
            ChatState state = new ChatState();
            var       local = state.GetFlowAnswers("sampleflow");

            local.FieldAnswers["test"] = "local test";

            string text = "Format '%local.test%'";

            var formattedText = MessageFormatter.FormatMessage(state, "sampleflow", text);

            Assert.AreEqual(formattedText, "Format 'local test'");
        }
コード例 #2
0
        public void TestMessageFormatterBracketVariables()
        {
            ChatState state = new ChatState();
            var       local = state.GetFlowAnswers("sampleflow");

            local.FieldAnswers["test/local"]   = "local test";
            state.GlobalAnswers["test/global"] = "global test";

            string text = "Format '%s[\"test/global\"]%' and '%local[\"test/local\"]%'";

            var formattedText = MessageFormatter.FormatMessage(state, "sampleflow", text);

            Assert.AreEqual(formattedText, "Format 'global test' and 'local test'");
        }
コード例 #3
0
        private static object ResolveVariable(Match match, ChatState state, string flowName)
        {
            string scope        = match.Groups["scope"].Value;
            string variableText = match.Groups[0].Value;
            string groupType    = match.Groups["group"].Value;

            var    variableLevels = match.Groups["varlevel"].Captures;
            string variableBase   = variableLevels[0].Value;

            object value = null;

            if (scope == "local")
            {
                var flowAnswers = state.GetFlowAnswers(flowName);
                value = flowAnswers[variableBase];
            }
            else
            {
                value = state.GlobalAnswers[variableBase];
            }

            if (value == null)
            {
                return(value);
            }

            if (!UtilityMethods.IsValueType(value) && (variableLevels.Count > 1))
            {
                var levels = variableLevels
                             .Cast <Capture>()
                             .Select(m => m.Value)
                             .ToArray();

                try
                {
                    value = FormatMultiLevel(levels, value);
                }
                catch (KeyNotFoundException)
                {
                    logger.WarnFormat("Flow: Message text variable not set.  {0}", variableText);
                    value = null;
                }
            }

            return(value);
        }
コード例 #4
0
 protected ChatVariables GetChatVariables(ChatState state, ChatFlowStep flowStep, VariableScope scope)
 {
     return(scope == VariableScope.Local ? state.GetFlowAnswers(flowStep.Flow) : state.GlobalAnswers);
 }