Ejemplo n.º 1
0
        public void Start()
        {
            _stoped = false;
            TrackTask trackTask = null;

            while (!_stoped)
            {
                trackTask = _taskProvider.GetPlannedTask();

                if (trackTask != null)
                {
                    //if we have enough resources to execute task
                    if (_runningTasks.Count() < _tasksMaximum || trackTask.Track.ServiceUser.Subscripe.Priority != Priority.Low)
                    {
                        _taskProvider.UpdateTaskStatus(trackTask.Id, TrackTaskStatus.Started);
                        TaskUpdated?.Invoke(this, trackTask);
                        //Async execute task
                        var executingTask = trackTask;
                        var task          = _taskFactory.StartNew(async() =>
                        {
                            //Execute task
                            var status = await _taskExecutor.ExecuteTask(executingTask);
                            _taskProvider.UpdateTaskStatus(executingTask.Id, status);
                            _taskProvider.UpdateTargetContent(executingTask.Id, executingTask.Track.TargetContent);
                            //User must knows about his track
                            _userNotifier.NotifyUser(executingTask);
                            TaskUpdated?.Invoke(this, executingTask);
                        });
                        _runningTasks.Add(task);
                        task.ContinueWith((t) =>
                        {
                            _runningTasks.Remove(t);
                        });
                    }
                }
            }
        }