Beispiel #1
0
 public void SetParent(Location parent)
 {
     this.Parent = parent;
 }
Beispiel #2
0
 public void AddChildLocation(Location child)
 {
     ChildLocations.Add(child);
 }
Beispiel #3
0
        public bool AddLocation(string locationToAdd, string parentLocation)
        {
            lock (allLocations)
            {
                if (allLocations.ContainsKey(locationToAdd))
                {
                    return false;
                }
                else if (!allLocations.ContainsKey(parentLocation))
                {
                    return false;
                }
                else
                {
                    Location location = new Location(locationToAdd);

                    location.SetParent(allLocations[parentLocation]);
                    allLocations[parentLocation].AddChildLocation(location);

                    allLocations.Add(locationToAdd, location);

                    WriteLocationTree();

                    return true;
                }
            }
        }
Beispiel #4
0
        private void WriteLocationSubTree(XmlElement xmlParent, Location parent, XmlDocument xmlDoc)
        {
            foreach (Location childLocation in parent.ChildLocations)
            {

                XmlElement xmlChild = xmlDoc.CreateElement("Location");

                xmlChild.SetAttribute("Name", childLocation.Name());

                xmlParent.AppendChild(xmlChild);

                WriteLocationSubTree(xmlChild, childLocation, xmlDoc);
            }
        }
Beispiel #5
0
        private void ReadLocationSubTree(XmlElement xmlParent, Location parent)
        {
            foreach (XmlElement xmlChild in xmlParent.ChildNodes)
            {
                if (!xmlChild.Name.Equals("Location"))
                    throw new Exception("Location file has node " + xmlChild.Name);

                string name = xmlChild.GetAttribute("Name");
                int id = ++nextLocId;

                Location child = new Location(id, name);

                allLocations.Add(name, child);

                child.SetParent(parent);
                parent.AddChildLocation(child);

                //read the rest of the tree
                ReadLocationSubTree(xmlChild, child);
             }
        }
Beispiel #6
0
        private void ReadLocationTree()
        {
            XmlDocument xmlDoc = new XmlDocument();
            XmlReader xmlReader = XmlReader.Create(LocationsFile, xmlReaderSettings);

            xmlDoc.Load(xmlReader);
            XmlElement root = xmlDoc.FirstChild as XmlElement;

            if (!root.Name.Equals("Location"))
                throw new Exception("modules file does not start with location. bad file: " + LocationsFile);

            string name = root.GetAttribute("Name");
            int id = ++nextLocId;

            //read the root location
            RootLocation = new Location(id, name);
            allLocations.Add(name, RootLocation);

            //read the rest of tree
            ReadLocationSubTree(root, RootLocation);

            xmlReader.Close();
        }