private static void GetNavigationLinks(INavLinkProvider linkProvider, SortedDictionary <int, NavLink> links)
        {
            foreach (NavLink link in linkProvider.GetLinks())
            {
                int order = link.Order;

                if (order == 0)
                {
                    order = links.Count == 0 ? 1 : links.Keys.Max() + 1;
                }

                links.Add(order, link);
            }
        }
        public string GetLinks()
        {
            try
            {
                var nodes = new XElement("Nodes");

                foreach (var provider in _linkProviders)
                {
                    INavLinkProvider linkProvider = provider.Value;

                    if (linkProvider == null)
                    {
                        continue;
                    }

                    string providerName = provider.Key;

                    var node = new XElement(providerName);

                    var links = new SortedDictionary <int, NavLink>();

                    try
                    {
                        GetNavigationLinks(linkProvider, links);
                    }
                    catch
                    {
                        try
                        {
                            Thread.Sleep(1000);
                            ((NavLinkProvider)linkProvider).ClearCache();
                            GetNavigationLinks(linkProvider, links);
                        }
                        catch { }
                    }

                    if (links.Count == 0)
                    {
                        continue;
                    }

                    foreach (var linkInfo in links)
                    {
                        NavLink navLink = linkInfo.Value;
                        navLink.Order = linkInfo.Key;
                        navLink.Id    = GetLinkId(navLink, providerName);

                        var link = new XElement("NavLink");

                        foreach (var property in _navLinkProperties)
                        {
                            try
                            {
                                string name  = property.Key;
                                string value = (property.Value.GetValue(navLink) ?? string.Empty).ToString().Trim();

                                if (name.Equals("Url") || name.Equals("Title"))
                                {
                                    link.Add(new XElement(name, new XCData(value)));
                                }
                                else
                                {
                                    link.Add(new XAttribute(name, value));
                                }
                            }
                            catch { }
                        }

                        node.Add(link);
                    }

                    nodes.Add(node);
                }

                return(nodes.ToString());
            }
            catch (Exception exception)
            {
                throw new APIException(20001, "[NavigationService:GetLinks] " + exception.Message);
            }
        }