Ejemplo n.º 1
0
        protected void LoadWebPart()
        {
            String partIDString = String.Empty;
            if (Settings.Contains("WebPartModuleWebPartSetting"))
            {
                partIDString = Settings["WebPartModuleWebPartSetting"].ToString();
            }

            if (partIDString.Length == 36)
            {
                Guid webPartID = new Guid(partIDString);
                WebPartContent webPartContent = new WebPartContent(webPartID);
                if (webPartContent.WebPartId != Guid.Empty)
                {
                    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)
                    {
                       this.Title = webPart.Title;
                       this.Description = webPart.Description;
                       this.ModuleConfiguration.ModuleTitle = webPart.Title;
                       this.pnlPlaceHolder.Controls.Add(webPart);
                    }

                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Handles the Click event of the btnDelete control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            if (this.webPartID != Guid.Empty)
            {
                WebPartContent webPartContent = new WebPartContent(webPartID);
                if (webPartContent.SiteId == siteSettings.SiteId)
                {
                    WebPartContent.DeleteWebPart(webPartID);
                }
            }

            if (hdnReturnUrl.Value.Length > 0)
            {
                WebUtils.SetupRedirect(this, hdnReturnUrl.Value);
                return;
            }

            WebUtils.SetupRedirect(this, SiteUtils.GetCurrentPageUrl());
        }
Ejemplo n.º 3
0
        protected void btnAddWebPart_Click(object sender, EventArgs e)
        {
            if (lstAllWebParts.SelectedIndex > -1)
            {
                foreach (ListItem item in lstAllWebParts.Items)
                {
                    if (item.Selected)
                    {
                        Guid webPartID = new Guid(item.Value);
                        WebPartContent baseSiteWebPart = new WebPartContent(webPartID);

                        WebPartContent childSiteWebPart = new WebPartContent();
                        childSiteWebPart.SiteId = selectedSite.SiteId;
                        childSiteWebPart.SiteGuid = selectedSite.SiteGuid;
                        childSiteWebPart.AllowMultipleInstancesOnMyPage = baseSiteWebPart.AllowMultipleInstancesOnMyPage;
                        childSiteWebPart.AssemblyName = baseSiteWebPart.AssemblyName;
                        childSiteWebPart.AvailableForContentSystem = baseSiteWebPart.AvailableForContentSystem;
                        childSiteWebPart.AvailableForMyPage = baseSiteWebPart.AvailableForMyPage;
                        childSiteWebPart.ClassName = baseSiteWebPart.ClassName;
                        childSiteWebPart.Description = baseSiteWebPart.Description;
                        childSiteWebPart.ImageUrl = baseSiteWebPart.ImageUrl;
                        childSiteWebPart.Title = baseSiteWebPart.Title;
                        childSiteWebPart.Save();

                    }

                }

                PopulateWebParts();
                upWebParts.Update();
            }
            else
            {
                lblWebPartMessage.Text = Resource.SiteSettingsSelectWebPartToAddWarning;
            }
        }
Ejemplo n.º 4
0
        protected void grdAvailableParts_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            if (sender == null) return;
            if (e == null) return;

            GridView grid = (GridView)sender;

            CheckBox chkAvailableForMyPage = (CheckBox)grid.Rows[e.RowIndex].Cells[1].FindControl("chkAvailableForMyPage");
            CheckBox chkAllowMultipleInstancesOnMyPage = (CheckBox)grid.Rows[e.RowIndex].Cells[1].FindControl("chkAllowMultipleInstancesOnMyPage");
            CheckBox chkAvailableForContentSystem = (CheckBox)grid.Rows[e.RowIndex].Cells[1].FindControl("chkAvailableForContentSystem");
            DropDownList ddIcons = (DropDownList)grid.Rows[e.RowIndex].Cells[1].FindControl("ddIcons");

            WebPartContent webPartContent = new WebPartContent();
            webPartContent.AllowMultipleInstancesOnMyPage = chkAllowMultipleInstancesOnMyPage.Checked;
            webPartContent.AssemblyName = this.CurrentAssembly;
            webPartContent.AvailableForContentSystem = chkAvailableForContentSystem.Checked;
            webPartContent.AvailableForMyPage = chkAvailableForMyPage.Checked;
            webPartContent.ClassName = this.CurrentClass;
            webPartContent.Description = this.CurrentDescription;
            webPartContent.ImageUrl = ddIcons.SelectedValue;
            webPartContent.SiteId = siteSettings.SiteId;
            webPartContent.SiteGuid = siteSettings.SiteGuid;
            webPartContent.Title = this.CurrentTitle;
            webPartContent.Save();

            WebUtils.SetupRedirect(this, Request.RawUrl);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Handles the Click event of the btnUpdate control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            if (this.webPartID != Guid.Empty)
            {
                WebPartContent webPartContent = new WebPartContent(webPartID);
                if (webPartContent.SiteId == siteSettings.SiteId)
                {
                    webPartContent.AvailableForMyPage = chkAvailableForMyPage.Checked;
                    webPartContent.AllowMultipleInstancesOnMyPage = chkAllowMultipleInstancesOnMyPage.Checked;
                    webPartContent.AvailableForContentSystem = chkAvailableForContentSystem.Checked;
                    webPartContent.ImageUrl = ddIcons.SelectedValue;
                    webPartContent.Save();
                }

            }

            if (hdnReturnUrl.Value.Length > 0)
            {
                WebUtils.SetupRedirect(this, hdnReturnUrl.Value);
                return;
            }

            WebUtils.SetupRedirect(this, SiteUtils.GetCurrentPageUrl());
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Populates the controls.
        /// </summary>
        private void PopulateControls()
        {
            this.ddIcons.DataSource = SiteUtils.GetFeatureIconList();
            this.ddIcons.DataBind();
            ddIcons.Items.Insert(0, new ListItem(MyPageResources.ModuleSettingsNoIconLabel, "blank.gif"));
            ddIcons.Attributes.Add("onChange", "javascript:showIcon(this);");
            ddIcons.Attributes.Add("size", "6");
            SetupIconScript(this.imgIcon);

            if (webPartID != Guid.Empty)
            {
                WebPartContent webPartContent = new WebPartContent(webPartID);
                if (webPartContent.SiteId == siteSettings.SiteId)
                {
                    ListItem item = this.ddIcons.Items.FindByValue(webPartContent.ImageUrl);
                    if (item != null)
                    {
                        ddIcons.ClearSelection();
                        ddIcons.Items.FindByValue(webPartContent.ImageUrl).Selected = true;
                    }
                    imgIcon.Src = this.iconPath + webPartContent.ImageUrl;
                    lblClassName.Text = webPartContent.ClassName;
                    lblAssemblyName.Text = webPartContent.AssemblyName;
                    lblTitle.Text = webPartContent.Title;
                    lblDescription.Text = webPartContent.Description;
                    chkAvailableForMyPage.Checked = webPartContent.AvailableForMyPage;
                    chkAllowMultipleInstancesOnMyPage.Checked = webPartContent.AllowMultipleInstancesOnMyPage;
                    chkAvailableForContentSystem.Checked = webPartContent.AvailableForContentSystem;
                }

            }
        }
Ejemplo n.º 7
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();

                            mojoWebPartManager mojoManager = (mojoWebPartManager)this.WebPartManager1;
                            mojoManager.AddWebPart(webPart, this.CenterWebPartZone, 0);
                            mojoManager.SetDirty();
                        }
                    }

                }

            }
        }
Ejemplo n.º 8
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;
        }