Refactor GQL code. Auto load and save active shops. Auto start monitors.
This commit is contained in:
@@ -40,6 +40,12 @@
|
||||
<setting name="AutoStartMonitors" serializeAs="String">
|
||||
<value>False</value>
|
||||
</setting>
|
||||
<setting name="LastSelectedShop" serializeAs="String">
|
||||
<value />
|
||||
</setting>
|
||||
<setting name="AutoStartMonitor" serializeAs="String">
|
||||
<value>True</value>
|
||||
</setting>
|
||||
</BodyshopUploader.Properties.Settings>
|
||||
</userSettings>
|
||||
</configuration>
|
||||
18
BodyshopUploader/Properties/Resources.Designer.cs
generated
18
BodyshopUploader/Properties/Resources.Designer.cs
generated
@@ -114,6 +114,15 @@ namespace BodyshopUploader.Properties {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Auto-start Monitors.
|
||||
/// </summary>
|
||||
public static string Label_AutoStartMonitor {
|
||||
get {
|
||||
return ResourceManager.GetString("Label_AutoStartMonitor", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to File Path.
|
||||
/// </summary>
|
||||
@@ -168,6 +177,15 @@ namespace BodyshopUploader.Properties {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Error uploading job..
|
||||
/// </summary>
|
||||
public static string Msg_NewJobUploadError {
|
||||
get {
|
||||
return ResourceManager.GetString("Msg_NewJobUploadError", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Password.
|
||||
/// </summary>
|
||||
|
||||
@@ -135,6 +135,9 @@
|
||||
<data name="Label_AddMonitoringPath" xml:space="preserve">
|
||||
<value>Add Path</value>
|
||||
</data>
|
||||
<data name="Label_AutoStartMonitor" xml:space="preserve">
|
||||
<value>Auto-start Monitors</value>
|
||||
</data>
|
||||
<data name="Label_FilePath" xml:space="preserve">
|
||||
<value>File Path</value>
|
||||
</data>
|
||||
@@ -153,6 +156,9 @@
|
||||
<data name="Msg_NewJobUploaded" xml:space="preserve">
|
||||
<value>New Job Uploaded</value>
|
||||
</data>
|
||||
<data name="Msg_NewJobUploadError" xml:space="preserve">
|
||||
<value>Error uploading job.</value>
|
||||
</data>
|
||||
<data name="Password" xml:space="preserve">
|
||||
<value>Password</value>
|
||||
</data>
|
||||
|
||||
24
BodyshopUploader/Properties/Settings.Designer.cs
generated
24
BodyshopUploader/Properties/Settings.Designer.cs
generated
@@ -68,5 +68,29 @@ namespace BodyshopUploader.Properties {
|
||||
this["AutoStartMonitors"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
[global::System.Configuration.UserScopedSettingAttribute()]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Configuration.DefaultSettingValueAttribute("")]
|
||||
public string LastSelectedShop {
|
||||
get {
|
||||
return ((string)(this["LastSelectedShop"]));
|
||||
}
|
||||
set {
|
||||
this["LastSelectedShop"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
[global::System.Configuration.UserScopedSettingAttribute()]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Configuration.DefaultSettingValueAttribute("True")]
|
||||
public bool AutoStartMonitor {
|
||||
get {
|
||||
return ((bool)(this["AutoStartMonitor"]));
|
||||
}
|
||||
set {
|
||||
this["AutoStartMonitor"] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,5 +14,11 @@
|
||||
<Setting Name="AutoStartMonitors" Type="System.Boolean" Scope="User">
|
||||
<Value Profile="(Default)">False</Value>
|
||||
</Setting>
|
||||
<Setting Name="LastSelectedShop" Type="System.String" Scope="User">
|
||||
<Value Profile="(Default)" />
|
||||
</Setting>
|
||||
<Setting Name="AutoStartMonitor" Type="System.Boolean" Scope="User">
|
||||
<Value Profile="(Default)">True</Value>
|
||||
</Setting>
|
||||
</Settings>
|
||||
</SettingsFile>
|
||||
@@ -1,4 +1,6 @@
|
||||
using GraphQL.Client;
|
||||
using GraphQL.Common.Request;
|
||||
using GraphQL.Common.Response;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -9,11 +11,33 @@ namespace BodyshopUploader.Utils
|
||||
{
|
||||
public static class GraphQL
|
||||
{
|
||||
private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
|
||||
|
||||
public static GraphQLClient CreateGQLClient()
|
||||
{
|
||||
var graphQLClient = new GraphQLClient("https://bodyshop-dev-db.herokuapp.com/v1/graphql");
|
||||
graphQLClient.DefaultRequestHeaders.Add("Authorization", "Bearer " + Utils.Auth.authlink.FirebaseToken);
|
||||
return graphQLClient;
|
||||
}
|
||||
|
||||
public static async Task<dynamic> ExecuteQuery(GraphQLRequest r)
|
||||
{
|
||||
using (var g = Utils.GraphQL.CreateGQLClient())
|
||||
{
|
||||
logger.Trace("Firing GQL Query: {0} {1}", r.Query.ToString(), r.Variables);
|
||||
var graphQLResponse = await g.PostAsync(r);
|
||||
if (graphQLResponse.Errors == null)
|
||||
{
|
||||
logger.Trace("GQL Response: {0}", graphQLResponse.Data);
|
||||
return graphQLResponse.Data;
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.Error("Error executing query.");
|
||||
Array.ForEach(graphQLResponse.Errors, x => logger.Error(x.ToString()));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,15 +83,12 @@ namespace BodyshopUploader.Utils
|
||||
}
|
||||
|
||||
private static async Task UpsertQueueItem(DTO_QueueItem item)
|
||||
{
|
||||
//Save the job to the DB.
|
||||
|
||||
|
||||
{
|
||||
item.Job.shopid = "52b7357c-0edd-4c95-85c3-dfdbcdfad9ac";
|
||||
item.Job.est_number = "123";
|
||||
item.Job.vehicle.data.shopid = "52b7357c-0edd-4c95-85c3-dfdbcdfad9ac";
|
||||
|
||||
logger.Info("Should upsert the job graphqlly here. {0}", item.Job);
|
||||
logger.Info("Manually setting the shop id! {0}", item.Job);
|
||||
|
||||
var r = new GraphQLRequest
|
||||
{
|
||||
@@ -104,20 +101,25 @@ namespace BodyshopUploader.Utils
|
||||
}
|
||||
}",
|
||||
Variables = new
|
||||
{
|
||||
|
||||
{
|
||||
jobInput = item.Job
|
||||
}
|
||||
};
|
||||
|
||||
using (var g = Utils.GraphQL.CreateGQLClient())
|
||||
var d = await Utils.GraphQL.ExecuteQuery(r);
|
||||
if(d!= null)
|
||||
{
|
||||
var graphQLResponse = await g.PostAsync(r);
|
||||
if(graphQLResponse.Errors == null)
|
||||
App.Current.Dispatcher.Invoke(() =>
|
||||
{
|
||||
logger.Trace("Job posted succesfully.");
|
||||
}
|
||||
Growler.AddNotification(new Notification()
|
||||
{
|
||||
Title = Properties.Resources.Msg_NewJobUploadError,
|
||||
Subtitle = item.Job?.owner?.first_name?.Value + " " + item.Job?.owner?.last_name?.Value,
|
||||
Message = item.Job?.vehicle?.v_model_yr?.Value + " " + item.Job?.vehicle?.v_make_desc?.Value + " " + item.Job?.vehicle?.v_model_desc?.Value
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
_jobs.Dequeue();
|
||||
|
||||
App.Current.Dispatcher.Invoke(() =>
|
||||
|
||||
@@ -79,9 +79,9 @@ namespace BodyshopUploader.ViewModels
|
||||
if (_startFolderMonitorsCommand == null)
|
||||
{
|
||||
_startFolderMonitorsCommand = new RelayCommand(
|
||||
p => MonitoringPaths.Count > 0,
|
||||
p => MonitoringPaths.Count > 0 && ActiveShop != null,
|
||||
p => StartAllFolderMonitors()
|
||||
);
|
||||
) ;
|
||||
}
|
||||
return _startFolderMonitorsCommand;
|
||||
}
|
||||
@@ -102,5 +102,24 @@ namespace BodyshopUploader.ViewModels
|
||||
return _stopFolderMonitorsCommand;
|
||||
}
|
||||
}
|
||||
|
||||
private ICommand _quitCommand;
|
||||
public ICommand QuitCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_quitCommand == null)
|
||||
{
|
||||
_quitCommand = new RelayCommand(
|
||||
p => true,
|
||||
p =>
|
||||
{
|
||||
Properties.Settings.Default.Save(); App.Current.Shutdown(0);
|
||||
});
|
||||
}
|
||||
return _quitCommand;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,12 +34,18 @@ namespace BodyshopUploader.ViewModels
|
||||
set { SetProperty(ref _progress, value); }
|
||||
}
|
||||
|
||||
private bool _indeterminateLoading;
|
||||
public bool IndeterminateLoading
|
||||
{
|
||||
get { return _indeterminateLoading; }
|
||||
set { SetProperty(ref _indeterminateLoading, value); }
|
||||
}
|
||||
|
||||
private Bodyshop _activeShop;
|
||||
public Bodyshop ActiveShop
|
||||
{
|
||||
get { return _activeShop; }
|
||||
set { SetProperty(ref _activeShop, value); SetActiveBodyshop(value); }
|
||||
set { SetProperty(ref _activeShop, value); Task.Run(async () => await SetActiveBodyshop()); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,11 @@
|
||||
<util:OpenMainWindowCommand x:Key="OpenMainWindowCommand" />
|
||||
</Window.Resources>
|
||||
<DockPanel>
|
||||
<ProgressBar DockPanel.Dock="Bottom"
|
||||
Value="{Binding Progress}"
|
||||
IsIndeterminate="{Binding IndeterminateLoading}"
|
||||
Height="10" />
|
||||
|
||||
<tb:TaskbarIcon DockPanel.Dock="Top"
|
||||
IconSource="../favicon.ico"
|
||||
DoubleClickCommand="{StaticResource OpenMainWindowCommand}"
|
||||
@@ -48,8 +53,7 @@
|
||||
</tb:TaskbarIcon.TrayPopup>
|
||||
<tb:TaskbarIcon.ContextMenu>
|
||||
<ContextMenu>
|
||||
<MenuItem Header="First Menu Item" />
|
||||
<MenuItem Header="Second Menu Item" />
|
||||
<MenuItem Header="Exit" Command="{Binding QuitCommand}" />
|
||||
</ContextMenu>
|
||||
</tb:TaskbarIcon.ContextMenu>
|
||||
</tb:TaskbarIcon>
|
||||
@@ -76,17 +80,16 @@
|
||||
</ItemsPanelTemplate>
|
||||
</ComboBox.ItemsPanel>
|
||||
</ComboBox>
|
||||
|
||||
|
||||
<Button Command="{Binding StartFolderMonitorsCommand}"
|
||||
Content="{x:Static p:Resources.Label_StartAllMonitors}" />
|
||||
<Button Command="{Binding StopFolderMonitorsCommand}"
|
||||
Content="{x:Static p:Resources.Label_StopAllMonitors}" />
|
||||
<CheckBox IsChecked="{Binding Source={x:Static p:Settings.Default}, Path=AutoStartMonitor}"
|
||||
Content="{x:Static p:Resources.Label_AutoStartMonitor}"/>
|
||||
|
||||
</StackPanel>
|
||||
|
||||
<ProgressBar DockPanel.Dock="Bottom"
|
||||
Value="{Binding Progress}" />
|
||||
|
||||
<DataGrid ItemsSource="{Binding MonitoringPaths}"
|
||||
AutoGenerateColumns="False"
|
||||
CanUserAddRows="False">
|
||||
|
||||
Reference in New Issue
Block a user