Refactor GQL code. Auto load and save active shops. Auto start monitors.
This commit is contained in:
@@ -31,20 +31,18 @@ namespace BodyshopUploader.ViewModels
|
||||
|
||||
Growler = new GrowlNotification(this);
|
||||
Utils.JobProcessingQueue.SetGrowler(Growler);
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void Bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
|
||||
{
|
||||
((BackgroundWorker)sender).Dispose();
|
||||
//Progress = 0;
|
||||
logger.Trace("BW Completed.");
|
||||
Progress = 0;
|
||||
}
|
||||
|
||||
private void Bw_ProgressChanged(object sender, ProgressChangedEventArgs e)
|
||||
{
|
||||
Progress = e.ProgressPercentage;
|
||||
StartFolderMonitorsCommand.Execute(null);
|
||||
}
|
||||
|
||||
private void bw_InitVm(object sender, DoWorkEventArgs e)
|
||||
@@ -65,7 +63,6 @@ namespace BodyshopUploader.ViewModels
|
||||
//Cannot use await.
|
||||
LoadBodyshopData().Wait(); ;
|
||||
|
||||
|
||||
_callingThread.ReportProgress(80);
|
||||
|
||||
logger.Debug("VM Init Complete");
|
||||
@@ -75,7 +72,10 @@ namespace BodyshopUploader.ViewModels
|
||||
|
||||
private void MonitoringPathsChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
|
||||
{
|
||||
logger.Warn("TODO: Change monitoring lifecycles for folder watchers.");
|
||||
IndeterminateLoading = true;
|
||||
StopAllFolderMonitors();
|
||||
StartAllFolderMonitors();
|
||||
IndeterminateLoading = false;
|
||||
}
|
||||
|
||||
public void AddFolderMonitoringPath()
|
||||
@@ -101,6 +101,7 @@ namespace BodyshopUploader.ViewModels
|
||||
|
||||
public void StartAllFolderMonitors()
|
||||
{
|
||||
IndeterminateLoading = true;
|
||||
if (MonitoringPaths.Count > 0)
|
||||
foreach (var m in MonitoringPaths)
|
||||
{
|
||||
@@ -109,19 +110,20 @@ namespace BodyshopUploader.ViewModels
|
||||
|
||||
foreach (var p in MonitoringPaths)
|
||||
{
|
||||
//Ensure the directory exists, then start monitoring for CIECA files.
|
||||
p.StartMonitor();
|
||||
|
||||
}
|
||||
IndeterminateLoading = false;
|
||||
}
|
||||
|
||||
public void StopAllFolderMonitors()
|
||||
{
|
||||
IndeterminateLoading = true;
|
||||
if (MonitoringPaths.Count > 0)
|
||||
foreach (var m in MonitoringPaths)
|
||||
{
|
||||
m.StopMonitor();
|
||||
}
|
||||
IndeterminateLoading = false;
|
||||
}
|
||||
|
||||
public async Task LoadBodyshopData()
|
||||
@@ -140,33 +142,31 @@ namespace BodyshopUploader.ViewModels
|
||||
}"
|
||||
};
|
||||
|
||||
using (var g = Utils.GraphQL.CreateGQLClient())
|
||||
var Data = await Utils.GraphQL.ExecuteQuery(r);
|
||||
if (Data != null)
|
||||
{
|
||||
logger.Trace("Firing GQL Query: {0}", r.ToString());
|
||||
var graphQLResponse = await g.PostAsync(r);
|
||||
if (graphQLResponse.Errors == null)
|
||||
{
|
||||
logger.Trace("GQL Response: {0}", graphQLResponse.Data.bodyshops);
|
||||
var p = graphQLResponse.Data.bodyshops;
|
||||
ShopData = graphQLResponse.Data.bodyshops.ToObject<ObservableCollection<Bodyshop>>();
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.Error("Error querying bodyshop data.");
|
||||
}
|
||||
|
||||
ShopData = Data.bodyshops.ToObject<ObservableCollection<Bodyshop>>();
|
||||
}
|
||||
string SettingsSelectedShopUuid = Properties.Settings.Default.LastSelectedShop;
|
||||
if (string.IsNullOrEmpty(SettingsSelectedShopUuid))
|
||||
{
|
||||
ActiveShop = ShopData[0] ?? null;
|
||||
Properties.Settings.Default.LastSelectedShop = ShopData[0].Id ?? null;
|
||||
Properties.Settings.Default.Save();
|
||||
}
|
||||
else
|
||||
{
|
||||
ActiveShop = ShopData.Where(_ => _.Id == SettingsSelectedShopUuid).FirstOrDefault();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task SetActiveBodyshop(Bodyshop b)
|
||||
public async Task SetActiveBodyshop()
|
||||
{
|
||||
IndeterminateLoading = true;
|
||||
foreach (var s in ShopData)
|
||||
{
|
||||
if (s.Id == ActiveShop.Id) s.AssociationActive = true;
|
||||
else s.AssociationActive = false;
|
||||
|
||||
|
||||
var r = new GraphQLRequest
|
||||
{
|
||||
Query = @"
|
||||
@@ -185,21 +185,11 @@ namespace BodyshopUploader.ViewModels
|
||||
assocActive = s.AssociationActive
|
||||
}
|
||||
};
|
||||
|
||||
using (var g = Utils.GraphQL.CreateGQLClient())
|
||||
{
|
||||
logger.Trace("Firing GQL Query: {0}", r.ToString());
|
||||
var graphQLResponse = await g.PostAsync(r);
|
||||
if (graphQLResponse.Errors == null)
|
||||
{
|
||||
logger.Trace("GQL Response: {0}", graphQLResponse.Data);
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.Error("Error mutating data.");
|
||||
}
|
||||
}
|
||||
await Utils.GraphQL.ExecuteQuery(r);
|
||||
}
|
||||
Properties.Settings.Default.LastSelectedShop = ActiveShop.Id;
|
||||
Properties.Settings.Default.Save();
|
||||
IndeterminateLoading = false;
|
||||
}
|
||||
|
||||
public async Task TestGql()
|
||||
@@ -213,7 +203,6 @@ namespace BodyshopUploader.ViewModels
|
||||
};
|
||||
Growler.AddNotification(_n);
|
||||
|
||||
|
||||
var r = new GraphQLRequest
|
||||
{
|
||||
Query = @"
|
||||
@@ -224,12 +213,7 @@ namespace BodyshopUploader.ViewModels
|
||||
}
|
||||
}"
|
||||
};
|
||||
|
||||
using (var g = Utils.GraphQL.CreateGQLClient())
|
||||
{
|
||||
var graphQLResponse = await g.PostAsync(r);
|
||||
logger.Info("GQL Response: {0}", graphQLResponse.Data.bodyshops);
|
||||
}
|
||||
await Utils.GraphQL.ExecuteQuery(r);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user