119 lines
3.8 KiB
C#
119 lines
3.8 KiB
C#
using BodyshopUploader.Models;
|
|
using BodyshopUploader.Utils.Growls;
|
|
using GraphQL.Client;
|
|
using GraphQL.Common.Request;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
|
|
namespace BodyshopUploader.ViewModels
|
|
{
|
|
public partial class MainViewModel : BaseViewModel
|
|
{
|
|
private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
|
|
|
|
public MainViewModel()
|
|
{
|
|
Growler = new GrowlNotification(this);
|
|
Utils.JobProcessingQueue.SetGrowler(Growler);
|
|
|
|
//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)
|
|
{
|
|
logger.Warn("TODO: Change monitoring lifecycles for folder watchers.");
|
|
}
|
|
|
|
public void AddFolderMonitoringPath()
|
|
{
|
|
var dialog = new Ookii.Dialogs.Wpf.VistaFolderBrowserDialog();
|
|
if (dialog.ShowDialog().GetValueOrDefault())
|
|
{
|
|
logger.Debug("Adding folder {0} to monitoring paths.", dialog.SelectedPath);
|
|
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(Monitor m)
|
|
{
|
|
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 (MonitoringPaths.Count > 0)
|
|
foreach (var m in MonitoringPaths)
|
|
{
|
|
m.StopMonitor();
|
|
}
|
|
|
|
foreach (var p in MonitoringPaths)
|
|
{
|
|
//Ensure the directory exists, then start monitoring for CIECA files.
|
|
p.StartMonitor();
|
|
|
|
}
|
|
}
|
|
|
|
public void StopAllFolderMonitors()
|
|
{
|
|
if (MonitoringPaths.Count > 0)
|
|
foreach (var m in MonitoringPaths)
|
|
{
|
|
m.StopMonitor();
|
|
}
|
|
}
|
|
|
|
public async Task TestGql()
|
|
{
|
|
Notification _n = new Notification()
|
|
{
|
|
Id = 123,
|
|
Title = "This is a title",
|
|
Subtitle = "Subtitle",
|
|
Message = "Somethin"
|
|
};
|
|
Growler.AddNotification(_n);
|
|
|
|
|
|
var r = new GraphQLRequest
|
|
{
|
|
Query = @"
|
|
query {
|
|
jobs {
|
|
id
|
|
est_number
|
|
ro_number
|
|
}
|
|
}
|
|
"
|
|
};
|
|
|
|
using (var g = Utils.GraphQL.CreateGQLClient())
|
|
{
|
|
var graphQLResponse = await g.PostAsync(r);
|
|
logger.Info(graphQLResponse.Data.jobs);
|
|
}
|
|
}
|
|
}
|
|
}
|