mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Added logging for invalid recipe files
This commit is contained in:
@@ -136,8 +136,8 @@ namespace Orchard.Tests.Modules.Recipes.Services {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void ParseRecipeThrowsOnInvalidXml() {
|
public void ParseRecipeReturnsNullOnInvalidXml() {
|
||||||
Assert.Throws(typeof(XmlException), () => _recipeParser.ParseRecipe("<reipe></recipe>"));
|
Assert.That(_recipeParser.ParseRecipe("<reipe></recipe>") == null);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
|||||||
@@ -133,6 +133,7 @@ namespace Orchard.Modules.Controllers {
|
|||||||
Module = x,
|
Module = x,
|
||||||
Recipes = _recipeHarvester.HarvestRecipes(x.Descriptor.Id).Where(recipe => !recipe.IsSetupRecipe).ToList()
|
Recipes = _recipeHarvester.HarvestRecipes(x.Descriptor.Id).Where(recipe => !recipe.IsSetupRecipe).ToList()
|
||||||
})
|
})
|
||||||
|
.ToList()
|
||||||
.Where(x => x.Recipes.Any());
|
.Where(x => x.Recipes.Any());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,10 +35,20 @@ namespace Orchard.Recipes.Services {
|
|||||||
if (extension != null) {
|
if (extension != null) {
|
||||||
var recipeLocation = Path.Combine(extension.Location, extensionId, "Recipes");
|
var recipeLocation = Path.Combine(extension.Location, extensionId, "Recipes");
|
||||||
var recipeFiles = _webSiteFolder.ListFiles(recipeLocation, true);
|
var recipeFiles = _webSiteFolder.ListFiles(recipeLocation, true);
|
||||||
recipes.AddRange(
|
|
||||||
from recipeFile in recipeFiles
|
recipeFiles.Where(r => r.EndsWith(".recipe.xml", StringComparison.OrdinalIgnoreCase)).ToList().ForEach(r =>
|
||||||
where recipeFile.EndsWith(".recipe.xml", StringComparison.OrdinalIgnoreCase)
|
{
|
||||||
select _recipeParser.ParseRecipe(_webSiteFolder.ReadFile(recipeFile)));
|
var recipe = _recipeParser.ParseRecipe(_webSiteFolder.ReadFile(r));
|
||||||
|
|
||||||
|
if (recipe == null)
|
||||||
|
{
|
||||||
|
Logger.Error(new Exception(string.Format("Invalid recipe file: {0}", r)), "Invalid recipe file: {0}", r);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
recipes.Add(recipe);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Logger.Error("Could not discover recipes because module '{0}' was not found.", extensionId);
|
Logger.Error("Could not discover recipes because module '{0}' was not found.", extensionId);
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
using Orchard.Localization;
|
using Orchard.Localization;
|
||||||
@@ -21,10 +20,23 @@ namespace Orchard.Recipes.Services {
|
|||||||
var recipe = new Recipe();
|
var recipe = new Recipe();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
if (string.IsNullOrEmpty(recipeText))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
XElement recipeTree;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
recipeTree = XElement.Parse(recipeText, LoadOptions.PreserveWhitespace);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
var recipeSteps = new List<RecipeStep>();
|
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()) {
|
foreach (var element in recipeTree.Elements()) {
|
||||||
// Recipe mETaDaTA
|
// Recipe mETaDaTA
|
||||||
|
|||||||
Reference in New Issue
Block a user