Improved recipe logging to give a trail of executed tasks

This commit is contained in:
Rob King
2015-06-09 15:59:44 +01:00
parent 3d25ca42c9
commit a0279f2d9c
7 changed files with 37 additions and 6 deletions

View File

@@ -13,9 +13,11 @@ namespace Orchard.Recipes.RecipeHandlers {
public class CommandRecipeHandler : IRecipeHandler {
private readonly ICommandManager _commandManager;
private readonly CommandParser _commandParser;
private readonly IRecipeJournal _recipeJournal;
public CommandRecipeHandler (ICommandManager commandManager) {
public CommandRecipeHandler(ICommandManager commandManager, IRecipeJournal recipeJournal) {
_commandManager = commandManager;
_recipeJournal = recipeJournal;
_commandParser = new CommandParser();
Logger = NullLogger.Instance;
T = NullLocalizer.Instance;
@@ -44,6 +46,9 @@ namespace Orchard.Recipes.RecipeHandlers {
foreach (var command in commands) {
if (!String.IsNullOrEmpty(command)) {
if (!String.IsNullOrEmpty(recipeContext.ExecutionId)) {
_recipeJournal.WriteJournalEntry(recipeContext.ExecutionId, string.Format("Commands: Executing item {0}.", command));
}
var commandParameters = _commandParser.ParseCommandParameters(command);
var input = new StringReader("");
var output = new StringWriter();

View File

@@ -12,10 +12,12 @@ namespace Orchard.Recipes.RecipeHandlers {
public class DataRecipeHandler : IRecipeHandler {
private readonly IOrchardServices _orchardServices;
private readonly ITransactionManager _transactionManager;
private readonly IRecipeJournal _recipeJournal;
public DataRecipeHandler(IOrchardServices orchardServices, ITransactionManager transactionManager) {
public DataRecipeHandler(IOrchardServices orchardServices, ITransactionManager transactionManager, IRecipeJournal recipeJournal) {
_orchardServices = orchardServices;
_transactionManager = transactionManager;
_recipeJournal = recipeJournal;
Logger = NullLogger.Instance;
T = NullLocalizer.Instance;
}
@@ -53,6 +55,10 @@ namespace Orchard.Recipes.RecipeHandlers {
//so that dependencies can be managed within the same transaction
var nextIdentity = importContentSession.GetNextInBatch();
while (nextIdentity != null) {
if (!string.IsNullOrEmpty(recipeContext.ExecutionId) && elementDictionary[nextIdentity.ToString()].HasAttributes) {
var itemId = elementDictionary[nextIdentity.ToString()].FirstAttribute.Value;
_recipeJournal.WriteJournalEntry(recipeContext.ExecutionId, string.Format("Data: Importing {0}.", itemId));
}
_orchardServices.ContentManager.Import(
elementDictionary[nextIdentity.ToString()],
importContentSession);

View File

@@ -17,14 +17,17 @@ namespace Orchard.Recipes.RecipeHandlers {
private readonly IPackagingSourceManager _packagingSourceManager;
private readonly IPackageManager _packageManager;
private readonly IExtensionManager _extensionManager;
private readonly IRecipeJournal _recipeJournal;
public ModuleRecipeHandler(
IPackagingSourceManager packagingSourceManager,
IPackageManager packageManager,
IExtensionManager extensionManager) {
IExtensionManager extensionManager,
IRecipeJournal recipeJournal) {
_packagingSourceManager = packagingSourceManager;
_packageManager = packageManager;
_extensionManager = extensionManager;
_recipeJournal = recipeJournal;
Logger = NullLogger.Instance;
T = NullLocalizer.Instance;
@@ -87,6 +90,9 @@ namespace Orchard.Recipes.RecipeHandlers {
if (packagingEntry != null) {
if (!ModuleAlreadyInstalled(packagingEntry.PackageId)) {
if (!string.IsNullOrEmpty(recipeContext.ExecutionId)) {
_recipeJournal.WriteJournalEntry(recipeContext.ExecutionId, string.Format("Installing module: {0}.", packagingEntry.Title));
}
_packageManager.Install(packagingEntry.PackageId, packagingEntry.Version, packagingSource.FeedUrl, HostingEnvironment.MapPath("~/"));
}
installed = true;

View File

@@ -16,11 +16,13 @@ namespace Orchard.Recipes.RecipeHandlers {
private readonly ISiteService _siteService;
private readonly IContentManager _contentManager;
private readonly Lazy<IEnumerable<IContentHandler>> _handlers;
private readonly IRecipeJournal _recipeJournal;
public SettingsRecipeHandler(ISiteService siteService, IContentManager contentManager, Lazy<IEnumerable<IContentHandler>> handlers) {
public SettingsRecipeHandler(ISiteService siteService, IContentManager contentManager, Lazy<IEnumerable<IContentHandler>> handlers, IRecipeJournal recipeJournal) {
_siteService = siteService;
_contentManager = contentManager;
_handlers = handlers;
_recipeJournal = recipeJournal;
Logger = NullLogger.Instance;
T = NullLocalizer.Instance;
}
@@ -56,6 +58,10 @@ namespace Orchard.Recipes.RecipeHandlers {
continue;
}
if (!string.IsNullOrEmpty(recipeContext.ExecutionId)) {
_recipeJournal.WriteJournalEntry(recipeContext.ExecutionId, string.Format("Setting: {0}.", contentPart.PartDefinition.Name));
}
ImportSettingPart(contentPart, partElement);
}

View File

@@ -34,7 +34,7 @@ namespace Orchard.Recipes.Services {
return false;
}
_recipeJournal.WriteJournalEntry(executionId, string.Format("Executing step {0}.", nextRecipeStep.Name));
var recipeContext = new RecipeContext { RecipeStep = nextRecipeStep, Executed = false };
var recipeContext = new RecipeContext { RecipeStep = nextRecipeStep, Executed = false, ExecutionId = executionId };
try {
_recipeExecuteEventHandler.RecipeStepExecuting(executionId, recipeContext);
foreach (var recipeHandler in _recipeHandlers) {

View File

@@ -14,13 +14,16 @@ namespace Orchard.Roles.ImportExport {
private readonly IRoleService _roleService;
private readonly IRepository<RoleRecord> _roleRecordRepository;
private readonly IRepository<PermissionRecord> _permissionRepository;
private readonly IRecipeJournal _recipeJournal;
public RolesRecipeHandler(IRoleService roleService,
IRepository<RoleRecord> roleRecordRepository,
IRepository<PermissionRecord> permissionRepository) {
IRepository<PermissionRecord> permissionRepository,
IRecipeJournal recipeJournal) {
_roleService = roleService;
_roleRecordRepository = roleRecordRepository;
_permissionRepository = permissionRepository;
_recipeJournal = recipeJournal;
Logger = NullLogger.Instance;
T = NullLocalizer.Instance;
}
@@ -38,6 +41,10 @@ namespace Orchard.Roles.ImportExport {
foreach (var roleElement in recipeContext.RecipeStep.Step.Elements()) {
var roleName = roleElement.Attribute("Name").Value;
if (string.IsNullOrEmpty(recipeContext.ExecutionId)) {
_recipeJournal.WriteJournalEntry(recipeContext.ExecutionId, string.Format("Roles: Executing item {0}.", roleName));
}
var role = _roleService.GetRoleByName(roleName);
if (role == null) {
_roleService.CreateRole(roleName);

View File

@@ -2,5 +2,6 @@
public class RecipeContext {
public RecipeStep RecipeStep { get; set; }
public bool Executed { get; set; }
public string ExecutionId { get; set; }
}
}