Ejemplo n.º 1
0
        public CompiledKnowledgeBase AddCompiledKnowledgeBase(string stPath)
        {
            CompiledKnowledgeBase ckb = LoadCompiledKnowledgeBase(stPath);

            this.addOrReplaceCompiledKnowlegeBase(stPath, ckb);
            return(ckb);
        }
Ejemplo n.º 2
0
        public void ReloadKnowledgeBase(KnowledgeBase kb, KnowledgeBaseItem knowledgeBaseItem)
        {
            CompiledKnowledgeBase ckb = this.LoadKnowledgeBase(kb, knowledgeBaseItem);
            string stPath             = knowledgeBaseItem.Fullpath + knowledgeBaseItem.Filename;

            this.addOrReplaceCompiledKnowlegeBase(stPath, ckb);
        }
Ejemplo n.º 3
0
        public void SaveCompiledKnowledgeBase(CompiledKnowledgeBase ckb, string stPath)
        {
            BinaryFormatter bf = new BinaryFormatter();
            FileStream      fs = new FileStream(stPath, FileMode.Create);

            bf.Serialize(fs, ckb);
            fs.Close();
        }
Ejemplo n.º 4
0
        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();
        }
Ejemplo n.º 5
0
        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.Verbot5.CompiledKnowledgeBase.CompileError(ckb_OnCompileError);
            ckb.OnCompileWarning    += new Conversive.Verbot5.CompiledKnowledgeBase.CompileWarning(ckb_OnCompileWarning);
            ckb.LoadKnowledgeBase(kb, knowledgeBaseItem);
            return(ckb);
        }
Ejemplo n.º 6
0
 private void addOrReplaceCompiledKnowlegeBase(string stPath, CompiledKnowledgeBase ckb)
 {
     if (ckb != null)
     {
         if (!compiledKnowledgeBases.ContainsKey(stPath))
         {
             this.compiledKnowledgeBases.Add(stPath, ckb);
         }
         else
         {
             this.compiledKnowledgeBases[stPath] = ckb;
         }
     }
 }
Ejemplo n.º 7
0
        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)
Ejemplo n.º 8
0
 private void addOrReplaceCompiledKnowlegeBase(string stPath, CompiledKnowledgeBase ckb)
 {
     if (ckb != null)
     {
         if (!compiledKnowledgeBases.ContainsKey(stPath))
         {
             this.compiledKnowledgeBases.Add(stPath, ckb);
         }
         else
         {
             this.compiledKnowledgeBases[stPath] = ckb;
         }
     }
 }
Ejemplo n.º 9
0
 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();
 }
Ejemplo n.º 10
0
 public void SaveCompiledKnowledgeBase(CompiledKnowledgeBase ckb, string stPath)
 {
     BinaryFormatter bf = new BinaryFormatter();
     FileStream fs = new FileStream(stPath, FileMode.Create);
     bf.Serialize(fs, ckb);
     fs.Close();
 }
Ejemplo n.º 11
0
 public void RemoveCompiledKnowledgeBase(CompiledKnowledgeBase ckb)
 {
     string stPath = ckb.KnowledgeBaseItem.Fullpath+ckb.KnowledgeBaseItem.Filename;
     this.RemoveCompiledKnowledgeBase(stPath);
 }
Ejemplo n.º 12
0
 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.Verbot5.CompiledKnowledgeBase.CompileError(ckb_OnCompileError);
     ckb.OnCompileWarning += new Conversive.Verbot5.CompiledKnowledgeBase.CompileWarning(ckb_OnCompileWarning);
     ckb.LoadKnowledgeBase(kb, knowledgeBaseItem);
     return ckb;
 }
Ejemplo n.º 13
0
 public void AddOrReplaceCompiledKnowlegeBase(string stPath, CompiledKnowledgeBase ckb)
 {
     this.addOrReplaceCompiledKnowlegeBase(stPath, ckb);
 }
Ejemplo n.º 14
0
        public Reply GetReply(string input, State state)
        {
            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))
                {
                    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)
                    {
                        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)
                    {
                        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)
Ejemplo n.º 15
0
        public void RemoveCompiledKnowledgeBase(CompiledKnowledgeBase ckb)
        {
            string stPath = ckb.KnowledgeBaseItem.Fullpath + ckb.KnowledgeBaseItem.Filename;

            this.RemoveCompiledKnowledgeBase(stPath);
        }
Ejemplo n.º 16
0
 public void AddOrReplaceCompiledKnowlegeBase(string stPath, CompiledKnowledgeBase ckb)
 {
     this.addOrReplaceCompiledKnowlegeBase(stPath, ckb);
 }