Horizon – Diff between revs 1 and 5

Subversion Repositories:
Rev:
Show entire fileRegard whitespace
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 { -  
737 await _changedFilesLock.WaitAsync(_cancellationToken); -  
738 try 739 {
739 { 740 var bufferBlock = new BufferBlock<string>(new DataflowBlockOptions() {CancellationToken = cancellationToken});
740 foreach (var path in _changedFiles) 741 var actionBlock = new ActionBlock<string>(async path =>
741 { 742 {
742 // In case files have vanished strictly due to the time specified by the tracked folders delay. 743 // 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);
Line 764... Line 765...
764 } 765 }
765 catch (Exception exception) 766 catch (Exception exception)
766 { 767 {
767 Log.Error(exception, "Could not take snapshot.", path); 768 Log.Error(exception, "Could not take snapshot.", path);
768 } 769 }
-   770 });
-   771  
-   772 using (var snapshotLink =
-   773 bufferBlock.LinkTo(actionBlock, new DataflowLinkOptions() { PropagateCompletion = true }))
-   774 {
-   775 await _changedFilesLock.WaitAsync(_cancellationToken);
-   776 try
-   777 {
-   778 foreach (var path in _changedFiles)
-   779 {
-   780 await bufferBlock.SendAsync(path, cancellationToken);
769 } 781 }
-   782 bufferBlock.Complete();
-   783 await bufferBlock.Completion;
770 } 784 }
771 catch (Exception exception) 785 catch (Exception exception)
772 { 786 {
773 Log.Error(exception, "Could not take snapshots."); 787 Log.Error(exception, "Could not take snapshots.");
774 } 788 }
Line 776... Line 790...
776 { 790 {
777 _changedFiles.Clear(); 791 _changedFiles.Clear();
778 _changedFilesLock.Release(); 792 _changedFilesLock.Release();
779 } 793 }
780 } 794 }
-   795 }
Line 781... Line 796...
781   796  
782 #endregion 797 #endregion
783 } 798 }
784 } 799 }