Example #1
0
        protected override void Execute(CodeActivityContext executionContext)
        {
            // TODO not very happy about these being outside try catch but need to think of way
            // of retrying a workflow even when we don't have a context and org service!

            var workflowContext     = GetWorkflowContext(executionContext);
            var organisationService = GetOrganizationService(workflowContext.UserId, executionContext);
            var tracingService      = GetTraceService(executionContext);
            var trace = new DynamicsLoggingService(tracingService, organisationService.GetUniqueOrganisationName(),
                                                   workflowContext.CorrelationId);

            var config = organisationService.GetFExConfiguration(workflowContext.PrimaryEntityId,
                                                                 ConfigAttribute.SchedulingAttributes, trace);

            try
            {
                var repo        = new DynamicsRepository(organisationService, trace);
                var nextRunDate = new CalculateNextRunDateJob(repo, config, trace, workflowContext.Depth, workflowContext.CorrelationId).Execute();
                CurrentRevision.Set(executionContext, config.Revision);
                NextRunDate.Set(executionContext, nextRunDate.NextDate.UtcDateTime);
            }
            catch (Exception exp)
            {
                var msg = "Error has Occured Running CalculateNextRunDate Activity. Seting Last Run Status to Error and logging.";
                HandleException(exp, msg, config, organisationService, trace);
            }
        }
Example #2
0
        private static void ScheduleNextRun()
        {
            // Destroy existing timers
            Stop();

            // Eliminate run started (no run now)
            m_runStarted = null;

            // Parse string for cron expression
            CronExpression cronExpression = null;

            try
            {
                cronExpression = new CronExpression(Settings.RunScheduleCron);
            }
            catch (Exception ex)
            {
                Logger.Log("Couldn't setup CRON expression.", ex);
            }

            // Calculate next run
            try
            {
                NextRunDate  = cronExpression.GetNextValidTimeAfter(DateTime.Now).Value;
                NextStopDate = null;

                m_startTimer           = new Timer(NO_FIRE);
                m_startTimer.AutoReset = false;
                m_startTimer.Interval  = NextRunDate.Value.Subtract(DateTime.Now).TotalMilliseconds;
                m_startTimer.Elapsed  += StartTimer_Elapsed;
                m_startTimer.Enabled   = true;

                // Log
                Logger.Log("Next run scheduled succesfully for " + NextRunDate.ToString());
            }
            catch (Exception ex)
            {
                Logger.Log("Couldn't schedule next run.", ex);
            }
        }