public IEnumerable <EntityWorkflowStageChange> GetStageChanges(EntityWorkflow workflow, Entity entity, IEnumerable <WorkflowStageChangeData> dataList) { if (HistoryConfiguration == null || !GetEntityStageId(entity, null, out _)) { yield break; } EntitySet historySet = entity.Connection.GetEntitySet(HistoryConfiguration.EntitySetGuid)?.CreateEntitySet(); if (historySet != null) { EntityLoadParameters loadParameters = new EntityLoadParameters(historySet); if (HistoryConfiguration.ResponsibleLinkGuid != Guid.Empty) { loadParameters.AddLink(HistoryConfiguration.ResponsibleLinkGuid); } loadParameters.Filter = new EntitySetFilter(historySet.GetInfo()); loadParameters.Filter.And(HistoryConfiguration.OwnerLinkGuid, "=", entity.Guid); if (HistoryConfiguration.EntityTypeGuid != Guid.Empty) { loadParameters.Filter.And(SystemPropertyItem.Type, "=", HistoryConfiguration.EntityTypeGuid); } IEntityCollection <Entity> historyItems = historySet.GetEntities(loadParameters); EntityCollection <LinkEntity> responsibleLinks = HistoryConfiguration.ResponsibleLinkGuid != Guid.Empty ? historyItems.GetLinks(HistoryConfiguration.ResponsibleLinkGuid) : null; foreach (Entity historyItem in historyItems) { EntityWorkflowStage stage = workflow.GetStage(historyItem[HistoryConfiguration.StagePropertyGuid]); Guid userGuid = responsibleLinks == null ? historyItem.CreatedBy : (responsibleLinks.FindOne <Entity>(historyItem.Guid)?.Guid ?? Guid.Empty); DateTime changeTime = HistoryConfiguration.DateTimePropertyGuid == Guid.Empty ? historyItem.Created.GetValueOrDefault() : (DateTime)historyItem[HistoryConfiguration.DateTimePropertyGuid]; string comment = HistoryConfiguration.CommentPropertyGuid == Guid.Empty ? string.Empty : (historyItem[HistoryConfiguration.CommentPropertyGuid]?.ToString() ?? string.Empty); yield return(new EntityWorkflowStageChange(workflow, stage, null, userGuid, changeTime, historyItem.Name, comment)); } } }