Horizon – Diff between revs 1 and 5
?pathlinks?
Rev 1 | Rev 5 | |||
---|---|---|---|---|
Line 8... | Line 8... | |||
8 | using System.Linq; |
8 | using System.Linq; |
|
9 | using System.Net; |
9 | using System.Net; |
|
10 | using System.Reflection; |
10 | using System.Reflection; |
|
11 | using System.Threading; |
11 | using System.Threading; |
|
12 | using System.Threading.Tasks; |
12 | using System.Threading.Tasks; |
|
- | 13 | using System.Threading.Tasks.Dataflow; |
||
13 | using System.Windows.Forms; |
14 | using System.Windows.Forms; |
|
- | 15 | using System.Windows.Shapes; |
||
14 | using Horizon.Database; |
16 | using Horizon.Database; |
|
15 | using Horizon.Snapshots; |
17 | using Horizon.Snapshots; |
|
16 | using Horizon.Utilities; |
18 | using Horizon.Utilities; |
|
17 | using Horizon.Utilities.Serialization; |
19 | using Horizon.Utilities.Serialization; |
|
18 | using NetSparkleUpdater; |
20 | using NetSparkleUpdater; |
|
Line 20... | Line 22... | |||
20 | using NetSparkleUpdater.SignatureVerifiers; |
22 | using NetSparkleUpdater.SignatureVerifiers; |
|
21 | using NetSparkleUpdater.UI.WinForms; |
23 | using NetSparkleUpdater.UI.WinForms; |
|
22 | using Serilog; |
24 | using Serilog; |
|
23 | using TrackedFolders; |
25 | using TrackedFolders; |
|
24 | using CaptureMode = Configuration.CaptureMode; |
26 | using CaptureMode = Configuration.CaptureMode; |
|
- | 27 | using Path = System.IO.Path; |
||
Line 25... | Line 28... | |||
25 | |
28 | |
|
26 | namespace Horizon |
29 | namespace Horizon |
|
27 | { |
30 | { |
|
28 | public partial class MainForm : Form |
31 | public partial class MainForm : Form |
|
Line 86... | Line 89... | |||
86 | .WriteTo.Conditional(condition => MemorySinkEnabled, configureSink => configureSink.Sink(_memorySink)) |
89 | .WriteTo.Conditional(condition => MemorySinkEnabled, configureSink => configureSink.Sink(_memorySink)) |
|
87 | .WriteTo.File(Path.Combine(Constants.UserApplicationDirectory, "Logs", $"{Constants.AssemblyName}.log"), |
90 | .WriteTo.File(Path.Combine(Constants.UserApplicationDirectory, "Logs", $"{Constants.AssemblyName}.log"), |
|
88 | rollingInterval: RollingInterval.Day) |
91 | rollingInterval: RollingInterval.Day) |
|
89 | .CreateLogger(); |
92 | .CreateLogger(); |
|
Line 90... | Line 93... | |||
90 | |
93 | |
|
91 | _snapshotDatabase = new SnapshotDatabase(); |
94 | _snapshotDatabase = new SnapshotDatabase(_cancellationToken); |
|
92 | _snapshotDatabase.SnapshotRevert += SnapshotDatabase_SnapshotRevert; |
95 | _snapshotDatabase.SnapshotRevert += SnapshotDatabase_SnapshotRevert; |
|
Line 93... | Line 96... | |||
93 | _snapshotDatabase.SnapshotCreate += SnapshotDatabase_SnapshotCreate; |
96 | _snapshotDatabase.SnapshotCreate += SnapshotDatabase_SnapshotCreate; |
|
94 | |
97 | |
|
Line 406... | Line 409... | |||
406 | color = folder.Color; |
409 | color = folder.Color; |
|
407 | } |
410 | } |
|
Line 408... | Line 411... | |||
408 | |
411 | |
|
409 | if (_changedFiles.Contains(e.FullPath)) |
412 | if (_changedFiles.Contains(e.FullPath)) |
|
410 | { |
413 | { |
|
411 | _changedFilesContinuation.Schedule(delay, () => TakeSnapshots(color), _cancellationToken); |
414 | _changedFilesContinuation.Schedule(delay, async () => await TakeSnapshots(color, _cancellationToken), _cancellationToken); |
|
412 | return; |
415 | return; |
|
Line 413... | Line 416... | |||
413 | } |
416 | } |
|
Line 414... | Line 417... | |||
414 | |
417 | |
|
415 | _changedFiles.Add(e.FullPath); |
418 | _changedFiles.Add(e.FullPath); |
|
416 | |
419 | |
|
417 | _changedFilesContinuation.Schedule(delay, () => TakeSnapshots(color), _cancellationToken); |
420 | _changedFilesContinuation.Schedule(delay, async () => await TakeSnapshots(color, _cancellationToken), _cancellationToken); |
|
418 | } |
421 | } |
|
419 | catch (Exception exception) |
422 | catch (Exception exception) |
|
Line 730... | Line 733... | |||
730 | |
733 | |
|
731 | break; |
734 | break; |
|
732 | } |
735 | } |
|
Line 733... | Line 736... | |||
733 | } |
736 | } |
|
734 | |
737 | |
|
735 | private async void TakeSnapshots(Color color) |
738 | private async Task TakeSnapshots(Color color, CancellationToken cancellationToken) |
|
736 | { |
739 | { |
|
737 | await _changedFilesLock.WaitAsync(_cancellationToken); |
740 | var bufferBlock = new BufferBlock<string>(new DataflowBlockOptions() {CancellationToken = cancellationToken}); |
|
- | 741 | var actionBlock = new ActionBlock<string>(async path => |
||
738 | try |
742 | { |
|
739 | { |
743 | // In case files have vanished strictly due to the time specified by the tracked folders delay. |
|
740 | foreach (var path in _changedFiles) |
- | ||
741 | { |
- | ||
742 | // In case files have vanished strictly due to the time specified by the tracked folders delay. |
- | ||
743 | if (!File.Exists(path)) |
744 | if (!File.Exists(path)) |
|
Line 744... | Line 745... | |||
744 | { |
745 | { |
|
745 | Log.Warning("File vanished after tracked folder delay.", path); |
746 | Log.Warning("File vanished after tracked folder delay.", path); |
|
Line 746... | Line 747... | |||
746 | |
747 | |
|
747 | continue; |
748 | return; |
|
748 | } |
749 | } |
|
749 | |
750 | |
|
Line 750... | Line 751... | |||
750 | try |
751 | try |
|
751 | { |
752 | { |
|
752 | var fileName = Path.GetFileName(path); |
753 | var fileName = System.IO.Path.GetFileName(path); |
|
753 | var screenCapture = ScreenCapture.Capture((Utilities.CaptureMode)Configuration.CaptureMode); |
754 | var screenCapture = ScreenCapture.Capture((Utilities.CaptureMode)Configuration.CaptureMode); |
|
- | 755 | |
||
- | 756 | await _snapshotDatabase.CreateSnapshot(fileName, path, screenCapture, color, |
||
754 | |
757 | _cancellationToken); |
|
755 | await _snapshotDatabase.CreateSnapshot(fileName, path, screenCapture, color, |
- | ||
756 | _cancellationToken); |
- | ||
757 | } |
758 | } |
|
758 | catch (SQLiteException exception) |
- | ||
759 | { |
759 | catch (SQLiteException exception) |
|
- | 760 | { |
||
760 | if (exception.ResultCode == SQLiteErrorCode.Constraint) |
761 | if (exception.ResultCode == SQLiteErrorCode.Constraint) |
|
- | 762 | { |
||
- | 763 | Log.Information(exception, "Snapshot already exists."); |
||
- | 764 | } |
||
- | 765 | } |
||
- | 766 | catch (Exception exception) |
||
- | 767 | { |
||
- | 768 | Log.Error(exception, "Could not take snapshot.", path); |
||
- | 769 | } |
||
- | 770 | }); |
||
- | 771 | |
||
- | 772 | using (var snapshotLink = |
||
- | 773 | bufferBlock.LinkTo(actionBlock, new DataflowLinkOptions() { PropagateCompletion = true })) |
||
761 | { |
774 | { |
|
762 | Log.Information(exception, "Snapshot already exists."); |
775 | await _changedFilesLock.WaitAsync(_cancellationToken); |
|
763 | } |
776 | try |
|
- | 777 | { |
||
- | 778 | foreach (var path in _changedFiles) |
||
- | 779 | { |
||
- | 780 | await bufferBlock.SendAsync(path, cancellationToken); |
||
- | 781 | } |
||
- | 782 | bufferBlock.Complete(); |
||
- | 783 | await bufferBlock.Completion; |
||
- | 784 | } |
||
- | 785 | catch (Exception exception) |
||
- | 786 | { |
||
- | 787 | Log.Error(exception, "Could not take snapshots."); |
||
764 | } |
788 | } |
|
765 | catch (Exception exception) |
- | ||
766 | { |
- | ||
767 | Log.Error(exception, "Could not take snapshot.", path); |
- | ||
768 | } |
- | ||
769 | } |
- | ||
770 | } |
- | ||
771 | catch (Exception exception) |
- | ||
772 | { |
- | ||
773 | Log.Error(exception, "Could not take snapshots."); |
- | ||
774 | } |
789 | finally |
|
775 | finally |
790 | { |
|
Line 776... | Line 791... | |||
776 | { |
791 | _changedFiles.Clear(); |
|
777 | _changedFiles.Clear(); |
792 | _changedFilesLock.Release(); |