public bool AddDialogVariableAssignment(DialogVariableAssignment variableAssignment, DialogNodeType nodeType)
        {
            switch (variableAssignment.Operator)
            {
            case DialogVariableOperator.SetTo:
            case DialogVariableOperator.SetToYes:
            case DialogVariableOperator.SetToNo:
                // Filter out all cases when variable assignment is not useful to simplify the code
                if (VariablesValues.ContainsKey(variableAssignment.Variable) &&
                    VariablesValues[variableAssignment.Variable].Count == 1)
                {
                    var previousValue = VariablesValues[variableAssignment.Variable][0];
                    // Case 1 : value not changed => variable assignment is not useful
                    if (previousValue == variableAssignment.Value)
                    {
                        return(false);
                    }
                }
                var values = new List <string>(1);
                values.Add(variableAssignment.Value);
                VariablesValues[variableAssignment.Variable] = values;
                return(true);

            case DialogVariableOperator.SetToBlank:
                if (VariablesValues.ContainsKey(variableAssignment.Variable))
                {
                    if (VariablesValues[variableAssignment.Variable].Count == 1 &&
                        entityVariablesNames.Contains(variableAssignment.VariableName))
                    {
                        var previousValue = VariablesValues[variableAssignment.Variable][0];
                        // Case 2 : the default behavior of FatHeadAnswer
                        // is to reset all entity variables not explicitly set => variable assignment is not useful
                        if (nodeType == DialogNodeType.FatHeadAnswers && (String.IsNullOrEmpty(previousValue) || previousValue.StartsWith("$(")))
                        {
                            return(VariableCouldHaveBeenSetByEntityMatchBefore(variableAssignment.VariableName));
                        }
                        // Case 3 : the default behavior of RedirectToLongTail / DirectAnswer
                        // is to reset all entity variables n=> variable assignment is not useful
                        else if ((nodeType == DialogNodeType.RedirectToLongTail || nodeType == DialogNodeType.DirectAnswer))
                        {
                            return(false);
                        }
                    }

                    VariablesValues.Remove(variableAssignment.Variable);
                    return(true);
                }
                else
                {
                    return(VariableCouldHaveBeenSetByEntityMatchBefore(variableAssignment.VariableName));
                }

            case DialogVariableOperator.CopyValueFromVariable:
                var            fromVariable = Variables[variableAssignment.Value];
                IList <string> fromValues   = null;
                VariablesValues.TryGetValue(fromVariable, out fromValues);
                IList <string> toValues = null;
                VariablesValues.TryGetValue(variableAssignment.Variable, out toValues);
                if (fromValues == null)
                {
                    if (toValues != null)
                    {
                        VariablesValues.Remove(variableAssignment.Variable);
                    }
                }
                else
                {
                    VariablesValues[variableAssignment.Variable] = fromValues;
                }
                return(true);

            default:
                throw new Exception("Unexpected variable assignment operator " + variableAssignment.Operator);
            }
        }
 public bool SetVariableValue(string variableName, string value, DialogNodeType nodeType)
 {
     return(AddDialogVariableAssignment(
                new DialogVariableAssignment(Variables[variableName], DialogVariableOperator.SetTo, value), nodeType));
 }