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();
}