Merge pull request #1314 from mmoening/master

Sync printer page updates progress of syncing operations
This commit is contained in:
johnlewin 2016-08-22 17:02:33 -07:00 committed by GitHub
commit 25a126ed87
4 changed files with 35 additions and 7 deletions

View file

@ -181,7 +181,7 @@ namespace MatterHackers.MatterControl
public static Func<string, Task<Dictionary<string, string>>> GetProfileHistory;
public static Func<PrinterInfo,string, Task<PrinterSettings>> GetPrinterProfileAsync;
public static Func<Task> SyncPrinterProfiles;
public static Func<IProgress<SyncReportType>,Task> SyncPrinterProfiles;
public static Func<Task<OemProfileDictionary>> GetPublicProfileList;
public static Func<string, Task<PrinterSettings>> DownloadPublicProfileAsync;
@ -510,7 +510,7 @@ namespace MatterHackers.MatterControl
}
else
{
ApplicationController.SyncPrinterProfiles.Invoke().ContinueWith((task) =>
ApplicationController.SyncPrinterProfiles.Invoke(null).ContinueWith((task) =>
{
RunSetupIfRequired();
});
@ -574,4 +574,10 @@ namespace MatterHackers.MatterControl
PrintLibraryWidget.Reload();
}
}
public class SyncReportType
{
public string actionLabel;
public double percComplete;
}
}

View file

@ -155,7 +155,7 @@ namespace MatterHackers.MatterControl.SettingsManagement
SetManufacturers(manufacturesList);
}
public async Task ReloadOemProfiles()
public async Task ReloadOemProfiles(IProgress<SyncReportType> syncReport = null)
{
// In public builds this won't be assigned to and we should abort and exit early
if (ApplicationController.GetPublicProfileList == null)
@ -176,16 +176,18 @@ namespace MatterHackers.MatterControl.SettingsManagement
var manufactures = oemProfiles.Keys.ToDictionary(oem => oem);
SetManufacturers(manufactures);
await DownloadMissingProfiles();
await DownloadMissingProfiles(syncReport);
}
}
private async Task DownloadMissingProfiles()
private async Task DownloadMissingProfiles(IProgress<SyncReportType> syncReport)
{
string cacheDirectory = Path.Combine(ApplicationDataStorage.ApplicationUserDataPath, "data", "temp", "cache", "profiles");
SyncReportType reportValue = new SyncReportType();
int index = 0;
foreach (string oem in OemProfiles.Keys)
{
index++;
foreach (string profileKey in OemProfiles[oem].Values)
{
string cacheKey = profileKey + ProfileManager.ProfileExtension;
@ -200,7 +202,14 @@ namespace MatterHackers.MatterControl.SettingsManagement
{
File.WriteAllText(cachePath, profileJson);
}
if (syncReport != null)
{
reportValue.actionLabel = String.Format("Downloading public profiles for {0}...", oem);
reportValue.percComplete = (double)index / OemProfiles.Count;
syncReport.Report(reportValue);
}
}
}
}
}

View file

@ -12,12 +12,17 @@ namespace MatterHackers.MatterControl.SetupWizard
{
public class SyncingPrintersPage: WizardPage
{
TextWidget syncingDetails;
public SyncingPrintersPage()
{
TextWidget syncingText = new TextWidget("Syncing Profiles...".Localize(),textColor: ActiveTheme.Instance.PrimaryTextColor);
syncingDetails = new TextWidget("Retreiving sync information...".Localize(), textColor: ActiveTheme.Instance.PrimaryTextColor, pointSize:10);
syncingDetails.AutoExpandBoundsToText = true;
contentRow.AddChild(syncingText);
contentRow.AddChild(syncingDetails);
Progress<SyncReportType> progress = new Progress<SyncReportType>(ReportProgress);
ApplicationController.SyncPrinterProfiles().ContinueWith((task) =>
ApplicationController.SyncPrinterProfiles(progress).ContinueWith((task) =>
{
if (!ProfileManager.Instance.ActiveProfiles.Any())
{
@ -34,5 +39,10 @@ namespace MatterHackers.MatterControl.SetupWizard
footerRow.AddChild(new HorizontalSpacer());
footerRow.AddChild(cancelButton);
}
private void ReportProgress(SyncReportType report)
{
syncingDetails.Text = report.actionLabel;
}
}
}

View file

@ -5323,3 +5323,6 @@ Translated:When this is checked MatterControl will attempt to resume a print in
English:Minimum Travel Requiring Retraction
Translated:Minimum Travel Requiring Retraction
English:Retreiving sync information...
Translated:Retreiving sync information...