public Controller(Model mod) { this.mod = mod; subNodesList = mod.GetNodesList(0); prevSubNodesList = new List<Node>(); currentNode = null; }
private void Cd(params string[] args) { if (args [1] == "..") { if(prevSubNodesList.Count>0) { int lastNode = prevSubNodesList.Count-1; this.currentNode = mod.GetNode(prevSubNodesList[lastNode].GetID()); ReloadLists(); } else { this.currentNode = null; ReloadLists(); } } else { if(subNodesList.Count==0) return; foreach(Node temp in subNodesList) { if(temp.name == args[1]) { currentNode = temp; ReloadLists(); break; } } } }
public Controller(string path) { this.mod = new Model(path); subNodesList = mod.GetNodesList(0); prevSubNodesList = new List<Node>(); currentNode = null; }
public override void realizeCommand(params string[] args) { View.WriteMessage(string.Format("dodaje nowy wezel o nazwie {0}", args[1])); UInt32 newID = 1000; //tymczasowa wartosc Node newNode = new Node(args[1],StateOfNode.uncompleted,newID,con.currentLvl+1); if(con.currentLvl!=0) mod.NewNode(con.currentNode.GetID(),newNode); else mod.NewNode(true,newNode); con.subNodesList.Add(newNode); }
private void AddNode(params string[] args) { Node newNode = new Node (args [1]); if (currentNode != null) { mod.NewNode (currentNode.GetID (), newNode); subNodesList = mod.GetSubNodesList (currentNode.GetID ()); } else { mod.NewNode (true, newNode); subNodesList=mod.GetNodesList(0); } }
void DestroyChildren(Node current) { List<Node> children = mod.GetSubNodesList (current.GetID ()); if (children.Count == 0) mod.Delete (current.GetID()); else { foreach(Node tmp in children) { DestroyChildren(tmp); children = mod.GetSubNodesList(current.GetID()); } DestroyChildren(current); } }
// overload, now you can send Node object like a argument private void SetReaderOn(Node nod) { reader.DiscardBufferedData(); reader.BaseStream.Position = 0;//zabezpieczyc przed reader bez sciezki do pliku string line; while ((line = reader.ReadLine()) != null) { if(ParseID(line) == nod.GetID()) return; } reader.BaseStream.Position = 0; }
private Node ParseNode(string line) { Node newNode = new Node(); newNode.name = ParseName(line); newNode.SetID(ParseID(line)); newNode.state = ParseState(line); newNode.Level = ParseLevel(line); return newNode; }
public void Save(Node NodeToSave) { reader.DiscardBufferedData(); reader.BaseStream.Position = 0; string line; while ((line = reader.ReadLine()) != null) { if (ParseID(line) == NodeToSave.GetID()) { line = NodeToSave.ToString (); } writer.WriteLine (line); } reader.BaseStream.Position=0; ReloadStreams(); }
public void NewNode(bool First, Node NewNodeToSave) { NewNodeToSave.Level=0; if(reader.BaseStream.Length != 0) NewNodeToSave.SetID(AssignNewID()); else NewNodeToSave.SetID(0); string lineToWrite = NewNodeToSave.ToString(); string line; reader.DiscardBufferedData(); reader.BaseStream.Position = 0; writer.BaseStream.Position=0; writer.WriteLine(lineToWrite); while ((line = reader.ReadLine()) != null) { writer.WriteLine(line); } ReloadStreams(); }
public void NewNode(UInt32 ParentID, Node NewNodeToSave) { reader.BaseStream.Position = 0; //writer.BaseStream.Position = 0; NewNodeToSave.SetID(AssignNewID()); NewNodeToSave.Level = GetLevel(ParentID) + 1; string newLineToWrite = NewNodeToSave.ToString (); string line; reader.DiscardBufferedData(); while ((line = reader.ReadLine()) != null) { writer.WriteLine(line); if(ParseID(line) == ParentID) { writer.WriteLine(newLineToWrite); } } ReloadStreams(); }