Exemple #1
0
        /// <summary>
        /// 构造函数。词典的集合。
        /// </summary>
        /// <param name="dirPath">词典所在的目录</param>
        /// <param name="type">词典的类型</param>
        private JDictionaryCollection(string dirPath, JDictionaryTypeEnum type)
        {
            string path = Path.GetFullPath(dirPath);

            string[] files = Directory.GetFiles(path, "*." + type.ToString(), SearchOption.TopDirectoryOnly);
            foreach (var item in files)
            {
                this.List.Add(item);
            }
        }
 public void Load(JDictionaryTypeEnum type, string indexFile)
 {
     this.JDictionaryType = type;
     this.InnerDocument   = new XmlDocument();
     this.DictFiles       = new Dictionary <string, FileInfo>();
     if (!File.Exists(indexFile))
     {
         XmlTextWriter writer = new XmlTextWriter(indexFile, Encoding.UTF8);
         writer.WriteStartDocument();
         writer.WriteStartElement("dictfiles");
         writer.WriteAttributeString("createdtime", DateTime.Now.ToString());
         writer.WriteAttributeString("version", "0");
         writer.WriteEndElement();
         writer.Flush();
         writer.Close();
     }
     File.SetAttributes(indexFile, FileAttributes.Normal);
     this.IndexFile = new FileInfo(indexFile);
     this.InnerDocument.Load(indexFile);
     this.SetDictFiles();
 }
Exemple #3
0
 /// <summary>
 /// 词典集合创建器
 /// </summary>
 /// <param name="dirPath">词典所在的目录</param>
 /// <param name="type">词典的类型</param>
 internal static JDictionaryCollection Creator(string dirPath, JDictionaryTypeEnum type)
 {
     Debug.Assert(Directory.Exists(dirPath), dirPath + " isn't Exists!");
     return(new JDictionaryCollection(dirPath, type));
 }