/// <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); }
public override bool Filter(object element) { Debug.ArgumentNotNull(element, "element"); Item item = element as Item; if (item == null) { return(true); } IWorkflow wf = Sitecore.Context.Workflow.GetWorkflow(item); if (wf == null) { return(false); } WorkflowState state = wf.GetState(item); if (state == null || state.FinalState) { return(false); } WorkflowEvent[] wevents = wf.GetHistory(item); if (wevents == null || wevents.Length == 0) { return(false); } return((System.DateTime.Now - wevents[wevents.Length - 1].Date).Days > Age); }
private User GetEditorUser(WorkflowPipelineArgs args) { Item item = args.DataItem; IWorkflow itemWorkflow = item.Database.WorkflowProvider.GetWorkflow(item); WorkflowEvent[] workflowHistory = itemWorkflow.GetHistory(item); if (workflowHistory.Any()) { string userName = workflowHistory.Last().User; return User.FromName(userName, false); } return null; }
/// <summary> /// Adds the events. /// </summary> /// <param name="results">The results.</param> /// <param name="version">The version.</param> private void AddEvents(List <ItemWorkflowEvent> results, Item item) { IWorkflow workflow = GetWorkflow(item); if (workflow != null) { var events = from wEvent in workflow.GetHistory(item) orderby wEvent.Date ascending select new ItemWorkflowEvent(wEvent.OldState, wEvent.NewState, wEvent.CommentFields.FirstOrDefault().Value, wEvent.User, wEvent.Date) { Item = item }; results.AddRange(events); } }
private string GetHistory(IWorkflow workflow, Item item) { WorkflowEvent[] history = workflow.GetHistory(item); if (history.Length > 0) { WorkflowEvent event2 = history[history.Length - 1]; string user = event2.User; string name = Context.Domain.Name; if (user.StartsWith(name + @"\", StringComparison.OrdinalIgnoreCase)) { user = StringUtil.Mid(user, name.Length + 1); } user = StringUtil.GetString(new string[] { user, Translate.Text("Unknown") }); string stateName = this.GetStateName(workflow, event2.OldState); string str5 = this.GetStateName(workflow, event2.NewState); return(string.Format(Translate.Text("{0} changed from <b>{1}</b> to <b>{2}</b> on {3}."), new object[] { user, stateName, str5, DateUtil.FormatDateTime(event2.Date, "D", Context.User.Profile.Culture) })); } return(Translate.Text("No changes have been made.")); }
private string GetSubmitter(WorkflowPipelineArgs args) { string result = String.Empty; Item contentItem = args.DataItem; IWorkflow contentWorkflow = contentItem.Database.WorkflowProvider.GetWorkflow(contentItem); WorkflowEvent[] contentHistory = contentWorkflow.GetHistory(contentItem); if (contentHistory.Length > 0) { string lastUser = contentHistory[contentHistory.Length - 1].User; User user = User.FromName(lastUser, false); UserProfile userProfile = user.Profile; result = userProfile.FullName; } return(result); }
/// <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> /// Fills out the report information section of the report /// </summary> private void SetTestInformation() { if (TestDefinitionItem.IsNull()) { return; } TestDefinitionItem testDefinition = new TestDefinitionItem(TestDefinitionItem); IWorkflow workflow = TestDefinitionItem.State.GetWorkflow(); DateTime testStartDate = DateTime.MinValue; DateTime testFinishDate = DateTime.MinValue; if (workflow != null) { WorkflowEvent testStartEvent = workflow.GetHistory(TestDefinitionItem).LastOrDefault <WorkflowEvent>(w => w.NewState == Sitecore.Analytics.Data.Items.TestDefinitionItem.StateIDs.Deployed); if (testStartEvent != null) { testStartDate = testStartEvent.Date; } WorkflowEvent testFinishEvent = workflow.GetHistory(TestDefinitionItem).LastOrDefault <WorkflowEvent>(w => w.NewState == Sitecore.Analytics.Data.Items.TestDefinitionItem.StateIDs.Completed); if (testFinishEvent != null) { testFinishDate = testFinishEvent.Date; } } //start date litTestStarted.Text = "Test has not started"; if (testStartDate != DateTime.MinValue && testStartDate != DateTime.MaxValue) { litTestStarted.Text = testStartDate.ToString("MMMM dd, yyyy"); } //end date litTestEnded.Text = "Test has not completed"; if (testFinishDate != DateTime.MinValue && testFinishDate != DateTime.MaxValue) { litTestEnded.Text = testFinishDate.ToString("MMMM dd, yyyy"); } if (testDefinition.IsRunning) { litProgress.Text = "Running"; } else if (testDefinition.IsFinished) { litProgress.Text = "Finished"; } else if (testDefinition.IsDraft) { litProgress.Text = "Draft"; } else if (testDefinition.IsDeployed) { litProgress.Text = "Deployed"; } else { litProgress.Text = "N/A"; } }
/// <summary> /// Gets the history. /// </summary> /// <param name="workflow"> /// The workflow. /// </param> /// <param name="item"> /// The item. /// </param> /// <returns> /// The get history. /// </returns> private string GetHistory(IWorkflow workflow, Item item) { string str; Assert.ArgumentNotNull(workflow, "workflow"); Assert.ArgumentNotNull(item, "item"); WorkflowEvent[] history = workflow.GetHistory(item); if ((int)history.Length <= 0) { str = Translate.Text("No changes have been made."); } else { WorkflowEvent workflowEvent = history[(int)history.Length - 1]; string user = workflowEvent.User; string name = Context.Domain.Name; if (user.StartsWith(string.Concat(name, "\\"), StringComparison.OrdinalIgnoreCase)) { user = StringUtil.Mid(user, name.Length + 1); } string[] strArrays = new string[] { user, Translate.Text("Unknown") }; user = StringUtil.GetString(strArrays); string stateName = this.GetStateName(workflow, workflowEvent.OldState); string stateName1 = this.GetStateName(workflow, workflowEvent.NewState); object[] objArray = new object[] { user, stateName, stateName1, DateUtil.FormatDateTime(workflowEvent.Date, "D", Context.User.Profile.Culture) }; str = string.Format(Translate.Text("{0} changed from <b>{1}</b> to <b>{2}</b> on {3}."), objArray); } return str; }
// Defines if an item has exceeded its staying in workflow state time limit public static bool IsTimeLimitExceeded(Item item, IWorkflow workflow, TimeSpan maxTimeInState) { var events = workflow.GetHistory(item); return(events.Length > 0 && (DateTime.Now - events[events.Length - 1].Date) > maxTimeInState); }
private string GetHistory(IWorkflow workflow, Item item) { WorkflowEvent[] history = workflow.GetHistory(item); if (history.Length > 0) { WorkflowEvent event2 = history[history.Length - 1]; string user = event2.User; string name = Context.Domain.Name; if (user.StartsWith(name + @"\", StringComparison.OrdinalIgnoreCase)) { user = StringUtil.Mid(user, name.Length + 1); } user = StringUtil.GetString(new string[] { user, Translate.Text("Unknown") }); string stateName = this.GetStateName(workflow, event2.OldState); string str5 = this.GetStateName(workflow, event2.NewState); return string.Format(Translate.Text("{0} changed from <b>{1}</b> to <b>{2}</b> on {3}."), new object[] { user, stateName, str5, DateUtil.FormatDateTime(event2.Date, "D", Context.User.Profile.Culture) }); } return Translate.Text("No changes have been made."); }
// Defines if an item has exceeded its staying in workflow state time limit public static bool IsTimeLimitExceeded(Item item, IWorkflow workflow, TimeSpan maxTimeInState) { var events = workflow.GetHistory(item); return events.Length > 0 && (DateTime.Now - events[events.Length - 1].Date) > maxTimeInState; }