Пример #1
0
        public List <NnTask> AddTask(
            List <NnParam> pars
            )
        {
            var newTasks = new Dictionary <NnParam, NnTask>();

            try {
                foreach (var param in pars)
                {
                    if (!param.Pad(Template))
                    {
                        continue;
                    }

                    string tag     = param.GetTag(Template.Variables);
                    NnTask newTask =
                        new NnTask(
                            tag,
                            Template.Type,
                            FSPath.SubPath("tasks").SubPath(tag),
                            Template.GenerateContent(param.Variables),
                            Template.GenerateContent(param.Variables, true),
                            Template.GenerateModuleOptions(param.Variables)
                            );

                    if (tasks.All(x => !x.Value.Equals(newTask)))
                    {
                        newTasks[param] = newTask;
                    }
                }
            } catch {
                Util.ErrorHappend("Error while creating task!");
                return(new List <NnTask>());
            }

            try {
                foreach (var newTask in newTasks)
                {
                    tasks[newTask.Key] = newTask.Value;
                }

                UpdateCommonData(newTasks.Keys.ToList());

                OnPropertyChanged("Plan - AddTask");
                OnPropertyChanged("TaskAmount");
                OnPropertyChanged("BusyTaskAmount");

                Save();
                return(newTasks.Values.ToList());
            } catch {
                Util.ErrorHappend("Error while adding task!");
                return(newTasks.Values.ToList());
            }
        }
Пример #2
0
        public bool DeleteTask(
            NnTask task
            )
        {
            bool success = false;

            try {
                if (task.IsBusy())
                {
                    if (Util.WarnAndDecide("Selected task is busy rn. Terminate and delete?"))
                    {
                        task.Terminate();
                    }
                    else
                    {
                        return(false);
                    }
                }

                foreach (var item in tasks.Where(kvp => kvp.Value == task).ToList())
                {
                    tasks.Remove(item.Key);
                    string path = FSPath.SubPath("tasks").SubPath("_removed").SubPath(task.Name);
                    while (Directory.Exists(path))
                    {
                        path += "_";
                    }
                    Directory.Move(task.FSPath, path);
                    DeleteParamInCommonData(item.Key);
                }
                success = true;
            } catch {
                Util.ErrorHappend("Error while deleting task!");
                success = false;
            } finally {
                OnPropertyChanged("Plan - DeleteTask");
                OnPropertyChanged("TaskAmount");
                OnPropertyChanged("BusyTaskAmount");

                Save();
            }
            return(success);
        }
Пример #3
0
        public static NnPlan?Load(RPath path)
        {
            try {
                var planData =
                    (SaveData)Util.DeserializeFromFile(
                        path.SubPath(NnAgent.planFileName)
                        );

                Dictionary <NnParam, NnTask> tasks = new Dictionary <NnParam, NnTask>();
                foreach (var taskId in planData.taskIds)
                {
                    NnTask?task = NnTask.Load(
                        path.SubPath("tasks").SubPath(taskId.Value)
                        );
                    if (task != null)
                    {
                        tasks[taskId.Key] = task;
                    }
                }

                NnTemplate?template = NnTemplate.Load(path);

                if (template == null)
                {
                    throw new Exception();
                }

                NnPlan plan = new NnPlan(
                    planData.name,
                    path,
                    template,
                    tasks,
                    // planData.consts?.ToImmutableDictionary(),
                    planData.Type
                    );

                return(plan);
            } catch {
                Util.ErrorHappend($"Error while loading plan!");
                return(null);
            }
        }
Пример #4
0
 public bool IsRef(NnTask data) =>
 this.Task == data;
Пример #5
0
 public NnTaskData(NnTask task, NnParam param)
 {
     this.Task  = task;
     this.Param = param;
     Subscribe(task);
 }