コード例 #1
0
        private void AddButton(GetChromeDataArgs args, Item libraryItem, RuleContext ruleContext, string click)
        {
            foreach (var scriptItem in libraryItem.Children.ToList())
            {
                if (!RulesUtils.EvaluateRules(scriptItem["ShowRule"], ruleContext))
                {
                    continue;
                }

                if (scriptItem.IsPowerShellLibrary())
                {
                    AddButton(args, scriptItem, ruleContext, click);
                    continue;
                }

                if (scriptItem.IsPowerShellScript())
                {
                    AddButtonsToChromeData(new[]
                    {
                        new WebEditButton
                        {
                            Click   = string.Format(click, scriptItem.ID, scriptItem.Database.Name),
                            Icon    = scriptItem.Appearance.Icon,
                            Tooltip = scriptItem.Name,
                            Header  = scriptItem.Name,
                            Type    = "sticky", // sticky keeps it from being hidden in the 'more' dropdown
                        }
                    }, args);
                }
            }
        }
コード例 #2
0
        public override void Render(HtmlTextWriter output, Ribbon ribbon, Item button, CommandContext context)
        {
            var viewName    = context.Parameters["viewName"];
            var ruleContext = new RuleContext
            {
                Item = context.CustomData as Item
            };

            ruleContext.Parameters["ViewName"] = viewName;

            ShowListViewFeatures features;
            var showShared = Enum.TryParse(context.Parameters["features"] ?? "", out features) &&
                             features.HasFlag(ShowListViewFeatures.SharedExport);

            foreach (
                Item scriptItem in
                ModuleManager.GetFeatureRoots(IntegrationPoints.ReportExportFeature)
                .SelectMany(parent => parent.Children)
                .Where(scriptItem => RulesUtils.EvaluateRulesForView(scriptItem[FieldNames.ShowRule], ruleContext, !showShared)))
            {
                RenderSmallButton(output, ribbon, Control.GetUniqueID("export"),
                                  Translate.Text(scriptItem.DisplayName),
                                  scriptItem[Sitecore.FieldIDs.Icon], scriptItem.Appearance.ShortDescription,
                                  string.Format("export:results(scriptDb={0},scriptID={1})", scriptItem.Database.Name,
                                                scriptItem.ID),
                                  RulesUtils.EvaluateRules(scriptItem[FieldNames.EnableRule], context.CustomData as Item) &&
                                  context.Parameters["ScriptRunning"] == "0",
                                  false);
            }
        }
コード例 #3
0
        public override void Render(HtmlTextWriter output, Ribbon ribbon, Item button, CommandContext context)
        {
            if (!ServiceAuthorizationManager.IsUserAuthorized(WebServiceSettings.ServiceExecution, Context.User.Name))
            {
                return;
            }
            var psButtons = button.GetChildren();

            foreach (Item psButton in psButtons)
            {
                var command  = (psButton.Fields["Click"] ?? psButton.Fields["Command"]).Value;
                var msg      = Message.Parse(this, command);
                var scriptDb = msg.Arguments["scriptDB"];
                var scriptId = msg.Arguments["script"];

                if (string.IsNullOrWhiteSpace(scriptDb) || string.IsNullOrWhiteSpace(scriptId))
                {
                    continue;
                }

                var scriptItem = Factory.GetDatabase(scriptDb).GetItem(scriptId);

                if (!scriptItem.IsPowerShellScript() ||
                    !RulesUtils.EvaluateRules(scriptItem[Templates.Script.Fields.ShowRule], context.Items[0]))
                {
                    continue;
                }

                RenderButton(output, psButton.TemplateID, ribbon, Control.GetUniqueID("script"),
                             Translate.Text(psButton.DisplayName), scriptItem["__Icon"], scriptItem[TemplateFieldIDs.ToolTip],
                             command, RulesUtils.EvaluateRules(scriptItem[Templates.Script.Fields.EnableRule], context.Items[0]), context,
                             psButton.Paths.Path);
            }
        }
コード例 #4
0
        // We override the GetIconDescriptor so a script can be called in it's place.
        protected override GutterIconDescriptor GetIconDescriptor(Item item)
        {
            return(SpeTimer.Measure("gutter script execution", true, () =>
            {
                // The scriptId parameter is configured when we create a new gutter
                // here /sitecore/content/Applications/Content Editor/Gutters
                if (!Parameters.ContainsKey("scriptId"))
                {
                    return null;
                }

                var scriptId = new ID(Parameters["scriptId"]);
                var scriptDb = string.IsNullOrEmpty(Parameters["scriptDb"])
                    ? ApplicationSettings.ScriptLibraryDb
                    : Parameters["scriptId"];

                var db = Factory.GetDatabase(scriptDb);
                var scriptItem = db.GetItem(scriptId);

                // If a script is configured but does not exist or is of a wrong template then do nothing.
                if (scriptItem == null || !scriptItem.IsPowerShellScript() ||
                    string.IsNullOrWhiteSpace(scriptItem[Templates.Script.Fields.ScriptBody]) ||
                    !RulesUtils.EvaluateRules(scriptItem[Templates.Script.Fields.EnableRule], item))
                {
                    return null;
                }

                var featureRoot = ModuleManager.GetItemModule(scriptItem)?
                                  .GetFeatureRoot(IntegrationPoints.ContentEditorGuttersFeature);
                if (!RulesUtils.EvaluateRules(featureRoot?[Templates.ScriptLibrary.Fields.EnableRule], item))
                {
                    return null;
                }

                try
                {
                    // Create a new session for running the script.
                    var session = ScriptSessionManager.GetSession(scriptItem[Templates.Script.Fields.PersistentSessionId],
                                                                  IntegrationPoints.ContentEditorGuttersFeature);

                    // We will need the item variable in the script.
                    session.SetItemLocationContext(item);

                    // Any objects written to the pipeline in the script will be returned.
                    var output = session.ExecuteScriptPart(scriptItem, false);
                    foreach (var result in output)
                    {
                        if (result.GetType() == typeof(GutterIconDescriptor))
                        {
                            return (GutterIconDescriptor)result;
                        }
                    }
                }
                catch (Exception ex)
                {
                    PowerShellLog.Error($"Error while invoking script '{scriptItem?.Paths.Path}' for rendering in Content Editor gutter.", ex);
                }
                return null;
            }));
        }
コード例 #5
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);
                        }
                    }
                }
            }
        }
コード例 #6
0
        protected static IEnumerable <Item> RunEnumeration(string scriptSource, Item item)
        {
            Assert.ArgumentNotNull(scriptSource, "scriptSource");

            scriptSource = scriptSource.Replace("script:", "").Trim();
            var database   = item?.Database ?? Sitecore.Context.ContentDatabase ?? Sitecore.Context.Database;
            var scriptItem = ID.IsID(scriptSource) ? database.GetItem(ID.Parse(scriptSource)) : database.GetItem(scriptSource);

            if (scriptItem == null || !scriptItem.IsPowerShellScript() ||
                string.IsNullOrWhiteSpace(scriptItem[Templates.Script.Fields.ScriptBody]) &&
                !RulesUtils.EvaluateRules(scriptItem[Templates.Script.Fields.EnableRule], item))
            {
                return(new[] { scriptItem ?? item });
            }

            using (var session = ScriptSessionManager.NewSession(ApplicationNames.Default, false))
            {
                if (item != null)
                {
                    session.SetItemLocationContext(item);
                }

                return(session.ExecuteScriptPart(scriptItem, false).Where(i => i is Item).Cast <Item>());
            }
        }
コード例 #7
0
        public void Process(WorkflowPipelineArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
            var processorItem = args.ProcessorItem;

            if (processorItem == null)
            {
                return;
            }
            var actionItem = processorItem.InnerItem;

            var dataItem = args.DataItem;

            if (string.IsNullOrEmpty(actionItem[ScriptItemFieldNames.Script]))
            {
                return;
            }

            var scriptItem = actionItem.Database.GetItem(new ID(actionItem[ScriptItemFieldNames.Script]));

            if (RulesUtils.EvaluateRules(actionItem[ScriptItemFieldNames.EnableRule], dataItem) &&
                RulesUtils.EvaluateRules(scriptItem[ScriptItemFieldNames.EnableRule], dataItem))
            {
                var str = new UrlString(UIUtil.GetUri("control:PowerShellRunner"));
                str.Append("id", dataItem.ID.ToString());
                str.Append("db", dataItem.Database.Name);
                str.Append("lang", dataItem.Language.Name);
                str.Append("ver", dataItem.Version.Number.ToString(CultureInfo.InvariantCulture));
                str.Append("scriptId", scriptItem.ID.ToString());
                str.Append("scriptDb", scriptItem.Database.Name);
                Context.ClientPage.ClientResponse.Broadcast(
                    SheerResponse.ShowModalDialog(str.ToString(), "400", "220", "PowerShell Script Results", false),
                    "Shell");
            }
        }
コード例 #8
0
        public override void Render(HtmlTextWriter output, Ribbon ribbon, Item button, CommandContext context)
        {
            var psButtons = button.GetChildren();

            foreach (Item psButton in psButtons)
            {
                var msg      = Message.Parse(this, psButton["Click"]);
                var scriptDb = msg.Arguments["scriptDB"];
                var scriptId = msg.Arguments["script"];

                if (string.IsNullOrWhiteSpace(scriptDb) || string.IsNullOrWhiteSpace(scriptId))
                {
                    continue;
                }

                var scriptItem = Factory.GetDatabase(scriptDb).GetItem(scriptId);
                if (scriptItem == null || !RulesUtils.EvaluateRules(scriptItem["ShowRule"], context.Items[0]))
                {
                    continue;
                }

                RenderLargeButton(output, ribbon, Control.GetUniqueID("script"),
                                  Translate.Text(scriptItem.DisplayName),
                                  scriptItem["__Icon"], string.Empty,
                                  psButton["Click"],
                                  RulesUtils.EvaluateRules(scriptItem["EnableRule"], context.Items[0]),
                                  false, context);

                return;
            }
        }
コード例 #9
0
        protected void Process(TPipelineArgs args)
        {
            Assert.ArgumentNotNull(args, "args");

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

                foreach (var scriptItem in libraryItem.Children.Where(si => si.IsPowerShellScript() && !string.IsNullOrWhiteSpace(si[Templates.Script.Fields.ScriptBody])))
                {
                    if (!RulesUtils.EvaluateRules(scriptItem[Templates.Script.Fields.EnableRule], scriptItem))
                    {
                        continue;
                    }

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

                        try
                        {
                            session.ExecuteScriptPart(scriptItem, false);
                        }
                        catch (Exception ex)
                        {
                            PowerShellLog.Error(
                                $"Error while executing script in {GetType().FullName} pipeline processor.", ex);
                        }
                    }
                }
            }
        }
コード例 #10
0
        internal static void GetLibraryMenuItems(Item contextItem, List <Control> menuItems, Item parent)
        {
            if (parent == null)
            {
                return;
            }
            foreach (Item scriptItem in parent.Children)
            {
                if (!RulesUtils.EvaluateRules(scriptItem["ShowRule"], contextItem))
                {
                    continue;
                }

                var menuItem = new MenuItem
                {
                    Header   = scriptItem.DisplayName,
                    Icon     = scriptItem.Appearance.Icon,
                    ID       = scriptItem.ID.ToShortID().ToString(),
                    Disabled = !RulesUtils.EvaluateRules(scriptItem["EnableRule"], contextItem)
                };

                if (scriptItem.IsPowerShellScript())
                {
                    if (contextItem != null)
                    {
                        menuItem.Click = string.Format("item:executescript(id={0},db={1},script={2},scriptDb={3})",
                                                       contextItem.ID, contextItem.Database.Name, scriptItem.ID, scriptItem.Database.Name);
                    }
                    else
                    {
                        menuItem.Click = string.Format("item:executescript(script={0},scriptDb={1})",
                                                       scriptItem.ID, scriptItem.Database.Name);
                    }
                }
                else
                {
                    menuItem.Type = MenuItemType.Submenu;
                    if (contextItem != null)
                    {
                        menuItem.Click = string.Format(
                            "item:scriptlibrary(id={0},db={1},scriptPath={2},scriptDB={3},menuItemId={4})",
                            contextItem.ID, contextItem.Database.Name, scriptItem.Paths.Path, scriptItem.Database.Name,
                            menuItem.ID);
                    }
                    else
                    {
                        menuItem.Click = string.Format(
                            "item:scriptlibrary(scriptPath={0},scriptDB={1},menuItemId={2})",
                            scriptItem.Paths.Path, scriptItem.Database.Name, menuItem.ID);
                    }
                }
                menuItems.Add(menuItem);
            }
        }
コード例 #11
0
        public void OnEvent(object sender, EventArgs args)
        {
            Item item      = null;
            var  eventName = EventArgToEventName(args);

            if (args is SitecoreEventArgs)
            {
                var scevent = (SitecoreEventArgs)args;
                item = scevent.Parameters[0] as Item;
            }

            if (String.IsNullOrEmpty(eventName))
            {
                return;
            }

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

            foreach (var root in ModuleManager.GetFeatureRoots(IntegrationPoints.EventHandlersFeature))
            {
                if (!RulesUtils.EvaluateRules(root?[Templates.ScriptLibrary.Fields.EnableRule], item))
                {
                    continue;
                }

                var libraryItem = root?.Paths.GetSubItem(eventName);

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

                using (var session = ScriptSessionManager.NewSession(ApplicationNames.Default, true))
                {
                    session.SetVariable("eventArgs", args);

                    if (item != null)
                    {
                        session.SetItemLocationContext(item);
                    }

                    foreach (var scriptItem in applicableScriptItems)
                    {
                        session.ExecuteScriptPart(scriptItem, true);
                    }
                }
            }
        }
コード例 #12
0
        public void Process(WorkflowPipelineArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
            var processorItem = args.ProcessorItem;

            if (processorItem == null)
            {
                return;
            }
            var actionItem = processorItem.InnerItem;

            var dataItem = args.DataItem;

            if (string.IsNullOrEmpty(actionItem[Templates.ScriptWorkflowAction.Fields.ScriptBody]))
            {
                return;
            }

            var scriptItem = actionItem.Database.GetItem(new ID(actionItem[Templates.ScriptWorkflowAction.Fields.ScriptBody]));

            if (!scriptItem.IsPowerShellScript())
            {
                Context.ClientPage.ClientResponse.Broadcast(SessionElevationErrors.OperationFailedWrongDataTemplate(), "Shell");
                return;
            }

            if (!RulesUtils.EvaluateRules(actionItem[Templates.ScriptWorkflowAction.Fields.EnableRule], dataItem) ||
                !RulesUtils.EvaluateRules(scriptItem[Templates.Script.Fields.ShowRule], dataItem))
            {
                return;
            }

            var str = new UrlString(UIUtil.GetUri("control:PowerShellRunner"));

            str.Append("id", dataItem.ID.ToString());
            str.Append("db", dataItem.Database.Name);
            str.Append("lang", dataItem.Language.Name);
            str.Append("ver", dataItem.Version.Number.ToString(CultureInfo.InvariantCulture));
            str.Append("scriptId", scriptItem.ID.ToString());
            str.Append("scriptDb", scriptItem.Database.Name);

            if (Context.ClientPage.Application != null)
            {
                Context.ClientPage.ClientResponse.Broadcast(SheerResponse.ShowModalDialog(str.ToString(), "400", "220", "PowerShell Script Results", false), "Shell");
            }
            else
            {
                SheerResponse.ShowModalDialog(str.ToString(), "400", "220");
            }
        }
コード例 #13
0
ファイル: ExecuteScriptTask.cs プロジェクト: vsegrad/Console
        public void Update(Item[] items, CommandItem command, ScheduleItem schedule)
        {
            using (var session = ScriptSessionManager.NewSession(ApplicationNames.Default, true))
            {
                foreach (var scriptItem in items.Where(si => si.IsPowerShellScript() && !string.IsNullOrWhiteSpace(si[Templates.Script.Fields.ScriptBody])))
                {
                    if (!RulesUtils.EvaluateRules(scriptItem[Templates.Script.Fields.EnableRule], scriptItem))
                    {
                        continue;
                    }

                    session.SetItemLocationContext(scriptItem);
                    session.ExecuteScriptPart(scriptItem, true);
                }
            }
        }
コード例 #14
0
        private static void ProcessTaskItem(Item item, ScriptSession session)
        {
            var featureRoot = ModuleManager.GetItemModule(item)?
                              .GetFeatureRoot(IntegrationPoints.TasksFeature);

            if (!RulesUtils.EvaluateRules(featureRoot?[Templates.ScriptLibrary.Fields.EnableRule], item))
            {
                return;
            }

            var queue = new Queue <Item>();

            queue.Enqueue(item);

            Item currentItem;

            while (queue.Count > 0 && (currentItem = queue.Dequeue()) != null)
            {
                if (currentItem.IsPowerShellScript())
                {
                    if (string.IsNullOrWhiteSpace(currentItem[Templates.Script.Fields.ScriptBody]))
                    {
                        continue;
                    }
                    if (!RulesUtils.EvaluateRules(currentItem[Templates.Script.Fields.EnableRule], currentItem))
                    {
                        continue;
                    }

                    session.SetItemLocationContext(currentItem);
                    session.ExecuteScriptPart(currentItem, true);
                }
                else if (currentItem.IsPowerShellLibrary() && currentItem.HasChildren)
                {
                    if (!RulesUtils.EvaluateRules(currentItem[Templates.ScriptLibrary.Fields.EnableRule], currentItem))
                    {
                        continue;
                    }

                    var children = currentItem.Children.ToArray();
                    foreach (var child in children)
                    {
                        queue.Enqueue(child);
                    }
                }
            }
        }
コード例 #15
0
        internal static void GetLibraryMenuItems(Item contextItem, List <Control> menuItems, Item parent)
        {
            if (parent == null)
            {
                return;
            }

            if (!ServiceAuthorizationManager.IsUserAuthorized(WebServiceSettings.ServiceExecution, Context.User.Name))
            {
                return;
            }


            foreach (var scriptItem in parent.Children.Where(p => p.IsPowerShellScript() || p.IsPowerShellLibrary()))
            {
                if (!RulesUtils.EvaluateRules(scriptItem[FieldNames.ShowRule], contextItem))
                {
                    continue;
                }

                if (contextItem == null && !RulesUtils.EvaluateRules(scriptItem[FieldNames.ShowRule], scriptItem))
                {
                    continue;
                }

                var menuItem = new MenuItem
                {
                    Header   = scriptItem.DisplayName,
                    Icon     = scriptItem.Appearance.Icon,
                    ID       = scriptItem.ID.ToShortID().ToString(),
                    Disabled = !RulesUtils.EvaluateRules(scriptItem[Templates.Script.Fields.EnableRule], contextItem),
                    ToolTip  = scriptItem.Appearance.ShortDescription
                };
                menuItem.Attributes.Add(FieldIDs.Sortorder.ToString(), scriptItem[FieldIDs.Sortorder]);

                if (scriptItem.IsPowerShellScript())
                {
                    menuItem.Click = contextItem != null ? $"item:executescript(id={contextItem.ID},db={contextItem.Database.Name},script={scriptItem.ID},scriptDb={scriptItem.Database.Name})" : $"item:executescript(script={scriptItem.ID},scriptDb={scriptItem.Database.Name})";
                }
                else
                {
                    menuItem.Type  = MenuItemType.Submenu;
                    menuItem.Click = contextItem != null ? $"item:scriptlibrary(id={contextItem.ID},db={contextItem.Database.Name},scriptPath={scriptItem.Paths.Path},scriptDB={scriptItem.Database.Name},menuItemId={menuItem.ID})" : $"item:scriptlibrary(scriptPath={scriptItem.Paths.Path},scriptDB={scriptItem.Database.Name},menuItemId={menuItem.ID})";
                }
                menuItems.Add(menuItem);
            }
        }
コード例 #16
0
        internal static void GetLibraryMenuItems(Item contextItem, List <Control> menuItems, Item parent)
        {
            if (parent == null)
            {
                return;
            }

            if (!ServiceAuthorizationManager.IsUserAuthorized(WebServiceSettings.ServiceExecution, Context.User.Name,
                                                              false))
            {
                return;
            }


            var scriptTemplateId       = new ID("{DD22F1B3-BD87-4DB2-9E7D-F7A496888D43}");
            var scriptLibaryTemplateId = new ID("{AB154D3D-1126-4AB4-AC21-8B86E6BD70EA}");

            foreach (var scriptItem in parent.Children.Where(p => p.TemplateID == scriptTemplateId || p.TemplateID == scriptLibaryTemplateId))
            {
                if (!RulesUtils.EvaluateRules(scriptItem["ShowRule"], contextItem))
                {
                    continue;
                }

                var menuItem = new MenuItem
                {
                    Header   = scriptItem.DisplayName,
                    Icon     = scriptItem.Appearance.Icon,
                    ID       = scriptItem.ID.ToShortID().ToString(),
                    Disabled = !RulesUtils.EvaluateRules(scriptItem["EnableRule"], contextItem)
                };

                if (scriptItem.IsPowerShellScript())
                {
                    menuItem.Click = contextItem != null ? $"item:executescript(id={contextItem.ID},db={contextItem.Database.Name},script={scriptItem.ID},scriptDb={scriptItem.Database.Name})" : $"item:executescript(script={scriptItem.ID},scriptDb={scriptItem.Database.Name})";
                }
                else
                {
                    menuItem.Type  = MenuItemType.Submenu;
                    menuItem.Click = contextItem != null ? $"item:scriptlibrary(id={contextItem.ID},db={contextItem.Database.Name},scriptPath={scriptItem.Paths.Path},scriptDB={scriptItem.Database.Name},menuItemId={menuItem.ID})" : $"item:scriptlibrary(scriptPath={scriptItem.Paths.Path},scriptDB={scriptItem.Database.Name},menuItemId={menuItem.ID})";
                }
                menuItems.Add(menuItem);
            }
        }
コード例 #17
0
        private void GetMasters(Item parent, GetMastersArgs args)
        {
            foreach (var scriptItem in parent.Children.Where(p => p.IsPowerShellScript() || p.IsPowerShellLibrary()))
            {
                if (!RulesUtils.EvaluateRules(scriptItem[FieldNames.ShowRule], args.Item))
                {
                    continue;
                }

                if (scriptItem.IsPowerShellScript())
                {
                    args.Masters.Add(scriptItem);
                }
                else
                {
                    GetMasters(scriptItem, args);
                }
            }
        }
コード例 #18
0
        public override void Render(HtmlTextWriter output, Ribbon ribbon, Item button, CommandContext context)
        {
            var typeName    = context.Parameters["type"];
            var viewName    = context.Parameters["viewName"];
            var ruleContext = new RuleContext
            {
                Item = context.CustomData as Item
            };

            ruleContext.Parameters["ViewName"] = viewName;

            var showShared = Enum.TryParse(context.Parameters["features"] ?? "", out ShowListViewFeatures features) &&
                             features.HasFlag(ShowListViewFeatures.SharedActions);

            if (string.IsNullOrEmpty(typeName))
            {
                return;
            }

            foreach (
                var scriptItem in
                ModuleManager.GetFeatureRoots(IntegrationPoints.ReportActionFeature)
                .Select(parent => parent.Paths.GetSubItem(typeName))
                .Where(scriptLibrary => scriptLibrary != null)
                .SelectMany(scriptLibrary => scriptLibrary.Children)
                .Where(
                    scriptItem =>
                    RulesUtils.EvaluateRulesForView(scriptItem[FieldNames.ShowRule], ruleContext, !showShared)))
            {
                RenderSmallButton(output, ribbon, Control.GetUniqueID("export"),
                                  Translate.Text(scriptItem.DisplayName),
                                  scriptItem["__Icon"], scriptItem.Appearance.ShortDescription,
                                  $"listview:action(scriptDb={scriptItem.Database.Name},scriptID={scriptItem.ID})",
                                  RulesUtils.EvaluateRules(scriptItem[FieldNames.EnableRule], ruleContext) &&
                                  context.Parameters["ScriptRunning"] == "0",
                                  false);
            }
        }
        public void Process(WorkflowPipelineArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
            ProcessorItem processorItem = args.ProcessorItem;

            if (processorItem != null)
            {
                Item innerItem = processorItem.InnerItem;
                Item dataItem  = args.DataItem;
                if (!string.IsNullOrEmpty(innerItem[Templates.ScriptWorkflowAction.Fields.ScriptBody]))
                {
                    Item item = innerItem.Database.GetItem(new ID(innerItem[Templates.ScriptWorkflowAction.Fields.ScriptBody]));
                    if (!ItemExtensions.IsPowerShellScript(item))
                    {
                        Context.ClientPage.ClientResponse.Broadcast(SessionElevationErrors.OperationFailedWrongDataTemplate(), "Shell");
                    }
                    else if ((!RulesUtils.EvaluateRules(innerItem[Templates.ScriptWorkflowAction.Fields.EnableRule], dataItem, false) ? false : RulesUtils.EvaluateRules(item[Templates.Script.Fields.ShowRule], dataItem, false)))
                    {
                        UrlString urlString = new UrlString(UIUtil.GetUri("control:PowerShellRunner"));
                        urlString.Append("id", dataItem.ID.ToString());
                        urlString.Append("db", dataItem.Database.Name);
                        urlString.Append("lang", dataItem.Language.Name);
                        int number = dataItem.Version.Number;
                        urlString.Append("ver", number.ToString(CultureInfo.InvariantCulture));
                        urlString.Append("scriptId", item.ID.ToString());
                        urlString.Append("scriptDb", item.Database.Name);
                        if (Context.ClientPage.Application == null)
                        {
                            SheerResponse.ShowModalDialog(urlString.ToString(), "400", "220");
                        }
                        else
                        {
                            Context.ClientPage.ClientResponse.Broadcast(SheerResponse.ShowModalDialog(urlString.ToString(), "400", "220", "PowerShell Script Results", false), "Shell");
                        }
                    }
                }
            }
        }
コード例 #20
0
        public override void Render(HtmlTextWriter output, Ribbon ribbon, Item button, CommandContext context)
        {
            var contextChunks = context.CustomData as List <Item>;

            if (contextChunks != null)
            {
                var chunk = contextChunks[0];
                contextChunks.RemoveAt(0);
                var psButtons   = chunk.Children;
                var contextItem = context.Items.Length > 0 ? context.Items[0] : null;

                var ruleContext = new RuleContext
                {
                    Item = contextItem
                };
                foreach (var parameter in context.Parameters.AllKeys)
                {
                    ruleContext.Parameters[parameter] = context.Parameters[parameter];
                }

                foreach (Item psButton in psButtons)
                {
                    if (!RulesUtils.EvaluateRules(psButton[FieldNames.ShowRule], ruleContext))
                    {
                        continue;
                    }

                    RenderLargeButton(output, ribbon, Control.GetUniqueID("script"),
                                      Translate.Text(psButton.DisplayName),
                                      psButton[Sitecore.FieldIDs.Icon], string.Empty,
                                      $"ise:runplugin(scriptDb={psButton.Database.Name},scriptId={psButton.ID})",
                                      context.Parameters["ScriptRunning"] == "0" && RulesUtils.EvaluateRules(psButton[FieldNames.EnableRule], ruleContext),
                                      false, context);
                }
            }
        }