public void Executed(RecipeExecuteContentContext context)
        {
            var properties = new Dictionary<string, object> {
                {"Content", context.ContentItem as IContent}
            };

            var metaData = _contentManager.GetItemMetadata(context.ContentItem);
            var eventData = new Dictionary<string, object> {
                {"ContentId", context.ContentItem.Id},
                {"ContentIdentity", metaData.Identity.ToString()},
                {"ContentType", context.ContentItem.ContentType},
                {"VersionId", context.ContentItem.Version},
                {"VersionNumber", context.ContentItem.VersionRecord != null ? context.ContentItem.VersionRecord.Number : 0},
                {"Published", context.ContentItem.VersionRecord != null && context.ContentItem.VersionRecord.Published},
                {"Title", metaData.DisplayText},
                {"Tenants", string.Join(",", context.TenantNames.ToArray())}
            };

            _auditTrailManager.CreateRecord<RecipeAuditTrailEventProvider>(
                RecipeAuditTrailEventProvider.Executed,
                _wca.GetContext().CurrentUser,
                properties,
                eventData,
                eventFilterKey: "content",
                eventFilterData: context.ContentItem.Id.ToString(CultureInfo.InvariantCulture));
        }
Ejemplo n.º 2
0
        public ActionResult ExecutePOST(int id, string moduleId, string name, IEnumerable<string> tenantNames)
        {
            if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not allowed to execute recipes")))
                return new HttpUnauthorizedResult();

            var recipe = _mainBitRecipeManager.Get(id);

            if (recipe == null)
            {
                return HttpNotFound();
            }

            foreach (var tenantName in tenantNames)
            {
                var tenantWorkContext = _tenantWorkContextAccessor.GetContext(tenantName);
                var tenantRecipeManager = tenantWorkContext.Resolve<Orchard.Recipes.Services.IRecipeManager>();

                try
                {
                    tenantRecipeManager.Execute(recipe.Recipe);
                }
                catch (Exception e)
                {
                    Logger.Error(e, "Error while executing recipe {0} in {1} - in tenant {2}", moduleId, name, tenantName);
                    Services.Notifier.Error(T("Recipes contains {0} unsupported module installation steps.", recipe.Recipe.Name));
                }
            }

            var recipeExecuteContentContext = new RecipeExecuteContentContext(recipe.ContentItem, tenantNames);
            _recipeEventHandler.Executed(recipeExecuteContentContext);

            Services.Notifier.Information(T("The recipe {0} was executed successfully.", recipe.Recipe.Name));

            return RedirectToAction("Execute", new { id, moduleId, name });
        }