Merge pull request #1180 from jlewin/master

Add Load event to ApplicationController
This commit is contained in:
johnlewin 2016-07-25 17:01:10 -07:00 committed by GitHub
commit 9d957dcb8c
4 changed files with 29 additions and 24 deletions

View file

@ -171,6 +171,11 @@ namespace MatterHackers.MatterControl
public static Action LogoutAction;
public static Func<string> GetSessionInfo;
/// <summary>
/// Allows application components to hook initial SystemWindow Load event without an existing Widget instance
/// </summary>
public static event EventHandler Load;
public static Func<string, Task<Dictionary<string, string>>> GetProfileHistory;
public static Func<PrinterInfo,string, Task> GetPrinterProfile;
public static Func<Task> SyncPrinterProfiles;
@ -461,6 +466,8 @@ namespace MatterHackers.MatterControl
public void OnLoadActions()
{
Load?.Invoke(this, null);
ApplicationController.Instance.UserChanged();
if (false && UserSettings.Instance.get("SoftwareLicenseAccepted") != "true")

View file

@ -133,34 +133,32 @@ namespace MatterHackers.MatterControl.SettingsManagement
var manufacturesList = OemProfiles.Keys.ToDictionary(oem => oem).ToList();
SetManufacturers(manufacturesList);
// Attempt to update from online
Task.Run(async () =>
ApplicationController.Load += ReloadOemProfiles;
}
public async void ReloadOemProfiles(object sender, EventArgs e)
{
// In public builds this won't be assigned to and we should abort and exit early
if (ApplicationController.GetPublicProfileList == null)
{
// In public builds this won't be assigned to and we should abort and exit early
if (ApplicationController.GetPublicProfileList == null)
{
return;
}
return;
}
var oemProfiles = await ApplicationController.LoadCacheableAsync<OemProfileDictionary>(
"oemProfiles.json",
"profiles",
ApplicationController.GetPublicProfileList);
var oemProfiles = await ApplicationController.LoadCacheableAsync<OemProfileDictionary>(
"oemprofiles.json",
"profiles",
ApplicationController.GetPublicProfileList);
// If we failed to get anything from load cacheable don't override potentially populated fields
if(oemProfiles != null)
{
UiThread.RunOnIdle(() =>
{
OemProfiles = oemProfiles;
// If we failed to get anything from load cacheable don't override potentially populated fields
if (oemProfiles != null)
{
OemProfiles = oemProfiles;
var manufactures = oemProfiles.Keys.ToDictionary(oem => oem);
SetManufacturers(manufactures);
var manufactures = oemProfiles.Keys.ToDictionary(oem => oem);
SetManufacturers(manufactures);
Task.Run((Action)DownloadMissingProfiles);
});
}
});
Task.Run((Action)DownloadMissingProfiles);
}
}
private async void DownloadMissingProfiles()

View file

@ -32,7 +32,7 @@ namespace MatterControl.Tests.MatterControl
/*
StaticData.Instance = new MatterHackers.Agg.FileSystemStaticData(Path.Combine("..", "..", "..", "..", "StaticData"));
string profilePath = Path.Combine(ApplicationDataStorage.ApplicationUserDataPath, "data", "temp", "cache", "profiles", "oemProfiles.json");
string profilePath = Path.Combine(ApplicationDataStorage.ApplicationUserDataPath, "data", "temp", "cache", "profiles", "oemprofiles.json");
//MatterControlUtilities.OverrideAppDataLocation();