Exemple #1
0
 public Controller(Model mod)
 {
     this.mod = mod;
     subNodesList = mod.GetNodesList(0);
     prevSubNodesList = new List<Node>();
     currentNode = null;
 }
Exemple #2
0
        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;
                    }
                }
            }
        }
Exemple #3
0
 public Controller(string path)
 {
     this.mod = new Model(path);
     subNodesList = mod.GetNodesList(0);
     prevSubNodesList = new List<Node>();
     currentNode = null;
 }
Exemple #4
0
 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);
 }
Exemple #5
0
 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);
     }
 }
Exemple #6
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);
     }
 }
Exemple #7
0
        // 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;
        }
Exemple #8
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;
        }
Exemple #9
0
        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();
        }
Exemple #10
0
        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();
        }
Exemple #11
0
        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();
        }