/// <summary>
        /// 按照名字查找任务
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public LogicTask FindTask(string name)
        {
            LogicTask task = null;

            foreach (var item in logicTasks)
            {
                if (item.Name == name)
                {
                    task = item;
                    break;
                }
            }
            return(task);
        }
 /// <summary>
 /// 卸载任务的子任务
 /// </summary>
 private void Disassemble(LogicTask task)
 {
     foreach (var item in task.GetType().GetProperties())
     {
         if (item.PropertyType.IsSubclassOf(typeof(LogicTask)))
         {
             if (item.CanWrite)
             {
                 LogicTask logic = (LogicTask)item.GetValue(task, null);
                 task.Manager.Remove(logic);
             }
         }
     }
 }
        /// <summary>
        /// 移除一个可控任务
        /// </summary>
        /// <param name="task"></param>
        public void Remove(LogicTask task)
        {
            int index = logicTasks.IndexOf(task);

            if (index >= 0)
            {
                lock (logicTasks)
                {
                    Disassemble(task);
                    typeof(LogicTask).GetProperty("Manager").SetValue(task, null, null);
                    logicTasks.RemoveAt(index);
                }
            }
        }
        /// <summary>
        /// 添加一个可控的任务
        /// </summary>
        /// <param name="task"></param>
        public void Add(LogicTask task)
        {
            lock (logicTasks)
            {
                for (int i = 0; i < logicTasks.Count; i++)
                {
                    if (logicTasks[i].Name == task.Name)
                    {
                        Remove(logicTasks[i]);
                        break;
                    }
                }

                if (task.Manager != null)
                {
                    task.Manager.Remove(task);
                }
                typeof(LogicTask).GetProperty("Manager").SetValue(task, this, null);
                logicTasks.Add(task);
                Assemble(task);
            }
        }
Beispiel #5
0
        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listBox1.SelectedIndex >= 0)
            {
                if (logicTask != null && logicTask.Name == Manager.FindTask(listBox1.SelectedItem.ToString()).Name)
                {
                    return;
                }
                logicTask         = Manager.FindTask(listBox1.SelectedItem.ToString());
                checkBox1.Checked = logicTask.LoopTask;
            }

            if (logicTask != null)
            {
                comboBox1.Items.Clear();
                propertyGrid1.SelectedObject = null;
                foreach (var item in logicTask.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly))
                {
                    comboBox1.Items.Add(item.Name);
                    comboBox1.SelectedIndex = 0;
                }
            }
        }
Beispiel #6
0
 public TaskCounter(LogicTask task)
 {
     logicTask = task;
 }