/// <summary> /// Loads the specified PrinterProfile, performing recovery options if required /// </summary> /// <param name="profileID">The profile ID to load</param> /// <param name="useActiveInstance">Return the in memory instance if already loaded. Alternatively, reload from disk</param> /// <returns></returns> public static async Task <PrinterSettings> LoadProfileAsync(string profileID, bool useActiveInstance = true) { var activePrinter = ApplicationController.Instance.ActivePrinter; if (useActiveInstance && activePrinter.Settings.ID == profileID) { return(activePrinter.Settings); } // Only load profiles by ID that are defined in the profiles document var printerInfo = Instance[profileID]; if (printerInfo == null) { return(null); } // Attempt to load from disk, pull from the web or fall back using recovery logic PrinterSettings printerSettings = Instance.LoadWithoutRecovery(profileID); if (printerSettings != null) { // Make sure we have the name set if (printerSettings.GetValue(SettingsKey.printer_name) == "") { // This can happen when a profile is pushed to a user account from the web. printerSettings.SetValue(SettingsKey.printer_name, printerInfo.Name); } return(printerSettings); } else if (ApplicationController.GetPrinterProfileAsync != null) { // Attempt to load from MCWS if missing on disk printerSettings = await ApplicationController.GetPrinterProfileAsync(printerInfo, null); if (printerSettings != null) { // If successful, persist downloaded profile and return printerSettings.Save(); return(printerSettings); } } // Otherwise attempt to recover to a working profile return(await PrinterSettings.RecoverProfile(printerInfo)); }
/// <summary> /// Loads the specified PrinterProfile, performing recovery options if required /// </summary> /// <param name="profileID">The profile ID to load</param> /// <param name="useActiveInstance">Return the in memory instance if already loaded. Alternatively, reload from disk</param> /// <returns></returns> public static async Task <PrinterSettings> LoadProfileAsync(string profileID, bool useActiveInstance = true) { if (useActiveInstance && ActiveSliceSettings.Instance?.ID == profileID) { return(ActiveSliceSettings.Instance); } // Only load profiles by ID that are defined in the profiles document var printerInfo = ProfileManager.Instance[profileID]; if (printerInfo == null) { return(null); } // Attempt to load from disk, pull from the web or fall back using recovery logic PrinterSettings printerSettings = LoadWithoutRecovery(profileID); if (printerSettings != null) { return(printerSettings); } else if (ApplicationController.GetPrinterProfileAsync != null) { // Attempt to load from MCWS if missing on disk printerSettings = await ApplicationController.GetPrinterProfileAsync(printerInfo, null); if (printerSettings != null) { // If successful, persist downloaded profile and return printerSettings.Save(); return(printerSettings); } } // Otherwise attempt to recover to a working profile return(await PrinterSettings.RecoverProfile(printerInfo)); }