Example #1
0
 public long? GetExpectedEndTime(
     ContextManagerRealization realization,
     ScheduleSpec[] scheduleSpecs)
 {
     var importService = realization.AgentInstanceContextCreate.ImportServiceRuntime;
     return ContextControllerInitTermUtil.ComputeScheduleMinimumNextOccurance(
         scheduleSpecs,
         realization.AgentInstanceContextCreate.TimeProvider.Time,
         importService);
 }
        public bool Activate(
            EventBean optionalTriggeringEvent,
            ContextControllerEndConditionMatchEventProvider endConditionMatchEventProvider, 
            IDictionary<string, object> optionalTriggeringPattern)
        {
            ScheduleHandleCallback scheduleCallback = new ProxyScheduleHandleCallback {
                ProcScheduledTrigger = () => {
                    var inProcAgentInstanceContext = controller.Realization.AgentInstanceContextCreate;
                    inProcAgentInstanceContext.InstrumentationProvider.QContextScheduledEval(
                        inProcAgentInstanceContext.StatementContext.ContextRuntimeDescriptor);

                    scheduleHandle = null; // terminates automatically unless scheduled again
                    inProcAgentInstanceContext.AuditProvider.ScheduleFire(
                        inProcAgentInstanceContext,
                        ScheduleObjectType.context,
                        NAME_AUDITPROVIDER_SCHEDULE);
                    callback.RangeNotification(conditionPath, this, null, null, null, null);

                    inProcAgentInstanceContext.InstrumentationProvider.AContextScheduledEval();
                }
            };
            var agentInstanceContext = controller.Realization.AgentInstanceContextCreate;
            scheduleHandle = new EPStatementHandleCallbackSchedule(
                agentInstanceContext.EpStatementAgentInstanceHandle,
                scheduleCallback);
            long nextScheduledTime = ContextControllerInitTermUtil.ComputeScheduleMinimumDelta(
                Schedules, agentInstanceContext.TimeProvider.Time, agentInstanceContext.ImportServiceRuntime);
            agentInstanceContext.AuditProvider.ScheduleAdd(
                nextScheduledTime,
                agentInstanceContext,
                scheduleHandle,
                ScheduleObjectType.context,
                NAME_AUDITPROVIDER_SCHEDULE);
            agentInstanceContext.SchedulingService.Add(nextScheduledTime, scheduleHandle, scheduleSlot);
            return false;
        }