-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIndexCleaner.cs
57 lines (52 loc) · 1.61 KB
/
IndexCleaner.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;
namespace CdrIndexer
{
public class IndexCleaner
{
private Action onEntryProcessed;
private Func<bool> cancellationRequested;
private Action<string> log;
public IndexCleaner(
Action onEntryProcessed,
Func<bool> cancellationRequested,
Action<string> log)
{
this.onEntryProcessed = onEntryProcessed;
this.cancellationRequested = cancellationRequested;
this.log = log;
}
public void Run()
{
int deletedCount = 0;
int presentCount = 0;
this.log("Cleanup...\r\n. - file present\r\n- - file missing (delete)\r\n");
foreach (string path in LuceneStore.Current.AllPaths())
{
if (this.cancellationRequested())
{
this.log("\r\nTerminating\r\n");
break;
}
if (File.Exists(path))
{
this.log(".");
presentCount++;
}
else
{
this.log("-");
deletedCount++;
LuceneStore.Current.Delete(path);
}
this.onEntryProcessed();
}
LuceneStore.Current.ReopenDirectory();
this.log(string.Format(
"\r\nFinished: {0} files present, {1} removed from index.\r\n",
presentCount, deletedCount));
}
}
}