diff --git a/mdfinder/DBHelper.cs b/mdfinder/DBHelper.cs
index 44c2d08..e6b030a 100644
--- a/mdfinder/DBHelper.cs
+++ b/mdfinder/DBHelper.cs
@@ -1,6 +1,7 @@
using LiteDB;
using System;
using System.Collections.Generic;
+using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Text;
@@ -9,7 +10,7 @@ using System.Threading.Tasks;
namespace mdfinder
{
/// A database helper class.
- public class DBHelper
+ public class DBHelper : PropertyChangedAlerter
{
#region Members
@@ -34,6 +35,15 @@ namespace mdfinder
}
}
+ public IEnumerable ASDF
+ {
+ get
+ {
+ return this.FileRecords.FindAll();
+ }
+ }
+
+
#endregion
#region Constructors
@@ -63,6 +73,7 @@ namespace mdfinder
public void InsertFileRecord(string path, long size, string hash, string hashProvider)
{
this.FileRecords.Insert(new FileRecord() { Path = path, Size = size, Hash = hash, HashProvider = hashProvider });
+ OnPropertyChanged("ASDF");
}
#endregion
diff --git a/mdfinder/FileRecord.cs b/mdfinder/FileRecord.cs
index d832fbd..1bcb946 100644
--- a/mdfinder/FileRecord.cs
+++ b/mdfinder/FileRecord.cs
@@ -12,7 +12,7 @@ namespace mdfinder
/// Gets or sets the identifier.
/// The identifier.
- public uint Id { get; set; }
+ public Int64 Id { get; set; }
/// Gets or sets the full pathname of the file.
/// The full pathname of the file.
diff --git a/mdfinder/MainWindow.xaml b/mdfinder/MainWindow.xaml
index 2ab37cd..7fd890d 100644
--- a/mdfinder/MainWindow.xaml
+++ b/mdfinder/MainWindow.xaml
@@ -69,7 +69,7 @@
-
+
diff --git a/mdfinder/MainWindow.xaml.cs b/mdfinder/MainWindow.xaml.cs
index cba95e0..7599019 100644
--- a/mdfinder/MainWindow.xaml.cs
+++ b/mdfinder/MainWindow.xaml.cs
@@ -39,7 +39,13 @@ namespace mdfinder
this.Scanner = new Scanner();
this.Scanner.DirectoryFound += (sender, args) => Dispatcher.Invoke(() => txtScanLocation.Text = args.Directory.Name);
- //this.Scanner.FilesFound += (sender, args) => args.Files;
+ this.Scanner.FilesFound += (sender, args) =>
+ {
+ foreach(var file in args.Files)
+ {
+ this.Database.InsertFileRecord(file.FullName, file.Length, Guid.NewGuid().ToString(), "test");
+ }
+ };
this.Scanner.ReportProgress += (sender, args) => Dispatcher.Invoke(() => { if (args.Processed > 0) { this.progressBar.Value = args.Percentage * 100; } });
InitializeComponent();
diff --git a/mdfinder/PropertyChangedAlerter.cs b/mdfinder/PropertyChangedAlerter.cs
new file mode 100644
index 0000000..d73e2a5
--- /dev/null
+++ b/mdfinder/PropertyChangedAlerter.cs
@@ -0,0 +1,89 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Runtime.CompilerServices;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace mdfinder
+{
+ /// A class responsible for implementing the interface and helper functions.
+ public abstract class PropertyChangedAlerter : INotifyPropertyChanged
+ {
+ #region Members
+
+ /// Occurs when a property value changes.
+ public event PropertyChangedEventHandler PropertyChanged;
+ /// A list of properties to always call as updated. Generally used for composite properties.
+ private List alwaysCall = new List();
+
+ #endregion
+
+ #region Properties
+
+ //
+
+ #endregion
+
+ #region Methods
+
+ ///
+ /// Executes the property changed action. This alerts subscribers to its change in value.
+ ///
+ /// (Optional) The name of the property.
+ ///
+ /// This will automatically pass in "SomeProperty" as the property name, derived useing the
+ /// attribute.
+ ///
+ /// public bool SomeProperty
+ /// {
+ /// get
+ /// {
+ /// return this.someProperty;
+ /// }
+ /// set
+ /// {
+ /// this.someProperty = value;
+ /// OnPropertyChanged();
+ /// }
+ /// }
+ ///
+ ///
+ protected virtual void OnPropertyChanged([CallerMemberName]string name = null)
+ {
+ if (!string.IsNullOrWhiteSpace(name))
+ {
+ this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
+ foreach (var updatedProperty in this.alwaysCall)
+ {
+ this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(updatedProperty));
+ }
+ }
+ }
+
+ /// Executes when all properties are changed and should be updated.
+ protected virtual void OnAllPropertiesChanged()
+ {
+ this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(string.Empty));
+ }
+
+ /// Adds a property that will always be called when any property is updated..
+ /// The name of the property.
+ public void AddConstantCallProperty(string name)
+ {
+ if (this.alwaysCall == null)
+ {
+ // This item has been deserialized and the list needs to be reinitialized.
+ this.alwaysCall = new List();
+ }
+
+ if (!this.alwaysCall.Any(c => c.Equals(name, StringComparison.OrdinalIgnoreCase)))
+ {
+ this.alwaysCall.Add(name);
+ }
+ }
+
+ #endregion
+ }
+}
diff --git a/mdfinder/Scanner.cs b/mdfinder/Scanner.cs
index ecf479a..2f654f6 100644
--- a/mdfinder/Scanner.cs
+++ b/mdfinder/Scanner.cs
@@ -43,24 +43,37 @@ namespace mdfinder
var scanPath = new DirectoryInfo(path);
if (scanPath.Exists)
{
+ Discover(scanPath);
Scan(scanPath);
}
}
+
+ private void Discover(DirectoryInfo directory)
+ {
+ try
+ {
+ this.Total += (uint)directory.EnumerateFiles().Count();
+ foreach (var subdirectory in directory.GetDirectories())
+ {
+ OnDirectoryFound(subdirectory);
+ Discover(subdirectory);
+ }
+ }
+ catch (UnauthorizedAccessException unauthorizedAccessException)
+ {
+ //Ignore and just continue.
+ }
+ }
private void Scan(DirectoryInfo directory)
{
try
{
- var files = directory.GetFiles();
- var fileBatches = files.Bin(Properties.Settings.Default.FilesFoundAlert);
+ var fileBatches = directory.EnumerateFiles().Bin(Properties.Settings.Default.FilesFoundAlert);
var subdirectories = directory.GetDirectories();
- this.Total += (uint)files.Count();
-
foreach (var subdirectory in subdirectories)
{
- OnDirectoryFound(subdirectory);
-
Scan(subdirectory);
}
diff --git a/mdfinder/mdfinder.csproj b/mdfinder/mdfinder.csproj
index 73f54f2..8989580 100644
--- a/mdfinder/mdfinder.csproj
+++ b/mdfinder/mdfinder.csproj
@@ -91,6 +91,7 @@
+
True