public bool pushValues(ISettingsDictionary settings, string n, Unifiable v) { bool local = settings.containsLocalCalled(n); bool containsAtAll = settings.containsSettingCalled(n); Unifiable oldValue = settings.grabSetting(n); if (oldValue == v) { return(false); } string debugStr = String.Format("pushValues {0} {1} {2}", settings, n, v); if (!local) { settings.addSetting(n, v); AddUndo(debugStr, () => { Unifiable newValue = settings.grabSetting(n); if (newValue != v) { writeToLog("ERROR unexpected '" + n + "'='" + Unifiable.DescribeUnifiable(newValue) + "' expecting '" + Unifiable.DescribeUnifiable(v) + "' "); } settings.removeSetting(n); }); } else { settings.updateSetting(n, v); AddUndo(debugStr, () => { Unifiable newValue = settings.grabSetting(n); if (newValue != v) { writeToLog("ERROR unexpected '" + n + "'='" + Unifiable.DescribeUnifiable(newValue) + "' expecting '" + Unifiable.DescribeUnifiable(v) + "' "); } settings.updateSetting(n, oldValue); }); } return(true); }
public static Action EnterTag(Request request, XmlNode templateNode, SubQuery query) { if (templateNode.NodeType != XmlNodeType.Element) { return(DoNothing); throw new NotImplementedException("EnterTag: " + templateNode.NodeType); } bool needsUnwind = false; UndoStackHolder thiz = (UndoStackHolder)query ?? request; ISettingsDictionary dict = query; if (dict == null && request != null) { dict = request.TargetSettings; } XmlAttributeCollection collection = templateNode.Attributes; EnterContext(request, query); if (collection == null || collection.Count <= 0) { return(() => { ExitContext(request, query); }); } else { var used = new List <XmlAttribute>(); string defaultElement = ""; Action gmrerstore; gmrerstore = request.WithAttributesForUnwind(templateNode, ref defaultElement, used); int uc = used.Count; UndoStack savedValues = null; foreach (XmlAttribute node in collection) { if (used.Contains(node)) { continue; } bool found; string n = node.Name.ToLower(); switch (n) { case "state": case "flag": case "graph": case "topic": case "that": break; default: { lock (ReservedAttributes) { if (ReservedAttributes.Contains(n)) { continue; } bool prev = NamedValuesFromSettings.UseLuceneForGet; try { NamedValuesFromSettings.UseLuceneForGet = false; if (!dict.containsSettingCalled(n)) { ReservedAttributes.Add(n); request.writeToLog("ReservedAttributes: {0}", n); } else { if (!PushableAttributes.Contains(n)) { PushableAttributes.Add(n); request.writeToLog("PushableAttributes: {0}", n); } } } finally { NamedValuesFromSettings.UseLuceneForGet = prev; } } // now require temp vars to s ay with_id="tempId" // to set the id="tempid" teporarily while evalig tags if (!n.StartsWith("with_")) { continue; } else { n = n.Substring(5); } Unifiable v = ReduceStar <Unifiable>(node.Value, query, dict, out found); UndoStack.FindUndoAll(thiz, true); savedValues = savedValues ?? UndoStack.GetStackFor(thiz); //savedValues = savedValues ?? query.GetFreshUndoStack(); savedValues.pushValues(dict, n, v); needsUnwind = true; } break; } } // unwind return(() => { if (needsUnwind) { try { EnterContext(request, query); if (savedValues != null) { savedValues.UndoAll(); } } catch (Exception ex) { request.writeToLog("ERROR " + ex); } finally { ExitContext(request, query); } } ExitContext(request, query); if (uc > 0) { gmrerstore(); } }); } }
static Unifiable IfSucceed(XmlNode templateNode, ISettingsDictionary dict, SubQuery query0, Func <Unifiable> Succeed, Func <string, Unifiable> Failure) { lock (templateNode) { // ISettingsDictionary dict = query; //if (GetAttribValue(templateNode, "type", "") == "bot" || GetAttribValue(templateNode,"bot", "").ToLower() == "true") // dict = query0.TargetBot.GlobalSettings; bool yesInherit = true; bool noLocal = false; string locally = GetAttribValue(templateNode, "scope,type,exists", ""); if (locally.Contains("local")) { yesInherit = false; } if (locally.Contains("inher")) { noLocal = true; yesInherit = true; } Func <IConvertible, string> query = query0.ReduceStarAttribute <string>; string name = GetAttribValue <string>(templateNode, "name,var,if", NullStringFunct, query); string expression = GetAttribValue <string>(templateNode, "expr", NullStringFunct, query); string exists = GetAttribValue(templateNode, "exists", NullStringFunct, query); string contains = GetAttribValue(templateNode, "contains", NullStringFunct, query); Unifiable value = GetAttribValue(templateNode, "value", NullStringFunct, query); string scope = GetAttribValue(templateNode, "local,scope", NullStringFunct, query); string realName0; string type = GetAttribValue(templateNode, "type,user,bot", out realName0, NullStringFunct, query); if (type == null) { type = realName0; } string varname = name ?? exists; bool mustNotExist = false; if (contains != null) { value = ".*" + contains + ".*"; } if (exists != null) { bool locallyContains = dict.containsLocalCalled(name); bool anyContains = dict.containsSettingCalled(name); if (exists.StartsWith("local")) { if (!locallyContains) { return(Unifiable.Empty); } return(Succeed()); } exists = exists.ToLower(); if (exists == "inherited") { if (!locallyContains && anyContains) { return(Succeed()); } return(Failure("" + name + "=" + anyContains + " !inherited ")); } if (exists == "false") { if (!yesInherit) { if (!locallyContains) { return(Succeed()); } } if (noLocal) { if (anyContains && !locallyContains) { return(Succeed()); } } return(Failure("" + name + "=" + anyContains + " !false ")); } if (exists == "true") { if (!yesInherit) { if (locallyContains) { return(Succeed()); } } if (noLocal) { if (!locallyContains && anyContains) { return(Succeed()); } } return(Failure("" + name + "=" + anyContains + " " + templateNode.OuterXml)); } string realName; bool succeed; //ReduceStar0 query = query0.ReduceStarAttribute; Unifiable actualValue = GetActualValue(templateNode, name, type ?? dict.NameSpace, out succeed, query0); if (IsPredMatch(value, actualValue, query0)) { return(Succeed()); } else { return(Failure("" + name + "=" + anyContains + " " + templateNode.OuterXml)); } } return(Succeed()); } }