Merge pull request #5344 from gcsuk/5342

Added logging for invalid recipe files
This commit is contained in:
Sébastien Ros
2015-06-04 13:10:38 -07:00
3 changed files with 20 additions and 9 deletions

View File

@@ -133,7 +133,8 @@ namespace Orchard.Modules.Controllers {
Module = x,
Recipes = _recipeHarvester.HarvestRecipes(x.Descriptor.Id).Where(recipe => !recipe.IsSetupRecipe).ToList()
})
.Where(x => x.Recipes.Any());
.Where(x => x.Recipes.Any())
.ToList();
}
return View(viewModel);

View File

@@ -35,10 +35,17 @@ namespace Orchard.Recipes.Services {
if (extension != null) {
var recipeLocation = Path.Combine(extension.Location, extensionId, "Recipes");
var recipeFiles = _webSiteFolder.ListFiles(recipeLocation, true);
recipes.AddRange(
from recipeFile in recipeFiles
where recipeFile.EndsWith(".recipe.xml", StringComparison.OrdinalIgnoreCase)
select _recipeParser.ParseRecipe(_webSiteFolder.ReadFile(recipeFile)));
recipeFiles.Where(r => r.EndsWith(".recipe.xml", StringComparison.OrdinalIgnoreCase)).ToList().ForEach(r => {
try {
recipes.Add(_recipeParser.ParseRecipe(_webSiteFolder.ReadFile(r)));
}
catch (Exception ex) {
Logger.Error(new Exception(string.Format("Invalid recipe file: {0}\nError: {1}", r, ex.Message)), "Invalid recipe file: {0}\nError: {1}", r, ex.Message);
}
});
}
else {
Logger.Error("Could not discover recipes because module '{0}' was not found.", extensionId);

View File

@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Xml;
using System.Xml.Linq;
using Orchard.Localization;
@@ -21,10 +20,14 @@ namespace Orchard.Recipes.Services {
var recipe = new Recipe();
try {
if (string.IsNullOrEmpty(recipeText)) {
throw new Exception("Recipe is empty");
}
XElement recipeTree = XElement.Parse(recipeText, LoadOptions.PreserveWhitespace);
var recipeSteps = new List<RecipeStep>();
TextReader textReader = new StringReader(recipeText);
var recipeTree = XElement.Load(textReader, LoadOptions.PreserveWhitespace);
textReader.Close();
foreach (var element in recipeTree.Elements()) {
// Recipe mETaDaTA