Rock.Model.LayoutService.RegisterLayouts C# (CSharp) Метод

RegisterLayouts() публичный статический Метод

Registers any layouts in a particular site's theme folder that do not currently have any layouts registered in Rock.
public static RegisterLayouts ( string physWebAppPath, SiteCache site ) : void
physWebAppPath string A containing the physical path to Rock on the server.
site SiteCache The site.
Результат void
        public static void RegisterLayouts( string physWebAppPath, SiteCache site )
        {
            // Dictionary for block types.  Key is path, value is friendly name
            var list = new Dictionary<string, string>();

            // Find all the layouts in theme layout folder...
            string layoutFolder = Path.Combine(physWebAppPath, string.Format("Themes\\{0}\\Layouts", site.Theme));

            // search for all layouts (aspx files) under the physical path
            var layoutFiles = new List<string>();
            DirectoryInfo di = new DirectoryInfo( layoutFolder );
            if ( di.Exists )
            {
                foreach(var file in di.GetFiles( "*.aspx", SearchOption.AllDirectories ))
                {
                    layoutFiles.Add( Path.GetFileNameWithoutExtension( file.Name ) );
                }
            }

            var rockContext = new RockContext();
            var layoutService = new LayoutService( rockContext );

            // Get a list of the layout filenames already registered
            var registered = layoutService.GetBySiteId( site.Id ).Select( l => l.FileName ).Distinct().ToList();

            // for each unregistered layout
            foreach ( string layoutFile in layoutFiles.Except( registered, StringComparer.CurrentCultureIgnoreCase ) )
            {
                // Create new layout record and save it
                Layout layout = new Layout();
                layout.SiteId = site.Id;
                layout.FileName = layoutFile;
                layout.Name = layoutFile.SplitCase();
                layout.Guid = new Guid();

                layoutService.Add( layout );
            }

            rockContext.SaveChanges();
        }

Usage Example

Пример #1
0
 private void LoadLayouts(SiteCache Site)
 {
     ddlLayout.Items.Clear();
     var layoutService = new LayoutService();
     layoutService.RegisterLayouts( Request.MapPath( "~" ), Site, CurrentPersonId );
     foreach ( var layout in layoutService.GetBySiteId( Site.Id ) )
     {
         ddlLayout.Items.Add( new ListItem( layout.Name, layout.Id.ToString() ) );
     }
 }
All Usage Examples Of Rock.Model.LayoutService::RegisterLayouts