Пример #1
0
 private void ElementSetEditor_Load(object sender, EventArgs e)
 {
     m_AutomationEngine = new AutomationEngine(wbElementSet);
     m_AutomationEngine.SetSequence(m_StepEditContext.Sequence);
     m_AutomationEngine.ExecutionComplete += m_AutomationEngine_ExecutionComplete;
     m_AutomationEngine.ExecuteSequence(m_StepEditContext.GetEditStepPosition());
 }
Пример #2
0
        public void ExecuteSequence(int executionScope)
        {
            if (!m_Executing)
            {
                m_Executing = true;
                zPauseRecording();

                m_AutomationEngine.ExecuteSequence(executionScope);
            }
        }
Пример #3
0
        private void GetValueSuggestor_Load(object sender, EventArgs e)
        {
            m_AutomationEngine = new AutomationEngine(wbPreview);
            m_AutomationEngine.SetSequence(m_StepEditContext.Sequence);
            m_AutomationEngine.ExecutionComplete += m_AutomationEngine_ExecutionComplete;

            int executionScope = m_GroupStepEditContext != null
                ? m_GroupStepEditContext.GetEditStepPosition()
                : m_StepEditContext.GetEditStepPosition();

            m_AutomationEngine.ExecuteSequence(executionScope);
        }
Пример #4
0
        public void Execute(IJobExecutionContext context)
        {
            ThreadSynchronizer threadSynchronizer = null;
            frmAutomation      frmAutomation      = null;

            try
            {
                m_JobKey = context.JobDetail.Key;
                m_Logger.InfoFormat("ExecuteSequenceJob {0} executing at {1}.", m_JobKey, DateTime.Now.ToString("r"));

                string connectionString = (string)context.MergedJobDataMap["connectionString"];
                AutomationController automationController = new AutomationController(connectionString);
                SchedulingController schedulingController = new SchedulingController(connectionString);

                long           scheduledTaskId = (long)context.MergedJobDataMap["scheduledTaskId"];
                ScheduledTask  scheduledTask   = schedulingController.GetScheduledTask(scheduledTaskId, DeletedInclusion.All);
                SequenceDetail sequenceDetail  = automationController.GetSequenceDetail(scheduledTask.TaskSequence.SequenceId);

                threadSynchronizer = (ThreadSynchronizer)context.MergedJobDataMap["threadSynchronizer"];
                threadSynchronizer.RunOnSynchronizedThread(() => frmAutomation = new frmAutomation(), true);

                using (AutomationEngine automationEngine = new AutomationEngine(frmAutomation.Browser))
                {
                    automationEngine.SetSequence(sequenceDetail.SequenceSteps);
                    Dictionary <string, IStateVariable> persistedData = automationController.GetSequencePersistedData(sequenceDetail.Sequence.SequenceId);
                    automationEngine.DataContext.LoadPersistedVariables(persistedData);

                    automationEngine.ExecutionComplete += automationEngine_ExecutionComplete;
                    using (m_ExecutionWaitHandle = new AutoResetEvent(false))
                    {
                        automationEngine.ExecuteSequence();

                        if (!m_ExecutionWaitHandle.WaitOne(scheduledTask.RunDurationLimit.HasValue
                            ? scheduledTask.RunDurationLimit.Value
                            : TimeSpan.FromMilliseconds(-1)))
                        {
                            throw new TimeoutException(
                                      String.Format("Scheduled sequence execution timed out because it reached the specified Run Duration Limit of {0}.",
                                                    scheduledTask.RunDurationLimit));
                        }
                    }
                    automationEngine.ExecutionComplete -= automationEngine_ExecutionComplete;

                    persistedData = automationEngine.DataContext.GetPersistedVariables();
                    automationController.SetSequencePersistedData(sequenceDetail.Sequence.SequenceId, persistedData);
                }

                ExecuteSequenceJobResult result = new ExecuteSequenceJobResult(
                    zGetScheduledTaskStatusFromExecutionState(m_ExecutionCompleteEventArgs.RunResult),
                    "");     //TODO: get error from ExecutionCompleteEventArgs
                context.Result = result;
            }
            catch (Exception ex)
            {
                JobExecutionException jobEx = new JobExecutionException(ex, false);
                throw jobEx;
            }
            finally
            {
                //Clean up
                try
                {
                    if (frmAutomation != null)
                    {
                        threadSynchronizer.RunOnSynchronizedThread(() => frmAutomation.Dispose(), true);
                    }
                }
                catch (Exception ex)
                {
                    if (m_Logger != null)
                    {
                        m_Logger.ErrorFormat("Cleanup failed for ExecuteSequenceJob {0}: {1}", m_JobKey, ex.Message);
                    }
                }

                //Dereference global variables
                m_Logger = null;
                m_JobKey = null;
                m_ExecutionCompleteEventArgs = null;
                m_ExecutionWaitHandle        = null;
            }
        }