mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Improved logging in recipe components.
This commit is contained in:
@@ -31,20 +31,19 @@ namespace Orchard.Recipes.Services {
|
|||||||
|
|
||||||
public IEnumerable<Recipe> HarvestRecipes(string extensionId) {
|
public IEnumerable<Recipe> HarvestRecipes(string extensionId) {
|
||||||
var recipes = new List<Recipe>();
|
var recipes = new List<Recipe>();
|
||||||
|
|
||||||
var extension = _extensionManager.GetExtension(extensionId);
|
var extension = _extensionManager.GetExtension(extensionId);
|
||||||
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);
|
||||||
|
|
||||||
recipeFiles.Where(r => r.EndsWith(".recipe.xml", StringComparison.OrdinalIgnoreCase)).ToList().ForEach(r => {
|
recipeFiles.Where(r => r.EndsWith(".recipe.xml", StringComparison.OrdinalIgnoreCase)).ToList().ForEach(r => {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
recipes.Add(_recipeParser.ParseRecipe(_webSiteFolder.ReadFile(r)));
|
recipes.Add(_recipeParser.ParseRecipe(_webSiteFolder.ReadFile(r)));
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
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);
|
Logger.Error(ex, "Error while parsing recipe file '{0}'.", r);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
@@ -19,64 +19,58 @@ namespace Orchard.Recipes.Services {
|
|||||||
public Recipe ParseRecipe(string recipeText) {
|
public Recipe ParseRecipe(string recipeText) {
|
||||||
var recipe = new Recipe();
|
var recipe = new Recipe();
|
||||||
|
|
||||||
try {
|
if (string.IsNullOrEmpty(recipeText)) {
|
||||||
|
throw new Exception("Recipe is empty");
|
||||||
|
}
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(recipeText)) {
|
XElement recipeTree = XElement.Parse(recipeText, LoadOptions.PreserveWhitespace);
|
||||||
throw new Exception("Recipe is empty");
|
|
||||||
}
|
|
||||||
|
|
||||||
XElement recipeTree = XElement.Parse(recipeText, LoadOptions.PreserveWhitespace);
|
var recipeSteps = new List<RecipeStep>();
|
||||||
|
|
||||||
var recipeSteps = new List<RecipeStep>();
|
foreach (var element in recipeTree.Elements()) {
|
||||||
|
// Recipe metadata
|
||||||
foreach (var element in recipeTree.Elements()) {
|
if (element.Name.LocalName == "Recipe") {
|
||||||
// Recipe mETaDaTA
|
foreach (var metadataElement in element.Elements()) {
|
||||||
if (element.Name.LocalName == "Recipe") {
|
switch (metadataElement.Name.LocalName) {
|
||||||
foreach (var metadataElement in element.Elements()) {
|
case "Name":
|
||||||
switch (metadataElement.Name.LocalName) {
|
recipe.Name = metadataElement.Value;
|
||||||
case "Name":
|
break;
|
||||||
recipe.Name = metadataElement.Value;
|
case "Description":
|
||||||
break;
|
recipe.Description = metadataElement.Value;
|
||||||
case "Description":
|
break;
|
||||||
recipe.Description = metadataElement.Value;
|
case "Author":
|
||||||
break;
|
recipe.Author = metadataElement.Value;
|
||||||
case "Author":
|
break;
|
||||||
recipe.Author = metadataElement.Value;
|
case "WebSite":
|
||||||
break;
|
recipe.WebSite = metadataElement.Value;
|
||||||
case "WebSite":
|
break;
|
||||||
recipe.WebSite = metadataElement.Value;
|
case "Version":
|
||||||
break;
|
recipe.Version = metadataElement.Value;
|
||||||
case "Version":
|
break;
|
||||||
recipe.Version = metadataElement.Value;
|
case "IsSetupRecipe":
|
||||||
break;
|
recipe.IsSetupRecipe = !string.IsNullOrEmpty(metadataElement.Value) ? bool.Parse(metadataElement.Value) : false;
|
||||||
case "IsSetupRecipe":
|
break;
|
||||||
recipe.IsSetupRecipe = !string.IsNullOrEmpty(metadataElement.Value) ? bool.Parse(metadataElement.Value) : false;
|
case "ExportUtc":
|
||||||
break;
|
recipe.ExportUtc = !string.IsNullOrEmpty(metadataElement.Value) ? (DateTime?)XmlConvert.ToDateTime(metadataElement.Value, XmlDateTimeSerializationMode.Utc) : null;
|
||||||
case "ExportUtc":
|
break;
|
||||||
recipe.ExportUtc = !string.IsNullOrEmpty(metadataElement.Value) ? (DateTime?)XmlConvert.ToDateTime(metadataElement.Value, XmlDateTimeSerializationMode.Utc) : null;
|
case "Tags":
|
||||||
break;
|
recipe.Tags = metadataElement.Value;
|
||||||
case "Tags":
|
break;
|
||||||
recipe.Tags = metadataElement.Value;
|
default:
|
||||||
break;
|
Logger.Warning("Unrecognized recipe metadata element '{0}' encountered; skipping.", metadataElement.Name.LocalName);
|
||||||
default:
|
break;
|
||||||
Logger.Error("Unrecognized recipe metadata element {0} encountered. Skipping.", metadataElement.Name.LocalName);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Recipe step
|
|
||||||
else {
|
|
||||||
var recipeStep = new RecipeStep { Name = element.Name.LocalName, Step = element };
|
|
||||||
recipeSteps.Add(recipeStep);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
recipe.RecipeSteps = recipeSteps;
|
// Recipe step
|
||||||
}
|
else {
|
||||||
catch (Exception exception) {
|
var recipeStep = new RecipeStep { Name = element.Name.LocalName, Step = element };
|
||||||
Logger.Error(exception, "Parsing recipe failed. Recipe text was: {0}.", recipeText);
|
recipeSteps.Add(recipeStep);
|
||||||
throw;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
recipe.RecipeSteps = recipeSteps;
|
||||||
|
|
||||||
return recipe;
|
return recipe;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||||||
using Orchard.Environment.Configuration;
|
using Orchard.Environment.Configuration;
|
||||||
using Orchard.Environment.Descriptor;
|
using Orchard.Environment.Descriptor;
|
||||||
using Orchard.Environment.State;
|
using Orchard.Environment.State;
|
||||||
|
using Orchard.Logging;
|
||||||
using Orchard.Recipes.Events;
|
using Orchard.Recipes.Events;
|
||||||
|
|
||||||
namespace Orchard.Recipes.Services {
|
namespace Orchard.Recipes.Services {
|
||||||
@@ -17,16 +18,21 @@ namespace Orchard.Recipes.Services {
|
|||||||
IProcessingEngine processingEngine,
|
IProcessingEngine processingEngine,
|
||||||
ShellSettings shellSettings,
|
ShellSettings shellSettings,
|
||||||
IShellDescriptorManager shellDescriptorManager,
|
IShellDescriptorManager shellDescriptorManager,
|
||||||
Lazy<IRecipeStepExecutor> recipeStepExecutor, IShellDescriptorManagerEventHandler events) {
|
Lazy<IRecipeStepExecutor> recipeStepExecutor,
|
||||||
|
IShellDescriptorManagerEventHandler events) {
|
||||||
_processingEngine = processingEngine;
|
_processingEngine = processingEngine;
|
||||||
_shellSettings = shellSettings;
|
_shellSettings = shellSettings;
|
||||||
_shellDescriptorManager = shellDescriptorManager;
|
_shellDescriptorManager = shellDescriptorManager;
|
||||||
_recipeStepExecutor = recipeStepExecutor;
|
_recipeStepExecutor = recipeStepExecutor;
|
||||||
_events = events;
|
_events = events;
|
||||||
|
Logger = NullLogger.Instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ILogger Logger;
|
||||||
|
|
||||||
public void ScheduleWork(string executionId) {
|
public void ScheduleWork(string executionId) {
|
||||||
var shellDescriptor = _shellDescriptorManager.GetShellDescriptor();
|
var shellDescriptor = _shellDescriptorManager.GetShellDescriptor();
|
||||||
|
Logger.Information("Scheduling execution of recipe {0}.", executionId);
|
||||||
// TODO: this task entry may need to become appdata folder backed if it isn't already
|
// TODO: this task entry may need to become appdata folder backed if it isn't already
|
||||||
_processingEngine.AddTask(
|
_processingEngine.AddTask(
|
||||||
_shellSettings,
|
_shellSettings,
|
||||||
@@ -36,6 +42,7 @@ namespace Orchard.Recipes.Services {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void ExecuteWork(string executionId) {
|
public void ExecuteWork(string executionId) {
|
||||||
|
Logger.Information("Executing next step of recipe {0}.", executionId);
|
||||||
// todo: this callback should be guarded against concurrency by the IProcessingEngine
|
// todo: this callback should be guarded against concurrency by the IProcessingEngine
|
||||||
var scheduleMore = _recipeStepExecutor.Value.ExecuteNextStep(executionId);
|
var scheduleMore = _recipeStepExecutor.Value.ExecuteNextStep(executionId);
|
||||||
if (scheduleMore)
|
if (scheduleMore)
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ namespace Orchard.Recipes.Services {
|
|||||||
public ILogger Logger { get; set; }
|
public ILogger Logger { get; set; }
|
||||||
|
|
||||||
public void Enqueue(string executionId, RecipeStep step) {
|
public void Enqueue(string executionId, RecipeStep step) {
|
||||||
|
Logger.Information("Enqueuing step '{0}' for recipe {1}.", step.Name, executionId);
|
||||||
var recipeStepElement = new XElement("RecipeStep");
|
var recipeStepElement = new XElement("RecipeStep");
|
||||||
recipeStepElement.Add(new XElement("Name", step.Name));
|
recipeStepElement.Add(new XElement("Name", step.Name));
|
||||||
recipeStepElement.Add(step.Step);
|
recipeStepElement.Add(step.Step);
|
||||||
@@ -40,6 +41,7 @@ namespace Orchard.Recipes.Services {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public RecipeStep Dequeue(string executionId) {
|
public RecipeStep Dequeue(string executionId) {
|
||||||
|
Logger.Information("Dequeuing steps for recipe {0}.", executionId);
|
||||||
if (!_appDataFolder.DirectoryExists(Path.Combine(_recipeQueueFolder, executionId))) {
|
if (!_appDataFolder.DirectoryExists(Path.Combine(_recipeQueueFolder, executionId))) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -50,6 +52,7 @@ namespace Orchard.Recipes.Services {
|
|||||||
// string to xelement
|
// string to xelement
|
||||||
var stepElement = XElement.Parse(_appDataFolder.ReadFile(stepPath));
|
var stepElement = XElement.Parse(_appDataFolder.ReadFile(stepPath));
|
||||||
var stepName = stepElement.Element("Name").Value;
|
var stepName = stepElement.Element("Name").Value;
|
||||||
|
Logger.Information("Dequeuing step '{0}' for recipe {1}.", stepName, executionId);
|
||||||
recipeStep = new RecipeStep {
|
recipeStep = new RecipeStep {
|
||||||
Name = stepName,
|
Name = stepName,
|
||||||
Step = stepElement.Element(stepName)
|
Step = stepElement.Element(stepName)
|
||||||
|
|||||||
Reference in New Issue
Block a user