Exemple #1
0
 public void EditorReader(Context context, System.Web.UI.Page page)
 {
     Context.Current = context;
     try
     {
         if (Module.Handler != null)
             Module.Handler.EditorLoad(context,  HttpContext.Current.Request.Params);
     }
     catch (Exception e_)
     {
         Context.GetLog_s<ModuleBuilder>().Error(string.Format("{0} editor load data error!", Module.Name), e_);
     }
     try
     {
         page.LoadControl(Module.Editor).RenderControl(new HtmlTextWriter(HttpContext.Current.Response.Output));
     }
     catch (Exception e_)
     {
         Context.GetLog_s<ModuleBuilder>().Error(string.Format("{0} editor load control error!", Module.Name), e_);
     }
 }
 public System.Web.UI.Control CreatePropertyControl(System.Web.UI.Page ownerPage)
 {
     return ownerPage.LoadControl(this.PropertyControlPath);
 }
 public static System.Web.UI.Control CreateMasterUserControl(System.Web.UI.Page mainPage, string strMasterPageUserControl)
 {
     System.Web.UI.Control userControl = null;
     try
     {
         string userControlPath = System.Configuration.ConfigurationManager.AppSettings[strMasterPageUserControl];
         userControl = mainPage.LoadControl(userControlPath);
     }
     catch (Exception ex)
     {
         ex.ToString();
     }
     return userControl;
 }
        /// <summary>
        /// Registers any block types that are not currently registered in Rock.
        /// </summary>
        /// <param name="physWebAppPath">A <see cref="System.String" /> containing the physical path to Rock on the server.</param>
        /// <param name="page">The <see cref="System.Web.UI.Page" />.</param>
        /// <param name="refreshAll">if set to <c>true</c> will refresh name, category, and description for all block types (not just the new ones)</param>
        public static void RegisterBlockTypes( string physWebAppPath, System.Web.UI.Page page, bool refreshAll = false)
        {
            // Dictionary for block types.  Key is path, value is friendly name
            var list = new Dictionary<string, string>();

            // Find all the blocks in the Blocks folder...
            FindAllBlocksInPath( physWebAppPath, list, "Blocks" );

            // Now do the exact same thing for the Plugins folder...
            FindAllBlocksInPath( physWebAppPath, list, "Plugins" );

            // Get a list of the BlockTypes already registered (via the path)
            var rockContext = new RockContext();
            var blockTypeService = new BlockTypeService( rockContext );
            var registered = blockTypeService.Queryable().ToList();

            // for each BlockType
            foreach ( string path in list.Keys)
            {
                if ( refreshAll || !registered.Any( b => b.Path.Equals( path, StringComparison.OrdinalIgnoreCase ) ) )
                {
                    // Attempt to load the control
                    try
                    {
                        System.Web.UI.Control control = page.LoadControl( path );

                        if ( control is Rock.Web.UI.RockBlock )
                        {
                            var blockType = registered.FirstOrDefault( b => b.Path.Equals( path, StringComparison.OrdinalIgnoreCase ) );
                            if ( blockType == null )
                            {
                                // Create new BlockType record and save it
                                blockType = new BlockType();
                                blockType.Path = path;
                                blockTypeService.Add( blockType );
                            }

                            Type controlType = control.GetType();

                            // Update Name, Category, and Description based on block's attribute definitions
                            blockType.Name = Rock.Reflection.GetDisplayName( controlType ) ?? string.Empty;
                            if ( string.IsNullOrWhiteSpace( blockType.Name ) )
                            {
                                // Parse the relative path to get the name
                                var nameParts = list[path].Split( '/' );
                                for ( int i = 0; i < nameParts.Length; i++ )
                                {
                                    if ( i == nameParts.Length - 1 )
                                    {
                                        nameParts[i] = Path.GetFileNameWithoutExtension( nameParts[i] );
                                    }
                                    nameParts[i] = nameParts[i].SplitCase();
                                }
                                blockType.Name = string.Join( " > ", nameParts );
                            }
                            if ( blockType.Name.Length > 100 )
                            {
                                blockType.Name = blockType.Name.Truncate( 100 );
                            }
                            blockType.Category = Rock.Reflection.GetCategory( controlType ) ?? string.Empty;
                            blockType.Description = Rock.Reflection.GetDescription( controlType ) ?? string.Empty;
                        }
                    }
                    catch ( Exception ex )
                    {
                        ExceptionLogService.LogException( new Exception( string.Format("Problem processing block with path '{0}'.", path ), ex ), null );
                    }
                }
            }

            rockContext.SaveChanges();
        }
        /// <summary>
        /// Registers any block types that are not currently registered in Rock.
        /// </summary>
        /// <param name="physWebAppPath">A <see cref="System.String" /> containing the physical path to Rock on the server.</param>
        /// <param name="page">The <see cref="System.Web.UI.Page" />.</param>
        /// <param name="currentPersonId">A <see cref="System.Int32" /> that contains the Id of the currently logged on <see cref="Rock.Model.Person" />.</param>
        /// <param name="refreshAll">if set to <c>true</c> will refresh name, category, and description for all block types (not just the new ones)</param>
        public void RegisterBlockTypes( string physWebAppPath, System.Web.UI.Page page, int? currentPersonId, bool refreshAll = false)
        {
            // Dictionary for block types.  Key is path, value is friendly name
            var list = new Dictionary<string, string>();

            // Find all the blocks in the Blocks folder...
            FindAllBlocksInPath( physWebAppPath, list, "Blocks" );

            // Now do the exact same thing for the Plugins folder...
            FindAllBlocksInPath( physWebAppPath, list, "Plugins" );

            // Get a list of the BlockTypes already registered (via the path)
            var registered = Repository.GetAll();

            // for each BlockType
            foreach ( string path in list.Keys)
            {
                if ( refreshAll || !registered.Any( b => b.Path.Equals( path, StringComparison.OrdinalIgnoreCase ) ) )
                {
                    // Attempt to load the control
                    System.Web.UI.Control control = page.LoadControl( path );
                    if ( control is Rock.Web.UI.RockBlock )
                    {
                        var blockType = registered.FirstOrDefault( b => b.Path.Equals( path, StringComparison.OrdinalIgnoreCase ) );
                        if ( blockType == null )
                        {
                            // Create new BlockType record and save it
                            blockType = new BlockType();
                            blockType.Path = path;
                            blockType.Guid = new Guid();
                            this.Add( blockType, currentPersonId );
                        }

                        Type controlType = control.GetType();

                        // Update Name, Category, and Description based on block's attribute definitions
                        blockType.Name = Rock.Reflection.GetDisplayName( controlType ) ?? string.Empty;
                        if ( string.IsNullOrWhiteSpace( blockType.Name ) )
                        {
                            // Parse the relative path to get the name
                            var nameParts = list[path].Split( '/' );
                            for ( int i = 0; i < nameParts.Length; i++ )
                            {
                                if ( i == nameParts.Length - 1 )
                                {
                                    nameParts[i] = Path.GetFileNameWithoutExtension( nameParts[i] );
                                }
                                nameParts[i] = nameParts[i].SplitCase();
                            }
                            blockType.Name = string.Join( " > ", nameParts );
                        }
                        if ( blockType.Name.Length > 100 )
                        {
                            blockType.Name = blockType.Name.Truncate( 100 );
                        }
                        blockType.Category = Rock.Reflection.GetCategory( controlType ) ?? string.Empty;
                        blockType.Description = Rock.Reflection.GetDescription( controlType ) ?? string.Empty;

                        this.Save( blockType, currentPersonId );
                    }
                }
            }
        }
        private static System.Web.UI.Control LoadSingleControl(string blockName, ref System.Web.UI.Page p)
        {
            System.Web.UI.Control result = null;

            if (p != null) {
                string controlName = p.Request.PhysicalApplicationPath;
                controlName = Path.Combine(controlName, blockName);
                if (File.Exists(controlName)) {
                    string virtualPath = "~/" + blockName.Replace("\\", "/");
                    result = p.LoadControl(virtualPath);
                }
            }

            return result;
        }
Exemple #7
0
        private BaseControl GetControl(System.Web.UI.Page page,ControlType c)
        {
            BaseControl control = null;
            switch (c)
            {
                case ControlType.ImageNews:

                    control = page.LoadControl("~/Controls/News/Layout1News.ascx") as Controls.News.Layout1News;
                    break;
                case ControlType.ImportantNews:
                    control = page.LoadControl("~/Controls/News/ImportantNews.ascx") as Controls.News.ImportantNews;
                    break;
                case ControlType.MainNews:
                    //control = new Controls.News.MainNews();
                    control = page.LoadControl("~/Controls/News/MainNews.ascx") as Controls.News.MainNews;
                    break;
                case ControlType.MostComments:
                    break;
                case ControlType.MostRead:
                    break;
                case ControlType.MultipleCategories:
                    control = page.LoadControl("~/Controls/News/Layout2News.ascx") as Controls.News.Layout2News;
                    //control = new Controls.News.Layout2News();
                    break;
                case ControlType.News:
                    control = page.LoadControl("~/Controls/News/Layout3News.ascx") as Controls.News.Layout3News;
                    //control = new Controls.News.Layout3News();
                    break;
                case ControlType.TitlePicture:
                    break;
                case ControlType.Urgent:
                    control = page.LoadControl("~/Controls/News/Urgent.ascx") as Controls.News.Urgent;
                    //control = new Controls.News.Urgent();
                    break;
                case ControlType.Columns:
                    control = page.LoadControl("~/Controls/Columns/ColumnsControl.ascx") as Controls.Columns.ColumnsControl;
                    //control = new Controls.Columns.ColumnsControl();
                    break;
                case ControlType.Ads1:
                    control = page.LoadControl("~/Controls/Ads/Advertisement1.ascx") as Controls.Ads.Advertisement1;

                    break;
                case ControlType.Ads2:
                    control = page.LoadControl("~/Controls/Ads/Advertisement2.ascx") as Controls.Ads.Advertisement2;
                    break;
            }
            return control;
        }
Exemple #8
0
        private BaseControl GetControlByID(System.Web.UI.Page page, int id)
        {
            BaseControl control = null;
            var con = (from x in ContentModuleTypes where x.ContentModuleTypeID == id select x).FirstOrDefault();
            if (con != null)
            {
                if (!string.IsNullOrEmpty(con.ControlPath))
                {
                    control = page.LoadControl(con.ControlPath) as BaseControl;
                }
            }

            return control;
        }
Exemple #9
0
        private static ContentView CreateFromActualPath(SNC.Content content, System.Web.UI.Page aspNetPage, ViewMode viewMode, string viewPath)
        {
            if (content == null)
                throw new ArgumentNullException("content");
            if (aspNetPage == null)
                throw new ArgumentNullException("aspNetPage");
            if (viewPath == null)
                throw new ArgumentNullException("viewPath");
            if (viewPath.Length == 0)
                throw new ArgumentOutOfRangeException("viewPath", "Parameter 'viewPath' cannot be empty");
            if (viewMode == ViewMode.None)
                throw new ArgumentOutOfRangeException("viewMode", "Parameter 'viewMode' cannot be ViewMode.None");

            string path = String.Concat("~", viewPath);

            ContentView view = GetContentViewFromCache(path);

            // if not in request cache
            if (view == null)
            {
                var addToCache = false;
                try
                {
                    view = aspNetPage.LoadControl(path) as ContentView;
                    addToCache = true;
                }
                catch (Exception e) //logged
                {
                    Logger.WriteException(e);
                    var errorContentViewPath = RepositoryPath.Combine(Repository.ContentViewFolderName, "Error.ascx");
                    var resolvedErrorContentViewPath = SkinManager.Resolve(errorContentViewPath);
                    path = String.Concat("~", resolvedErrorContentViewPath);
                    view = aspNetPage.LoadControl(path) as ContentView;
                    view.ContentException = e;
                }
                if (view == null)
                    throw new ApplicationException(string.Format("ContentView instantiation via LoadControl for path '{0}' failed.", path));
                if (addToCache)
                    AddContentViewToCache(path, view);
            }

            view.Initialize(content, viewMode);
            return view;
        }