From 135b4df7ad3cdcaafceee12daf47bb77a3501aae Mon Sep 17 00:00:00 2001 From: John Lewin Date: Sun, 24 Jul 2016 08:21:59 -0700 Subject: [PATCH] Refactor for clarity, conciseness --- SlicerConfiguration/Settings/ProfileManager.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/SlicerConfiguration/Settings/ProfileManager.cs b/SlicerConfiguration/Settings/ProfileManager.cs index 83e4a0927..7810e9b8e 100644 --- a/SlicerConfiguration/Settings/ProfileManager.cs +++ b/SlicerConfiguration/Settings/ProfileManager.cs @@ -374,19 +374,24 @@ namespace MatterHackers.MatterControl.SlicerConfiguration private async static Task LoadHttpOemProfile(string make, string model) { string deviceToken = OemSettings.Instance.OemProfiles[make][model]; + string cacheKey = deviceToken + ProfileManager.ProfileExtension; + string cachePath = Path.Combine(ApplicationDataStorage.ApplicationUserDataPath, "data", "temp", "cache", "profiles", cacheKey); + return await ApplicationController.LoadCacheableAsync( - String.Format("{0}{1}", deviceToken, ProfileManager.ProfileExtension), + cacheKey, "profiles", () => { string responseText = null; - if(!File.Exists(Path.Combine(ApplicationDataStorage.ApplicationUserDataPath, "data", "temp", "cache", "profiles",String.Format("{0}{1}",deviceToken, ProfileManager.ProfileExtension)))) + if(!File.Exists(cachePath)) { + // If the cache file for the current deviceToken does not exist, attempt to download it responseText = RetrievePublicProfileRequest.DownloadPrinterProfile(deviceToken); } + return Task.FromResult(responseText); }, - Path.Combine("Profiles",make,String.Format("{0}{1}",model,ProfileManager.ProfileExtension))); + Path.Combine("Profiles",make, model + ProfileManager.ProfileExtension)); } public void EnsurePrintersImported()