private void Jump(object sender, Message message, int offset) { string control = Context.ClientPage.ClientRequest.Control; string workflowID = ShortID.Decode(control.Substring(0, 0x20)); string stateID = ShortID.Decode(control.Substring(0x21, 0x20)); control = control.Substring(0, 0x41); IWorkflowProvider workflowProvider = Context.ContentDatabase.WorkflowProvider; Error.Assert(workflowProvider != null, "Workflow provider for database \"" + Context.ContentDatabase.Name + "\" not found."); IWorkflow workflow = workflowProvider.GetWorkflow(workflowID); Error.Assert(workflow != null, "Workflow \"" + workflowID + "\" not found."); Assert.IsNotNull(workflow, "workflow"); WorkflowState state = workflow.GetState(stateID); Error.Assert(state != null, "Workflow state \"" + stateID + "\" not found."); Border border = new Border { ID = control + "_content" }; DataUri[] items = this.GetItems(state, workflow); this.DisplayState(workflow, state, items, border, offset, this.PageSize); Context.ClientPage.ClientResponse.SetOuterHtml(control + "_content", border); }
public override void Process(GetPageEditorNotificationsArgs arguments) { Assert.ArgumentNotNull((object)arguments, "arguments"); Item contextItem = arguments.ContextItem; Database database = contextItem.Database; IWorkflowProvider workflowProvider = database.WorkflowProvider; if (workflowProvider == null) { return; } IWorkflow 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>"; string description = GetDescription(workflow, state, database); string icon = state.Icon; PageEditorNotification editorNotification = new PageEditorNotification(description, PageEditorNotificationType.Information) { Icon = icon }; var commands = WorkflowFilterer.FilterVisibleCommands(workflow.GetCommands(contextItem)); foreach (WorkflowCommand filterVisibleCommand in commands) { PageEditorNotificationOption notificationOption = new PageEditorNotificationOption(filterVisibleCommand.DisplayName, new WorkflowCommandBuilder(contextItem, workflow, filterVisibleCommand).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 IWorkflowProvider GetProvider(Workflow workflow) { IWorkflowProvider retVal = null; App app = Configuration.GetInstance().App; WorkflowType workflowType = workflow.GetWorkflowType(); if (workflowType != null) { if (this.Providers.ContainsKey(workflowType.Name)) { //get cached data command provider retVal = this.Providers[workflowType.Name]; } else { string assemblyName = workflowType.Assembly; string className = workflowType.Class; if (!String.IsNullOrEmpty(assemblyName) && !String.IsNullOrEmpty(className)) { try { Assembly providerAssembly = Assembly.Load(assemblyName); if (providerAssembly != null) { Type type = providerAssembly.GetType(className, true, true); if (type != null) { ConstructorInfo constructor = type.GetConstructor(Type.EmptyTypes); retVal = constructor.Invoke(null) as IWorkflowProvider; retVal.Initialize(workflowType.Settings); this.Providers.Add(workflowType.Name, retVal); } } } catch { //silent error } } } } if (retVal == null) { throw new Exception(String.Format("No valid workflow provider was found")); } return(retVal); }
private void SendSelected(Message message) { IWorkflowProvider workflowProvider = Context.ContentDatabase.WorkflowProvider; if (workflowProvider != null) { string workflowID = message["wf"]; string str2 = message["ws"]; IWorkflow workflow = workflowProvider.GetWorkflow(workflowID); if (workflow != null) { int num = 0; bool flag = false; foreach (string str3 in Context.ClientPage.ClientRequest.Form.Keys) { if ((str3 != null) && str3.StartsWith("check_")) { string str4 = "hidden_" + str3.Substring(6); string[] strArray = Context.ClientPage.ClientRequest.Form[str4].Split(new char[] { ',' }); Item item = Context.ContentDatabase.Items[strArray[0], Language.Parse(strArray[1]), Version.Parse(strArray[2])]; if (item != null) { WorkflowState state = workflow.GetState(item); if (state.StateID == str2) { try { workflow.Execute(message["command"], item, state.DisplayName, true, new object[0]); } catch (WorkflowStateMissingException) { flag = true; } num++; } } } } if (flag) { SheerResponse.Alert("One or more items could not be processed because their workflow state does not specify the next step.", new string[0]); } if (num == 0) { Context.ClientPage.ClientResponse.Alert("There are no selected items."); } else { Context.ClientPage.ClientResponse.SetLocation(string.Empty); } } } }
private static bool CheckWorkflow(ClientPipelineArgs args, Item item) { Assert.ArgumentNotNull((object)args, "args"); Assert.ArgumentNotNull((object)item, "item"); if (args.Parameters["workflow"] == "1") { return(true); } args.Parameters["workflow"] = "1"; if (args.IsPostBack) { if (args.Result == "yes") { args.IsPostBack = false; return(true); } args.AbortPipeline(); return(false); } SiteContext site = Factory.GetSite("publisher"); if (site != null && !site.EnableWorkflow) { return(true); } IWorkflowProvider workflowProvider = Context.ContentDatabase.WorkflowProvider; if (workflowProvider == null || workflowProvider.GetWorkflows().Length <= 0) { return(true); } IWorkflow workflow = workflowProvider.GetWorkflow(item); if (workflow == null) { return(true); } WorkflowState state = workflow.GetState(item); if (state == null || state.FinalState) { return(true); } args.Parameters["workflow"] = "0"; if (state.PreviewPublishingTargets.Any <string>()) { return(true); } SheerResponse.Confirm(Translate.Text("The current item \"{0}\" is in the workflow state \"{1}\"\nand will not be published.\n\nAre you sure you want to publish?", (object)item.DisplayName, (object)state.DisplayName)); args.WaitForPostBack(); return(false); }
/// <summary>Gets the icon.</summary> /// <param name="item">The item.</param> /// <returns>The icon.</returns> protected override GutterIconDescriptor GetIconDescriptor(Item item) { Assert.ArgumentNotNull((object)item, nameof(item)); string str1 = item[FieldIDs.Workflow]; string str2 = item[FieldIDs.WorkflowState]; if (!Settings.Workflows.Enabled || !item.Access.CanWrite()) { return((GutterIconDescriptor)null); } if (string.IsNullOrEmpty(str1) || string.IsNullOrEmpty(str2)) { return((GutterIconDescriptor)null); } IWorkflowProvider workflowProvider = item.Database.WorkflowProvider; if (workflowProvider == null) { return((GutterIconDescriptor)null); } IWorkflow workflow = workflowProvider.GetWorkflow(item); if (workflow == null) { return((GutterIconDescriptor)null); } Sitecore.Workflows.WorkflowState state = workflow.GetState(item); if (state == null) { return((GutterIconDescriptor)null); } if (state.FinalState) { return((GutterIconDescriptor)null); } GutterIconDescriptor gutterIconDescriptor = new GutterIconDescriptor(); gutterIconDescriptor.Icon = state.Icon; gutterIconDescriptor.Tooltip = state.DisplayName; WorkflowCommand[] workflowCommandArray = WorkflowFilterer.FilterVisibleCommands(workflow.GetCommands(item), item); if (workflowCommandArray != null && workflowCommandArray.Length != 0) { //Modify the event subscribed to the gutterIconDescriptor to call custom command, found at ExtendedShowWorkflowCommands.cs gutterIconDescriptor.Click = "ss:extendedshowworkflowcommands(id=" + (object)item.ID + ",language=" + (object)item.Language + ",version=" + (object)item.Version + ",database=" + item.Database.Name + ")"; } return(gutterIconDescriptor); }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (!Context.ClientPage.IsEvent) { IWorkflowProvider workflowProvider = Context.ContentDatabase.WorkflowProvider; if (workflowProvider != null) { foreach (IWorkflow workflow in workflowProvider.GetWorkflows()) { this.DisplayWorkflow(workflow); } } this.UpdateRibbon(); } this.WireUpNavigators(Context.ClientPage); }
public ItemWorkflowModel(Item i) { if (i != null) { _contextItem = i; _database = i.Database; if (_database != null) { _workflowProvider = _database.WorkflowProvider; if (_workflowProvider != null) { _workflow = _workflowProvider.GetWorkflow(ContextItem); if (_workflow != null) { _workflowState = _workflow.GetState(ContextItem); } } } } }
protected void OnViewMenuClick() { Menu control = new Menu(); IWorkflowProvider workflowProvider = Context.ContentDatabase.WorkflowProvider; if (workflowProvider != null) { foreach (IWorkflow workflow in workflowProvider.GetWorkflows()) { string paneID = this.GetPaneID(workflow); string str2 = Registry.GetString("/Current_User/Panes/" + paneID); control.Add(Control.GetUniqueID("ctl"), workflow.Appearance.DisplayName, workflow.Appearance.Icon, string.Empty, ((str2 != "hidden") ? "workbox:hide" : "workbox:show") + "(id=" + paneID + ")", str2 != "hidden", string.Empty, MenuItemType.Check); } if (control.Controls.Count > 0) { control.AddDivider(); } control.Add("Refresh", "Applications/16x16/refresh.png", "Refresh"); } Context.ClientPage.ClientResponse.ShowPopup("ViewMenu", "below", control); }
/// <summary>Gets the commands.</summary> /// <param name="items">The items to get commands for.</param> /// <param name="workflow">The workflow.</param> /// <param name="commands">The commands.</param> private static void GetCommands(Item[] items, out IWorkflow workflow, out WorkflowCommand[] commands) { Assert.ArgumentNotNull((object)items, "items"); Item obj = items[0]; if (obj != null) { IWorkflowProvider workflowProvider = Context.ContentDatabase.WorkflowProvider; if (workflowProvider != null && workflowProvider.GetWorkflows().Length > 0) { workflow = workflowProvider.GetWorkflow(obj); if (workflow != null && workflow.GetState(obj) != null) { commands = WorkflowFilterer.FilterVisibleCommands(workflow.GetCommands(obj), obj); return; } } } workflow = (IWorkflow)null; commands = (WorkflowCommand[])null; }
private void SendAll(Message message) { IWorkflowProvider workflowProvider = Context.ContentDatabase.WorkflowProvider; if (workflowProvider != null) { string workflowID = message["wf"]; string stateID = message["ws"]; IWorkflow workflow = workflowProvider.GetWorkflow(workflowID); if (workflow != null) { WorkflowState state = workflow.GetState(stateID); DataUri[] items = this.GetItems(state, workflow); string comments = (state != null) ? state.DisplayName : string.Empty; bool flag = false; foreach (DataUri uri in items) { Item item = Context.ContentDatabase.Items[uri]; if (item != null) { try { workflow.Execute(message["command"], item, comments, true, new object[0]); } catch (WorkflowStateMissingException) { flag = true; } } } if (flag) { SheerResponse.Alert("One or more items could not be processed because their workflow state does not specify the next step.", new string[0]); } Context.ClientPage.ClientResponse.SetLocation(string.Empty); } } }
private void Send(Message message) { IWorkflowProvider workflowProvider = Context.ContentDatabase.WorkflowProvider; if (workflowProvider != null) { string workflowID = message["wf"]; IWorkflow workflow = workflowProvider.GetWorkflow(workflowID); if (workflow != null) { Item item = Context.ContentDatabase.Items[message["id"], Language.Parse(message["la"]), Version.Parse(message["vs"])]; if (item != null) { if ((message["ui"] != "1") && !(message["suppresscomment"] == "1")) { Context.ClientPage.ServerProperties["id"] = message["id"]; Context.ClientPage.ServerProperties["language"] = message["la"]; Context.ClientPage.ServerProperties["version"] = message["vs"]; Context.ClientPage.ServerProperties["command"] = message["command"]; Context.ClientPage.ServerProperties["workflowid"] = workflowID; Context.ClientPage.Start(this, "Comment"); } else { try { workflow.Execute(message["command"], item, string.Empty, true, new object[0]); } catch (WorkflowStateMissingException) { SheerResponse.Alert("One or more items could not be processed because their workflow state does not specify the next step.", new string[0]); } Context.ClientPage.ClientResponse.SetLocation(string.Empty); } } } } }
// Methods public void Comment(ClientPipelineArgs args) { if (!args.IsPostBack) { Context.ClientPage.ClientResponse.Input("Enter a comment:", string.Empty); args.WaitForPostBack(); } else if (args.Result.Length > 0x7d0) { Context.ClientPage.ClientResponse.ShowError(new Exception(string.Format("The comment is too long.\n\nYou have entered {0} characters.\nA comment cannot contain more than 2000 characters.", args.Result.Length))); Context.ClientPage.ClientResponse.Input("Enter a comment:", string.Empty); args.WaitForPostBack(); } else if (((args.Result != null) && (args.Result != "null")) && (args.Result != "undefined")) { IWorkflowProvider workflowProvider = Context.ContentDatabase.WorkflowProvider; if (workflowProvider != null) { IWorkflow workflow = workflowProvider.GetWorkflow(Context.ClientPage.ServerProperties["workflowid"] as string); if (workflow != null) { Item item = Context.ContentDatabase.Items[Context.ClientPage.ServerProperties["id"] as string, Language.Parse(Context.ClientPage.ServerProperties["language"] as string), Version.Parse(Context.ClientPage.ServerProperties["version"] as string)]; if (item != null) { try { workflow.Execute(Context.ClientPage.ServerProperties["command"] as string, item, args.Result, true, new object[0]); } catch (WorkflowStateMissingException) { SheerResponse.Alert("One or more items could not be processed because their workflow state does not specify the next step.", new string[0]); } Context.ClientPage.ClientResponse.SetLocation(string.Empty); } } } } }
/// <summary> /// Move an item to a particular workflow state /// </summary> /// <param name="item">The item to go through workflow</param> /// <param name="workflowStateId">The ID of the workflow state</param> public void MoveToStateAndExecuteActions(Item item, ID workflowStateId) { IWorkflowProvider workflowProvider = item.Database.WorkflowProvider; IWorkflow workflow = workflowProvider.GetWorkflow(item); // if item is in any workflow if (workflow != null) { using (new EditContext(item)) { // update item's state to the new one item[FieldIDs.WorkflowState] = workflowStateId.ToString(); } Item stateItem = ItemManager.GetItem(workflowStateId, Language.Current, Version.Latest, item.Database, SecurityCheck.Disable); // if there are any actions for the new state if (!stateItem.HasChildren) { return; } // TODO: Obsolete constructor var workflowPipelineArgs = new WorkflowPipelineArgs(item, string.Empty, null); // start executing the actions Pipeline pipeline = Pipeline.Start(stateItem, workflowPipelineArgs); if (pipeline == null) { return; } // TODO: Obsolete class WorkflowCounters.ActionsExecuted.IncrementBy(pipeline.Processors.Count); } }
public ContentWorkflowManager(IWorkflowProvider workflowProvider, IPendingWorkflowItemProvider pendingWorkflowItemProvider, IWorkflowHistoryProvider workflowHistoryProvider) : base(workflowProvider, pendingWorkflowItemProvider, workflowHistoryProvider) { }
private (AkismetSpamCheck processor, CreateCommentArgs args, Mock <IAkismet> akismetApiMock) CreateAkismetSpamCheck(IWeBlogCommentSettings settings, IWorkflowProvider workflowProvider) { var linkManager = Mock.Of <BaseLinkManager>(x => #if FEATURE_URL_BUILDERS x.GetItemUrl(It.IsAny <Item>(), It.Is <ItemUrlBuilderOptions>(y => y.AlwaysIncludeServerUrl == true)) == "link" #else x.GetItemUrl(It.IsAny <Item>(), It.Is <UrlOptions>(y => y.AlwaysIncludeServerUrl == true)) == "link" #endif ); var blogItem = ItemFactory.CreateItem().Object; var blogManager = Mock.Of <IBlogManager>(x => x.GetCurrentBlog() == new BlogHomeItem(blogItem) ); var akismetApiMock = new Mock <IAkismet>(); var processor = new AkismetSpamCheck(settings, blogManager, akismetApiMock.Object, linkManager); var item = CreateCommentItem(); var database = Mock.Of <Database>(x => x.WorkflowProvider == workflowProvider ); var args = new CreateCommentArgs(); args.CommentItem = new CommentItem(item); args.Database = database; return(processor, args, akismetApiMock); }
protected void Run(ClientPipelineArgs args) { Assert.ArgumentNotNull((object)args, "args"); bool flag1 = args.IsPostBack; if (args.Parameters["checkmodified"] == "1") { if (!flag1) { if (Context.ClientPage.Modified) { SheerResponse.CheckModified(true); args.WaitForPostBack(); return; } } else if (args.Result == "cancel") { return; } args.Parameters["checkmodified"] = (string)null; flag1 = false; } string comments = string.Empty; bool flag2 = StringUtil.GetString(new string[1] { args.Parameters["ui"] }) != "1"; bool flag3 = StringUtil.GetString(new string[1] { args.Parameters["suppresscomment"] }) == "1"; if (!flag1 && flag2 && !flag3) { SheerResponse.Input("Enter a comment:", ""); args.WaitForPostBack(); } else { if (flag1) { if (args.Result == "null") { return; } comments = args.Result; } IWorkflowProvider workflowProvider = Sitecore.Client.ContentDatabase.WorkflowProvider; if (workflowProvider != null) { IWorkflow workflow = workflowProvider.GetWorkflow(args.Parameters["workflowid"]); if (workflow != null) { Item obj = Sitecore.Client.ContentDatabase.Items[args.Parameters["id"], Language.Parse(args.Parameters["language"]), Sitecore.Data.Version.Parse(args.Parameters["version"])]; if (obj != null) { var workflowState = workflow.GetState(obj); var repository = new WorxboxItemsRepository(workflow); try { if (repository.IsWorxboxItem(workflowState, new DataUri(obj.Uri)) && repository.GetWorkflowCommandIDs().Any(x => x == ID.Parse(args.Parameters["commandid"]))) { var items = repository.GetWorxboxItems( repository.GetWorxboxWorkflowStates(workflow) .First(x => x.WorkflowCommands.Any(y => y.CommandID == args.Parameters["commandid"])), obj); foreach (var compositeItem in items) { var compositeWorkflowResult = workflow.Execute(args.Parameters["commandid"], compositeItem, comments, true); if (!compositeWorkflowResult.Succeeded) { if (!string.IsNullOrEmpty(compositeWorkflowResult.Message)) { SheerResponse.Alert(compositeWorkflowResult.Message); } } } } WorkflowResult workflowResult = workflow.Execute(args.Parameters["commandid"], obj, comments, true); if (!workflowResult.Succeeded) { if (!string.IsNullOrEmpty(workflowResult.Message)) { SheerResponse.Alert(workflowResult.Message); } } } catch (WorkflowStateMissingException ex) { SheerResponse.Alert("One or more items could not be processed because their workflow state does not specify the next step."); } } } } Context.ClientPage.SendMessage((object)this, "item:refresh"); SheerResponse.Eval("window.top.location.reload();"); } }
public WorkflowRunner(IWorkflowProvider workflowProvider, IEventBroker eventBroker) { _workflowProvider = workflowProvider; _eventBroker = eventBroker; }
/// <summary> /// Retrieves the latest history entry and determines if its latest modify date is within the date range /// </summary> /// <param name="workflowProvider"></param> /// <param name="item"></param> /// <param name="begin"></param> /// <param name="end"></param> /// <param name="lastHistoryItem"></param> /// <returns></returns> private static bool GetLatestWorkflowHistoryEntry(IWorkflowProvider workflowProvider, Item item, DateTime begin, DateTime end, out WorkflowEvent lastHistoryItem) { lastHistoryItem = null; //Get the workflow for the current item var itemWorkflow = workflowProvider.GetWorkflow(item); //If the workflow for the item is null then move to the next item if (itemWorkflow == null) return true; //Grab the history of the items workflow var itemHistory = itemWorkflow.GetHistory(item); //If the history of the item is null or has no entries then move to the next item if (itemHistory == null || itemHistory.Length <= 0) return true; //Grab the latest history update to an item lastHistoryItem = itemHistory[itemHistory.Length -1]; //Ensure that the latest history update exist in the specified date range return lastHistoryItem.Date <= begin || lastHistoryItem.Date >= end; }