Exemple #1
0
        public static void ProcessQueue()
        {
            lock (_syncLock)
            {
                if (_isQueueProcessing)
                {
                    return;
                }
            }

            _isQueueProcessing = true;

            var task = new Task(() =>
            {
                using (var repository = ContainerBootstrapper.Container.Resolve <IRepository <WorkerTask> >())
                {
                    var hasUnprocessedTasks = repository.Any(workerTask => workerTask.IsProcessing == false && workerTask.Processed == null && workerTask.Deleted == null);
                    if (hasUnprocessedTasks)
                    {
                        foreach (var unprocessedTask in repository.Where(workerTask => workerTask.IsProcessing == false && workerTask.Processed == null && workerTask.Deleted == null))
                        {
                            Type plugin = Find(unprocessedTask.TaskName);
                            if (plugin == null)
                            {
                                throw new InvalidOperationException(string.Format(Resources.EXEC_UNABLE_TO_FIND_PLUGIN, unprocessedTask.TaskName));
                            }

                            IPipeServer server = new PipeServer(plugin);
                            server.Completed  += OnCompleted;
                            server.Error      += OnError;

                            unprocessedTask.WorkerId     = server.Id;
                            unprocessedTask.IsProcessing = true;

                            repository.AddOrUpdate(unprocessedTask);

                            _workers.Add(server);

                            server.Connect(unprocessedTask.GetWorkerParameters());
                        }
                    }
                }

                _isQueueProcessing = false;
            });

            task.Start();
        }