Horizon – Diff between revs 13 and 15

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 13 Rev 15
Line 1... Line 1...
1 using Horizon.Database; 1 using Horizon.Database;
-   2 using Horizon.Searching;
-   3 using Horizon.Snapshots;
2 using Serilog; 4 using Serilog;
3 using System; 5 using System;
4 using System.Collections.Generic; 6 using System.Collections.Generic;
5 using System.Data.SQLite; 7 using System.Data.SQLite;
6 using System.Diagnostics; 8 using System.Diagnostics;
Line 29... Line 31...
29 /// <summary> 31 /// <summary>
30 /// https://stackoverflow.com/questions/7311734/split-sentence-into-words-but-having-trouble-with-the-punctuations-in-c-sharp 32 /// https://stackoverflow.com/questions/7311734/split-sentence-into-words-but-having-trouble-with-the-punctuations-in-c-sharp
31 /// </summary> 33 /// </summary>
32 private static readonly Regex _splitWordRegex = new Regex(@"((\b[^\s]+\b)((?<=\.\w).)?)", RegexOptions.Compiled); 34 private static readonly Regex _splitWordRegex = new Regex(@"((\b[^\s]+\b)((?<=\.\w).)?)", RegexOptions.Compiled);
Line 33... Line 35...
33   35  
34 public static async Task TakeSnapshot(string path, TrackedFolders.TrackedFolders trackedFolders, SnapshotDatabase snapshotDatabase, CancellationToken cancellationToken) 36 public static async Task TakeSnapshot(string path, TrackedFolders.TrackedFolders trackedFolders, SnapshotDatabase snapshotDatabase, SearchEngine searchEngine, [EnumeratorCancellation] CancellationToken cancellationToken)
35 { 37 {
36 foreach (var file in Directory.EnumerateFiles(path, "*.*", SearchOption.TopDirectoryOnly)) 38 foreach (var file in Directory.EnumerateFiles(path, "*.*", SearchOption.TopDirectoryOnly))
-   39 {
-   40 var fileName = Path.GetFileName(file);
-   41 var directory = Path.GetDirectoryName(fileName);
-   42 var color = Color.Empty;
-   43 if (trackedFolders.TryGet(directory, out var folder))
-   44 {
-   45 color = folder.Color;
-   46 }
37 { 47  
38 try 48 try
39 { -  
40 var fileName = Path.GetFileName(file); -  
41 var directory = Path.GetDirectoryName(fileName); -  
-   49 {
42 var color = Color.Empty; 50
43 if (trackedFolders.TryGet(directory, out var folder)) 51 if(await snapshotDatabase.CreateSnapshotAsync(fileName, file, color, cancellationToken) is Snapshot snapshot)
44 { 52 {
45 color = folder.Color; 53 await searchEngine.Index(snapshot, cancellationToken);
46 } -  
47   -  
48 await snapshotDatabase.CreateSnapshotAsync(fileName, file, color, cancellationToken); 54 }
49 } 55 }
50 catch (SQLiteException exception) 56 catch (SQLiteException exception)
51 { 57 {
52 if (exception.ResultCode == SQLiteErrorCode.Constraint) 58 if (exception.ResultCode == SQLiteErrorCode.Constraint)
Line 59... Line 65...
59 Log.Error(exception, $"Could not take snapshot of file: {file}"); 65 Log.Error(exception, $"Could not take snapshot of file: {file}");
60 } 66 }
61 } 67 }
62 } 68 }
Line 63... Line 69...
63   69  
64 public static async Task TakeSnapshotRecursive(string path, TrackedFolders.TrackedFolders trackedFolders, SnapshotDatabase snapshotDatabase, CancellationToken cancellationToken) 70 public static async Task TakeSnapshotRecursive(string path, TrackedFolders.TrackedFolders trackedFolders, SnapshotDatabase snapshotDatabase, SearchEngine searchEngine, [EnumeratorCancellation] CancellationToken cancellationToken)
65 { 71 {
66 foreach (var file in Directory.EnumerateFiles(path, "*.*", SearchOption.AllDirectories)) 72 foreach (var file in Directory.EnumerateFiles(path, "*.*", SearchOption.AllDirectories))
-   73 {
-   74 var fileName = Path.GetFileName(file);
-   75 var directory = Path.GetDirectoryName(fileName);
-   76 var color = Color.Empty;
-   77 if (trackedFolders.TryGet(directory, out var folder))
-   78 {
-   79 color = folder.Color;
-   80 }
67 { 81  
68 try 82 try
69 { -  
70 var fileName = Path.GetFileName(file); -  
71 var directory = Path.GetDirectoryName(fileName); -  
-   83 {
72 var color = Color.Empty; 84  
73 if (trackedFolders.TryGet(directory, out var folder)) 85 if (await snapshotDatabase.CreateSnapshotAsync(fileName, file, color, cancellationToken) is Snapshot snapshot)
74 { 86 {
75 color = folder.Color; 87 await searchEngine.Index(snapshot, cancellationToken);
76 } -  
77   -  
78 await snapshotDatabase.CreateSnapshotAsync(fileName, file, color, cancellationToken); 88 }
79 } 89 }
80 catch (SQLiteException exception) 90 catch (SQLiteException exception)
81 { 91 {
82 if (exception.ResultCode == SQLiteErrorCode.Constraint) 92 if (exception.ResultCode == SQLiteErrorCode.Constraint)