Exemplo n.º 1
0
        public override BaseElement Clone()
        {
            TimerEventDefinition clone = new TimerEventDefinition
            {
                Values = this
            };

            return(clone);
        }
Exemplo n.º 2
0
        protected internal virtual void HandleTimerEventDefinition(Process process, Event @event, EventDefinition eventDefinition, IList <ValidationError> errors)
        {
            TimerEventDefinition timerEventDefinition = (TimerEventDefinition)eventDefinition;

            if (string.IsNullOrWhiteSpace(timerEventDefinition.TimeDate) && string.IsNullOrWhiteSpace(timerEventDefinition.TimeCycle) && string.IsNullOrWhiteSpace(timerEventDefinition.TimeDuration))
            {
                // neither date, cycle or duration configured
                AddError(errors, ProblemsConstants.EVENT_TIMER_MISSING_CONFIGURATION, process, @event, ProcessValidatorResource.EVENT_TIMER_MISSING_CONFIGURATION);
            }
        }
Exemplo n.º 3
0
        public override void ParseChildElement(XMLStreamReader xtr, BaseElement parentElement, BpmnModel model)
        {
            if (!(parentElement is TimerEventDefinition))
            {
                return;
            }

            TimerEventDefinition eventDefinition = (TimerEventDefinition)parentElement;

            eventDefinition.TimeDate = xtr.ElementText;
        }
        public override object Clone()
        {
            var result = new TimerEventDefinition
            {
                TimeCycle    = TimeCycle,
                TimeDate     = TimeDate,
                TimeDuration = TimeDuration
            };

            FeedElt(result);
            return(result);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Sets an event definition for the timer with a time date.
        /// </summary>
        /// <param name="timerDate"> the time date of the timer </param>
        /// <returns> the builder object </returns>
        public virtual B timerWithDate(string timerDate)
        {
            TimeDate timeDate = createInstance(typeof(TimeDate));

            timeDate.TextContent = timerDate;

            TimerEventDefinition timerEventDefinition = createInstance(typeof(TimerEventDefinition));

            timerEventDefinition.TimeDate = timeDate;

            element.EventDefinitions.add(timerEventDefinition);

            return(myself);
        }
Exemplo n.º 6
0
        protected virtual ScheduledJob CreateTimerJob(ProcessDefinition processDefinition,
                                                      StartEvent startEvent,
                                                      TimerEventDefinition timerEvent)
        {
            ScheduledJob job = new ScheduledJob();

            job.ActivityId        = startEvent.Id;
            job.Key               = Guid.NewGuid().ToString("n");
            job.ProcessDefinition = processDefinition;
            job.TenantId          = this.tenantId;
            job.Handler           = "timerStartEvent";

            return(job);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Sets an event definition for the timer with a time duration.
        /// </summary>
        /// <param name="timerDuration"> the time duration of the timer </param>
        /// <returns> the builder object </returns>
        public virtual B timerWithDuration(string timerDuration)
        {
            TimeDuration timeDuration = createInstance(typeof(TimeDuration));

            timeDuration.TextContent = timerDuration;

            TimerEventDefinition timerEventDefinition = createInstance(typeof(TimerEventDefinition));

            timerEventDefinition.TimeDuration = timeDuration;

            element.EventDefinitions.add(timerEventDefinition);

            return(myself);
        }
Exemplo n.º 8
0
        public override void ParseChildElement(XMLStreamReader xtr, BaseElement parentElement, BpmnModel model)
        {
            if (!(parentElement is TimerEventDefinition))
            {
                return;
            }

            TimerEventDefinition eventDefinition = (TimerEventDefinition)parentElement;

            if (!string.IsNullOrWhiteSpace(xtr.GetAttributeValue(BpmnXMLConstants.ACTIVITI_EXTENSIONS_NAMESPACE, BpmnXMLConstants.ATTRIBUTE_END_DATE)))
            {
                eventDefinition.EndDate = xtr.GetAttributeValue(BpmnXMLConstants.ACTIVITI_EXTENSIONS_NAMESPACE, BpmnXMLConstants.ATTRIBUTE_END_DATE);
            }
            eventDefinition.TimeCycle = xtr.ElementText;
        }
        public override void ParseChildElement(XMLStreamReader xtr, BaseElement parentElement, BpmnModel model)
        {
            if (!(parentElement is Event))
            {
                return;
            }
            TimerEventDefinition eventDefinition = new TimerEventDefinition();
            string calendarName = xtr.GetAttributeValue(BpmnXMLConstants.ACTIVITI_EXTENSIONS_NAMESPACE, BpmnXMLConstants.ATTRIBUTE_CALENDAR_NAME);

            if (!string.IsNullOrWhiteSpace(calendarName))
            {
                eventDefinition.CalendarName = calendarName;
            }
            BpmnXMLUtil.AddXMLLocation(eventDefinition, xtr);
            BpmnXMLUtil.ParseChildElements(BpmnXMLConstants.ELEMENT_EVENT_TIMERDEFINITION, eventDefinition, xtr, model);

            ((Event)parentElement).EventDefinitions.Add(eventDefinition);
        }
Exemplo n.º 10
0
        protected internal virtual void restoreTimerStartEvent(IProcessDefinition previousProcessDefinition, StartEvent startEvent, EventDefinition eventDefinition)
        {
            TimerEventDefinition timerEventDefinition = (TimerEventDefinition)eventDefinition;
            ITimerJobEntity      timer = TimerUtil.CreateTimerEntityForTimerEventDefinition((TimerEventDefinition)eventDefinition, false, null, TimerStartEventJobHandler.TYPE, TimerEventHandler.CreateConfiguration(startEvent.Id, timerEventDefinition.EndDate, timerEventDefinition.CalendarName));

            if (timer != null)
            {
                ITimerJobEntity timerJob = JobManager.CreateTimerJob((TimerEventDefinition)eventDefinition, false, null, TimerStartEventJobHandler.TYPE, TimerEventHandler.CreateConfiguration(startEvent.Id, timerEventDefinition.EndDate, timerEventDefinition.CalendarName));

                timerJob.ProcessDefinitionId = previousProcessDefinition.Id;

                if (!ReferenceEquals(previousProcessDefinition.TenantId, null))
                {
                    timerJob.TenantId = previousProcessDefinition.TenantId;
                }

                JobManager.ScheduleTimerJob(timerJob);
            }
        }
Exemplo n.º 11
0
        protected internal virtual void WriteTimerDefinition(Event parentEvent, TimerEventDefinition timerDefinition, XMLStreamWriter xtw)
        {
            xtw.WriteStartElement(BpmnXMLConstants.BPMN_PREFIX, BpmnXMLConstants.ELEMENT_EVENT_TIMERDEFINITION, BpmnXMLConstants.BPMN2_NAMESPACE);
            if (!string.IsNullOrWhiteSpace(timerDefinition.CalendarName))
            {
                WriteQualifiedAttribute(BpmnXMLConstants.ATTRIBUTE_CALENDAR_NAME, timerDefinition.CalendarName, xtw);
            }
            bool didWriteExtensionStartElement = BpmnXMLUtil.WriteExtensionElements(timerDefinition, false, xtw);

            if (didWriteExtensionStartElement)
            {
                xtw.WriteEndElement();
            }
            if (!string.IsNullOrWhiteSpace(timerDefinition.TimeDate))
            {
                xtw.WriteStartElement(BpmnXMLConstants.BPMN_PREFIX, BpmnXMLConstants.ATTRIBUTE_TIMER_DATE, BpmnXMLConstants.BPMN2_NAMESPACE);
                xtw.WriteCharacters(timerDefinition.TimeDate);
                xtw.WriteEndElement();
            }
            else if (!string.IsNullOrWhiteSpace(timerDefinition.TimeCycle))
            {
                xtw.WriteStartElement(BpmnXMLConstants.BPMN_PREFIX, BpmnXMLConstants.ATTRIBUTE_TIMER_CYCLE, BpmnXMLConstants.BPMN2_NAMESPACE);

                if (!string.IsNullOrWhiteSpace(timerDefinition.EndDate))
                {
                    xtw.WriteAttribute(BpmnXMLConstants.ACTIVITI_EXTENSIONS_PREFIX, BpmnXMLConstants.ACTIVITI_EXTENSIONS_NAMESPACE, BpmnXMLConstants.ATTRIBUTE_END_DATE, timerDefinition.EndDate);
                }

                xtw.WriteCharacters(timerDefinition.TimeCycle);
                xtw.WriteEndElement();
            }
            else if (!string.IsNullOrWhiteSpace(timerDefinition.TimeDuration))
            {
                xtw.WriteStartElement(BpmnXMLConstants.BPMN_PREFIX, BpmnXMLConstants.ATTRIBUTE_TIMER_DURATION, BpmnXMLConstants.BPMN2_NAMESPACE);
                xtw.WriteCharacters(timerDefinition.TimeDuration);
                xtw.WriteEndElement();
            }

            xtw.WriteEndElement();
        }
Exemplo n.º 12
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="timerEventDefinition"></param>
        /// <param name="interrupting"></param>
        /// <param name="execution"></param>
        /// <param name="timerEventType"></param>
        /// <param name="jobHandlerConfiguration"></param>
        /// <returns></returns>
        public virtual ITimerJobEntity CreateTimerJob(TimerEventDefinition timerEventDefinition, bool interrupting, IExecutionEntity execution, string timerEventType, string jobHandlerConfiguration)
        {
            ITimerJobEntity timerEntity = TimerUtil.CreateTimerEntityForTimerEventDefinition(timerEventDefinition, interrupting, execution, timerEventType, jobHandlerConfiguration);

            return(timerEntity);
        }
Exemplo n.º 13
0
 public BoundaryTimerEventActivityBehavior(TimerEventDefinition timerEventDefinition, bool interrupting) : base(interrupting)
 {
     this.timerEventDefinition = timerEventDefinition;
 }
 public virtual BoundaryTimerEventActivityBehavior CreateBoundaryTimerEventActivityBehavior(BoundaryEvent boundaryEvent, TimerEventDefinition timerEventDefinition, bool interrupting)
 {
     return(new BoundaryTimerEventActivityBehavior(timerEventDefinition, interrupting));
 }
 public virtual IntermediateCatchTimerEventActivityBehavior CreateIntermediateCatchTimerEventActivityBehavior(IntermediateCatchEvent intermediateCatchEvent, TimerEventDefinition timerEventDefinition)
 {
     return(new IntermediateCatchTimerEventActivityBehavior(timerEventDefinition));
 }
Exemplo n.º 16
0
 public IntermediateCatchTimerEventActivityBehavior(TimerEventDefinition timerEventDefinition)
 {
     this.timerEventDefinition = timerEventDefinition;
 }
Exemplo n.º 17
0
        /// <summary>
        /// The event definition on which the timer is based.
        ///
        /// Takes in an optional execution, if missing the <seealso cref="NoExecutionVariableScope"/> will be used (eg Timer start event)
        /// </summary>
        public static ITimerJobEntity CreateTimerEntityForTimerEventDefinition(TimerEventDefinition timerEventDefinition, bool isInterruptingTimer, IExecutionEntity executionEntity, string jobHandlerType, string jobHandlerConfig)
        {
            ProcessEngineConfigurationImpl processEngineConfiguration = Context.ProcessEngineConfiguration;

            string            businessCalendarRef = null;
            IExpression       expression          = null;
            ExpressionManager expressionManager   = processEngineConfiguration.ExpressionManager;

            // ACT-1415: timer-declaration on start-event may contain expressions NOT
            // evaluating variables but other context, evaluating should happen nevertheless
            IVariableScope scopeForExpression = executionEntity;

            if (scopeForExpression == null)
            {
                //scopeForExpression = NoExecutionVariableScope.SharedInstance;
            }

            if (!string.IsNullOrWhiteSpace(timerEventDefinition.TimeDate))
            {
                businessCalendarRef = DueDateBusinessCalendar.NAME;
                expression          = expressionManager.CreateExpression(timerEventDefinition.TimeDate);
            }
            else if (!string.IsNullOrWhiteSpace(timerEventDefinition.TimeCycle))
            {
                businessCalendarRef = CycleBusinessCalendar.NAME;
                expression          = expressionManager.CreateExpression(timerEventDefinition.TimeCycle);
            }
            else if (!string.IsNullOrWhiteSpace(timerEventDefinition.TimeDuration))
            {
                businessCalendarRef = DurationBusinessCalendar.NAME;
                expression          = expressionManager.CreateExpression(timerEventDefinition.TimeDuration);
            }

            if (!string.IsNullOrWhiteSpace(timerEventDefinition.CalendarName))
            {
                businessCalendarRef = timerEventDefinition.CalendarName;
                IExpression businessCalendarExpression = expressionManager.CreateExpression(businessCalendarRef);
                businessCalendarRef = businessCalendarExpression.GetValue(scopeForExpression).ToString();
            }

            if (expression == null)
            {
                throw new ActivitiException("Timer needs configuration (either timeDate, timeCycle or timeDuration is needed) (" + timerEventDefinition.Id + ")");
            }

            IBusinessCalendar businessCalendar = processEngineConfiguration.BusinessCalendarManager.GetBusinessCalendar(businessCalendarRef);

            string   dueDateString = null;
            DateTime?duedate       = null;

            object dueDateValue = expression.GetValue(scopeForExpression);

            if (dueDateValue is string)
            {
                dueDateString = (string)dueDateValue;
            }
            else if (dueDateValue is DateTime)
            {
                duedate = (DateTime)dueDateValue;
            }
            else if (dueDateValue is Nullable <DateTime> )
            {
                //JodaTime support
                duedate = (DateTime?)dueDateValue;
            }
            else if (dueDateValue != null)
            {
                throw new ActivitiException("Timer '" + executionEntity.ActivityId + "' was not configured with a valid duration/time, either hand in a java.util.Date or a String in format 'yyyy-MM-dd'T'hh:mm:ss'");
            }

            if (duedate == null && !string.IsNullOrWhiteSpace(dueDateString))
            {
                duedate = businessCalendar.ResolveDuedate(dueDateString);
            }

            ITimerJobEntity timer = null;

            if (duedate != null)
            {
                timer                         = Context.CommandContext.TimerJobEntityManager.Create();
                timer.JobType                 = JobFields.JOB_TYPE_TIMER;
                timer.Revision                = 1;
                timer.JobHandlerType          = jobHandlerType;
                timer.JobHandlerConfiguration = jobHandlerConfig;
                timer.Exclusive               = true;
                timer.Retries                 = processEngineConfiguration.AsyncExecutorNumberOfRetries;
                timer.Duedate                 = duedate;
                if (executionEntity != null)
                {
                    timer.Execution           = executionEntity;
                    timer.ProcessDefinitionId = executionEntity.ProcessDefinitionId;
                    timer.ProcessInstanceId   = executionEntity.ProcessInstanceId;

                    // Inherit tenant identifier (if applicable)
                    if (!string.IsNullOrWhiteSpace(executionEntity.TenantId))
                    {
                        timer.TenantId = executionEntity.TenantId;
                    }
                }
            }

            if (!string.IsNullOrWhiteSpace(timerEventDefinition.TimeCycle))
            {
                // See ACT-1427: A boundary timer with a cancelActivity='true', doesn't need to repeat itself
                bool repeat = !isInterruptingTimer;

                // ACT-1951: intermediate catching timer events shouldn't repeat according to spec
                if (executionEntity != null)
                {
                    FlowElement currentElement = executionEntity.CurrentFlowElement;
                    if (currentElement is IntermediateCatchEvent)
                    {
                        repeat = false;
                    }
                }

                if (repeat)
                {
                    string prepared = PrepareRepeat(dueDateString);
                    timer.Repeat = prepared;
                }
            }

            if (timer != null && executionEntity != null)
            {
                timer.Execution           = executionEntity;
                timer.ProcessDefinitionId = executionEntity.ProcessDefinitionId;

                // Inherit tenant identifier (if applicable)
                if (!string.IsNullOrWhiteSpace(executionEntity.TenantId))
                {
                    timer.TenantId = executionEntity.TenantId;
                }
            }

            return(timer);
        }
        public override object Create(object parent, IParseContext context, XElement element)
        {
            EventDefinition eventDefinition = null;
            var             localName       = Helper.GetRealLocalName(element);

            switch (localName)
            {
            case "cancelEventDefinition":
                eventDefinition = new CancelEventDefinition();
                break;

            case "errorEventDefinition":
                var errorEventDefinition = new ErrorEventDefinition();
                eventDefinition = errorEventDefinition;
                var errorRef = element.GetAttribute("errorRef");
                if (errorRef != null)
                {
                    context.AddReferenceRequest <Error>(errorRef, x => errorEventDefinition.ErrorRef = x);
                }
                break;

            case "timerEventDefinition":
                eventDefinition = new TimerEventDefinition();
                break;

            case "terminateEventDefinition":
                eventDefinition = new TerminateEventDefinition();
                break;

            case "messageEventDefinition":
                var messageEventDefinition = new MessageEventDefinition();
                eventDefinition = messageEventDefinition;

                var operationRef = element.GetAttribute("operationRef");
                if (operationRef != null)
                {
                    context.AddReferenceRequest <Operation>(operationRef, x => messageEventDefinition.OperationRef = x);
                }

                var messageRef = element.GetAttribute("messageRef");
                if (messageRef != null)
                {
                    context.AddReferenceRequest <Message>(messageRef, x => messageEventDefinition.MessageRef = x);
                }
                break;

            case "conditionalEventDefinition":
                eventDefinition = new ConditionalEventDefinition();
                break;

            case "compensateEventDefinition":
                var compensateEventDefinition = new CompensateEventDefinition();
                eventDefinition = compensateEventDefinition;

                compensateEventDefinition.WaitForCompletion = element.GetBoolean("waitForCompletion");
                var activityRef = element.GetAttribute("activityRef");
                if (activityRef != null)
                {
                    context.AddReferenceRequest <Activity>(activityRef, x => compensateEventDefinition.ActivityRef = x);
                }
                break;

            case "signalEventDefinition":
                var signalEventDefinition = new SignalEventDefinition();
                eventDefinition = signalEventDefinition;

                var signalRef = element.GetAttribute("signalRef");
                if (signalRef != null)
                {
                    context.AddReferenceRequest <Signal>(signalRef, x => signalEventDefinition.SignalRef = x);
                }
                break;

            case "escalationEventDefinition":
                eventDefinition = new EscalationEventDefinition()
                {
                    EscalationRef = element.GetAttribute("escalationRef")
                };
                break;

            case "linkEventDefinition":
                eventDefinition = new LinkEventDefinition()
                {
                    Name   = element.GetAttribute("name"),
                    Target = element.GetAttribute("target")
                };
                break;
            }

            if (this.callback != null)
            {
                this.callback(parent, context, element, eventDefinition);
            }

            base.Init(eventDefinition, context, element);

            context.Push(eventDefinition);

            return(eventDefinition);
        }