/// <summary> /// Adds a bespoke setting to the Settings class (accessed via the grabSettings(string name) /// method. /// </summary> /// <param name="name">The name of the new setting</param> /// <param name="value">The value associated with this setting</param> public bool addSetting(string name, object value) { ISettingsDictionary dict = Request.TargetSettings; if (!UseLuceneForSet) { return(SettingsDictionaryReal.addSettingWithUndoCommit(this, dict, dict.addSetting, name, value)); } else { string realName; bool succeed; var prev = NamedValuesFromSettings.UseLuceneForGet; NamedValuesFromSettings.UseLuceneForGet = true; try { NamedValuesFromSettings.SetSettingForType(dict.NameSpace, this, dict, name, null, value, null, null); } finally { NamedValuesFromSettings.UseLuceneForGet = prev; } return(true); } }
static public Unifiable SetSettingForType(string subject, SubQuery query, ISettingsDictionary dict, string name, string gName, object value, string setReturn, XmlNode templateNode) { string _sreturn = setReturn; setReturn = StaticXMLUtils.GetAttribValue <string>(templateNode, "set-return", () => _sreturn, query.ReduceStarAttribute <string>); Request request = query.Request; AltBot TargetBot = request.TargetBot; // try to use a global blackboard predicate User gUser = TargetBot.ExemplarUser; string realName; Unifiable resultGet = SettingsDictionaryReal.grabSettingDefaultDict(dict, name, out realName); bool shouldSet = ShouldSet(templateNode, dict, realName, value, resultGet, query); User user = query.CurrentUser; ITripleStore userbotLuceneIndexer = (ITripleStore)user.mbot.TripleStore; string userName = user.UserID; if (!shouldSet) { writeToLog("!shouldSet ERROR {0} name={1} value={2} old={3}", dict, realName, value, resultGet); bool shouldSet2 = ShouldSet(templateNode, dict, realName, value, resultGet, query); return(ReturnSetSetting(dict, name, setReturn)); } if (IsIncomplete(value)) { if (UseLuceneForSet && userbotLuceneIndexer != null) { userbotLuceneIndexer.retractAllTriple(userName, name); } SettingsDictionaryReal.removeSettingWithUndoCommit(query, dict, name); if (!IsNullOrEmpty(gName)) { SettingsDictionaryReal.removeSettingWithUndoCommit(query, gUser, gName); } } else { if (UseLuceneForSet && userbotLuceneIndexer != null) { userbotLuceneIndexer.updateTriple(userName, name, value); } if (!String.IsNullOrEmpty(gName)) { SettingsDictionaryReal.addSettingWithUndoCommit(query, gUser.Predicates, gUser.addSetting, gName, value); } query.SetDictValue++; SettingsDictionaryReal.addSettingWithUndoCommit(query, dict, dict.addSetting, name, value); } var retVal = ReturnSetSetting(dict, name, setReturn); if (!IsIncomplete(retVal) || !IsNullOrEmpty(retVal)) { string comment = null; //if (query.LastTagHandler!=null) comment = query.LastTagHandler.Succeed(" setting " + name); return(retVal);// +comment; } return(retVal); }
/// <summary> /// Updates the named setting with a new value whilst retaining the position in the /// dictionary /// </summary> /// <param name="name">the name of the setting</param> /// <param name="value">the new value</param> public bool updateSetting(string name, object value) { return(SettingsDictionaryReal.addSettingWithUndoCommit(this, TargetSettings, TargetSettings.updateSetting, name, value)); }