Esempio n. 1
0
        public void MapInstanceEventsToProcessHistoryTest(InstanceEvent instanceEvent, string expectedPerformedBy, string expectedEventType)
        {
            ProcessHistoryItem actual = ProcessHelper.MapInstanceEventsToProcessHistory(new List <InstanceEvent> {
                instanceEvent
            }).First();

            Assert.Equal(expectedPerformedBy, actual.PerformedBy);
            Assert.Equal(expectedEventType, actual.EventType);
        }
Esempio n. 2
0
        /// <summary>
        /// Maps an instance events related to process into process history items and sorts them in a list.
        /// </summary>
        /// <param name="events">List of instance events.</param>
        /// <returns>A list of process history items.</returns>
        public static List <ProcessHistoryItem> MapInstanceEventsToProcessHistory(List <InstanceEvent> events)
        {
            List <ProcessHistoryItem> history = new List <ProcessHistoryItem>();

            foreach (InstanceEvent instanceEvent in events)
            {
                switch (Enum.Parse(typeof(InstanceEventType), instanceEvent.EventType))
                {
                case InstanceEventType.process_StartEvent:
                    history.Add(
                        new ProcessHistoryItem
                    {
                        Occured   = instanceEvent.Created,
                        EventType = instanceEvent.EventType,
                        ElementId = instanceEvent.ProcessInfo.StartEvent
                    });
                    break;

                case InstanceEventType.process_EndEvent:
                    history.Add(
                        new ProcessHistoryItem
                    {
                        Occured   = instanceEvent.Created,
                        EventType = instanceEvent.EventType,
                        ElementId = instanceEvent.ProcessInfo.EndEvent
                    });
                    break;

                case InstanceEventType.process_StartTask:
                    ProcessHistoryItem task_1 = history.FirstOrDefault(i => i.ElementId.Equals(instanceEvent.ProcessInfo.CurrentTask.ElementId));

                    if (task_1 != null)
                    {
                        task_1.Started = instanceEvent.Created;
                    }
                    else
                    {
                        history.Add(new ProcessHistoryItem
                        {
                            EventType = instanceEvent.EventType,
                            ElementId = instanceEvent.ProcessInfo.CurrentTask.ElementId,
                            Started   = instanceEvent.Created
                        });
                    }

                    break;

                case InstanceEventType.process_EndTask:
                    ProcessHistoryItem task_2 = history.FirstOrDefault(i => i.ElementId.Equals(instanceEvent?.ProcessInfo?.CurrentTask?.ElementId));
                    if (task_2 != null)
                    {
                        task_2.Ended = instanceEvent.Created;
                    }
                    else
                    {
                        history.Add(new ProcessHistoryItem
                        {
                            EventType = instanceEvent.EventType,
                            ElementId = instanceEvent.ProcessInfo.CurrentTask.ElementId,
                            Ended     = instanceEvent.Created
                        });
                    }

                    break;
                }
            }

            return(history);
        }