Carrotware.CMS.Core.SiteNavHelper.GetSiteDirectoryPaths C# (CSharp) Method

GetSiteDirectoryPaths() static private method

static private GetSiteDirectoryPaths ( ) : List
return List
        internal static List<string> GetSiteDirectoryPaths()
        {
            List<string> lstContent = null;

            using (CarrotCMSDataContext _db = CarrotCMSDataContext.Create()) {
                lstContent = (from ct in _db.vw_carrot_Contents
                              where ct.IsLatestVersion == true
                                  && ct.FileName.ToLowerInvariant().EndsWith(SiteData.DefaultDirectoryFilename)
                              select ct.FileName.ToLowerInvariant()).Distinct().ToList();
            }

            return lstContent;
        }

Usage Example

Example #1
0
        public static void RegisterRoutes(RouteCollection routes, bool OverrideRefresh)
        {
            try {
                string sKeyPrefix = "CarrotCakeCMS_";

                if (!HasRegisteredRoutes || OverrideRefresh)
                {
                    List <string> listFiles = SiteNavHelper.GetSiteDirectoryPaths();
                    int           iRoute    = 0;
                    List <Route>  lstRoute  = new List <Route>();

                    //routes.Clear();
                    //only remove routes that are tagged as coming from the CMS
                    foreach (Route rr in routes)
                    {
                        if (rr.DataTokens != null && rr.DataTokens["RouteName"] != null && rr.DataTokens["RouteName"].ToString().StartsWith(sKeyPrefix))
                        {
                            lstRoute.Add(rr);
                        }
                    }
                    foreach (Route rr in lstRoute)
                    {
                        RouteTable.Routes.Remove(rr);
                    }

                    foreach (string fileName in listFiles)
                    {
                        string sKeyName = sKeyPrefix + iRoute.ToString();

                        VirtualDirectory vd = new VirtualDirectory(fileName);
                        Route            r  = new Route(fileName.Substring(1, fileName.LastIndexOf("/")), vd);
                        if (r.DataTokens == null)
                        {
                            r.DataTokens = new RouteValueDictionary();
                        }
                        r.DataTokens["RouteName"] = sKeyName;
                        routes.Add(sKeyName, r);

                        iRoute++;
                    }

                    HasRegisteredRoutes = true;
                }
            } catch (Exception ex) {
                //assumption is database is probably empty / needs updating, so trigger the under construction view
                if (DatabaseUpdate.SystemNeedsChecking(ex) || DatabaseUpdate.AreCMSTablesIncomplete())
                {
                    routes.Clear();
                    HasRegisteredRoutes = false;
                }
                else
                {
                    //something bad has gone down, toss back the error
                    throw;
                }
            }
        }