// Verify workflow state and update workflow state public WorkflowResult ChangeWorkflowState(Item item, string workflowStateName, bool isPageOrResourceFolder) { IWorkflow workflow = item.Database.WorkflowProvider.GetWorkflow(item); if (workflow == null) { Sitecore.Diagnostics.Log.Info("HealthIS - " + item.Name + " - No workflow assigned to item", this); return(new WorkflowResult(false, "No workflow assigned to item")); } WorkflowState newState = workflow.GetStates().FirstOrDefault(state => state.DisplayName == workflowStateName); if (newState == null) { Sitecore.Diagnostics.Log.Info("HealthIS - " + item.Name + " - Cannot find workflow state " + workflowStateName, this); return(new WorkflowResult(false, "Cannot find workflow state " + workflowStateName)); } if (isPageOrResourceFolder) { Helper.UpdateItemInformation(item, newState); Helper.UpdateItemInformation(item.GetChildren().Where(c => c.DisplayName.EndsWith("_Resources")).FirstOrDefault(), newState); } else { datasourceUpdate(item, newState); } return(ChangeWorkflowState(item, ID.Parse(newState.StateID))); }
public static void SetWorkflowToPublishable(Item i) { Item wfs = i.Database.GetItem(i[FieldIDs.WorkflowState]); if (wfs == null) { return; } if (IsFinalState(wfs)) { return; } IWorkflow workflow = i.Database.WorkflowProvider.GetWorkflow(i); if (workflow == null) { return; } foreach (WorkflowState state in workflow.GetStates()) { if (!state.FinalState) { continue; } using (new EditContext(i, true, false)) { i[FieldIDs.WorkflowState] = state.StateID; } } }
/// <summary> /// Gets the workflow history for the current item /// </summary> /// <returns>A list of all workflow events.</returns> /// <remarks>Because of versioning, there are duplicate item created workflow events. This method filters /// those duplicates out.</remarks> public List <WorkflowEvent> GetWorkflowHistory(Item currentItem) { var completeWorkflowHistory = new List <WorkflowEvent>(); try { bool addedFirstEvent = false; // versions are in a 1-based array; if you give it "0", it will give you the most recent. for (int i = 1; i < currentItem.Versions.Count + 1; i++) { Item thisVersion = currentItem.Versions[new Sitecore.Data.Version(i)]; IWorkflow workflow = _service.Database.WorkflowProvider.GetWorkflow(thisVersion[FieldIDs.Workflow]); if (workflow != null) { List <WorkflowEvent> events = workflow.GetHistory(thisVersion).ToList(); if (addedFirstEvent) { WorkflowState firstState = workflow.GetStates()[0]; events.RemoveAll(e => e.OldState == "" && e.NewState == firstState.StateID); addedFirstEvent = true; } addedFirstEvent = true; completeWorkflowHistory.AddRange(events); } } } catch (Exception exception) { throw; } return(completeWorkflowHistory); }
private string GetStateName(IWorkflow workflow, string stateID) { if (this._stateNames == null) { this._stateNames = new NameValueCollection(); foreach (WorkflowState state in workflow.GetStates()) { this._stateNames.Add(state.StateID, state.DisplayName); } } return(StringUtil.GetString(new string[] { this._stateNames[stateID], "?" })); }
protected virtual void DisplayStates(IWorkflow workflow, XmlControl placeholder) { this._stateNames = null; foreach (WorkflowState state in workflow.GetStates()) { if (WorkflowFilterer.FilterVisibleCommands(workflow.GetCommands(state.StateID)).Length > 0) { string str2; DataUri[] items = this.GetItems(state, workflow); string str = ShortID.Encode(workflow.WorkflowID) + "_" + ShortID.Encode(state.StateID); Section section2 = new Section { ID = str + "_section" }; Section control = section2; control.Attributes["Width"] = "100%"; placeholder.AddControl(control); int length = items.Length; if (length <= 0) { str2 = Translate.Text("None"); } else if (length == 1) { str2 = string.Format("1 {0}", Translate.Text("item")); } else { str2 = string.Format("{0} {1}", length, Translate.Text("items")); } str2 = string.Format("<span style=\"font-weight:normal\"> - ({0})</span>", str2); control.Header = state.DisplayName + str2; control.Icon = state.Icon; if (Settings.ClientFeeds.Enabled) { FeedUrlOptions options2 = new FeedUrlOptions("/sitecore/shell/~/feed/workflowstate.aspx") { UseUrlAuthentication = true }; FeedUrlOptions options = options2; options.Parameters["wf"] = workflow.WorkflowID; options.Parameters["st"] = state.StateID; control.FeedLink = options.ToString(); } control.Collapsed = length <= 0; Border child = new Border(); control.Controls.Add(child); child.ID = str + "_content"; this.DisplayState(workflow, state, items, child, 0, this.PageSize); this.CreateNavigator(control, str + "_navigator", length); } } }
// Returns all none-final states based on a specific template of a specific workflow public static IEnumerable <WorkflowState> GetNonFinalStatesByTemplate(IWorkflow workflow, string templateName) { using (new SecurityModel.SecurityDisabler()) { Database masterDb = Factory.GetDatabase(DbName); var allStates = workflow.GetStates(); return (allStates.Where( s => !s.FinalState && string.Equals(masterDb.GetItem(new ID(s.StateID)).TemplateName, templateName, StringComparison.InvariantCultureIgnoreCase))); } }
public IEnumerable <WorxboxWorkflowState> GetWorxboxWorkflowStates(IWorkflow workflow) { var worxBoxCommands = GetWorkflowCommands(); foreach (var state in workflow.GetStates()) { var commands = from cmd in worxBoxCommands join wfCmd in workflow.GetCommands(state.StateID).ToList() on cmd.ID equals ID.Parse(wfCmd.CommandID) select wfCmd; if (commands.Any()) { yield return(new WorxboxWorkflowState() { Workflow = workflow, WorkflowState = state, WorkflowCommands = commands }); } } }
/// <summary> /// Gets the workflow history for the current item /// </summary> /// <returns>A list of all workflow events.</returns> /// <remarks>Because of versioning, there are duplicate item created workflow events. This method filters /// those duplicates out.</remarks> public List <Tuple <DateTime, string, bool> > GetWorkflowHistory(ID itemID) { var completeWorkflowHistory = new List <Tuple <DateTime, string, bool> >(); try { var masterDb = Sitecore.Data.Database.GetDatabase(Informa.Library.Utilities.References.Constants.MasterDb); var currentItem = masterDb.GetItem(itemID); bool addedFirstEvent = false; // versions are in a 1-based array; if you give it "0", it will give you the most recent. for (int i = 1; i < currentItem.Versions.Count + 1; i++) { Item thisVersion = currentItem.Versions[new Sitecore.Data.Version(i)]; IWorkflow workflow = masterDb.WorkflowProvider.GetWorkflow(thisVersion[FieldIDs.Workflow]); if (workflow != null) { List <WorkflowEvent> events = workflow.GetHistory(thisVersion).ToList(); if (addedFirstEvent) { WorkflowState firstState = workflow.GetStates()[0]; events.RemoveAll(e => e.OldState == "" && e.NewState == firstState.StateID); addedFirstEvent = true; } addedFirstEvent = true; completeWorkflowHistory.AddRange(events.Select(s => new Tuple <DateTime, string, bool>(s.Date, s.NewState, workflow.GetStates()[0].FinalState))); } } } catch (Exception exception) { Sitecore.Diagnostics.Log.Error(exception.ToString(), this); } return(completeWorkflowHistory); }
/// <summary> /// Gets the name of the state. /// </summary> /// <param name="workflow"> /// The workflow. /// </param> /// <param name="stateID"> /// The state ID. /// </param> /// <returns> /// The get state name. /// </returns> private string GetStateName(IWorkflow workflow, string stateID) { Assert.ArgumentNotNull(workflow, "workflow"); Assert.ArgumentNotNull(stateID, "stateID"); if (this.stateNames == null) { this.stateNames = new NameValueCollection(); WorkflowState[] states = workflow.GetStates(); for (int i = 0; i < (int)states.Length; i++) { WorkflowState workflowState = states[i]; this.stateNames.Add(workflowState.StateID, workflowState.DisplayName); } } string[] item = new string[] { this.stateNames[stateID], "?" }; return StringUtil.GetString(item); }
/// <summary> /// Displays the states. /// </summary> /// <param name="workflow"> /// The workflow. /// </param> /// <param name="placeholder"> /// The placeholder. /// </param> protected virtual void DisplayStates(IWorkflow workflow, XmlControl placeholder) { string str; Assert.ArgumentNotNull(workflow, "workflow"); Assert.ArgumentNotNull(placeholder, "placeholder"); this.stateNames = null; WorkflowState[] states = workflow.GetStates(); for (int i = 0; i < (int)states.Length; i++) { WorkflowState workflowState = states[i]; WorkflowCommand[] workflowCommandArray = WorkflowFilterer.FilterVisibleCommands(workflow.GetCommands(workflowState.StateID)); if ((int)workflowCommandArray.Length > 0) { DataUri[] items = this.GetItems(workflowState, workflow); Assert.IsNotNull(items, "items is null"); string str1 = string.Concat(ShortID.Encode(workflow.WorkflowID), "_", ShortID.Encode(workflowState.StateID)); Section section = new Section(); section.ID = string.Concat(str1, "_section"); Section icon = section; placeholder.AddControl(icon); int length = (int)items.Length; if (length > 0) { str = (length != 1 ? string.Format("{0} {1}", length, Translate.Text("items")) : string.Format("1 {0}", Translate.Text("item"))); } else { str = "none"; } str = string.Format("<span style=\"font-weight:normal\"> - ({0})</span>", str); icon.Header = string.Concat(workflowState.DisplayName, str); icon.Icon = workflowState.Icon; if (Settings.ClientFeeds.Enabled) { FeedUrlOptions feedUrlOption = new FeedUrlOptions("/sitecore/shell/~/feed/workflowstate.aspx"); feedUrlOption.UseUrlAuthentication = true; FeedUrlOptions workflowID = feedUrlOption; workflowID.Parameters["wf"] = workflow.WorkflowID; workflowID.Parameters["st"] = workflowState.StateID; icon.FeedLink = workflowID.ToString(); } icon.Collapsed = length <= 0; Border border = new Border(); icon.Controls.Add(border); border.ID = string.Concat(str1, "_content"); this.DisplayState(workflow, workflowState, items, border, 0, this.PageSize); this.CreateNavigator(icon, string.Concat(str1, "_navigator"), length); } } }
private string GetStateName(IWorkflow workflow, string stateID) { if (this._stateNames == null) { this._stateNames = new NameValueCollection(); foreach (WorkflowState state in workflow.GetStates()) { this._stateNames.Add(state.StateID, state.DisplayName); } } return StringUtil.GetString(new string[] { this._stateNames[stateID], "?" }); }
// Returns all none-final states based on a specific template of a specific workflow public static IEnumerable<WorkflowState> GetNonFinalStatesByTemplate(IWorkflow workflow, string templateName) { using (new SecurityModel.SecurityDisabler()) { Database masterDb = Factory.GetDatabase(DbName); var allStates = workflow.GetStates(); return allStates.Where( s => !s.FinalState && string.Equals(masterDb.GetItem(new ID(s.StateID)).TemplateName, templateName, StringComparison.InvariantCultureIgnoreCase)); } }