Exemple #1
0
 public TaskManagerConfiguration()
 {
     MaxTaskPerQueue     = 4;
     MaxRerunAttempts    = 2;
     TimeShiftAfterCrash = TimeSpan.FromSeconds(20);
     State = TaskManagerState.Both;
 }
Exemple #2
0
        public TaskMessage Send()
        {
            TaskMessage message = new TaskMessage();
            ITask       task    = _dispatcher.Dispatch();

            if (task == null && _dispatcher.ActiveTasks == 0 && _mode == TaskMode.SearchAll)
            {
                _state = TaskManagerState.Completed;
            }
            message.Task = task;
            if (_result != null && _mode == TaskMode.SearchOne)
            {
                message.Result = _result;
            }
            message.TaskId = this.GetHashCode();
            return(message);
        }
Exemple #3
0
        public void Receive(TaskMessage message)
        {
            if (message != null && message.Task != null)
            {
                _dispatcher.Update(message.Task);

                if (message.Result != null)
                {
                    _result = message.Result;
                    _results.Add(_result);
                    if (_mode == TaskMode.SearchOne)
                    {
                        _state = TaskManagerState.Completed;
                    }
                }
            }
        }
Exemple #4
0
                public void Deserialize(MemoryStream ms)
                {
                    int tasks_count;

                    ms.ReadInt(out tasks_count);
                    for (int i = 0; i < tasks_count; i++)
                    {
                        var task = new Task();
                        task.Deserialize(ms);
                        tasks.Add(task);
                    }
                    ms.ReadInt(out active_task);
                    spaceship.debug.WriteText(active_task.ToString() + "\n");


                    int temp_state; ms.ReadInt(out temp_state); state = (TaskManagerState)temp_state;
                    int temp_next_state; ms.ReadInt(out temp_next_state); next_state = (TaskManagerState)temp_next_state;
                }
Exemple #5
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="expressionConverter">The <see cref="IExpressionConverter"/> instance.</param>
        /// <param name="taskDataContext">The <see cref="ITaskDataContext"/> instance.</param>
        /// <param name="serverManager">The <see cref="IQueueManager"/> instance.</param>
        /// <param name="queueManager">The <see cref="IServerManager"/> instance.</param>
        /// <param name="loggerFactory">The <see cref="ICommonLoggerFactory"/> instance.</param>
        /// <exception cref="ArgumentNullException"><paramref name="expressionConverter"/> is <see langword="null" />.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="taskDataContext"/> is <see langword="null" />.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="serverManager"/> is <see langword="null" />.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="queueManager"/> is <see langword="null" />.</exception>
        public TaskManager(TaskManagerConfiguration taskManagerConfiguration, ITaskBuilder taskBuilder, IExpressionConverter expressionConverter, ITaskDataContext taskDataContext, IServerManager serverManager, IQueueManager queueManager, ICommonLoggerFactory loggerFactory)
            : base("Task Manager", loggerFactory)
        {
            if (taskManagerConfiguration == null)
            {
                throw new ArgumentNullException(nameof(taskManagerConfiguration));
            }
            if (taskBuilder == null)
            {
                throw new ArgumentNullException(nameof(taskBuilder));
            }
            if (expressionConverter == null)
            {
                throw new ArgumentNullException("expressionConverter");
            }
            if (taskDataContext == null)
            {
                throw new ArgumentNullException("taskDataContext");
            }
            if (serverManager == null)
            {
                throw new ArgumentNullException("serverManager");
            }
            if (queueManager == null)
            {
                throw new ArgumentNullException("queueManager");
            }

            this.taskBuilder         = taskBuilder;
            this.expressionConverter = expressionConverter;
            this.taskDataContext     = taskDataContext;
            this.serverManager       = serverManager;
            this.queueManager        = queueManager;

            activeTasks = new Dictionary <Int64, IRunningTask>();

            maxRerunCount       = taskManagerConfiguration.MaxRerunAttempts;
            maxTasksPerQueue    = taskManagerConfiguration.MaxTaskPerQueue;
            timeShiftAfterCrash = taskManagerConfiguration.TimeShiftAfterCrash;
            taskManagerState    = taskManagerConfiguration.State;
        }
Exemple #6
0
 public TaskManager()
 {
     _state   = TaskManagerState.Suspended;
     _mode    = TaskMode.SearchOne;
     _results = new TaskResultCollection();
 }
Exemple #7
0
                public void OnUpdateFrame()
                {
                    state = next_state;
                    switch (state)
                    {
                    case TaskManagerState.Navigation:
                        if (tasks[active_task].destination != 0)
                        {
                            spaceship.fd.SetFlightPlan(spaceship.GenerateFlightPlan(spaceship.destinations[tasks[active_task].destination]));
                            spaceship.fd.StartFlight();
                            next_state = TaskManagerState.Travelling;
                        }
                        else
                        {
                            next_state = TaskManagerState.Action;
                        }
                        break;

                    case TaskManagerState.Travelling:
                        if (spaceship.fd.flightplan == null)
                        {
                            next_state = TaskManagerState.Action;
                        }
                        break;

                    case TaskManagerState.Action:
                        switch ((TaskType)tasks[active_task].type)
                        {
                        case TaskType.Navigation:
                            break;

                        case TaskType.Load: {
                            List <IMyCargoContainer> containers = FindBlocksOfType <IMyCargoContainer>(spaceship.system, spaceship, Settings.TAG);
                            bool all_are_full = true;
                            foreach (IMyCargoContainer container in containers)
                            {
                                if (!container.GetInventory().IsFull)
                                {
                                    all_are_full = false;
                                }
                            }
                            if (all_are_full)
                            {
                                next_state = TaskManagerState.NextTask;
                            }
                        }
                        break;

                        case TaskType.Unload: {
                            List <IMyCargoContainer> containers = FindBlocksOfType <IMyCargoContainer>(spaceship.system, spaceship, Settings.TAG);
                            bool all_are_empty = true;
                            foreach (IMyCargoContainer container in containers)
                            {
                                if (container.GetInventory().CurrentVolume > 0)
                                {
                                    all_are_empty = false;
                                }
                            }
                            if (all_are_empty)
                            {
                                next_state = TaskManagerState.NextTask;
                            }
                        }
                        break;

                        case TaskType.Charge:
                            break;

                        case TaskType.Repeat:
                            active_task = -1;
                            next_state  = TaskManagerState.NextTask;
                            break;

                        case TaskType.Total:
                            break;
                        }
                        break;

                    case TaskManagerState.NextTask:
                        active_task++;
                        if (active_task < tasks.Count)
                        {
                            next_state = TaskManagerState.Navigation;
                        }
                        break;
                    }
                }