Пример #1
0
        public static string GetReplyForMPLinks(Comment comment)
        {
            List <MPObject> foundMPObjects = new List <MPObject>();

            foreach (string url in ExtractMPLinks(WebUtility.HtmlDecode(comment.Body)))
            {
                MPObject mpObjectWithUrl = MountainProjectDataSearch.GetItemWithMatchingUrl(url);
                if (mpObjectWithUrl != null)
                {
                    foundMPObjects.Add(mpObjectWithUrl);
                }
            }

            string response = "";

            if (foundMPObjects.Count == 0)
            {
                return(null);
            }

            foundMPObjects.ForEach(p => response += GetFormattedString(p, includeUrl: false) + Markdown.HRule);
            response += GetBotLinks(comment);

            return(response);
        }
Пример #2
0
        private static string GetPopularRoutes(Area area, ResultParameters parameters)
        {
            string result = "Popular routes:\n";

            List <Route> popularRoutes = new List <Route>();

            if (area.PopularRouteUrls.Count == 0) //MountainProject doesn't list any popular routes. Figure out some ourselves
            {
                popularRoutes = area.GetPopularRoutes(3);
            }
            else
            {
                List <MPObject> itemsToSearch = new List <MPObject>();
                itemsToSearch.AddRange(area.SubAreas);
                itemsToSearch.AddRange(area.Routes);

                area.PopularRouteUrls.ForEach(p => popularRoutes.Add(MountainProjectDataSearch.GetItemWithMatchingUrl(p, itemsToSearch) as Route));
            }

            foreach (Route popularRoute in popularRoutes)
            {
                result += $"\n- {Markdown.Link(popularRoute.Name, popularRoute.URL)} {GetRouteAdditionalInfo(popularRoute, parameters)}";
            }

            if (string.IsNullOrEmpty(result))
            {
                return("");
            }

            result += Markdown.NewLine;

            return(result);
        }
Пример #3
0
        public static string GetPopularRoutes(Area area)
        {
            string result = "Popular routes:\n";

            if (area.PopularRouteUrls.Count == 0)
            {
                return("");
            }

            foreach (string url in area.PopularRouteUrls)
            {
                List <MPObject> itemsToSearch = new List <MPObject>();
                itemsToSearch.AddRange(area.SubAreas);
                itemsToSearch.AddRange(area.Routes);

                Route popularRoute = MountainProjectDataSearch.GetItemWithMatchingUrl(url, itemsToSearch) as Route;
                result += $"\n- {popularRoute.Name}";
            }

            result += "\n\n";

            return(result);
        }