2016-07-13 13:39:11 -07:00
|
|
|
|
using MatterHackers.Agg;
|
|
|
|
|
|
using MatterHackers.Agg.UI;
|
2016-07-12 17:23:45 -07:00
|
|
|
|
using MatterHackers.MatterControl.CustomWidgets;
|
|
|
|
|
|
using MatterHackers.MatterControl.SlicerConfiguration;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
2016-07-22 17:49:03 -07:00
|
|
|
|
using System.Globalization;
|
2016-07-12 17:23:45 -07:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Threading.Tasks;
|
2017-01-04 10:25:19 -08:00
|
|
|
|
using MatterHackers.Localizations;
|
2016-07-12 17:23:45 -07:00
|
|
|
|
|
|
|
|
|
|
namespace MatterHackers.MatterControl.SetupWizard
|
|
|
|
|
|
{
|
2017-11-08 15:56:37 -08:00
|
|
|
|
class PrinterProfileHistoryPage : DialogPage
|
2016-07-12 17:23:45 -07:00
|
|
|
|
{
|
|
|
|
|
|
List<RadioButton> radioButtonList = new List<RadioButton>();
|
|
|
|
|
|
Dictionary<string, string> printerProfileData = new Dictionary<string, string>();
|
2016-07-22 17:49:03 -07:00
|
|
|
|
List<string> orderedProfiles = new List<string>();
|
2018-11-11 21:25:50 -08:00
|
|
|
|
private PrinterConfig printer;
|
2016-07-12 17:23:45 -07:00
|
|
|
|
ScrollableWidget scrollWindow;
|
|
|
|
|
|
|
2018-11-11 21:25:50 -08:00
|
|
|
|
public PrinterProfileHistoryPage(PrinterConfig printer)
|
2016-07-12 17:23:45 -07:00
|
|
|
|
{
|
2017-08-23 15:51:29 -07:00
|
|
|
|
this.WindowTitle = "Restore Settings".Localize();
|
2017-08-24 00:16:31 -07:00
|
|
|
|
this.HeaderText = "Restore Settings".Localize();
|
2018-11-11 21:25:50 -08:00
|
|
|
|
this.printer = printer;
|
2017-08-23 15:51:29 -07:00
|
|
|
|
|
2016-07-12 17:23:45 -07:00
|
|
|
|
scrollWindow = new ScrollableWidget()
|
|
|
|
|
|
{
|
|
|
|
|
|
AutoScroll = true,
|
2017-08-07 15:47:27 -07:00
|
|
|
|
HAnchor = HAnchor.Stretch,
|
|
|
|
|
|
VAnchor = VAnchor.Stretch,
|
2016-07-12 17:23:45 -07:00
|
|
|
|
};
|
2017-08-07 15:47:27 -07:00
|
|
|
|
scrollWindow.ScrollArea.HAnchor = HAnchor.Stretch;
|
2018-11-03 10:12:27 -07:00
|
|
|
|
contentRow.FlowDirection = FlowDirection.TopToBottom;
|
|
|
|
|
|
contentRow.AddChild(scrollWindow);
|
2016-07-12 17:23:45 -07:00
|
|
|
|
|
2018-04-14 20:51:01 -07:00
|
|
|
|
var revertButton = theme.CreateDialogButton("Restore".Localize());
|
2016-07-13 13:39:11 -07:00
|
|
|
|
revertButton.Click += async (s, e) =>
|
2016-07-12 17:23:45 -07:00
|
|
|
|
{
|
2016-07-22 17:49:03 -07:00
|
|
|
|
int index = radioButtonList.IndexOf(radioButtonList.Where(r => r.Checked).FirstOrDefault());
|
|
|
|
|
|
|
|
|
|
|
|
if (index != -1)
|
2016-07-12 17:23:45 -07:00
|
|
|
|
{
|
2016-07-22 17:49:03 -07:00
|
|
|
|
string profileToken = printerProfileData[orderedProfiles[index]];
|
2016-07-13 13:39:11 -07:00
|
|
|
|
|
2018-11-11 21:25:50 -08:00
|
|
|
|
var profile = ProfileManager.Instance[printer.Settings.ID];
|
2016-07-13 13:39:11 -07:00
|
|
|
|
|
|
|
|
|
|
// Download the specified json profile
|
2019-01-31 09:42:54 -08:00
|
|
|
|
PrinterSettings printerSettings = null;
|
|
|
|
|
|
if (Application.EnableNetworkTraffic)
|
|
|
|
|
|
{
|
|
|
|
|
|
await ApplicationController.GetPrinterProfileAsync(profile, profileToken);
|
|
|
|
|
|
}
|
2017-09-23 14:44:43 -07:00
|
|
|
|
if (printerSettings != null)
|
2016-07-28 09:38:03 -07:00
|
|
|
|
{
|
|
|
|
|
|
// Persist downloaded profile
|
2019-05-29 14:16:25 -07:00
|
|
|
|
printerSettings.Save(userDrivenChange: false);
|
2016-07-13 13:39:11 -07:00
|
|
|
|
|
2018-11-12 08:04:17 -08:00
|
|
|
|
// Update/switch printer instance to new settings
|
|
|
|
|
|
printer.SwapToSettings(printerSettings);
|
2016-07-28 09:38:03 -07:00
|
|
|
|
}
|
2018-04-14 20:51:01 -07:00
|
|
|
|
|
2019-06-28 22:22:58 -07:00
|
|
|
|
DialogWindow.Close();
|
2016-07-12 17:23:45 -07:00
|
|
|
|
}
|
|
|
|
|
|
};
|
2017-08-23 17:27:30 -07:00
|
|
|
|
this.AddPageAction(revertButton);
|
2016-07-12 17:23:45 -07:00
|
|
|
|
|
|
|
|
|
|
LoadHistoryItems();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private async void LoadHistoryItems()
|
|
|
|
|
|
{
|
2016-07-13 13:39:11 -07:00
|
|
|
|
TextWidget loadingText = new TextWidget("Retrieving History from Web...");
|
2018-11-03 09:13:07 -07:00
|
|
|
|
loadingText.TextColor = theme.TextColor;
|
2016-07-13 13:39:11 -07:00
|
|
|
|
scrollWindow.AddChild(loadingText);
|
2016-07-12 17:23:45 -07:00
|
|
|
|
|
2018-11-11 21:25:50 -08:00
|
|
|
|
var profile = ProfileManager.Instance[printer.Settings.ID];
|
|
|
|
|
|
|
2022-06-19 20:13:32 -07:00
|
|
|
|
Dictionary<string, string> results = null;
|
|
|
|
|
|
if (ApplicationController.GetProfileHistory != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
results = await ApplicationController.GetProfileHistory.Invoke(profile.DeviceToken);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-07-12 17:23:45 -07:00
|
|
|
|
printerProfileData = results;
|
2016-07-13 13:39:11 -07:00
|
|
|
|
if(printerProfileData != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
loadingText.Visible= false;
|
2016-07-12 17:23:45 -07:00
|
|
|
|
|
2016-07-22 17:49:03 -07:00
|
|
|
|
List<DateTime> sourceTimes = new List<DateTime>();
|
|
|
|
|
|
foreach (var printerProfile in results.OrderByDescending(d => d.Key))
|
|
|
|
|
|
{
|
|
|
|
|
|
// AppEngine results are current in the form of: "2016-07-21 00:43:30.965830"
|
|
|
|
|
|
sourceTimes.Add(Convert.ToDateTime(printerProfile.Key).ToLocalTime());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var groupedTimes = RelativeTime.GroupTimes(DateTime.Now, sourceTimes);
|
|
|
|
|
|
|
|
|
|
|
|
FlowLayoutWidget topToBottomStuff = new FlowLayoutWidget(FlowDirection.TopToBottom);
|
|
|
|
|
|
scrollWindow.AddChild(topToBottomStuff);
|
|
|
|
|
|
foreach (var group in groupedTimes)
|
|
|
|
|
|
{
|
|
|
|
|
|
// add in the group header
|
2018-11-03 09:13:07 -07:00
|
|
|
|
topToBottomStuff.AddChild(new TextWidget(RelativeTime.BlockDescriptions[group.Key], textColor: theme.TextColor)
|
2016-07-22 17:49:03 -07:00
|
|
|
|
{
|
|
|
|
|
|
Margin = new BorderDouble(0, 0, 0, 5),
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var time in group.Value)
|
|
|
|
|
|
{
|
|
|
|
|
|
// add in the radio buttons
|
2018-11-03 09:13:07 -07:00
|
|
|
|
var profileVersionButton = new RadioButton(time.Value, textColor: theme.TextColor)
|
2016-07-22 17:49:03 -07:00
|
|
|
|
{
|
|
|
|
|
|
Margin = new BorderDouble(5, 0),
|
|
|
|
|
|
};
|
|
|
|
|
|
profileVersionButton.Checked = false;
|
|
|
|
|
|
radioButtonList.Add(profileVersionButton);
|
|
|
|
|
|
topToBottomStuff.AddChild(profileVersionButton);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-07-13 13:39:11 -07:00
|
|
|
|
foreach(var printerProfile in results)
|
|
|
|
|
|
{
|
2016-07-22 17:49:03 -07:00
|
|
|
|
orderedProfiles.Add(printerProfile.Key.ToString());
|
2016-07-13 13:39:11 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
2016-07-12 17:23:45 -07:00
|
|
|
|
{
|
2016-07-13 13:39:11 -07:00
|
|
|
|
loadingText.Text = "Failed To Download History!";
|
2017-10-31 11:43:25 -07:00
|
|
|
|
loadingText.TextColor = Color.Red;
|
2016-07-12 17:23:45 -07:00
|
|
|
|
}
|
2018-11-11 21:25:50 -08:00
|
|
|
|
|
2016-07-12 17:23:45 -07:00
|
|
|
|
//remove loading profile text/icon
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|