public override void Execute()
        {
            try
            {
                // Get all outstanding provisioning tasks
                var tasks = _taskService.AllProvisioningHandlerTasks().ToList();

                if (tasks.Any())
                {
                    foreach (var task in tasks)
                    {
                        try
                        {
                            // Create a new DI container to keep all work with the handler discrete
                            _objectBuilder.AddChildContainer();

                            // Instantiate the task handler
                            using (var taskHandler = _objectBuilder.Resolve <ITaskHandler>(task.Handler))
                            {
                                // Check that the task is scheduled to be executed
                                if (!taskHandler.CanExecute(task, null))
                                {
                                    return;
                                }

                                taskHandler.Execute(task, null);
                            }
                        }
                        finally
                        {
                            _objectBuilder.RemoveAllChildContainers();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _loggingManager.Write(LoggingEventSource.ProvisioningService, LoggingEventType.Error, ex.Message);
            }
        }
Пример #2
0
        public override void Execute()
        {
            try
            {
                var serviceInstanceId = Settings.Default.ServiceInstanceId;

                // Check that the Service Instance Id is not empty
                if (serviceInstanceId == Guid.Empty)
                {
                    throw new ArgumentNullException(string.Format(TaskResources.ConfigurationFile_SettingMissing, nameof(serviceInstanceId)));
                }

                // Get all outstanding operations tasks
                var tasks = _taskService.AllOperationsHandlerTasks().ToList();

                if (tasks.Any())
                {
                    foreach (var task in tasks)
                    {
                        try
                        {
                            RetryableOperation.Invoke(
                                ExceptionPolicies.General,
                                () =>
                            {
                                // Create a new DI container to keep all work with the handler discrete
                                _objectBuilder.AddChildContainer();

                                // Instantiate the task handler
                                using (var taskHandler = _objectBuilder.Resolve <ITaskHandler>(task.Handler))
                                {
                                    // Check that the task is scheduled to be executed
                                    if (!taskHandler.CanExecute(task, serviceInstanceId))
                                    {
                                        return;
                                    }

                                    taskHandler.Execute(task, serviceInstanceId);
                                }
                            });
                        }
                        catch (UnRecoverableErrorException)
                        {
                            // Already handled
                        }
                        catch (Exception ex)
                        {
                            // Create a History Log
                            var historyLog = task.CreateHistoryLog(_userIdentity.Name);
                            historyLog.EventType   = LoggingEventTypeNames.Error;
                            historyLog.EventDetail = string.Format(TaskResources.UnexpectedApplicationErrorInstanceHandlingId, ex.Message);
                            historyLog.Escalated   = false;
                            _historyLogService.Create(historyLog);

                            // Update Task NextScheduledDate
                            task.NextScheduledDate = DateTime.Now.AddMinutes(_parameterService.GetParameterByNameAndCache <int>(ParameterNames.RecoverableExceptionRetryDelayIntervalInMinutes));
                            _taskService.Update(task);
                        }
                        finally
                        {
                            _objectBuilder.RemoveAllChildContainers();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _loggingManager.Write(LoggingEventSource.OperationsService, LoggingEventType.Error, ex.Message);
            }
        }