Exemplo n.º 1
0
        private void LoadBlockTypes()
        {
            using (new Rock.Data.UnitOfWorkScope())
            {
                Rock.Model.BlockTypeService blockTypeService = new Rock.Model.BlockTypeService();

                // Add any unregistered blocks
                foreach (Rock.Model.BlockType blockType in blockTypeService.GetUnregisteredBlocks(Request.MapPath("~")))
                {
                    try
                    {
                        Control control = LoadControl(blockType.Path);
                        if (control is Rock.Web.UI.RockBlock)
                        {
                            blockType.Name = Path.GetFileNameWithoutExtension(blockType.Path);
                            // Split the name on intercapped changes (ie, "HelloWorld" becomes "Hello World")
                            blockType.Name        = System.Text.RegularExpressions.Regex.Replace(blockType.Name, "([a-z](?=[A-Z])|[A-Z](?=[A-Z][a-z]))", "$1 ");
                            blockType.Description = blockType.Path;

                            blockTypeService.Add(blockType, CurrentPersonId);
                            blockTypeService.Save(blockType, CurrentPersonId);
                        }
                    }
                    catch
                    {
                    }
                }

                ddlBlockType.DataSource     = blockTypeService.Queryable().OrderBy(b => b.Name).ToList();
                ddlBlockType.DataTextField  = "Name";
                ddlBlockType.DataValueField = "Id";
                ddlBlockType.DataBind();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Scans for unregistered blocks.
        /// </summary>
        private void ScanForUnregisteredBlocks()
        {
            BlockTypeService blockTypeService = new BlockTypeService();
            foreach ( Rock.Model.BlockType blockType in blockTypeService.GetUnregisteredBlocks( Request.MapPath( "~" ) ) )
            {
                try
                {
                    Control control = LoadControl( blockType.Path );
                    if ( control is Rock.Web.UI.RockBlock )
                    {
                        blockType.Name = Path.GetFileNameWithoutExtension( blockType.Path ).SplitCase();
                        blockType.Description = Rock.Reflection.GetDescription( control.GetType() ) ?? string.Empty;

                        blockTypeService.Add( blockType, CurrentPersonId );
                        blockTypeService.Save( blockType, CurrentPersonId );
                    }
                }
                catch
                {
                    //
                }
            }
        }
Exemplo n.º 3
0
        private void LoadBlockTypes()
        {
            using ( new Rock.Data.UnitOfWorkScope() )
            {
                Rock.Model.BlockTypeService blockTypeService = new Rock.Model.BlockTypeService();

                // Add any unregistered blocks
                foreach ( Rock.Model.BlockType blockType in blockTypeService.GetUnregisteredBlocks( Request.MapPath( "~" ) ) )
                {
                    try
                    {
                        Control control = LoadControl( blockType.Path );
                        if ( control is Rock.Web.UI.RockBlock )
                        {
                            blockType.Name = Path.GetFileNameWithoutExtension( blockType.Path );
                            // Split the name on intercapped changes (ie, "HelloWorld" becomes "Hello World")
                            blockType.Name = System.Text.RegularExpressions.Regex.Replace( blockType.Name, "([a-z](?=[A-Z])|[A-Z](?=[A-Z][a-z]))", "$1 " );
                            blockType.Description = blockType.Path;

                            blockTypeService.Add( blockType, CurrentPersonId );
                            blockTypeService.Save( blockType, CurrentPersonId );
                        }
                    }
                    catch
                    {
                    }
                }

                ddlBlockType.DataSource = blockTypeService.Queryable().OrderBy( b => b.Name).ToList();
                ddlBlockType.DataTextField = "Name";
                ddlBlockType.DataValueField = "Id";
                ddlBlockType.DataBind();
            }
        }