Ejemplo n.º 1
0
        private void ExecutionLoop(ITaskProvider taskProvider, IRepository repository)
        {
            while (true)
            {
                status.CurrentTask = null;
                status.Status = ExecutionStatus.WaitingForTask;
                engine.SystemResources = systemResources;
                engine.Repository = wrapperFactory.CreateWrapper(repository);
                Task task;
                try
                {
                    task = taskProvider.GetTask();
                    if(task == null)
                        continue;
                }
                catch (TimeoutException)
                {
                    (taskProvider as ITaskProviderChannel).Abort();
                    return;
                }

                var interval = taskProvider.QueryNotifyInterval();
                using (new Timer(
                    x => OnTimer((Tuple<ITaskProvider, Guid>) x),
                    Tuple.Create(taskProvider, task.Id),
                    TimeSpan.Zero,
                    interval))
                {
                    status.CurrentTask = task;
                    status.Status = ExecutionStatus.ProcessingTask;
                    try
                    {
                        using (Perfomance.Trace("GeneralCore::StartExecution()").BindToTrace())
                        {
                            engine.ExecuteTask(task);
                        }
                        ReportSuccess(taskProvider, task);
                    }
                    catch (TaskRejectedException)
                    {
                        ReportReject(taskProvider, task);
                    }
                    catch (TaskFailedException e)
                    {
                        ReportFailure(taskProvider, task, ErrorSource.Task, e.InnerException);
                    }
                    catch (Exception e)
                    {
                        ReportFailure(taskProvider, task, ErrorSource.Engine, e.InnerException);
                    }
                }
            }
        }