Periodic Checkin

Got the application scanning and displaying results.
This commit is contained in:
Jordan Wages 2019-02-17 21:17:05 -06:00
parent c0afde943e
commit f81e4f13da
7 changed files with 130 additions and 10 deletions

View File

@ -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
{
/// <summary> A database helper class. </summary>
public class DBHelper
public class DBHelper : PropertyChangedAlerter
{
#region Members
@ -34,6 +35,15 @@ namespace mdfinder
}
}
public IEnumerable<FileRecord> 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

View File

@ -12,7 +12,7 @@ namespace mdfinder
/// <summary> Gets or sets the identifier. </summary>
/// <value> The identifier. </value>
public uint Id { get; set; }
public Int64 Id { get; set; }
/// <summary> Gets or sets the full pathname of the file. </summary>
/// <value> The full pathname of the file. </value>

View File

@ -69,7 +69,7 @@
</Button>
</Grid>
</GroupBox>
<DataGrid Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="3" ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type mdfinder:MainWindow}} }" />
<DataGrid Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="3" ItemsSource="{Binding Database.ASDF, Mode=OneWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type mdfinder:MainWindow}}}" />
<ProgressBar Grid.Row="3" Grid.ColumnSpan="4" Name="progressBar" Minimum="0" Height="16"/>
</Grid>
</DockPanel>

View File

@ -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();

View File

@ -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
{
/// <summary> A class responsible for implementing the <see cref="INotifyPropertyChanged"/> interface and helper functions. </summary>
public abstract class PropertyChangedAlerter : INotifyPropertyChanged
{
#region Members
/// <summary> Occurs when a property value changes. </summary>
public event PropertyChangedEventHandler PropertyChanged;
/// <summary> A list of properties to always call as updated. Generally used for composite properties. </summary>
private List<string> alwaysCall = new List<string>();
#endregion
#region Properties
//
#endregion
#region Methods
/// <summary>
/// Executes the property changed action. This alerts subscribers to its change in value.
/// </summary>
/// <param name="name"> (Optional) The name of the property. </param>
/// <example>
/// This will automatically pass in "SomeProperty" as the property name, derived useing the
/// <see cref="CallerMemberNameAttribute" /> attribute.
/// <code lang="cs" title="Automatic Property Detection">
/// public bool SomeProperty
/// {
/// get
/// {
/// return this.someProperty;
/// }
/// set
/// {
/// this.someProperty = value;
/// OnPropertyChanged();
/// }
/// }
/// </code>
/// </example>
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));
}
}
}
/// <summary> Executes when all properties are changed and should be updated. </summary>
protected virtual void OnAllPropertiesChanged()
{
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(string.Empty));
}
/// <summary> Adds a property that will always be called when any property is updated.. </summary>
/// <param name="name"> The name of the property. </param>
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<string>();
}
if (!this.alwaysCall.Any(c => c.Equals(name, StringComparison.OrdinalIgnoreCase)))
{
this.alwaysCall.Add(name);
}
}
#endregion
}
}

View File

@ -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);
}

View File

@ -91,6 +91,7 @@
<Compile Include="FileRecord.cs" />
<Compile Include="InverseBoolConverter.cs" />
<Compile Include="InverseBoolVisibilityConverter.cs" />
<Compile Include="PropertyChangedAlerter.cs" />
<Compile Include="Scanner.cs" />
<Compile Include="Localization\Localization.Designer.cs">
<AutoGen>True</AutoGen>