Exemple #1
0
        // Same as other WriteNodesAndTagsToFile(), but accepts hashtables
        private static void WriteHashNodesToFile(Hashtable points)
        {
            System.Console.WriteLine("In Write HashNodes()");
            StreamWriter file;

            file = new StreamWriter(_path + "hashNodes.txt", false);

            foreach (DictionaryEntry pair in points)
            {
                HashNode node = (YouRunApp.HashNode)pair.Value;

                file.WriteLine("HashNode: " + node.GetName());
                file.WriteLine("Lat: " + node.GetLocation().GetLatitude());
                file.WriteLine("Lon: " + node.GetLocation().GetLongitude());
                file.WriteLine("Key: " + node.GetKeyword());
                file.WriteLine("Description: " + node.GetDescription());

                // Write tags of node to file
                foreach (HashNode.Tag tag in node.GetTagList())
                {
                    file.WriteLine("Keyword: " + tag.Keyword);
                    file.WriteLine("Value: " + tag.Value);
                }

                file.WriteLine();
            }

            file.Close();

            System.Console.WriteLine("Leaving HashNodes()");
        }
        private static bool IsPointOfInterest(HashNode node)
        {
            //runcalculations on point of interest?


            return(false);
        }
Exemple #3
0
        // Adds the tags found in XmlNode to the HashNode as keyword and value pairs
        private static void AddTagsToNode(XmlNode node, HashNode hashNode)
        {
            foreach (XmlNode child in node.ChildNodes)
            {
                string keyword = child.Attributes[GlobalConstants.OSM_ATTR_KEYWORD].Value;
                string value   = child.Attributes[GlobalConstants.OSM_ATTR_VALUE].Value;

                hashNode.AddTag(keyword, value);
            }
        }
Exemple #4
0
        // Test function that is used to write the test output to a file
        private static void WriteTestOutput(HashNode hashNode)
        {
            StreamWriter file;

            // Create a file stream to test out the node data
            file = new StreamWriter(_path + "test2.txt", true);

            WriteNodeToFile(hashNode, file);

            file.Close();
        }
Exemple #5
0
        // The function writes the given node to a file
        private static void WriteNodeToFile(HashNode hashNode, StreamWriter file)
        {
            file.Write("Name: ");
            file.WriteLine(hashNode.GetName());

            file.Write("Key: ");
            file.WriteLine(hashNode.GetKeyword());

            file.Write("Lat: ");
            file.WriteLine(hashNode.GetLocation().GetLatitude());

            file.Write("Lon: ");
            file.WriteLine(hashNode.GetLocation().GetLongitude());

            file.WriteLine("\n");
        }
Exemple #6
0
        // The function checks if the node is runnable. If it is, it sets its
        // runnable attribute to true and adds it to the runnablePoints
        // hashtable
        private static void CheckRun(HashNode hashNode, Hashtable runnablePoints)
        {
            StreamWriter runnableFile;

            if (hashNode.GetName() == "sidewalk" ||
                hashNode.GetName() == "footway")
            {
                hashNode.SetRunnable();
                runnablePoints.Add(hashNode.GetLocation(), hashNode);

                // The node is runnable, write it to the runnableFile
                runnableFile = new StreamWriter(_path + "/runable.txt", true);
                WriteNodeToFile(hashNode, runnableFile);

                runnableFile.Close();
            }
        }
Exemple #7
0
        // Helper function that converts XmlNodes to Nodes
        // If an XmlNode does not have any attributes then it returns null
        private static HashNode ConvertToHashNode(XmlNode node)
        {
            XmlAttributeCollection attributes;
            HashNode hashNode;

            string nodeName, keyword;
            double lat, lon;


            attributes = node.Attributes;

            if (attributes.Count == 0)
            {
                Debug.WriteLine("No attributes found in XmlNode");
                return(null);
            }

            foreach (XmlAttribute attr in attributes)
            {
                Console.Write(attr.Name + ": " + attr.Value + " ");
                Console.WriteLine();
            }
            Console.WriteLine();

            // Check if any of the attributes are null

            // Set Lat
            if (attributes[GlobalConstants.OSM_LAT] == null)
            {
                lat = GlobalConstants.LAT_NOT_FOUND;
            }
            else
            {
                lat = Double.Parse(attributes[GlobalConstants.OSM_LAT].Value);
            }

            // Set Lon
            if (attributes[GlobalConstants.OSM_LON] == null)
            {
                lon = GlobalConstants.LON_NOT_FOUND;
            }
            else
            {
                lon = Double.Parse(attributes[GlobalConstants.OSM_LON].Value);
            }

            // Set Node Name
            if (attributes[GlobalConstants.OSM_NODE_NAME] == null)
            {
                nodeName = GlobalConstants.NAME_NOT_FOUND;
            }
            else
            {
                nodeName = attributes[GlobalConstants.OSM_NODE_NAME].Value;
            }

            // Set Keyword
            if (attributes[GlobalConstants.OSM_ATTR_KEYWORD] == null)
            {
                keyword = GlobalConstants.KEYWORD_NOT_FOUND;
            }
            else
            {
                keyword = attributes[GlobalConstants.OSM_ATTR_KEYWORD].Value;
            }

            // Create an instance of our Node class
            hashNode = new HashNode(lat, lon, nodeName, keyword,
                                    GlobalConstants.DESCRIPTION_NOT_FOUND);

            AddTagsToNode(node, hashNode);

            //WriteTestOutput(hashNode);

            return(hashNode);
        }