Extended recipe execution logging.

This commit is contained in:
Daniel Stolt
2015-08-03 15:01:33 +01:00
parent 4740283ab2
commit 43922eaf20
24 changed files with 275 additions and 120 deletions

View File

@@ -24,6 +24,7 @@ using Orchard.Packaging.Models;
using Orchard.Packaging.Services; using Orchard.Packaging.Services;
using Orchard.Recipes.Models; using Orchard.Recipes.Models;
using Orchard.Recipes.Providers.Executors; using Orchard.Recipes.Providers.Executors;
using Orchard.Recipes.Services;
using Orchard.Tests.Environment.Extensions; using Orchard.Tests.Environment.Extensions;
using Orchard.Tests.Environment.Features; using Orchard.Tests.Environment.Features;
using Orchard.Tests.Stubs; using Orchard.Tests.Stubs;
@@ -53,6 +54,8 @@ namespace Orchard.Tests.Modules.Recipes.RecipeHandlers {
_packagesInRepository = new StubPackagingSourceManager(); _packagesInRepository = new StubPackagingSourceManager();
_packageManager = new StubPackageManager(); _packageManager = new StubPackageManager();
builder.RegisterInstance(_folders).As<IExtensionFolders>(); builder.RegisterInstance(_folders).As<IExtensionFolders>();
builder.RegisterType<StubWorkContextAccessor>().As<IWorkContextAccessor>();
builder.RegisterType<RecipeExecutionLogger>().AsSelf();
builder.RegisterType<ExtensionManager>().As<IExtensionManager>(); builder.RegisterType<ExtensionManager>().As<IExtensionManager>();
builder.RegisterType<FeatureManager>().As<IFeatureManager>(); builder.RegisterType<FeatureManager>().As<IFeatureManager>();
builder.RegisterType<StubCacheManager>().As<ICacheManager>(); builder.RegisterType<StubCacheManager>().As<ICacheManager>();

View File

@@ -4,6 +4,7 @@ using NUnit.Framework;
using Orchard.Recipes.Models; using Orchard.Recipes.Models;
using Orchard.Recipes.Providers.RecipeHandlers; using Orchard.Recipes.Providers.RecipeHandlers;
using Orchard.Recipes.Services; using Orchard.Recipes.Services;
using Orchard.Tests.Stubs;
namespace Orchard.Tests.Modules.Recipes.RecipeHandlers { namespace Orchard.Tests.Modules.Recipes.RecipeHandlers {
[TestFixture] [TestFixture]
@@ -13,6 +14,8 @@ namespace Orchard.Tests.Modules.Recipes.RecipeHandlers {
[SetUp] [SetUp]
public void Init() { public void Init() {
var builder = new ContainerBuilder(); var builder = new ContainerBuilder();
builder.RegisterType<StubWorkContextAccessor>().As<IWorkContextAccessor>();
builder.RegisterType<RecipeExecutionLogger>().AsSelf();
builder.RegisterType<StubRecipeExecutionStep>().As<IRecipeExecutionStep>().AsSelf().SingleInstance(); builder.RegisterType<StubRecipeExecutionStep>().As<IRecipeExecutionStep>().AsSelf().SingleInstance();
builder.RegisterType<RecipeExecutionStepHandler>().SingleInstance(); builder.RegisterType<RecipeExecutionStepHandler>().SingleInstance();
@@ -37,6 +40,10 @@ namespace Orchard.Tests.Modules.Recipes.RecipeHandlers {
} }
public class StubRecipeExecutionStep : RecipeExecutionStep { public class StubRecipeExecutionStep : RecipeExecutionStep {
public StubRecipeExecutionStep(IWorkContextAccessor workContextAccessor) : base(workContextAccessor) {
}
public override string Name { public override string Name {
get { return "FakeRecipeStep"; } get { return "FakeRecipeStep"; }
} }

View File

@@ -22,6 +22,7 @@ using Orchard.FileSystems.VirtualPath;
using Orchard.Packaging.GalleryServer; using Orchard.Packaging.GalleryServer;
using Orchard.Packaging.Services; using Orchard.Packaging.Services;
using Orchard.Recipes.Models; using Orchard.Recipes.Models;
using Orchard.Recipes.Services;
using Orchard.Tests.DisplayManagement.Descriptors; using Orchard.Tests.DisplayManagement.Descriptors;
using Orchard.Tests.Environment.Extensions; using Orchard.Tests.Environment.Extensions;
using Orchard.Tests.Environment.Features; using Orchard.Tests.Environment.Features;
@@ -56,6 +57,8 @@ namespace Orchard.Tests.Modules.Recipes.RecipeHandlers {
_packagesInRepository = new ModuleStepTest.StubPackagingSourceManager(); _packagesInRepository = new ModuleStepTest.StubPackagingSourceManager();
_packageManager = new ModuleStepTest.StubPackageManager(); _packageManager = new ModuleStepTest.StubPackageManager();
builder.RegisterInstance(_folders).As<IExtensionFolders>(); builder.RegisterInstance(_folders).As<IExtensionFolders>();
builder.RegisterType<StubWorkContextAccessor>().As<IWorkContextAccessor>();
builder.RegisterType<RecipeExecutionLogger>().AsSelf();
builder.RegisterType<ExtensionManager>().As<IExtensionManager>(); builder.RegisterType<ExtensionManager>().As<IExtensionManager>();
builder.RegisterType<FeatureManager>().As<IFeatureManager>(); builder.RegisterType<FeatureManager>().As<IFeatureManager>();
builder.RegisterType<StubCacheManager>().As<ICacheManager>(); builder.RegisterType<StubCacheManager>().As<ICacheManager>();

View File

@@ -1,4 +1,5 @@
using System; using System;
using System.Linq;
using Orchard.AuditTrail.Models; using Orchard.AuditTrail.Models;
using Orchard.ContentManagement; using Orchard.ContentManagement;
using Orchard.Data; using Orchard.Data;
@@ -15,7 +16,11 @@ namespace Orchard.AuditTrail.Recipes.Executors {
private readonly IAuthorizer _authorizer; private readonly IAuthorizer _authorizer;
private readonly IWorkContextAccessor _wca; private readonly IWorkContextAccessor _wca;
public AuditTrailStep(IRepository<AuditTrailEventRecord> auditTrailEventRepository, IAuthorizer authorizer, IWorkContextAccessor wca) { public AuditTrailStep(
IRepository<AuditTrailEventRecord> auditTrailEventRepository,
IAuthorizer authorizer,
IWorkContextAccessor wca) : base(wca) {
_auditTrailEventRepository = auditTrailEventRepository; _auditTrailEventRepository = auditTrailEventRepository;
_authorizer = authorizer; _authorizer = authorizer;
_wca = wca; _wca = wca;
@@ -31,7 +36,12 @@ namespace Orchard.AuditTrail.Recipes.Executors {
return; return;
} }
foreach (var eventElement in context.RecipeStep.Step.Elements()) { var elements = context.RecipeStep.Step.Elements().ToArray();
for (var i = 0; i < elements.Length; i ++) {
var eventElement = elements[i];
Logger.Information("Importing audit trail event {0}/{1}.", i + 1, elements.Length);
try {
var record = new AuditTrailEventRecord { var record = new AuditTrailEventRecord {
EventName = eventElement.Attr<string>("Name"), EventName = eventElement.Attr<string>("Name"),
FullEventName = eventElement.Attr<string>("FullName"), FullEventName = eventElement.Attr<string>("FullName"),
@@ -46,6 +56,11 @@ namespace Orchard.AuditTrail.Recipes.Executors {
_auditTrailEventRepository.Create(record); _auditTrailEventRepository.Create(record);
} }
catch (Exception ex) {
Logger.Error(ex, "Error while importing audit trail event {0}/{1}.", i + 1, elements.Length);
throw;
}
}
} }
} }
} }

View File

@@ -1,28 +1,37 @@
using System; using System;
using System.Linq;
using Orchard.ContentManagement; using Orchard.ContentManagement;
using Orchard.DynamicForms.Models; using Orchard.DynamicForms.Models;
using Orchard.DynamicForms.Services; using Orchard.DynamicForms.Services;
using Orchard.Environment.Extensions; using Orchard.Logging;
using Orchard.Recipes.Models; using Orchard.Recipes.Models;
using Orchard.Recipes.Services; using Orchard.Recipes.Services;
namespace Orchard.DynamicForms.Recipes.Executors { namespace Orchard.DynamicForms.Recipes.Executors {
public class FormSubmissionsStep : RecipeExecutionStep { public class FormSubmissionsStep : RecipeExecutionStep {
private readonly IFormService _formService; private readonly IFormService _formService;
public FormSubmissionsStep(IFormService formService) {
public FormSubmissionsStep(IFormService formService,
IWorkContextAccessor workContextAccessor) : base(workContextAccessor) {
_formService = formService; _formService = formService;
} }
public override string Name { public override string Name {
get { return "Forms"; } get { return "Forms"; }
} }
public override void Execute(RecipeExecutionContext context) {
var formsElement = context.RecipeStep.Step.Elements();
foreach (var formElement in formsElement) {
var formName = formElement.Attr<string>("Name");
var submissionElements = formElement.Element("Submissions").Elements();
foreach (var submissionElement in submissionElements) { public override void Execute(RecipeExecutionContext context) {
var formElements = context.RecipeStep.Step.Elements();
foreach (var formElement in formElements) {
var formName = formElement.Attr<string>("Name");
Logger.Information("Importing form '{0}'.", formName);
try {
var submissionElements = formElement.Element("Submissions").Elements().ToArray();
for (var i = 0; i < submissionElements.Length; i++) {
Logger.Information("Importing form submission {0}/{1}.", i + 1, submissionElements.Length);
var submissionElement = submissionElements[i];
_formService.CreateSubmission(new Submission { _formService.CreateSubmission(new Submission {
FormName = formName, FormName = formName,
CreatedUtc = submissionElement.Attr<DateTime>("CreatedUtc"), CreatedUtc = submissionElement.Attr<DateTime>("CreatedUtc"),
@@ -30,6 +39,11 @@ namespace Orchard.DynamicForms.Recipes.Executors {
}); });
} }
} }
catch (Exception ex) {
Logger.Error(ex, "Error while importing form '{0}'.", formName);
throw;
}
}
} }
} }
} }

View File

@@ -1,6 +1,8 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using Orchard.Data; using Orchard.Data;
using Orchard.Layouts.Models; using Orchard.Layouts.Models;
using Orchard.Logging;
using Orchard.Recipes.Models; using Orchard.Recipes.Models;
using Orchard.Recipes.Services; using Orchard.Recipes.Services;
@@ -8,7 +10,10 @@ namespace Orchard.Layouts.Recipes.Executors {
public class CustomElementsStep : RecipeExecutionStep { public class CustomElementsStep : RecipeExecutionStep {
private readonly IRepository<ElementBlueprint> _repository; private readonly IRepository<ElementBlueprint> _repository;
public CustomElementsStep(IRepository<ElementBlueprint> repository) { public CustomElementsStep(
IRepository<ElementBlueprint> repository,
IWorkContextAccessor workContextAccessor) : base(workContextAccessor) {
_repository = repository; _repository = repository;
} }
@@ -23,14 +28,21 @@ namespace Orchard.Layouts.Recipes.Executors {
public override void Execute(RecipeExecutionContext context) { public override void Execute(RecipeExecutionContext context) {
foreach (var elementElement in context.RecipeStep.Step.Elements()) { foreach (var elementElement in context.RecipeStep.Step.Elements()) {
var typeName = elementElement.Attribute("ElementTypeName").Value; var typeName = elementElement.Attribute("ElementTypeName").Value;
var element = GetOrCreateElement(typeName); Logger.Information("Importing custom element '{0}'.", typeName);
try {
var element = GetOrCreateElement(typeName);
element.BaseElementTypeName = elementElement.Attribute("BaseElementTypeName").Value; element.BaseElementTypeName = elementElement.Attribute("BaseElementTypeName").Value;
element.ElementDisplayName = elementElement.Attribute("ElementDisplayName").Value; element.ElementDisplayName = elementElement.Attribute("ElementDisplayName").Value;
element.ElementDescription = elementElement.Attribute("ElementDescription").Value; element.ElementDescription = elementElement.Attribute("ElementDescription").Value;
element.ElementCategory = elementElement.Attribute("ElementCategory").Value; element.ElementCategory = elementElement.Attribute("ElementCategory").Value;
element.BaseElementState = elementElement.Element("BaseElementState").Value; element.BaseElementState = elementElement.Element("BaseElementState").Value;
} }
catch (Exception ex) {
Logger.Error(ex, "Error while importing custom element '{0}'.", typeName);
throw;
}
}
} }
private ElementBlueprint GetOrCreateElement(string typeName) { private ElementBlueprint GetOrCreateElement(string typeName) {

View File

@@ -10,12 +10,11 @@ namespace Orchard.Modules.Recipes.Executors {
public class FeatureStep : RecipeExecutionStep { public class FeatureStep : RecipeExecutionStep {
private readonly IFeatureManager _featureManager; private readonly IFeatureManager _featureManager;
public FeatureStep(IFeatureManager featureManager) { public FeatureStep(IFeatureManager featureManager, IWorkContextAccessor workContextAccessor) : base(workContextAccessor) {
_featureManager = featureManager; _featureManager = featureManager;
} }
public override string Name public override string Name {
{
get { return "Feature"; } get { return "Feature"; }
} }

View File

@@ -13,7 +13,8 @@ namespace Orchard.Recipes.Providers.Executors {
private readonly ICommandManager _commandManager; private readonly ICommandManager _commandManager;
private readonly CommandParser _commandParser; private readonly CommandParser _commandParser;
public CommandStep(ICommandManager commandManager) { public CommandStep(ICommandManager commandManager,
IWorkContextAccessor workContextAccessor) : base(workContextAccessor) {
_commandManager = commandManager; _commandManager = commandManager;
_commandParser = new CommandParser(); _commandParser = new CommandParser();
} }

View File

@@ -23,7 +23,8 @@ namespace Orchard.Recipes.Providers.Executors {
public ContentDefinitionStep( public ContentDefinitionStep(
IContentDefinitionManager contentDefinitionManager, IContentDefinitionManager contentDefinitionManager,
IContentDefinitionReader contentDefinitionReader, IContentDefinitionReader contentDefinitionReader,
IContentDefinitionEventHandler contentDefinitonEventHandlers) { IContentDefinitionEventHandler contentDefinitonEventHandlers,
IWorkContextAccessor workContextAccessor) : base(workContextAccessor) {
_contentDefinitionManager = contentDefinitionManager; _contentDefinitionManager = contentDefinitionManager;
_contentDefinitionReader = contentDefinitionReader; _contentDefinitionReader = contentDefinitionReader;

View File

@@ -14,7 +14,11 @@ namespace Orchard.Recipes.Providers.Executors {
private readonly IOrchardServices _orchardServices; private readonly IOrchardServices _orchardServices;
private readonly ITransactionManager _transactionManager; private readonly ITransactionManager _transactionManager;
public ContentStep(IOrchardServices orchardServices, ITransactionManager transactionManager) { public ContentStep(
IOrchardServices orchardServices,
ITransactionManager transactionManager,
IWorkContextAccessor workContextAccessor) : base(workContextAccessor) {
_orchardServices = orchardServices; _orchardServices = orchardServices;
_transactionManager = transactionManager; _transactionManager = transactionManager;
BatchSize = 64; BatchSize = 64;
@@ -79,6 +83,7 @@ namespace Orchard.Recipes.Providers.Executors {
// Determine if the import is to be batched in multiple transactions. // Determine if the import is to be batched in multiple transactions.
var startIndex = 0; var startIndex = 0;
var itemIndex = 0;
var batchSize = GetBatchSizeForDataStep(context.RecipeStep.Step); var batchSize = GetBatchSizeForDataStep(context.RecipeStep.Step);
Logger.Debug("Using batch size {0}.", batchSize); Logger.Debug("Using batch size {0}.", batchSize);
@@ -96,7 +101,7 @@ namespace Orchard.Recipes.Providers.Executors {
if (elementDictionary[nextIdentity.ToString()].HasAttributes) { if (elementDictionary[nextIdentity.ToString()].HasAttributes) {
itemId = elementDictionary[nextIdentity.ToString()].FirstAttribute.Value; itemId = elementDictionary[nextIdentity.ToString()].FirstAttribute.Value;
} }
Logger.Information("Importing data item '{0}'.", itemId); Logger.Information("Importing data item '{0}' (item {1}/{2}).", itemId, itemIndex + 1, elementDictionary.Count);
try { try {
_orchardServices.ContentManager.Import( _orchardServices.ContentManager.Import(
elementDictionary[nextIdentity.ToString()], elementDictionary[nextIdentity.ToString()],
@@ -106,6 +111,7 @@ namespace Orchard.Recipes.Providers.Executors {
Logger.Error(ex, "Error while importing data item '{0}'.", itemId); Logger.Error(ex, "Error while importing data item '{0}'.", itemId);
throw; throw;
} }
itemIndex++;
nextIdentity = importContentSession.GetNextInBatch(); nextIdentity = importContentSession.GetNextInBatch();
} }

View File

@@ -10,7 +10,10 @@ namespace Orchard.Recipes.Providers.Executors {
public class MigrationStep : RecipeExecutionStep { public class MigrationStep : RecipeExecutionStep {
private readonly IDataMigrationManager _dataMigrationManager; private readonly IDataMigrationManager _dataMigrationManager;
public MigrationStep(IDataMigrationManager dataMigrationManager) { public MigrationStep(
IDataMigrationManager dataMigrationManager,
IWorkContextAccessor workContextAccessor) : base(workContextAccessor) {
_dataMigrationManager = dataMigrationManager; _dataMigrationManager = dataMigrationManager;
} }

View File

@@ -18,7 +18,8 @@ namespace Orchard.Recipes.Providers.Executors {
public ModuleStep( public ModuleStep(
IPackagingSourceManager packagingSourceManager, IPackagingSourceManager packagingSourceManager,
IPackageManager packageManager, IPackageManager packageManager,
IExtensionManager extensionManager) { IExtensionManager extensionManager,
IWorkContextAccessor workContextAccessor) : base(workContextAccessor) {
_packagingSourceManager = packagingSourceManager; _packagingSourceManager = packagingSourceManager;
_packageManager = packageManager; _packageManager = packageManager;
@@ -47,7 +48,7 @@ namespace Orchard.Recipes.Providers.Executors {
} }
if (packageId == null) { if (packageId == null) {
throw new InvalidOperationException("PackageId is required in a Module declaration in a recipe file."); throw new InvalidOperationException("PackageId is required in a module declaration in a recipe file.");
} }
// download and install module from the orchard feed or a custom feed if repository is specified. // download and install module from the orchard feed or a custom feed if repository is specified.

View File

@@ -19,7 +19,8 @@ namespace Orchard.Recipes.Providers.Executors {
IRecipeHarvester recipeHarvester, IRecipeHarvester recipeHarvester,
IRecipeStepQueue recipeStepQueue, IRecipeStepQueue recipeStepQueue,
IRepository<RecipeStepResultRecord> recipeStepResultRecordRepository, IRepository<RecipeStepResultRecord> recipeStepResultRecordRepository,
ISessionLocator sessionLocator) { ISessionLocator sessionLocator,
IWorkContextAccessor workContextAccessor) : base(workContextAccessor) {
_recipeHarvester = recipeHarvester; _recipeHarvester = recipeHarvester;
_recipeStepQueue = recipeStepQueue; _recipeStepQueue = recipeStepQueue;
@@ -42,20 +43,23 @@ namespace Orchard.Recipes.Providers.Executors {
foreach (var recipeElement in recipeElements) { foreach (var recipeElement in recipeElements) {
var extensionId = recipeElement.Attr("ExtensionId"); var extensionId = recipeElement.Attr("ExtensionId");
var recipeName = recipeElement.Attr("Name"); var recipeName = recipeElement.Attr("Name");
Logger.Information("Executing recipe '{0}' in extension '{1}'.", recipeName, extensionId);
try {
var recipes = recipesDictionary.ContainsKey(extensionId) ? recipesDictionary[extensionId] : default(IDictionary<string, Recipe>); var recipes = recipesDictionary.ContainsKey(extensionId) ? recipesDictionary[extensionId] : default(IDictionary<string, Recipe>);
if (recipes == null)
if (recipes == null) {
recipes = recipesDictionary[extensionId] = HarvestRecipes(extensionId); recipes = recipesDictionary[extensionId] = HarvestRecipes(extensionId);
if (!recipes.ContainsKey(recipeName))
throw new Exception(String.Format("No recipe named '{0}' was found in extension '{1}'.", recipeName, extensionId));
EnqueueRecipe(session, context.ExecutionId, recipes[recipeName]);
} }
catch (Exception ex) {
var recipe = recipes.ContainsKey(recipeName) ? recipes[recipeName] : default(Recipe); Logger.Error(ex, "Error while executing recipe '{0}' in extension '{1}'.", recipeName, extensionId);
throw;
if (recipe == null) {
Logger.Error(String.Format("No recipe named {0} was found for extension {1}", recipeName, extensionId));
continue;
} }
EnqueueRecipe(session, context.ExecutionId, recipe);
} }
} }

View File

@@ -14,7 +14,12 @@ namespace Orchard.Recipes.Providers.Executors {
private readonly IContentManager _contentManager; private readonly IContentManager _contentManager;
private readonly Lazy<IEnumerable<IContentHandler>> _handlers; private readonly Lazy<IEnumerable<IContentHandler>> _handlers;
public SettingsStep(ISiteService siteService, IContentManager contentManager, Lazy<IEnumerable<IContentHandler>> handlers) { public SettingsStep(
ISiteService siteService,
IContentManager contentManager,
Lazy<IEnumerable<IContentHandler>> handlers,
IWorkContextAccessor workContextAccessor) : base(workContextAccessor) {
_siteService = siteService; _siteService = siteService;
_contentManager = contentManager; _contentManager = contentManager;
_handlers = handlers; _handlers = handlers;

View File

@@ -33,7 +33,6 @@ namespace Orchard.Recipes.Services {
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,
@@ -45,16 +44,19 @@ namespace Orchard.Recipes.Services {
public void ExecuteWork(string executionId) { public void ExecuteWork(string executionId) {
ThreadContext.Properties["ExecutionId"] = executionId; ThreadContext.Properties["ExecutionId"] = executionId;
try { try {
Logger.Information("Executing next step of recipe.");
// 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) {
Logger.Information("Scheduling next step of recipe.");
ScheduleWork(executionId); ScheduleWork(executionId);
else }
else {
Logger.Information("All recipe steps executed; restarting shell.");
// https://github.com/OrchardCMS/Orchard/issues/3672 // https://github.com/OrchardCMS/Orchard/issues/3672
// Because recipes execute in their own workcontext, we need to restart the shell, as signaling a cache won't work across workcontexts. // Because recipes execute in their own workcontext, we need to restart the shell, as signaling a cache won't work across workcontexts.
_events.Changed(_shellDescriptorManager.GetShellDescriptor(), _shellSettings.Name); _events.Changed(_shellDescriptorManager.GetShellDescriptor(), _shellSettings.Name);
} }
}
finally { finally {
ThreadContext.Properties["ExecutionId"] = null; ThreadContext.Properties["ExecutionId"] = null;
} }

View File

@@ -28,12 +28,12 @@ namespace Orchard.Recipes.Services {
public bool ExecuteNextStep(string executionId) { public bool ExecuteNextStep(string executionId) {
var nextRecipeStep = _recipeStepQueue.Dequeue(executionId); var nextRecipeStep = _recipeStepQueue.Dequeue(executionId);
if (nextRecipeStep == null) { if (nextRecipeStep == null) {
Logger.Information("Recipe execution completed."); Logger.Information("No more recipe steps left to execute.");
_recipeExecuteEventHandler.ExecutionComplete(executionId); _recipeExecuteEventHandler.ExecutionComplete(executionId);
return false; return false;
} }
Logger.Information("Running all recipe handlers for step '{0}'.", nextRecipeStep.Name); Logger.Information("Executing recipe step '{0}'.", nextRecipeStep.Name);
var recipeContext = new RecipeContext { RecipeStep = nextRecipeStep, Executed = false, ExecutionId = executionId }; var recipeContext = new RecipeContext { RecipeStep = nextRecipeStep, Executed = false, ExecutionId = executionId };

View File

@@ -9,7 +9,10 @@ namespace Orchard.Roles.Recipes.Executors {
public class RolesStep : RecipeExecutionStep { public class RolesStep : RecipeExecutionStep {
private readonly IRoleService _roleService; private readonly IRoleService _roleService;
public RolesStep(IRoleService roleService) { public RolesStep(
IRoleService roleService,
IWorkContextAccessor workContextAccessor) : base(workContextAccessor) {
_roleService = roleService; _roleService = roleService;
} }
@@ -23,7 +26,7 @@ namespace Orchard.Roles.Recipes.Executors {
foreach (var roleElement in context.RecipeStep.Step.Elements()) { foreach (var roleElement in context.RecipeStep.Step.Elements()) {
var roleName = roleElement.Attribute("Name").Value; var roleName = roleElement.Attribute("Name").Value;
Logger.Information("Processing role '{0}'.", roleName); Logger.Information("Importing role '{0}'.", roleName);
try { try {
var role = _roleService.GetRoleByName(roleName); var role = _roleService.GetRoleByName(roleName);
@@ -40,7 +43,7 @@ namespace Orchard.Roles.Recipes.Executors {
_roleService.UpdateRole(role.Id, role.Name, permissionsValid.Union(role.RolesPermissions.Select(p => p.Permission.Name))); _roleService.UpdateRole(role.Id, role.Name, permissionsValid.Union(role.RolesPermissions.Select(p => p.Permission.Name)));
} }
catch (Exception ex) { catch (Exception ex) {
Logger.Error(ex, "Error while processing role '{0}'.", roleName); Logger.Error(ex, "Error while importing role '{0}'.", roleName);
throw; throw;
} }
} }

View File

@@ -1,5 +1,6 @@
using System; using System;
using System.Linq; using System.Linq;
using Orchard.Logging;
using Orchard.Recipes.Models; using Orchard.Recipes.Models;
using Orchard.Recipes.Services; using Orchard.Recipes.Services;
using Orchard.Rules.Models; using Orchard.Rules.Models;
@@ -9,7 +10,10 @@ namespace Orchard.Rules.Recipes.Executors {
public class RulesStep : RecipeExecutionStep { public class RulesStep : RecipeExecutionStep {
private readonly IRulesServices _rulesServices; private readonly IRulesServices _rulesServices;
public RulesStep(IRulesServices rulesServices) { public RulesStep(
IRulesServices rulesServices,
IWorkContextAccessor workContextAccessor) : base(workContextAccessor) {
_rulesServices = rulesServices; _rulesServices = rulesServices;
} }
@@ -19,8 +23,11 @@ namespace Orchard.Rules.Recipes.Executors {
public override void Execute(RecipeExecutionContext context) { public override void Execute(RecipeExecutionContext context) {
foreach (var rule in context.RecipeStep.Step.Elements()) { foreach (var rule in context.RecipeStep.Step.Elements()) {
var ruleName = rule.Attribute("Name").Value;
Logger.Information("Importing rule '{0}'.", ruleName);
var ruleRecord = _rulesServices.CreateRule(rule.Attribute("Name").Value); try {
var ruleRecord = _rulesServices.CreateRule(ruleName);
ruleRecord.Enabled = bool.Parse(rule.Attribute("Enabled").Value); ruleRecord.Enabled = bool.Parse(rule.Attribute("Enabled").Value);
ruleRecord.Actions = rule.Element("Actions").Elements().Select(action => ruleRecord.Actions = rule.Element("Actions").Elements().Select(action =>
@@ -39,7 +46,11 @@ namespace Orchard.Rules.Recipes.Executors {
Parameters = action.Attribute("Parameters").Value, Parameters = action.Attribute("Parameters").Value,
RuleRecord = ruleRecord RuleRecord = ruleRecord
}).ToList(); }).ToList();
}
catch (Exception ex) {
Logger.Error(ex, "Error while importing rule '{0}'.", ruleName);
throw;
}
} }
} }
} }

View File

@@ -1,3 +1,5 @@
using System;
using Orchard.Logging;
using Orchard.Recipes.Models; using Orchard.Recipes.Models;
using Orchard.Recipes.Services; using Orchard.Recipes.Services;
using Orchard.Themes.Services; using Orchard.Themes.Services;
@@ -10,13 +12,21 @@ namespace Orchard.Themes.Recipes.Executors {
get { return "CurrentTheme"; } get { return "CurrentTheme"; }
} }
public CurrentThemeStep(ISiteThemeService siteThemeService) { public CurrentThemeStep(ISiteThemeService siteThemeService, IWorkContextAccessor workContextAccessor) : base(workContextAccessor) {
_siteThemeService = siteThemeService; _siteThemeService = siteThemeService;
} }
public override void Execute(RecipeExecutionContext context) { public override void Execute(RecipeExecutionContext context) {
var themeId = context.RecipeStep.Step.Attribute("id").Value; var themeId = context.RecipeStep.Step.Attribute("id").Value;
Logger.Information("Setting site theme to '{0}'.", themeId);
try {
_siteThemeService.SetSiteTheme(themeId); _siteThemeService.SetSiteTheme(themeId);
} }
catch (Exception ex) {
Logger.Error(ex, "Error while setting site theme to '{0}'.", themeId);
throw;
}
}
} }
} }

View File

@@ -23,7 +23,8 @@ namespace Orchard.Themes.Recipes.Executors {
IPackageManager packageManager, IPackageManager packageManager,
IExtensionManager extensionManager, IExtensionManager extensionManager,
IThemeService themeService, IThemeService themeService,
ISiteThemeService siteThemeService) { ISiteThemeService siteThemeService,
IWorkContextAccessor workContextAccessor) : base(workContextAccessor) {
_packagingSourceManager = packagingSourceManager; _packagingSourceManager = packagingSourceManager;
_packageManager = packageManager; _packageManager = packageManager;

View File

@@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Orchard.Data; using Orchard.Data;
using Orchard.Logging;
using Orchard.Recipes.Models; using Orchard.Recipes.Models;
using Orchard.Recipes.Services; using Orchard.Recipes.Services;
using Orchard.Workflows.Models; using Orchard.Workflows.Models;
@@ -14,7 +15,8 @@ namespace Orchard.Workflows.Recipes.Executors {
public WorkflowsStep( public WorkflowsStep(
IRepository<WorkflowDefinitionRecord> workflowDefinitionRepository, IRepository<WorkflowDefinitionRecord> workflowDefinitionRepository,
IRepository<ActivityRecord> activityRepository, IRepository<ActivityRecord> activityRepository,
IRepository<TransitionRecord> transitionRepository) { IRepository<TransitionRecord> transitionRepository,
IWorkContextAccessor workContextAccessor) : base(workContextAccessor) {
_workflowDefinitionRepository = workflowDefinitionRepository; _workflowDefinitionRepository = workflowDefinitionRepository;
_activityRepository = activityRepository; _activityRepository = activityRepository;
@@ -27,7 +29,11 @@ namespace Orchard.Workflows.Recipes.Executors {
public override void Execute(RecipeExecutionContext context) { public override void Execute(RecipeExecutionContext context) {
foreach (var workflowDefinitionElement in context.RecipeStep.Step.Elements()) { foreach (var workflowDefinitionElement in context.RecipeStep.Step.Elements()) {
var workflowDefinition = GetOrCreateWorkflowDefinition(workflowDefinitionElement.Attribute("Name").Value); var workflowName = workflowDefinitionElement.Attribute("Name").Value;
Logger.Information("Importing workflow '{0}'.", workflowName);
try {
var workflowDefinition = GetOrCreateWorkflowDefinition(workflowName);
var activitiesElement = workflowDefinitionElement.Element("Activities"); var activitiesElement = workflowDefinitionElement.Element("Activities");
var transitionsElement = workflowDefinitionElement.Element("Transitions"); var transitionsElement = workflowDefinitionElement.Element("Transitions");
var activitiesDictionary = new Dictionary<int, ActivityRecord>(); var activitiesDictionary = new Dictionary<int, ActivityRecord>();
@@ -36,8 +42,10 @@ namespace Orchard.Workflows.Recipes.Executors {
foreach (var activityElement in activitiesElement.Elements()) { foreach (var activityElement in activitiesElement.Elements()) {
var localId = Int32.Parse(activityElement.Attribute("Id").Value); var localId = Int32.Parse(activityElement.Attribute("Id").Value);
var activityName = activityElement.Attribute("Name").Value;
Logger.Information("Importing activity '{0}' with ID '{1}'.", activityName, localId);
var activity = new ActivityRecord { var activity = new ActivityRecord {
Name = activityElement.Attribute("Name").Value, Name = activityName,
Start = Boolean.Parse(activityElement.Attribute("Start").Value), Start = Boolean.Parse(activityElement.Attribute("Start").Value),
X = Int32.Parse(activityElement.Attribute("X").Value), X = Int32.Parse(activityElement.Attribute("X").Value),
Y = Int32.Parse(activityElement.Attribute("Y").Value), Y = Int32.Parse(activityElement.Attribute("Y").Value),
@@ -53,6 +61,7 @@ namespace Orchard.Workflows.Recipes.Executors {
var sourceEndpoint = transitionElement.Attribute("SourceEndpoint").Value; var sourceEndpoint = transitionElement.Attribute("SourceEndpoint").Value;
var destinationActivityId = Int32.Parse(transitionElement.Attribute("DestinationActivityId").Value); var destinationActivityId = Int32.Parse(transitionElement.Attribute("DestinationActivityId").Value);
var destinationEndpoint = transitionElement.Attribute("DestinationEndpoint").Value; var destinationEndpoint = transitionElement.Attribute("DestinationEndpoint").Value;
Logger.Information("Importing transition between activities '{0}' and '{1}'.", sourceActivityId, destinationActivityId);
workflowDefinition.TransitionRecords.Add(new TransitionRecord { workflowDefinition.TransitionRecords.Add(new TransitionRecord {
SourceActivityRecord = activitiesDictionary[sourceActivityId], SourceActivityRecord = activitiesDictionary[sourceActivityId],
@@ -62,6 +71,11 @@ namespace Orchard.Workflows.Recipes.Executors {
}); });
} }
} }
catch (Exception ex) {
Logger.Error(ex, "Error while importing workflow '{0}'.", workflowName);
throw;
}
}
} }
private WorkflowDefinitionRecord GetOrCreateWorkflowDefinition(string name) { private WorkflowDefinitionRecord GetOrCreateWorkflowDefinition(string name) {

View File

@@ -165,6 +165,7 @@
<Compile Include="Recipes\Services\RecipeBuilder.cs" /> <Compile Include="Recipes\Services\RecipeBuilder.cs" />
<Compile Include="Recipes\Services\RecipeBuilderStep.cs" /> <Compile Include="Recipes\Services\RecipeBuilderStep.cs" />
<Compile Include="Recipes\Models\RecipeExecutionContext.cs" /> <Compile Include="Recipes\Models\RecipeExecutionContext.cs" />
<Compile Include="Recipes\Services\RecipeExecutionLogger.cs" />
<Compile Include="Recipes\Services\RecipeExecutionStep.cs" /> <Compile Include="Recipes\Services\RecipeExecutionStep.cs" />
<Compile Include="Recipes\Services\RecipeExecutor.cs" /> <Compile Include="Recipes\Services\RecipeExecutor.cs" />
<Compile Include="Recipes\Services\UpdateRecipeExecutionStepContext.cs" /> <Compile Include="Recipes\Services\UpdateRecipeExecutionStepContext.cs" />

View File

@@ -0,0 +1,22 @@
using System;
using Orchard.Logging;
namespace Orchard.Recipes.Services {
public class RecipeExecutionLogger : ITransientDependency, ILogger {
public RecipeExecutionLogger() {
Logger = NullLogger.Instance;
}
public Type ComponentType { get; internal set; }
public ILogger Logger { get; set; }
public bool IsEnabled(LogLevel level) {
return Logger.IsEnabled(level);
}
public void Log(LogLevel level, Exception exception, string format, params object[] args) {
var message = String.Format(format, args);
Logger.Log(level, exception, "{0}: {1}", ComponentType.Name, message);
}
}
}

View File

@@ -1,10 +1,23 @@
using System.Collections.Generic; using System.Collections.Generic;
using Orchard.ContentManagement; using Orchard.ContentManagement;
using Orchard.Localization; using Orchard.Localization;
using Orchard.Logging;
using Orchard.Recipes.Models; using Orchard.Recipes.Models;
namespace Orchard.Recipes.Services { namespace Orchard.Recipes.Services {
public abstract class RecipeExecutionStep : Component, IRecipeExecutionStep { public abstract class RecipeExecutionStep : IDependency, IRecipeExecutionStep {
private readonly IWorkContextAccessor _workContextAccessor;
private readonly RecipeExecutionLogger _logger;
public RecipeExecutionStep(IWorkContextAccessor workContextAccessor) {
_workContextAccessor = workContextAccessor;
_logger = _workContextAccessor.GetContext().Resolve<RecipeExecutionLogger>();
_logger.ComponentType = GetType();
T = NullLocalizer.Instance;
}
public Localizer T { get; set; }
public abstract string Name { get; } public abstract string Name { get; }
public virtual IEnumerable<string> Names { public virtual IEnumerable<string> Names {
@@ -23,6 +36,10 @@ namespace Orchard.Recipes.Services {
get { return GetType().Name; } get { return GetType().Name; }
} }
protected virtual ILogger Logger {
get { return _logger; }
}
public virtual dynamic BuildEditor(dynamic shapeFactory) { public virtual dynamic BuildEditor(dynamic shapeFactory) {
return null; return null;
} }