/// <summary> /// Attempt to load from file /// </summary> public static async Task <(bool IsSuccess, Recipe Result)> TryLoadRecipeFromFileAsync(Path recipeFile) { // Verify the requested file exists Log.Diag("Load Recipe: " + recipeFile.ToString()); if (!System.IO.File.Exists(recipeFile.ToString())) { Log.Info("Recipe file does not exist."); return(false, new Recipe()); } // Open the file to read from using (var fileStream = System.IO.File.OpenRead(recipeFile.ToString())) using (var reader = new System.IO.StreamReader(fileStream)) { // Read the contents of the recipe file try { var result = ValueTableTomlUtilities.Deserialize( recipeFile, await reader.ReadToEndAsync()); return(true, new Recipe(result)); } catch (Exception ex) { Log.Error($"Deserialize Threw: {ex.Message}"); Log.Info("Failed to parse Recipe."); return(false, new Recipe()); } } }
/// <summary> /// Attempt to load from file /// </summary> public static async Task <(bool IsSuccess, LocalUserConfig Result)> TryLoadLocalUserConfigFromFileAsync( Path localUserConfigFile) { // Verify the requested file exists Log.Diag("Load Local User Config: " + localUserConfigFile.ToString()); if (!LifetimeManager.Get <IFileSystem>().Exists(localUserConfigFile)) { Log.Warning("Local User Config file does not exist."); return(false, new LocalUserConfig()); } // Open the file to read from var file = LifetimeManager.Get <IFileSystem>().OpenRead(localUserConfigFile); // Open the file to read from using (var reader = new System.IO.StreamReader(file.GetInStream())) { // Read the contents of the local user config file try { var result = ValueTableTomlUtilities.Deserialize( localUserConfigFile, await reader.ReadToEndAsync()); return(true, new LocalUserConfig(result)); } catch (Exception ex) { Log.Error("Deserialize Threw: " + ex.Message); Log.Info("Failed to parse local user config."); return(false, new LocalUserConfig()); } } }