예제 #1
0
        private static void ParseInputString()
        {
            MountainProjectDataSearch.InitMountainProjectData(serializationPath);
            if (MountainProjectDataSearch.DestAreas.Count() == 0)
            {
                Console.WriteLine("The xml either doesn't exist or is empty");
                Environment.Exit(0);
            }

            Console.WriteLine("File read.");

            bool keepSearching = true;

            while (keepSearching)
            {
                Console.WriteLine("\n\nPlease input the string you would like to parse: ");
                string input = Console.ReadLine();

                Stopwatch stopwatch = Stopwatch.StartNew();
                MPObject  result    = MountainProjectDataSearch.SearchMountainProject(input);
                stopwatch.Stop();

                if (result == null)
                {
                    Console.WriteLine("Nothing found matching \"" + input + "\"");
                }
                else
                {
                    string resultStr = "";
                    if (result is Area)
                    {
                        resultStr = (result as Area).ToString();
                    }
                    else if (result is Route)
                    {
                        resultStr = (result as Route).ToString();
                    }

                    Console.WriteLine("The following was found: " + resultStr + " (Found in " + stopwatch.ElapsedMilliseconds + " ms)");
                    Console.WriteLine($"Parent: {MountainProjectDataSearch.GetParent(result, -1).Name}");
                    Console.WriteLine("\nOpen result? (y/n) ");
                    if (Console.ReadKey().Key == ConsoleKey.Y)
                    {
                        Process.Start(result.URL);
                    }
                }

                Console.WriteLine("\nSearch something else? (y/n) ");
                keepSearching = Console.ReadKey().Key == ConsoleKey.Y;
            }
        }
예제 #2
0
        public static string GetLocationString(MPObject child)
        {
            MPObject innerParent, outerParent;

            innerParent = null;
            if (child is Route)
            {
                innerParent = MountainProjectDataSearch.GetParent(child, -2); //Get the "second to last" parent https://github.com/derekantrican/MountainProject/issues/12
            }
            else if (child is Area)
            {
                innerParent = MountainProjectDataSearch.GetParent(child, -1); //Get immediate parent
            }
            if (innerParent == null ||                                        //If "child" is a dest area, the parent will be "All Locations" which won't be in our directory
                innerParent.URL == Utilities.INTERNATIONALURL)                //If "child" is an area like "Europe"
            {
                return("");
            }

            outerParent = MountainProjectDataSearch.GetParent(child, 1); //Get state that route/area is in
            if (outerParent.URL == Utilities.INTERNATIONALURL)           //If this is international, get the country instead of the state (eg "China")
            {
                if (child.ParentUrls.Count > 3)
                {
                    if (child.ParentUrls.Contains(Utilities.AUSTRALIAURL)) //Australia is both a continent and a country so it is an exception
                    {
                        outerParent = MountainProjectDataSearch.GetParent(child, 2);
                    }
                    else
                    {
                        outerParent = MountainProjectDataSearch.GetParent(child, 3);
                    }
                }
                else
                {
                    return(""); //Return a blank string if we are in an area like "China" (so we don't return a string like "China is located in Asia")
                }
            }

            string locationString = $"Located in {innerParent.Name}";

            if (outerParent != null && outerParent.URL != innerParent.URL)
            {
                locationString += $", {outerParent.Name}";
            }

            locationString += "\n\n";

            return(locationString);
        }
예제 #3
0
        public static string GetLocationString(MPObject child, Area referenceLocation = null)
        {
            MPObject innerParent, outerParent;

            innerParent = null;
            outerParent = MountainProjectDataSearch.GetParent(child, 1); //Get state that route/area is in
            if (child is Route)
            {
                innerParent = MountainProjectDataSearch.GetParent(child, -2); //Get the "second to last" parent https://github.com/derekantrican/MountainProject/issues/12

                if (innerParent.URL == outerParent.URL)
                {
                    innerParent = MountainProjectDataSearch.GetParent(child, -1);
                }
            }
            else if (child is Area)
            {
                innerParent = MountainProjectDataSearch.GetParent(child, -1); //Get immediate parent
            }
            if (innerParent == null ||                                        //If "child" is a dest area, the parent will be "All Locations" which won't be in our directory
                innerParent.URL == Utilities.INTERNATIONALURL)                //If "child" is an area like "Europe"
            {
                return("");
            }

            if (outerParent.URL == Utilities.INTERNATIONALURL) //If this is international, get the country instead of the state (eg "China")
            {
                if (child.ParentUrls.Count > 3)
                {
                    if (child.ParentUrls.Contains(Utilities.AUSTRALIAURL)) //Australia is both a continent and a country so it is an exception
                    {
                        outerParent = MountainProjectDataSearch.GetParent(child, 2);
                    }
                    else
                    {
                        outerParent = MountainProjectDataSearch.GetParent(child, 3);
                    }
                }
                else
                {
                    return(""); //Return a blank string if we are in an area like "China" (so we don't return a string like "China is located in Asia")
                }
            }

            if (referenceLocation != null) //Override the "innerParent" in situations where we want the location string to include the "insisted" location
            {
                //Only override if the location is not already present
                if (innerParent.URL != referenceLocation.URL &&
                    outerParent.URL != referenceLocation.URL)
                {
                    innerParent = referenceLocation;
                }
            }

            string locationString = $"Located in {Markdown.Link(innerParent.Name, innerParent.URL)}";

            if (outerParent != null && outerParent.URL != innerParent.URL)
            {
                locationString += $", {Markdown.Link(outerParent.Name, outerParent.URL)}";
            }

            locationString += Markdown.NewLine;

            return(locationString);
        }