Beispiel #1
0
 private void UpdateIndex(DirectoryInfo dir)
 {
     try
     {
         Notify(new StatusEventArgs("重建目录索引 {0} ...", new object[] { dir.FullName }));
         FileInfo[]     files          = GetFiles(dir);
         FileCollection fileCollection = FileCollection.Load(dir);
         foreach (FileInfo fi in files)
         {
             FileItem fileItem1 = fileCollection.GetItem(fi.Name);
             if (fileItem1 == null)
             {
                 Notify(new StatusEventArgs("读取文件: {0}", fi.FullName));
                 FileItem fileItem2 = FileItem.Load(fi);
                 if (fileItem2 != null)
                 {
                     fileCollection.AddItem(fileItem2);
                 }
             }
             else if (fileItem1.IsChanged(fi))
             {
                 Notify(new StatusEventArgs("读取文件: {0}", fi.FullName));
                 FileItem updateItem = FileItem.Load(fi);
                 if (updateItem != null)
                 {
                     fileCollection.UpdateItem(updateItem);
                 }
             }
         }
         foreach (FileItem fileItem in fileCollection.Where(it => FileNotExist(files, it)).ToArray())
         {
             fileCollection.RemoveItem(fileItem);
         }
         if (fileCollection.IsChanged)
         {
             fileCollection.Save(dir);
         }
         Interlocked.Add(ref _processFiles, files.Length);
         Notify(new ProgressEventArgs(_processFiles, _totalFiles));
     }
     catch (Exception exp)
     {
         Console.WriteLine(exp.Message);
     }
 }