private void Stop_bot() { ///If parameter script to be lauched when we received a bot response ///cannot include command to the bot just event ExecEZScript(_cf.STORAGE[ConfigurationDictionary._STORAGE_BOT_STOP_SCRIPT_VALUE].ToString()); // // If bot before stop event if configured - raise the corresponding bot event // string event1 = _cf.STORAGE[ConfigurationDictionary._STORAGE_BOT_BEFORE_STOP_EVENT].ToString(); if (event1 != string.Empty) { synbot.Bot_raiseevent(event1); } /// Stop Bot synbot.Stopbot(); synbot = null; Set_buttons_bot_stopped(); EZ_Builder.Scripting.VariableManager.SetVariable(variablebotstatus, false.ToString()); // clear the values of EZ variable user id bot name and username EZ_Builder.Scripting.VariableManager.SetVariable(variablebotuserid, string.Empty); flagbotrunning = false; // Message saving OK to Bot Console EZ_Builder.Invokers.SetAppendText(botConsole, true, "Saving Bot Context completed for user id {0}", nomuser); }
private string Bot_Query(string userphrase) { // Message to Bot Console with userphrase // Do some filtering not easy to do in Synbot StringBuilder sb = new StringBuilder(userphrase.ToLower()); sb.Replace("-", " "); sb.Replace('\t', ' '); sb.Replace('\n', ' '); sb.Replace('\r', ' '); string tempo = sb.ToString(); if (!flagmessageerror) { EZ_Builder.Invokers.SetAppendText(botConsole, true, "{0} : {1}", Synbot.Synbot.nameuser, tempo); } flagmessageerror = false; // Query the bot with Userphrase string botMessage = synbot.BotQuery(tempo); // If error due to licensing problem Stop restart the bot and submit again if (botMessage == "ERRORERRORERROR") { EZ_Builder.Invokers.SetAppendText(botConsole, true, "{0} : {1}", Synbot.Synbot.nameuser, "Restarting the Bot "); synbot.Stopbot(); synbot = null; // Bot_ReStart(nomuser); ///botMessage = Bot_Query(userphrase); } botMessage = Messagereceived_processing(botMessage); return(botMessage); }
private void Bot_ReStart(string nomuser) { /// Create Synbot class instance synbot = new Synbot.Synbot(nomuser, _cf.STORAGE[ConfigurationDictionary._STORAGE_BOT_PATH].ToString(), packagename, _cf.STORAGE[ConfigurationDictionary._STORAGE_BOT_SAVE_PATH].ToString(), _cf.STORAGE[ConfigurationDictionary._STORAGE_BOT_ROBOTTYPE].ToString(), _executor_0, defautbotname, vrlanguageused); /// event handler attached to the response message received from the Bot synbot.botUser.ResponseReceived += SimlBot_Responsereceived; /// Set EZB variables with userid Bot Name and User Name return; }
private void Bot_Start(string nomuser) { EZ_Builder.Invokers.SetText(textBoxUserid, nomuser); vrlanguageused = _cf.STORAGE[ConfigurationDictionary._STORAGE_BOT_DEFAULT_LANGUAGE].ToString(); /// Create Synbot class instance synbot = new Synbot.Synbot(nomuser, _cf.STORAGE[ConfigurationDictionary._STORAGE_BOT_PATH].ToString(), packagename, _cf.STORAGE[ConfigurationDictionary._STORAGE_BOT_SAVE_PATH].ToString(), _cf.STORAGE[ConfigurationDictionary._STORAGE_BOT_ROBOTTYPE].ToString(), _executor_0, defautbotname, vrlanguageused); /// event handler attached to the response message received from the Bot synbot.botUser.ResponseReceived += SimlBot_Responsereceived; /// Set EZB variables with userid Bot Name and User Name EZ_Builder.Scripting.VariableManager.SetVariable(variablebotuserid, nomuser); // Message initialize OK to Bot Console EZ_Builder.Invokers.SetAppendText(botConsole, true, "Bot initialized for user id {0}", nomuser); flagbotrunning = true; EZ_Builder.Scripting.VariableManager.SetVariable(variablebotstatus, true.ToString()); // // If bot init event if configured - raise the corresponding bot event // string event1 = _cf.STORAGE[ConfigurationDictionary._STORAGE_BOT_INIT_EVENT].ToString(); if (event1 != string.Empty) { synbot.Bot_raiseevent(event1); } ///If parameter script to be lauched just after bot Start ExecEZScript(_cf.STORAGE[ConfigurationDictionary._STORAGE_BOT_START_SCRIPT_VALUE].ToString()); // // Process welcom message if configured // string welcomemess = _cf.STORAGE[ConfigurationDictionary._STORAGE_BOT_WELCOME_MESSAGE].ToString(); if (welcomemess != string.Empty) { Bot_Query(welcomemess); } return; }
public Synbot(string userid, string botpath, string packagename, string botsavepath, string robottype , EZ_Builder.Scripting.Executor executor, string defautbotname, string language) { string packageString = ""; string pathbotpk = botpath + packagename + ".simlpk"; string pathbotsource = botpath; _executor_bot = executor; this.simlBot = new SimlBot(); simlBot.Adapters.Add(new EzvarAdapter()); simlBot.Adapters.Add(new EzcmdAdapter()); simlBot.Adapters.Add(new CompareAdapter()); simlBot.Adapters.Add(new VaropAdapter()); simlBot.Adapters.Add(new LearnAdapter()); Simladaptators.Simladaptators.adaptators.Add(this.simlBot); UserSIMLadaptators.Simladaptators.adaptators.Add(this.simlBot); this.botUser = simlBot.MainUser; //this.botUser = simlBot.CreateUser(userid); // Recreate package var elementList = new System.Collections.Generic.List <XDocument>(); foreach (var simlFile in Directory.GetFiles(pathbotsource, "*.siml")) { var simlElement = XDocument.Load(simlFile); elementList.Add(simlElement); } string pathsettings = pathbotsource + @"\" + "Settings" + @"\"; if (Directory.Exists(pathsettings)) { foreach (var simlFile in Directory.GetFiles(pathsettings)) { var simlElement = XDocument.Load(simlFile); elementList.Add(simlElement); } } var packageref = simlBot.PackageManager.ConvertToPackage(elementList); File.WriteAllText(pathbotpk, packageref); /// Load SIML Package file var t = Task.Run(() => packageString = File.ReadAllText(pathbotpk)); t.Wait(); this.simlBot.PackageManager.LoadFromString(packageString); this.nomsave = userid + "-Settings.siml"; this.useridbot = userid; this.botsavepath = botsavepath; refbot = this; path_bot = botpath; // attach event handler for the learning event of the bot this.simlBot.Learning += SimlBot_Learning; // attach event handler for the memorizing event of the bot this.simlBot.Memorizing += simlBot_Memorizing; Bot_Load(this.botsavepath); /// Extract Bot Name and User Name in settings bot_name = simlBot.Settings["Name"].Value; user_name = botUser.Settings["Name"].Value; /// Set Bot settings for robot type parameter botUser.Settings[botrobottype_variable].Value = robottype; /// Set Bot settings for language parameter botUser.Settings[botlanguage_variable].Value = language.Substring(0, 2); if (user_name == null) { user_name = string.Empty; botUser.Settings["Name"].Value = user_name; } /// If Name is not initialized in bot settings intialize it to detaut robot name if (bot_name == null || bot_name == string.Empty) { simlBot.Settings["Name"].Value = defautbotname; bot_name = defautbotname; } //Events to detect change in Bot Name and User Name // simlBot.Settings["Name"].Changed += (sender, args) => { Synbot.bot_name = simlBot.Settings["Name"].Value; }; botUser.Settings["Name"].Changed += (sender, args) => { Synbot.user_name = botUser.Settings["Name"].Value; }; }