/// <summary> /// Loads bespoke settings into the class from the url referenced in urlToSettings using WWW class. /// /// The XML should have an XML declaration like this: /// /// <?xml version="1.0" encoding="utf-8" ?> /// /// followed by a <root> tag with child nodes of the form: /// /// <item name="name" value="value"/> /// </summary> /// <param name="urlToSettings">The file containing the settings</param> public IEnumerator loadSettingsWWW(string urlToSettings, AIMLbot.Utils.SettingsDictionary settingsdictionary) { // Acces files through Unity WWW class WWW webReq = new WWW(ConvertToUrlFriendly(urlToSettings)); // Wait for webReq to finish downloading yield return(webReq); // Did an error appear during loading? if (webReq.error != null) { // Log error and skip this file Debug.LogWarning(webReq.error + " Skipped file."); } else { // Create a XmlReader instance with the retrieved string XmlReader reader = XmlReader.Create(new StringReader(webReq.text)); // Create XmlDocument equal to Windows, Linux and Mac OSX code. XmlDocument xmlDoc = new XmlDocument(); // Now load xml doc from XmlReader instance xmlDoc.Load(reader); if (settingsdictionary == null) { Debug.LogWarning("No AIMLbot.Utils.SettingsDictionary instance passed!"); } // And call loadSettings function settingsdictionary.loadSettings(xmlDoc); } }
public void testClone() { mockDictionary.AddSetting("test", "value"); mockDictionary.AddSetting("test2", "value2"); mockDictionary.AddSetting("test3", "value3"); SettingsDictionary newDictionary = new SettingsDictionary(_mockChatBot); mockDictionary.Clone(newDictionary); Assert.AreEqual(3, newDictionary.SettingNames.Length); }
/// <summary> /// Static helper that applies replacements from the passed dictionary object to the /// target string /// </summary> /// <param name="chatBot">The ChatBot for whom this is being processed</param> /// <param name="dictionary">The dictionary containing the substitutions</param> /// <param name="target">the target string to which the substitutions are to be applied</param> /// <returns>The processed string</returns> public static string Substitute(ChatBot chatBot, SettingsDictionary dictionary, string target) { string marker = GetMarker(5); string result = target; foreach (string pattern in dictionary.SettingNames) { string p2 = MakeRegexSafe(pattern); //string match = "\\b"[email protected]().Replace(" ","\\s*")+"\\b"; string match = "\\b" + p2.TrimEnd().TrimStart() + "\\b"; string replacement = marker + dictionary.GrabSetting(pattern).Trim() + marker; result = Regex.Replace(result, match, replacement, RegexOptions.IgnoreCase); } return result.Replace(marker, ""); }
/// <summary> /// Ctor /// </summary> /// <param name="UserID">The GUID of the user</param> /// <param name="bot">the bot the user is connected to</param> public User(string UserID, Bot bot) { if (UserID.Length > 0) { id = UserID; this.bot = bot; Predicates = new Utils.SettingsDictionary(this.bot); this.bot.DefaultPredicates.Clone(Predicates); Predicates.addSetting("topic", "*"); } else { throw new Exception("The UserID cannot be empty"); } }
/// <summary> /// Copies the values in the current object into the SettingsDictionary passed as the target /// </summary> /// <param name="target">The target to recieve the values from this SettingsDictionary</param> public void Clone(SettingsDictionary target) { foreach (string key in this.orderedKeys) { target.addSetting(key, this.grabSetting(key)); } }
/// <summary> /// Copies the values in the current object into the SettingsDictionary passed as the target /// </summary> /// <param name="target">The target to recieve the values from this SettingsDictionary</param> public void Clone(SettingsDictionary target) { foreach (string key in _orderedKeys) { target.AddSetting(key, GrabSetting(key)); } }
/// <summary> /// Instantiates the dictionary objects and collections associated with this class /// </summary> private void setup() { this.GlobalSettings = new SettingsDictionary(this); this.GenderSubstitutions = new SettingsDictionary(this); this.Person2Substitutions = new SettingsDictionary(this); this.PersonSubstitutions = new SettingsDictionary(this); this.Substitutions = new SettingsDictionary(this); this.DefaultPredicates = new SettingsDictionary(this); this.CustomTags = new Dictionary<string, TagHandler>(); this.Graphmaster = new AIMLbot.Utils.Node(); }
public void setupMockDictionary() { this.mockDictionary = new SettingsDictionary(this.mockBot); this.pathToConfigs = Path.Combine(Environment.CurrentDirectory, Path.Combine("config", "Settings.xml")); }
public void setupMockDictionary() { mockDictionary = new SettingsDictionary(_mockChatBot); pathToConfigs = Path.Combine(Environment.CurrentDirectory, Path.Combine("config", "Settings.xml")); }