Пример #1
0
        /// <summary>
        /// Queues the scheduled task.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        public void QueueScheduledTask <T>()
            where T : IScheduledTask
        {
            var scheduledTask = ScheduledTasks.First(t => t.ScheduledTask.GetType() == typeof(T));

            QueueScheduledTask(scheduledTask);
        }
Пример #2
0
        /// <summary>
        /// Executes the queued tasks.
        /// </summary>
        private void ExecuteQueuedTasks()
        {
            Logger.LogInformation("ExecuteQueuedTasks");

            // Execute queued tasks
            lock (_taskQueue)
            {
                var list = new List <Tuple <Type, TaskOptions> >();

                while (_taskQueue.TryDequeue(out var item))
                {
                    if (list.All(i => i.Item1 != item.Item1))
                    {
                        list.Add(item);
                    }
                }

                foreach (var enqueuedType in list)
                {
                    var scheduledTask = ScheduledTasks.First(t => t.ScheduledTask.GetType() == enqueuedType.Item1);

                    if (scheduledTask.State == TaskState.Idle)
                    {
                        Execute(scheduledTask, enqueuedType.Item2);
                    }
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Cancels if running
        /// </summary>
        /// <typeparam name="T"></typeparam>
        public void CancelIfRunning <T>()
            where T : IScheduledTask
        {
            var task = ScheduledTasks.First(t => t.ScheduledTask.GetType() == typeof(T));

            ((ScheduledTaskWorker)task).CancelIfRunning();
        }
Пример #4
0
        /// <summary>
        /// Queues the scheduled task.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="options">Task options</param>
        public void QueueScheduledTask <T>(TaskExecutionOptions options)
            where T : IScheduledTask
        {
            var scheduledTask = ScheduledTasks.First(t => t.ScheduledTask.GetType() == typeof(T));

            QueueScheduledTask(scheduledTask, options);
        }
Пример #5
0
        /// <summary>
        /// Cancels if running and queue.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="options">Task options.</param>
        public void CancelIfRunningAndQueue <T>(TaskOptions options)
            where T : IScheduledTask
        {
            var task = ScheduledTasks.First(t => t.ScheduledTask.GetType() == typeof(T));

            ((ScheduledTaskWorker)task).CancelIfRunning();

            QueueScheduledTask <T>(options);
        }
Пример #6
0
        public void QueueIfNotRunning <T>()
            where T : IScheduledTask
        {
            var task = ScheduledTasks.First(t => t.ScheduledTask.GetType() == typeof(T));

            if (task.State != TaskState.Running)
            {
                QueueScheduledTask <T>(new TaskOptions());
            }
        }
Пример #7
0
        /// <summary>
        /// Executes the queued tasks.
        /// </summary>
        private void ExecuteQueuedTasks()
        {
            // Execute queued tasks
            lock (_taskQueue)
            {
                foreach (var type in _taskQueue.ToList())
                {
                    var scheduledTask = ScheduledTasks.First(t => t.ScheduledTask.GetType() == type);

                    if (scheduledTask.State == TaskState.Idle)
                    {
                        Execute(scheduledTask);

                        _taskQueue.Remove(type);
                    }
                }
            }
        }
Пример #8
0
        /// <summary>
        /// Queues the scheduled task.
        /// </summary>
        /// <param name="task">The task.</param>
        public void QueueScheduledTask(IScheduledTask task)
        {
            var scheduledTask = ScheduledTasks.First(t => t.ScheduledTask.GetType() == task.GetType());

            QueueScheduledTask(scheduledTask);
        }
Пример #9
0
        /// <summary>
        /// Queues the scheduled task.
        /// </summary>
        /// <param name="task">The task.</param>
        /// <param name="options">The task options.</param>
        public void QueueScheduledTask(IScheduledTask task, TaskExecutionOptions options)
        {
            var scheduledTask = ScheduledTasks.First(t => t.ScheduledTask.GetType() == task.GetType());

            QueueScheduledTask(scheduledTask, options);
        }