Ejemplo n.º 1
0
        /// <summary>
        /// 持久化存储知识库管理器实例
        /// </summary>
        /// <param name="konwledgeBaseManagement"></param>
        public static void saveKBM(KonwledgeBaseManagement konwledgeBaseManagement)
        {
            // 获得程序当前工作路径
            String Path = getRecordLocation();

            // 若存在则删除该XML文件
            if (File.Exists(Path + @"\KBM.xml"))
            {
                File.Delete(Path + @"\KBM.xml");
            }

            // 序列化为XML文件保存
            XMLTransformation xMLTransformation = new XMLTransformation();

            xMLTransformation.serialize(Path, "KBM", konwledgeBaseManagement);
        }
Ejemplo n.º 2
0
        public static KonwledgeBaseManagement loadKnowledgeBaseManagement()
        {
            // 知识库管理器
            KonwledgeBaseManagement konwledgeBaseManagement;

            // 获得当前工作路径
            String path = getRecordLocation();

            // 如果存在持久化存储的知识库管理器实例,则加载
            if (File.Exists(getRecordLocation() + @"\KBM.xml"))
            {
                XMLTransformation xMLTransformation = new XMLTransformation();
                konwledgeBaseManagement = xMLTransformation.deserialization(path, "KBM");
            }
            // 若不存在,则新建知识库管理器实例
            else
            {
                konwledgeBaseManagement = new KonwledgeBaseManagement();

                // 在当前工作路径下新建知识库
                // 测试名?
                KnowledgeBase kb = new KnowledgeBase(getRecordLocation() + @"\默认知识库");

                // 在当前工作路径中,添加与新建的知识库对应的文件夹
                if (!Directory.Exists(kb.getRecordLocation()))
                {
                    Directory.CreateDirectory(kb.getRecordLocation());
                }

                // 新建笔记页
                // 测试代码?
                Note note1 = new Note("默认笔记", kb.getRecordLocation());

                // 在新建知识库路径中,创建与新建的笔记页对应的富文本文件
                // 若对应文件已存在,则将其删除以便新建
                if (!File.Exists(note1.getRecordLocation()))
                {
                    File.Delete(note1.getRecordLocation());
                }
                creatFile(note1.getRecordLocation());
                kb.addNote(note1);

                // 添加新建的知识库实例到当前知识库管理器中
                konwledgeBaseManagement.addKnowledgeBase(kb);
            }
            return(konwledgeBaseManagement);
        }