/// <summary> /// Save the config to file /// </summary> public static async Task SaveToFileAsync( Path configFile, LocalUserConfig config) { // Ensure the parent folder exists var folder = configFile.GetParent(); if (!LifetimeManager.Get <IFileSystem>().Exists(folder)) { Log.Info($"Creating directory {folder}"); LifetimeManager.Get <IFileSystem>().CreateDirectory2(folder); } // Open the file to write to var file = LifetimeManager.Get <IFileSystem>().OpenWrite(configFile, true); // Serialize the contents of the recipe var documentSyntax = config.MirrorSyntax; if (documentSyntax == null) { throw new ArgumentException("The provided config does not have a mirrored syntax tree.", nameof(config)); } // Write the recipe to the file stream await ValueTableTomlUtilities.SerializeAsync(documentSyntax, file.GetOutStream()); }
/// <summary> /// Save the recipe to file /// </summary> public static async Task SaveToFileAsync( Path recipeFile, Recipe recipe) { // Open the file to write to var file = LifetimeManager.Get <IFileSystem>().OpenWrite(recipeFile, true); // Serialize the contents of the recipe var documentSyntax = recipe.MirrorSyntax; if (documentSyntax == null) { throw new ArgumentException("The provided recipe does not have a mirrored syntax tree.", nameof(recipe)); } // Write the recipe to the file stream await ValueTableTomlUtilities.SerializeAsync(documentSyntax, file.GetOutStream()); }