public bool SaveProject(String path) { if (null != path) { path_ = path; } if (null == path_) { return(false); } try { if (path_.Length != 0 && root_obj_ != null) { System.Text.UTF8Encoding utf8 = new System.Text.UTF8Encoding(false); root_obj_.UpdateProperty(true); var charData = JsonConvert.SerializeObject(root_obj_); File.WriteAllText(path_, charData, utf8); } } catch (Exception e) { Console.Write(e.ToString()); return(false); } return(true); }
public void Init(ToolObj tools) { if (tools != null) { tools.UpdateProperty(false); } tasks_ = new List <Task>(); foreach (var tool in tools.children) { var task = new Task(); task.Init(tool, OnTaskStateChanged); tasks_.Add(task); } }
public bool AddObj(int id, ToolObj obj, bool insert) { if (id == -1 && insert) { if (null == children) { children = new List <ToolObj>(); } obj.parent = new WeakReference(this); obj.UpdateProperty(false); children.Add(obj); changedNotify?.Invoke(new NotifyParam(TOOL_CHANGED_TYPE.TCT_ADD, obj, this)); return(true); } if (children == null) { return(false); } bool ret = false; int index = 0; foreach (var e in children) { ++index; if (e != null && e.tree_id_ == id) { if (insert) { if (e.children == null) { e.children = new List <ToolObj>(); } obj.parent = new WeakReference(e); e.children.Add(obj); changedNotify?.Invoke(new NotifyParam(TOOL_CHANGED_TYPE.TCT_ADD, obj, e)); } else { obj.parent = new WeakReference(this); children.Insert(index, obj); changedNotify?.Invoke(new NotifyParam(TOOL_CHANGED_TYPE.TCT_ADD, obj, this, index)); } ret = true; break; } } return(ret); }