Ejemplo n.º 1
0
        private void AddWebPart()
        {
            String webPartIDString = Request.Params.Get("addpart");

            if (webPartIDString.Length == 36)
            {
                Guid webPartID = new Guid(webPartIDString);

                WebPartContent webPartContent = new WebPartContent(webPartID);
                if ((webPartContent.WebPartId != Guid.Empty) && (webPartContent.AvailableForMyPage))
                {
                    if (HttpContext.Current != null)
                    {
                        String path = HttpContext.Current.Server.MapPath("~/bin")
                                      + Path.DirectorySeparatorChar + webPartContent.AssemblyName + ".dll";
                        Assembly assembly = Assembly.LoadFrom(path);
                        Type     type     = assembly.GetType(webPartContent.ClassName, true, true);
                        WebPart  webPart  = Activator.CreateInstance(type) as WebPart;
                        if (webPart != null)
                        {
                            WebPartContent.UpdateCountOfUseOnMyPage(webPartContent.WebPartId, 1);
                            webPart.ID = Guid.NewGuid().ToString();

                            CWebPartManager CManager = (CWebPartManager)this.WebPartManager1;
                            CManager.AddWebPart(webPart, this.CenterWebPartZone, 0);
                            CManager.SetDirty();
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public override WebPart GetWebPart(WebPartDescription description)
        {
            SiteSettings siteSettings = CacheHelper.GetCurrentSiteSettings();

            if (siteSettings == null)
            {
                return(null);
            }

            WebPart webPart = null;

            if (description.ID.Length == 36)
            {
                Guid           webPartID      = new Guid(description.ID);
                WebPartContent webPartContent = new WebPartContent(webPartID);
                if (webPartContent.WebPartId != Guid.Empty)
                {
                    if (HttpContext.Current != null)
                    {
                        String path = HttpContext.Current.Server.MapPath("~/bin")
                                      + Path.DirectorySeparatorChar + webPartContent.AssemblyName + ".dll";
                        Assembly assembly = Assembly.LoadFrom(path);
                        Type     type     = assembly.GetType(webPartContent.ClassName, true, true);
                        object   obj      = Activator.CreateInstance(type);
                        if (obj != null)
                        {
                            webPart = (WebPart)obj;
                            WebPartContent.UpdateCountOfUseOnMyPage(webPartContent.WebPartId, 1);
                        }
                    }
                }
            }
            else
            {
                mojoPortal.Business.Module module = new mojoPortal.Business.Module(int.Parse(description.ID));

                SiteModuleControl siteModule = Page.LoadControl("~/" + module.ControlSource) as SiteModuleControl;
                if (siteModule != null)
                {
                    siteModule.SiteId = siteSettings.SiteId;
                    siteModule.ID     = "module" + module.ModuleId.ToString(CultureInfo.InvariantCulture);

                    siteModule.ModuleConfiguration = module;
                    siteModule.RenderInWebPartMode = true;

                    webPart = WebPartManager.CreateWebPart(siteModule);


                    siteModule.ModuleId = module.ModuleId;
                    mojoPortal.Business.Module.UpdateCountOfUseOnMyPage(module.ModuleId, 1);
                }
            }

            return(webPart);
        }