Пример #1
0
        public override void Execute(Task task, Guid?serviceInstanceId)
        {
            try
            {
                if (!Enum.IsDefined(typeof(ProvisionTaskType), task.Name))
                {
                    var message = string.Format(TaskResources.ProvisioningTaskRequest_InvalidRequestInvalidTaskName, task.Name);
                    throw new UnRecoverableErrorException(string.Format(message, task.Name));
                }

                // We do not want the task to retry if we have a problem
                var provisioningTask = _objectBuilder.Resolve <IProvisioningTaskProcessor>(task.Name);
                provisioningTask.Execute(task);

                // Complete the task
                _taskService.CompleteTask(task, true);
            }
            catch (UnRecoverableErrorException ex)
            {
                // Catch and log the exception
                _loggingManager.Write(LoggingEventSource.ProvisioningService, LoggingEventType.Error, ex.Message);

                // Complete UnRecoverable Exception
                _taskService.CompleteUnrecoverableTaskException(task, ex.Message);
            }
            catch (Exception ex)
            {
                // Catch and log the exception
                _loggingManager.Write(LoggingEventSource.ProvisioningService, LoggingEventType.Error, ex.Message);

                // Create a History Log
                var historyLog = task.CreateHistoryLog(_userIdentity.Name);
                historyLog.EventType   = LoggingEventTypeNames.Error;
                historyLog.EventDetail = string.Format(TaskResources.UnexpectedApplicationError, "Provisioning");
                historyLog.Escalated   = false;
                _historyLogService.Create(historyLog);

                // Complete the task
                _taskService.CompleteTask(task, false);
            }
        }
        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);
            }
        }
Пример #3
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);
            }
        }
Пример #4
0
 public void LoggingManager_Execute_LoggingAllEventTypeError_ExecutesSuccessfully()
 {
     _target.Write(LoggingEventSource.ProvisioningService, LoggingEventType.Error, "Test Message");
     _target.Write(LoggingEventSource.ProvisioningService, LoggingEventType.Warning, "Test Message");
     _target.Write(LoggingEventSource.ProvisioningService, LoggingEventType.Information, "Test Message");
 }