Ejemplo n.º 1
0
        public QueueManager AddProcess(BaseProcessable processable, int priority = 0, string id = null)
        {
            var process = new Process(processable, priority, id);

            _queue.Add(process);
            if (PriorityEnabled)
            {
                _queue.OrderByPriority();
            }
            if (_saveQueueMethod != null)
            {
                SaveQueue();
            }
            return(this);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Set the queue as a List type instead of BlockingCollection
        /// </summary>
        /// <returns>Context</returns>
        public QueueManager UseListQueue()
        {
            if (_queueType == "List")
            {
                return(this);
            }

            bool running = Status == QueueStatus.Running;

            Stop();
            var queue = new ProcessList();

            foreach (var process in _queue.ProcessBlockingCollection)
            {
                queue.Add(process);
            }

            _queueType = "List";
            _queue     = new BaseProcessQueue(_queueType);
            foreach (var process in queue)
            {
                _queue.Add(process);
            }

            Console.WriteLine("Queue Changed to list");
            if (running)
            {
                Start();
            }
            return(this);
        }
Ejemplo n.º 3
0
        private void GetStoredQueue()
        {
            try
            {
                List <Process> list;
                if (_getQueueMethod == null)
                {
                    list = _getQueueListMethod.Invoke(Id);
                }
                else
                {
                    var jsonQueue = _getQueueMethod.Invoke(Id);

                    list = JsonConvert.DeserializeObject <List <Process> >(jsonQueue);
                }

                _queue = new BaseProcessQueue(_queueType);
                foreach (var process in list)
                {
                    _queue.Add(process);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error on queue, " + ex.Message);
                throw;
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Use a BlockingCollection as a queue, this is the default queue not necessary if you don't call UseListQueue before
        /// </summary>
        /// <returns>Context</returns>
        public QueueManager UseBlockingCollectionQueue()
        {
            bool running = Status == QueueStatus.Running;

            Stop();
            var queue = new ProcessBlockingCollection();

            foreach (var process in _queue.ProcessList)
            {
                queue.Add(process);
            }

            _queueType = "BlockingCollection";

            _queue = new BaseProcessQueue(_queueType);
            foreach (var process in queue)
            {
                _queue.Add(process);
            }

            if (running)
            {
                Start();
            }
            return(this);
        }