示例#1
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)