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(); } } } } }
/// <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; } } }
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); } } } }
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); }
protected void BindList() { using (IDataReader reader = WebPartContent.GetWebPartsForMyPage(siteSettings.SiteId)) { this.dlWebParts.DataSource = reader; this.dlWebParts.DataBind(); } }
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); }
/// <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()); }
/// <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()); }
private void BindInstalledWebParts() { DataTable dt = WebPartContent.SelectPage( siteSettings.SiteId, this.pageNumber, this.pageSize, this.sortByClassName, this.sortByAssemblyName); if (dt.Rows.Count > 0) { totalPages = Convert.ToInt32(dt.Rows[0]["TotalPages"], CultureInfo.InvariantCulture); } this.grdWebParts.DataSource = dt; this.grdWebParts.PageIndex = this.pageNumber; this.grdWebParts.PageSize = this.pageSize; this.grdWebParts.DataBind(); if (this.totalPages > 1) { Literal pageLinks = new Literal(); string pageUrl = SiteRoot + "/Admin/WebPartAdmin.aspx" + "?sort=" + this.sort + "&pagenumber="; pageLinks.Text = UIHelper.GetPagerLinksWithPrevNext( pageUrl, 1, this.totalPages, this.pageNumber, "modulepager", "selectedpage"); this.spnPager.Controls.Add(pageLinks); } }
public static Collection <Type> GetUninstalledWebPartsFromAssemblies(int siteId, string excludedAssemblies) { Collection <Type> webPartTypes = new Collection <Type>(); if (HttpContext.Current != null) { DirectoryInfo currentDirectory = new DirectoryInfo(HttpContext.Current.Server.MapPath("~/bin")); foreach (FileInfo fileInfo in currentDirectory.GetFiles("*.dll")) { //if (fileInfo.FullName.IndexOf("sqlite") == -1) if (!excludedAssemblies.Contains(fileInfo.Name)) { Assembly assembly = Assembly.LoadFrom(fileInfo.FullName); foreach (Type type in assembly.GetTypes()) { if (type.IsSubclassOf(typeof(WebPart))) { String assemblyName = type.Assembly.FullName; if (assemblyName.IndexOf(",") > -1) { assemblyName = assemblyName.Substring(0, assemblyName.IndexOf(",")); } if (!WebPartContent.Exists(siteId, type.FullName, assemblyName)) { webPartTypes.Add(type); } } } } } } return(webPartTypes); }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); SiteSettings siteSettings = CacheHelper.GetCurrentSiteSettings(); if (siteSettings == null) { return; } int countOfWebParts = WebPartContent.Count(siteSettings.SiteId); if (countOfWebParts > WebConfigSettings.NumberOfWebPartsToShowInMiniCatalog) { string text = "<a href='" + WebUtils.GetSiteRoot() + "/ChooseContent.aspx' " + " class='webpartcatalogmorelink'>" + Resources.MyPageResources.WebPartCatalogMoreLink + "</a><br /><br />"; this.Controls.Add(new LiteralControl(text)); } }
public override WebPartDescriptionCollection GetAvailableWebPartDescriptions() { Collection <WebPartDescription> colDescriptions = new Collection <WebPartDescription>(); SiteSettings siteSettings = CacheHelper.GetCurrentSiteSettings(); if (siteSettings != null) { using (IDataReader reader = WebPartContent.GetMostPopular (siteSettings.SiteId, WebConfigSettings.NumberOfWebPartsToShowInMiniCatalog)) { while (reader.Read()) { bool allowMultipleInstances = Convert.ToBoolean(reader["AllowMultipleInstancesOnMyPage"]); bool isAssembly = Convert.ToBoolean(reader["IsAssembly"]); String moduleIcon = reader["ModuleIcon"].ToString(); String featureIcon = reader["FeatureIcon"].ToString(); String imageUrl = featureIcon; if (moduleIcon.Length > 0) { imageUrl = moduleIcon; } if (imageUrl.Length > 0) { imageUrl = Page.ResolveUrl("~/Data/SiteImages/FeatureIcons/" + imageUrl); } WebPartDescription wpDescription; if (isAssembly) { wpDescription = new WebPartDescription( reader["WebPartID"].ToString(), reader["ModuleTitle"].ToString(), ResourceHelper.GetResourceString(reader["ResourceFile"].ToString(), reader["FeatureName"].ToString()), imageUrl); } else { wpDescription = new WebPartDescription( reader["ModuleID"].ToString(), reader["ModuleTitle"].ToString(), ResourceHelper.GetResourceString(reader["ResourceFile"].ToString(), reader["FeatureName"].ToString()), imageUrl); } if (allowMultipleInstances) { colDescriptions.Add(wpDescription); } else { if (!PageHasPart(wpDescription.Title, wpDescription.Description)) { colDescriptions.Add(wpDescription); } } } } } WebPartDescriptionCollection wpdCollection = new WebPartDescriptionCollection(colDescriptions); return(wpdCollection); }
private void AddSettingControl(CustomModuleSetting s) { if (s.SettingName == "WebPartModuleWebPartSetting") { // Special handling for this one this.divWebParts.Visible = true; using (IDataReader reader = WebPartContent.SelectBySite(siteSettings.SiteId)) { this.ddWebParts.DataSource = reader; this.ddWebParts.DataBind(); } if (s.SettingValue.Length == 36) { ListItem listItem = ddWebParts.Items.FindByValue(s.SettingValue); if (listItem != null) { ddWebParts.ClearSelection(); listItem.Selected = true; } } } else { if (s.SettingControlType == string.Empty) { return; } String settingLabel = s.SettingName; String resourceFile = "Resource"; if (s.ResourceFile.Length > 0) { resourceFile = s.ResourceFile; } try { settingLabel = GetGlobalResourceObject(resourceFile, s.SettingName).ToString(); } catch (NullReferenceException ex) { if (log.IsErrorEnabled) { log.Error("ModuleSettings.aspx.cs error getting resource for s.SettingName " + s.SettingName, ex); } } Panel panel = new Panel(); panel.CssClass = "settingrow"; Literal label = new Literal(); label.Text = "<label class='settinglabel' >" + settingLabel + "</label>"; panel.Controls.Add(label); if ((s.SettingControlType == "TextBox") || (s.SettingControlType == string.Empty)) { Literal textBox = new Literal(); textBox.Text = "<input name=\"" + s.SettingName + this.moduleId.ToInvariantString() + "\" type='text' class=\"forminput\" value=\"" + s.SettingValue.HtmlEscapeQuotes() + "\" size=\"45\" id=\"" + s.SettingName + this.moduleId.ToInvariantString() + "\" />"; panel.Controls.Add(textBox); } if (s.SettingControlType == "CheckBox") { Literal checkBox = new Literal(); String isChecked = String.Empty; if (string.Equals(s.SettingValue, "true", StringComparison.InvariantCultureIgnoreCase)) { isChecked = "checked"; } checkBox.Text = "<input id='" + s.SettingName + this.moduleId.ToInvariantString() + "' type='checkbox' class='forminput' " + isChecked + " name='" + s.SettingName + this.moduleId.ToInvariantString() + "' />"; panel.Controls.Add(checkBox); } if (s.SettingControlType == "ISettingControl") { if (s.ControlSrc.Length > 0) { Control uc = Page.LoadControl(s.ControlSrc); if (uc is ISettingControl) { ISettingControl sc = uc as ISettingControl; if (!IsPostBack) { sc.SetValue(s.SettingValue); } uc.ID = "uc" + moduleId.ToString(CultureInfo.InvariantCulture) + s.SettingName; panel.Controls.Add(uc); } } else { log.Error("could not add setting control for ISettingControl, missing controlsrc for " + s.SettingName); } } if (s.HelpKey.Length > 0) { CHelpLink.AddHelpLink(panel, s.HelpKey); } this.PlaceHolderAdvancedSettings.Controls.Add(panel); } }