Exemplo n.º 1
0
        public override void Init(IServiceContainer serviceContainer, IDictionary <string, string> jobArgsDictionary)
        {
            base.Init(serviceContainer, jobArgsDictionary);

            _taskName      = jobArgsDictionary[JobArgumentNames.ScheduledTask];
            _configuration = _serviceProvider.GetRequiredService <IOptionsSnapshot <InitializationConfiguration> >().Value;
        }
Exemplo n.º 2
0
        private static IScheduledTask GetTaskOfType(
            string taskName,
            InitializationConfiguration configuration,
            Func <Task <SqlConnection> > openSupportRequestSqlConnectionAsync,
            ILoggerFactory loggerFactory)
        {
            if (string.IsNullOrEmpty(taskName))
            {
                throw new ArgumentException(nameof(taskName));
            }

            if (!taskName.EndsWith("Task", StringComparison.OrdinalIgnoreCase))
            {
                taskName = $"{taskName}Task";
            }

            var scheduledTaskType = Type.GetType($"{_tasksNamespace}.{taskName}");

            IScheduledTask scheduledTask;

            if (scheduledTaskType != null && typeof(IScheduledTask).IsAssignableFrom(scheduledTaskType))
            {
                var args = new object[] {
                    configuration,
                    openSupportRequestSqlConnectionAsync,
                    loggerFactory
                };

                scheduledTask = (IScheduledTask)Activator.CreateInstance(scheduledTaskType, args);
            }
            else
            {
                // task is invalid
                throw new NotSupportedException($"Unknown scheduled task: '{taskName}'.");
            }

            return(scheduledTask);
        }
Exemplo n.º 3
0
        public static IScheduledTask Create(
            string scheduledTaskName,
            InitializationConfiguration configuration,
            Func <Task <SqlConnection> > openSupportRequestSqlConnectionAsync,
            ILoggerFactory loggerFactory)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            if (loggerFactory == null)
            {
                throw new ArgumentNullException(nameof(loggerFactory));
            }

            var scheduledTask = GetTaskOfType(
                scheduledTaskName,
                configuration,
                openSupportRequestSqlConnectionAsync,
                loggerFactory);

            return(scheduledTask);
        }