public void SaveCompiledKnowledgeBase(CompiledKnowledgeBase ckb, string stPath) { var bf = new BinaryFormatter(); var fs = new FileStream(stPath, FileMode.Create); bf.Serialize(fs, ckb); fs.Close(); }
public void SaveEncryptedCompiledKnowledgeBase(CompiledKnowledgeBase ckb, string stPath) { var bf = new BinaryFormatter(); var fs = new FileStream(stPath, FileMode.Create); var 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) { var ckb = new CompiledKnowledgeBase { Build = kb.Build, Name = knowledgeBaseItem.Fullpath + knowledgeBaseItem.Filename }; ckb.KbList.Add(kb); ckb.OnRuleCompiled += this.compiledKnowledgeBase_OnRuleCompiled; ckb.OnRuleCompileFailed += this.compiledKnowledgeBase_OnRuleCompileFailed; ckb.OnCompileError += ckb_OnCompileError; ckb.OnCompileWarning += ckb_OnCompileWarning; ckb.LoadKnowledgeBase(kb, knowledgeBaseItem); return(ckb); }
public CompiledKnowledgeBase LoadCompiledKnowledgeBase(string stPath) { var bf = new BinaryFormatter(); var fs = Stream.Null; CompiledKnowledgeBase ckb = null; try { fs = new FileStream(stPath, FileMode.Open, FileAccess.Read); ckb = (CompiledKnowledgeBase)bf.Deserialize(fs); ckb.AddConditionsAndCode(); fs.Close(); } catch (Exception eOpenOrDeserial) { // ReSharper disable once UnusedVariable //TODO: use or discard method var openOrSerserialError = eOpenOrDeserial.ToString(); try //to open an encrypted CKB { if (fs != Stream.Null) { fs.Seek(0, SeekOrigin.Begin); } var csDecrypt = new CryptoStream(fs, this._decryptor, CryptoStreamMode.Read); ckb = (CompiledKnowledgeBase)bf.Deserialize(csDecrypt); ckb.AddConditionsAndCode(); } catch (Exception e) { // ReSharper disable once UnusedVariable //TODO: use or remove var var str = e.ToString(); } } return(ckb); } //LoadCompiledKnowledgeBase(string stPath)
public void RemoveCompiledKnowledgeBase(CompiledKnowledgeBase ckb) { var stPath = ckb.KnowledgeBaseItem.Fullpath + ckb.KnowledgeBaseItem.Filename; this.RemoveCompiledKnowledgeBase(stPath); }