/// <summary>
        /// Creates and displays the page editor notification
        /// </summary>
        /// <param name="arguments"></param>
        public override void Process(GetPageEditorNotificationsArgs arguments)
        {
            Assert.ArgumentNotNull(arguments, "arguments");
            if (arguments.ContextItem == null)
            {
                return;
            }

            Log.Info($"Sauron Page Editor Notification service called", this.GetType());

            var contextItem  = arguments.ContextItem;
            var templateName = contextItem.TemplateName;
            var templateId   = contextItem.TemplateID;
            var helpText     = PageEditorNotificationsService.GetPageEditorNotification(templateId);
            var intro        = Settings.GetSetting("SauronPageInfoIntro");

            if (!string.IsNullOrEmpty(helpText))
            {
                Log.Info($"Getting Sauron Page Editor Notification for template: {templateId}", this.GetType());

                //add page editor notification
                //var pageEditorNotificationType = new PageEditorNotificationType(); //TODO: ideally we would set a custom type here and make the view aware of it
                var notification = new PageEditorNotification($"<div class=\"sauron-page-editor-notification\">{string.Format(intro, templateName)}{helpText}</div>", (PageEditorNotificationType)ExtendedPageEditorNotificationType.Information);
                arguments.Notifications.Add(notification);
            }
        }
Example #2
0
        public void Process(GetPageEditorNotificationsArgs args)
        {
            Assert.ArgumentNotNull(args, "args");

            foreach (var libraryItem in ModuleManager.GetFeatureRoots(IntegrationPoint))
            {
                if (!libraryItem.HasChildren)
                {
                    return;
                }

                foreach (var scriptItem in libraryItem.Children.ToList())
                {
                    using (var session = ScriptSessionManager.NewSession(ApplicationNames.Default, true))
                    {
                        session.SetVariable("pipelineArgs", args);

                        try
                        {
                            session.SetItemLocationContext(args.ContextItem);
                            session.ExecuteScriptPart(scriptItem, false);
                        }
                        catch (Exception ex)
                        {
                            LogUtils.Error(ex.Message, this);
                        }
                    }
                }
            }
        }
Example #3
0
        public void Process(GetPageEditorNotificationsArgs args)
        {
            Assert.ArgumentNotNull(args, "args");

            Func <Item, bool> filter = si => si.IsPowerShellScript() &&
                                       !string.IsNullOrWhiteSpace(si[Templates.Script.Fields.ScriptBody]) &&
                                       RulesUtils.EvaluateRules(si[Templates.Script.Fields.EnableRule], args.ContextItem);

            foreach (var libraryItem in ModuleManager.GetFeatureRoots(IntegrationPoint))
            {
                var applicableScriptItems = libraryItem?.Children?.Where(filter).ToArray();
                if (applicableScriptItems == null || !applicableScriptItems.Any())
                {
                    return;
                }

                foreach (var scriptItem in applicableScriptItems)
                {
                    using (var session = ScriptSessionManager.NewSession(ApplicationNames.Default, true))
                    {
                        session.SetVariable("pipelineArgs", args);

                        try
                        {
                            session.SetItemLocationContext(args.ContextItem);
                            session.ExecuteScriptPart(scriptItem, false);
                        }
                        catch (Exception ex)
                        {
                            PowerShellLog.Error($"Error while invoking script '{scriptItem?.Paths.Path}' in Page Editor Notification pipeline.", ex);
                        }
                    }
                }
            }
        }
Example #4
0
        public override void Process(GetPageEditorNotificationsArgs arguments)
        {
            Assert.ArgumentNotNull((object)arguments, "arguments");
            var contextItem      = arguments.ContextItem;
            var database         = contextItem.Database;
            var workflowProvider = database.WorkflowProvider;

            if (workflowProvider == null)
            {
                return;
            }
            var workflow = workflowProvider.GetWorkflow(contextItem);

            if (workflow == null)
            {
                return;
            }
            WorkflowState state = workflow.GetState(contextItem);

            if (state == null)
            {
                return;
            }

            var repository = new WorxboxItemsRepository(workflow);

            var worxBoxIcon = "/~/icon/worxbox/32x32/worxbox.png";
            var displayIcon =
                $"<span><img src='{worxBoxIcon}'  style='vertical-align:middle; padding-right: 1px;'/></span>";

            using (new LanguageSwitcher(WebUtility.ClientLanguage))
            {
                string description        = GetDescription(workflow, state, database);
                string icon               = state.Icon;
                var    editorNotification = new PageEditorNotification(description, PageEditorNotificationType.Information)
                {
                    Icon = icon
                };
                var commands = WorkflowFilterer.FilterVisibleCommands(workflow.GetCommands(contextItem), contextItem);
                if (CanShowCommands(contextItem, commands))
                {
                    foreach (WorkflowCommand command in commands)
                    {
                        var notificationOption = new PageEditorNotificationOption(command.DisplayName, new WorkflowCommandBuilder(contextItem, workflow, command).ToString());
                        editorNotification.Options.Add(notificationOption);
                    }
                    editorNotification.Options.Add(new PageEditorNotificationOption("|", ""));
                    foreach (WorkflowCommand command in commands)
                    {
                        if (repository.IsWorxboxItem(state, new DataUri(contextItem.Uri)) &&
                            repository.GetWorkflowCommandIDs().Contains(ID.Parse(command.CommandID)))
                        {
                            var notificationOption = new PageEditorNotificationOption(displayIcon + command.DisplayName, new WorxBoxWorkflowCommandBuilder(contextItem, workflow, command).ToString());
                            editorNotification.Options.Add(notificationOption);
                        }
                    }
                }
                arguments.Notifications.Add(editorNotification);
            }
        }
        public void Process(GetPageEditorNotificationsArgs args)
        {
            Assert.ArgumentNotNull(args, "args");

            foreach (var libraryItem in ModuleManager.GetFeatureRoots(IntegrationPoint))
            {
                if (!libraryItem.HasChildren) return;

                foreach (var scriptItem in libraryItem.Children.ToList())
                {
                    using (var session = ScriptSessionManager.NewSession(ApplicationNames.Default, true))
                    {
                        session.SetVariable("pipelineArgs", args);

                        try
                        {
                            session.SetItemLocationContext(args.ContextItem);
                            session.ExecuteScriptPart(scriptItem, false);
                        }
                        catch (Exception ex)
                        {
                            Log.Error(ex.Message, this);
                        }
                    }
                }
            }
        }
 public void GetNotifications(GetPageEditorNotificationsArgs arguments)
 {
     if (arguments == null) return;
     var wfModel = new ItemWorkflowModel(arguments.ContextItem);
     if (wfModel.ShowNotification)
     {
         SetNotification(arguments, wfModel);
     }
 }
 public override void Process(GetPageEditorNotificationsArgs arguments)
 {
     Assert.ArgumentNotNull(arguments, "arguments");
     if (arguments.ContextItem == null) return;
     foreach (var dataSourceArguments in arguments.ContextItem.GetAllUniqueDataSourceItems().Select(ds => new GetPageEditorNotificationsArgs(ds)))
     {
         GetNotifications(dataSourceArguments);
         arguments.Notifications.AddRange(dataSourceArguments.Notifications);
     }
 }
Example #8
0
        public void Process(GetPageEditorNotificationsArgs args)
        {
            Item contextItem = args.ContextItem;

            if (contextItem.IsProjectItem())
            {
                string command = string.Format("Sitecore Project: This item is part of the '{0}' project", contextItem.ProjectTitle());
                PageEditorNotification editorNotification = new PageEditorNotification(command, PageEditorNotificationType.Information);
                args.Notifications.Add(editorNotification);
            }
        }
Example #9
0
        public void GetNotifications(GetPageEditorNotificationsArgs arguments)
        {
            if (arguments == null)
            {
                return;
            }
            var wfModel = new ItemWorkflowModel(arguments.ContextItem);

            if (wfModel.ShowNotification)
            {
                SetNotification(arguments, wfModel);
            }
        }
Example #10
0
 public override void Process(GetPageEditorNotificationsArgs arguments)
 {
     Assert.ArgumentNotNull(arguments, "arguments");
     if (arguments.ContextItem == null)
     {
         return;
     }
     foreach (var dataSourceArguments in arguments.ContextItem.GetAllUniqueDataSourceItems().Select(ds => new GetPageEditorNotificationsArgs(ds)))
     {
         GetNotifications(dataSourceArguments);
         arguments.Notifications.AddRange(dataSourceArguments.Notifications);
     }
 }
 private void SetNotification(GetPageEditorNotificationsArgs arguments, ItemWorkflowModel wfModel)
 {
     var editorNotification = new PageEditorNotification(wfModel.GetEditorDescription(), PageEditorNotificationType.Warning)
     {
         Icon = wfModel.WorkflowState.Icon
     };
     if (wfModel.HasWriteAccess())
     {
         foreach (var notificationOption in wfModel.Commands.Select(command => new PageEditorNotificationOption(command.DisplayName, new WorkflowCommandBuilder(wfModel.ContextItem, wfModel.Workflow, command).ToString())))
         {
             editorNotification.Options.Add(notificationOption);
         }
     }
     arguments.Notifications.Add(editorNotification);
 }
Example #12
0
        private void SetNotification(GetPageEditorNotificationsArgs arguments, ItemWorkflowModel wfModel)
        {
            var editorNotification = new PageEditorNotification(wfModel.GetEditorDescription(), PageEditorNotificationType.Warning)
            {
                Icon = wfModel.WorkflowState.Icon
            };

            if (wfModel.HasWriteAccess())
            {
                foreach (var notificationOption in wfModel.Commands.Select(command => new PageEditorNotificationOption(command.DisplayName, new WorkflowCommandBuilder(wfModel.ContextItem, wfModel.Workflow, command).ToString())))
                {
                    editorNotification.Options.Add(notificationOption);
                }
            }
            arguments.Notifications.Add(editorNotification);
        }
Example #13
0
        public override void Process(GetPageEditorNotificationsArgs arguments)
        {
            Assert.ArgumentNotNull(arguments, "arguments");
            if (arguments.ContextItem == null || Sitecore.Context.User.IsAdministrator)
            {
                return;
            }

            NotificationsController       controller    = new NotificationsController();
            List <PageEditorNotification> notifications = controller.GetPageEditorNotifications(arguments.ContextItem);

            if (notifications.Count > 0)
            {
                for (int i = 0; i < notifications.Count; i++)
                {
                    arguments.Notifications.Add(notifications[i]);
                }
            }
        }