Created monitoring object and refactored code accordingly.
This commit is contained in:
@@ -63,8 +63,8 @@ namespace BodyshopUploader.ViewModels
|
||||
if (_removeMonitoringPathCommand == null)
|
||||
{
|
||||
_removeMonitoringPathCommand = new RelayCommand(
|
||||
p => FolderMonitors.Count == 0,
|
||||
p => RemoveFolderMonitoringPath(p as string)
|
||||
p => true,
|
||||
p => RemoveFolderMonitoringPath(p as Models.Monitor)
|
||||
);
|
||||
}
|
||||
return _removeMonitoringPathCommand;
|
||||
@@ -95,7 +95,7 @@ namespace BodyshopUploader.ViewModels
|
||||
if (_stopFolderMonitorsCommand == null)
|
||||
{
|
||||
_stopFolderMonitorsCommand = new RelayCommand(
|
||||
p => FolderMonitors.Count > 0,
|
||||
p => MonitoringPaths.Count > 0,
|
||||
p => StopAllFolderMonitors()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using BodyshopUploader.Utils.Growls;
|
||||
using BodyshopUploader.Models;
|
||||
|
||||
namespace BodyshopUploader.ViewModels
|
||||
{
|
||||
@@ -12,15 +13,8 @@ namespace BodyshopUploader.ViewModels
|
||||
{
|
||||
public GrowlNotification Growler;
|
||||
|
||||
private ObservableCollection<Utils.CIECAMonitor> _folderMonitors = new ObservableCollection<Utils.CIECAMonitor>() ;
|
||||
public ObservableCollection<Utils.CIECAMonitor> FolderMonitors
|
||||
{
|
||||
get { return _folderMonitors; }
|
||||
set { SetProperty(ref _folderMonitors, value); }
|
||||
}
|
||||
|
||||
private ObservableCollection<string> _monitoringPaths = Properties.Settings.Default.MonitoringPaths ;
|
||||
public ObservableCollection<string> MonitoringPaths
|
||||
private ObservableCollection<Monitor> _monitoringPaths = new ObservableCollection<Monitor>();
|
||||
public ObservableCollection<Monitor> MonitoringPaths
|
||||
{
|
||||
get { return _monitoringPaths; }
|
||||
set { SetProperty(ref _monitoringPaths, value); }
|
||||
|
||||
Reference in New Issue
Block a user