Use short identifiers for public profiles
- Add support for new GetProfileList schema - Add CacheablePath function to abstract and reuse path generation logic - Serialize LoadCacheable content in human readable form - Move public-profile cache into like named folder - Move public-profile items into oem specific folders - Reuse LoadOemProfileAsync for persistence instead of custom implementation - Issues MatterHackers/MCWS#72, MatterHackers/MCWS#84
This commit is contained in:
parent
97524d55ed
commit
312f652bbb
7 changed files with 82 additions and 57 deletions
|
|
@ -329,8 +329,10 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
|
||||
try
|
||||
{
|
||||
string publicProfileDeviceToken = OemSettings.Instance.OemProfiles[profile.Make][profile.Model];
|
||||
string publicProfileToLoad = Path.Combine(ApplicationDataStorage.ApplicationUserDataPath, "data", "temp", "cache", "profiles", publicProfileDeviceToken + ProfileManager.ProfileExtension);
|
||||
var publicDevice = OemSettings.Instance.OemProfiles[profile.Make][profile.Model];
|
||||
string cacheScope = Path.Combine("public-profiles", profile.Make);
|
||||
|
||||
string publicProfileToLoad = ApplicationController.CacheablePath(cacheScope, publicDevice.CacheKey);
|
||||
|
||||
oemProfile = JsonConvert.DeserializeObject<PrinterSettings>(File.ReadAllText(publicProfileToLoad));
|
||||
oemProfile.ID = profile.ID;
|
||||
|
|
|
|||
|
|
@ -387,7 +387,12 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
{
|
||||
string guid = Guid.NewGuid().ToString();
|
||||
|
||||
var newProfile = await LoadHttpOemProfile(make, model);
|
||||
var publicDevice = OemSettings.Instance.OemProfiles[make][model];
|
||||
|
||||
// TODO: jlewin - how can we handle lookup failures at this point? Should we throw and check for the exception?
|
||||
//if (publicDevice == null)
|
||||
|
||||
var newProfile = await LoadOemProfileAsync(publicDevice, make);
|
||||
newProfile.ID = guid;
|
||||
newProfile.DocumentVersion = PrinterSettings.LatestVersion;
|
||||
|
||||
|
|
@ -463,28 +468,31 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
"Pink - Light",
|
||||
};
|
||||
|
||||
private async static Task<PrinterSettings> LoadHttpOemProfile(string make, string model)
|
||||
public async static Task<PrinterSettings> LoadOemProfileAsync(PublicDevice publicDevice, string make)
|
||||
{
|
||||
string deviceToken = OemSettings.Instance.OemProfiles[make][model];
|
||||
string cacheKey = deviceToken + ProfileManager.ProfileExtension;
|
||||
string cachePath = Path.Combine(ApplicationDataStorage.ApplicationUserDataPath, "data", "temp", "cache", "profiles", cacheKey);
|
||||
string cacheScope = Path.Combine("public-profiles", make);
|
||||
string cachePath = ApplicationController.CacheablePath(cacheScope, publicDevice.CacheKey);
|
||||
|
||||
return await ApplicationController.LoadCacheableAsync<PrinterSettings>(
|
||||
cacheKey,
|
||||
"profiles",
|
||||
publicDevice.CacheKey,
|
||||
cacheScope,
|
||||
async () =>
|
||||
{
|
||||
// The collector specifically returns null to ensure LoadCacheable skips writing the
|
||||
// result to the cache. After this result is returned, it will attempt to load from
|
||||
// the local cache if the collector yielded no result
|
||||
if(File.Exists(cachePath))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
// If the cache file for the current deviceToken does not exist, attempt to download it
|
||||
return await ApplicationController.DownloadPublicProfileAsync(deviceToken);
|
||||
// If the cache file for the current deviceToken does not exist, attempt to download it.
|
||||
// An http 304 results in a null value and LoadCacheable will then load from the cache
|
||||
return await ApplicationController.DownloadPublicProfileAsync(publicDevice.ProfileToken);
|
||||
}
|
||||
},
|
||||
Path.Combine("Profiles",make, model + ProfileManager.ProfileExtension));
|
||||
Path.Combine("Profiles", make, make + ProfileManager.ProfileExtension));
|
||||
}
|
||||
|
||||
public void EnsurePrintersImported()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue