Created monitoring object and refactored code accordingly.

This commit is contained in:
Patrick Fic
2020-01-17 14:19:49 -08:00
parent 3357a8a564
commit b7218b6771
16 changed files with 217 additions and 76 deletions

View File

@@ -1,4 +1,5 @@
using BodyshopUploader.Utils.Growls;
using BodyshopUploader.Models;
using BodyshopUploader.Utils.Growls;
using GraphQL.Client;
using GraphQL.Common.Request;
using System;
@@ -17,12 +18,18 @@ namespace BodyshopUploader.ViewModels
public MainViewModel()
{
logger.Trace("Main VM Created.");
Growler = new GrowlNotification(this);
Utils.JobProcessingQueue.SetGrowler(Growler);
//Create Variables
if (MonitoringPaths == null) MonitoringPaths = new ObservableCollection<string>();
//Restore list of paths, convert to monitor object.
List<string> listOfPaths = Properties.Settings.Default.MonitoringPaths;
if (listOfPaths == null) listOfPaths = new List<string>();
foreach (var p in listOfPaths)
{
MonitoringPaths.Add(new Models.Monitor() { FilePath = p });
}
MonitoringPaths.CollectionChanged += MonitoringPathsChanged;
logger.Trace("Main VM Created.");
}
private void MonitoringPathsChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
@@ -36,42 +43,43 @@ namespace BodyshopUploader.ViewModels
if (dialog.ShowDialog().GetValueOrDefault())
{
logger.Debug("Adding folder {0} to monitoring paths.", dialog.SelectedPath);
MonitoringPaths.Add(dialog.SelectedPath);
Properties.Settings.Default.MonitoringPaths = MonitoringPaths;
MonitoringPaths.Add(new Models.Monitor() { FilePath = dialog.SelectedPath });
Properties.Settings.Default.MonitoringPaths = MonitoringPaths.Select(x => x.FilePath).ToList(); ;
Properties.Settings.Default.Save();
}
}
public void RemoveFolderMonitoringPath(string Path)
public void RemoveFolderMonitoringPath(Monitor m)
{
logger.Debug("Removing folder {0} to monitoring paths.", Path);
MonitoringPaths.Remove(Path);
Properties.Settings.Default.MonitoringPaths = MonitoringPaths;
logger.Debug("Removing folder {0} to monitoring paths.", m.FilePath);
m.StopMonitor();
MonitoringPaths.Remove(m);
Properties.Settings.Default.MonitoringPaths = MonitoringPaths.Select(x => x.FilePath).ToList();
Properties.Settings.Default.Save();
}
public void StartAllFolderMonitors()
{
if (FolderMonitors.Count > 0)
foreach (var m in FolderMonitors)
if (MonitoringPaths.Count > 0)
foreach (var m in MonitoringPaths)
{
m.Dispose();
m.StopMonitor();
}
foreach (var p in MonitoringPaths)
{
//Ensure the directory exists, then start monitoring for CIECA files.
System.IO.Directory.CreateDirectory(p);
FolderMonitors.Add(new Utils.CIECAMonitor(p));
p.StartMonitor();
}
}
public void StopAllFolderMonitors()
{
if (FolderMonitors.Count > 0)
foreach (var m in FolderMonitors)
if (MonitoringPaths.Count > 0)
foreach (var m in MonitoringPaths)
{
m.Dispose();
m.StopMonitor();
}
}
@@ -80,7 +88,6 @@ namespace BodyshopUploader.ViewModels
Notification _n = new Notification()
{
Id = 123,
ThreadId = 123,
Title = "This is a title",
Subtitle = "Subtitle",
Message = "Somethin"