public CompiledKnowledgeBase AddCompiledKnowledgeBase(string stPath) { CompiledKnowledgeBase ckb = LoadCompiledKnowledgeBase(stPath); this.addOrReplaceCompiledKnowlegeBase(stPath, ckb); return(ckb); }
public void ReloadKnowledgeBase(KnowledgeBase kb, KnowledgeBaseItem knowledgeBaseItem) { CompiledKnowledgeBase ckb = this.LoadKnowledgeBase(kb, knowledgeBaseItem); string stPath = knowledgeBaseItem.Fullpath + knowledgeBaseItem.Filename; this.addOrReplaceCompiledKnowlegeBase(stPath, ckb); }
public void SaveCompiledKnowledgeBase(CompiledKnowledgeBase ckb, string stPath) { BinaryFormatter bf = new BinaryFormatter(); FileStream fs = new FileStream(stPath, FileMode.Create); bf.Serialize(fs, ckb); fs.Close(); }
public void SaveEncryptedCompiledKnowledgeBase(CompiledKnowledgeBase ckb, string stPath) { BinaryFormatter bf = new BinaryFormatter(); FileStream fs = new FileStream(stPath, FileMode.Create); CryptoStream csEncrypt = new CryptoStream(fs, this.encryptor, CryptoStreamMode.Write); bf.Serialize(csEncrypt, ckb); csEncrypt.FlushFinalBlock(); fs.Flush(); fs.Close(); }
public CompiledKnowledgeBase LoadKnowledgeBase(KnowledgeBase kb, KnowledgeBaseItem knowledgeBaseItem) { CompiledKnowledgeBase ckb = new CompiledKnowledgeBase(); ckb.Build = kb.Build; ckb.Name = knowledgeBaseItem.Fullpath + knowledgeBaseItem.Filename; ckb.OnRuleCompiled += new CompiledKnowledgeBase.RuleCompiled(this.compiledKnowledgeBase_OnRuleCompiled); ckb.OnRuleCompileFailed += new CompiledKnowledgeBase.RuleCompileFailed(this.compiledKnowledgeBase_OnRuleCompileFailed); ckb.OnCompileError += new Conversive.DevBot5.CompiledKnowledgeBase.CompileError(ckb_OnCompileError); ckb.OnCompileWarning += new Conversive.DevBot5.CompiledKnowledgeBase.CompileWarning(ckb_OnCompileWarning); ckb.LoadKnowledgeBase(kb, knowledgeBaseItem); return(ckb); }
private void addOrReplaceCompiledKnowlegeBase(string stPath, CompiledKnowledgeBase ckb) { if (ckb != null) { if (!compiledKnowledgeBases.ContainsKey(stPath)) { this.compiledKnowledgeBases.Add(stPath, ckb); } else { this.compiledKnowledgeBases[stPath] = ckb; } } }
public CompiledKnowledgeBase LoadCompiledKnowledgeBase(string stPath) { BinaryFormatter bf = new BinaryFormatter(); Stream fs = Stream.Null; CompiledKnowledgeBase ckb = null; try { fs = new FileStream(stPath, FileMode.Open, FileAccess.Read); ckb = (CompiledKnowledgeBase)bf.Deserialize(fs); ckb.AddConditionsAndCode(); } catch (Exception eOpenOrDeserial) { bool bErrorHandled = false; string openOrSerserialError = eOpenOrDeserial.ToString(); try//to open an encrypted CKB { if (fs != FileStream.Null) { fs.Seek(0, SeekOrigin.Begin); } CryptoStream csDecrypt = new CryptoStream(fs, this.decryptor, CryptoStreamMode.Read); ckb = (CompiledKnowledgeBase)bf.Deserialize(csDecrypt); ckb.AddConditionsAndCode(); bErrorHandled = true; } catch (Exception e) { string str = e.ToString(); } if (!bErrorHandled) { if (this.OnKnowledgeBaseLoadError != null) { this.OnKnowledgeBaseLoadError(eOpenOrDeserial, stPath); } } } finally { if (fs != null && fs != FileStream.Null) { fs.Close(); } } return(ckb); } //LoadCompiledKnowledgeBase(string stPath)
public Reply GetReply(string input, State state) { logger.LogMessage("GetReply"); state.Vars["_input"] = input; state.Vars["_lastinput"] = state.Lastinput; state.Vars["_lastfired"] = state.Lastfired; state.Vars["_time"] = DateTime.Now.ToString("h:mm tt"); state.Vars["_time24"] = DateTime.Now.ToString("HH:mm"); state.Vars["_date"] = DateTime.Now.ToString("MMM. d, yyyy"); state.Vars["_month"] = DateTime.Now.ToString("MMMM"); state.Vars["_dayofmonth"] = DateTime.Now.ToString("d ").Trim(); state.Vars["_year"] = DateTime.Now.ToString("yyyy"); state.Vars["_dayofweek"] = DateTime.Now.ToString("dddd"); if (input.Length == 0) { input = "_blank"; } state.Lastinput = input; bool standardNoRuleFiredDefined = false; Reply noRuleFiredReply = new Reply("", "", "", "", 0.0, null); foreach (string stPath in state.CurrentKBs) { if (this.compiledKnowledgeBases.ContainsKey(stPath)) { logger.LogMessage("compiledKnowledgeBases(" + stPath + ")"); CompiledKnowledgeBase ckb = (CompiledKnowledgeBase)this.compiledKnowledgeBases[stPath]; string ckbOutput = ckb.CSToolbox.ExecuteOnBeforeRuleFired(state); //update our input var incase the Before Rule Fired changes it input = (string)state.Vars["_input"]; state.Lastinput = input; Reply reply = ckb.GetReply(input, state.Lastfired, state.Vars, ckbOutput); if (reply != null) { logger.LogMessage("reply != null"); ckbOutput = ckb.CSToolbox.ExecuteOnAfterRuleFired(state, reply); string outputText = ckb.DoTextReplacements(ckbOutput); string agentText = ckb.DoAgentTextReplacements(ckbOutput); reply.Text += outputText; reply.AgentText += agentText; state.Lastfired = reply.RuleId; state.Vars["_lastoutput"] = reply.Text; return(reply); } if (ckb.CSToolbox.StandardNoRuleFiredDefined) { logger.LogMessage("ckb.CSToolbox.StandardNoRuleFiredDefined"); standardNoRuleFiredDefined = true; //if this ckb has a no rule fired handler, fire it noRuleFiredReply.KBItem = ckb.KnowledgeBaseItem; string noReplyText = ckb.CSToolbox.ExecuteOnNoRuleFired(state, noRuleFiredReply); noRuleFiredReply.Text += ckb.DoTextReplacements(noReplyText); noRuleFiredReply.AgentText += ckb.DoAgentTextReplacements(noReplyText); } } } if (standardNoRuleFiredDefined) { return(noRuleFiredReply); } return(null); //if there's no reply, return null } //GetReply(string input)
public void RemoveCompiledKnowledgeBase(CompiledKnowledgeBase ckb) { string stPath = ckb.KnowledgeBaseItem.Fullpath + ckb.KnowledgeBaseItem.Filename; this.RemoveCompiledKnowledgeBase(stPath); }
public void AddOrReplaceCompiledKnowlegeBase(string stPath, CompiledKnowledgeBase ckb) { this.addOrReplaceCompiledKnowlegeBase(stPath, ckb); }