/// <summary> /// Gets and bulk updates web parts. Called when the "Get and bulk update parts" button is pressed. /// Expects the CreateWebPart method to be run first. /// </summary> private bool GetAndBulkUpdateWebParts() { // Prepare the parameters string where = "WebPartName LIKE N'MyNewWebpart%'"; // Get the data DataSet webparts = WebPartInfoProvider.GetWebParts(where, null); if (!DataHelper.DataSourceIsEmpty(webparts)) { // Loop through the individual items foreach (DataRow webpartDr in webparts.Tables[0].Rows) { // Create object from DataRow WebPartInfo modifyWebpart = new WebPartInfo(webpartDr); // Update the properties modifyWebpart.WebPartDisplayName = modifyWebpart.WebPartDisplayName.ToUpper(); // Save the changes WebPartInfoProvider.SetWebPartInfo(modifyWebpart); } return(true); } return(false); }
void fieldEditor_AfterItemDeleted(object sender, FieldEditorEventArgs e) { if (e == null) { return; } // Remove deleted field or category from inherited web parts InfoDataSet <WebPartInfo> webParts = WebPartInfoProvider.GetWebParts() .WhereEquals("WebPartParentID", WebPartID).TypedResult; if (!DataHelper.DataSourceIsEmpty(webParts)) { foreach (WebPartInfo info in webParts) { switch (e.ItemType) { case FieldEditorSelectedItemEnum.Field: info.WebPartProperties = FormHelper.RemoveFieldFromAlternativeDefinition(info.WebPartProperties, e.ItemName, e.ItemOrder); break; case FieldEditorSelectedItemEnum.Category: info.WebPartProperties = FormHelper.RemoveCategoryFromAlternativeDefinition(info.WebPartProperties, e.ItemName, e.ItemOrder); break; } // Update web part info.Update(); } } // Remove deleted field or category from widgets based on this web part InfoDataSet <WidgetInfo> widgets = WidgetInfoProvider.GetWidgets() .WhereEquals("WidgetWebPartID", WebPartID).TypedResult; if (!DataHelper.DataSourceIsEmpty(widgets)) { foreach (WidgetInfo info in widgets) { switch (e.ItemType) { case FieldEditorSelectedItemEnum.Field: info.WidgetProperties = FormHelper.RemoveFieldFromAlternativeDefinition(info.WidgetProperties, e.ItemName, e.ItemOrder); break; case FieldEditorSelectedItemEnum.Category: info.WidgetProperties = FormHelper.RemoveCategoryFromAlternativeDefinition(info.WidgetProperties, e.ItemName, e.ItemOrder); break; } // Update widget info.Update(); } } }
/// <summary> /// Update web part properties default values /// </summary> private static void UpdateWebPartProperties() { try { List <string> wpGuid = new List <string>() { "A03A0766-F018-4BC0-9FEB-55058E40DF53", "B5AB1C37-61E8-4C88-B06D-4F2100BFC43A", "DA9F49D4-9D7C-49A8-AE5E-6FFD85A2F59B", "5D6B8461-9537-4AA0-83EC-893F59A2B729", "2166181D-EA9B-4394-B40F-230AC973317B", "E16EC646-63C1-41E9-B14A-BB52F031E1B9", "75324B10-3E56-4952-9F9B-B36A2AC7FD1A", "D6C4FFA3-B17D-41F4-9C1A-AD8A75A835A8", "E54BFF78-5410-438F-AB4D-43322D6AB5C1", "DDF2FA96-58D1-45D6-9B56-4F288051683C", "7AA8A4DB-C56E-4C8F-A605-F739D01540C0" }; // Get inherited webparts with properties stored in old way string where = "WebPartParentID IS NULL AND WebPartDefaultValues LIKE N'%field name=\"%' AND WebPartGUID NOT IN ('" + wpGuid.Join("','") + "')"; InfoDataSet <WebPartInfo> data = WebPartInfoProvider.GetWebParts().Where(where).TypedResult; if (!DataHelper.DataSourceIsEmpty(data)) { foreach (WebPartInfo info in data) { info.WebPartDefaultValues = ModifyProperties(info.WebPartDefaultValues); // Update webpart info.Update(); } } } catch (Exception ex) { EventLogProvider.LogException("Upgrade - Web part properties", "Upgrade", ex); } }
protected void Page_Load(object sender, EventArgs e) { // Security test if (!CMSContext.CurrentUser.UserSiteManagerAdmin) { RedirectToAccessDenied(GetString("attach.actiondenied")); } // Add link to external stylesheet CSSHelper.RegisterCSSLink(this, "Default", "/CMSDesk.css"); // Get current resolver resolver = CMSContext.CurrentResolver.CreateContextChild(); DataSet ds = null; DataSet cds = null; // Check init settings bool allWidgets = QueryHelper.GetBoolean("allWidgets", false); bool allWebParts = QueryHelper.GetBoolean("allWebparts", false); // Get webpart (widget) from querystring - only if no allwidget or allwebparts set bool isWebpartInQuery = false; bool isWidgetInQuery = false; String webpartQueryParam = String.Empty; //If not show all widgets or webparts - check if any widget or webpart is present if ((!allWidgets) && (!allWebParts)) { webpartQueryParam = QueryHelper.GetString("webpart", ""); if (!string.IsNullOrEmpty(webpartQueryParam)) { isWebpartInQuery = true; } else { webpartQueryParam = QueryHelper.GetString("widget", ""); if (!string.IsNullOrEmpty(webpartQueryParam)) { isWidgetInQuery = true; } } } // Set development option if is required if (QueryHelper.GetString("details", "0") == "1") { development = true; } // Generate all webparts if (allWebParts) { // Get all webpart categories cds = WebPartCategoryInfoProvider.GetAllCategories(); } // Generate all widgets else if (allWidgets) { // Get all widget categories cds = WidgetCategoryInfoProvider.GetWidgetCategories(String.Empty, String.Empty, 0, String.Empty); } // Generate single webpart else if (isWebpartInQuery) { // Split weparts string[] webparts = webpartQueryParam.Split(';'); if (webparts.Length > 0) { string webpartWhere = SqlHelperClass.GetWhereCondition("WebpartName", webparts); ds = WebPartInfoProvider.GetWebParts(webpartWhere, null); // If any webparts found if (!DataHelper.DataSourceIsEmpty(ds)) { StringBuilder categoryWhere = new StringBuilder(""); foreach (DataRow dr in ds.Tables[0].Rows) { categoryWhere.Append(ValidationHelper.GetString(dr["WebpartCategoryID"], "NULL") + ","); } string ctWhere = "CategoryID IN (" + categoryWhere.ToString().TrimEnd(',') + ")"; cds = WebPartCategoryInfoProvider.GetCategories(ctWhere, null); } } } // Generate single widget else if (isWidgetInQuery) { string[] widgets = webpartQueryParam.Split(';'); if (widgets.Length > 0) { string widgetsWhere = SqlHelperClass.GetWhereCondition("WidgetName", widgets); ds = WidgetInfoProvider.GetWidgets(widgetsWhere, null, 0, String.Empty); } if (!DataHelper.DataSourceIsEmpty(ds)) { StringBuilder categoryWhere = new StringBuilder(""); foreach (DataRow dr in ds.Tables[0].Rows) { categoryWhere.Append(ValidationHelper.GetString(dr["WidgetCategoryID"], "NULL") + ","); } string ctWhere = "WidgetCategoryID IN (" + categoryWhere.ToString().TrimEnd(',') + ")"; cds = WidgetCategoryInfoProvider.GetWidgetCategories(ctWhere, null, 0, String.Empty); } } if (allWidgets || isWidgetInQuery) { documentationTitle = "Kentico CMS Widgets"; Page.Header.Title = "Widgets documentation"; } if (!allWebParts && !allWidgets && !isWebpartInQuery && !isWidgetInQuery) { pnlContent.Visible = false; pnlInfo.Visible = true; } // Check whether at least one category is present if (!DataHelper.DataSourceIsEmpty(cds)) { string namePrefix = ((isWidgetInQuery) || (allWidgets)) ? "Widget" : String.Empty; // Loop through all web part categories foreach (DataRow cdr in cds.Tables[0].Rows) { // Get all webpart in the categories if (allWebParts) { ds = WebPartInfoProvider.GetAllWebParts(Convert.ToInt32(cdr["CategoryId"])); } // Get all widgets in the category else if (allWidgets) { int categoryID = Convert.ToInt32(cdr["WidgetCategoryId"]); ds = WidgetInfoProvider.GetWidgets("WidgetCategoryID = " + categoryID.ToString(), null, 0, null); } // Check whether current category contains at least one webpart if (!DataHelper.DataSourceIsEmpty(ds)) { // Generate category name code menu += "<br /><strong>" + HTMLHelper.HTMLEncode(cdr[namePrefix + "CategoryDisplayName"].ToString()) + "</strong><br /><br />"; // Loop through all web web parts in categories foreach (DataRow dr in ds.Tables[0].Rows) { // Init isImagePresent = false; undocumentedProperties = 0; documentation = 0; // Webpart (Widget) information string itemDisplayName = String.Empty; string itemDescription = String.Empty; string itemDocumentation = String.Empty; string itemType = String.Empty; int itemID = 0; WebPartInfo wpi = null; WidgetInfo wi = null; // Set webpart info if ((isWebpartInQuery) || (allWebParts)) { wpi = new WebPartInfo(dr); if (wpi != null) { itemDisplayName = wpi.WebPartDisplayName; itemDescription = wpi.WebPartDescription; itemDocumentation = wpi.WebPartDocumentation; itemID = wpi.WebPartID; itemType = PortalObjectType.WEBPART; if (wpi.WebPartCategoryID != ValidationHelper.GetInteger(cdr["CategoryId"], 0)) { wpi = null; } } } // Set widget info else if ((isWidgetInQuery) || (allWidgets)) { wi = new WidgetInfo(dr); if (wi != null) { itemDisplayName = wi.WidgetDisplayName; itemDescription = wi.WidgetDescription; itemDocumentation = wi.WidgetDocumentation; itemType = PortalObjectType.WIDGET; itemID = wi.WidgetID; if (wi.WidgetCategoryID != ValidationHelper.GetInteger(cdr["WidgetCategoryId"], 0)) { wi = null; } } } // Check whether web part (widget) exists if ((wpi != null) || (wi != null)) { // Link GUID Guid mguid = Guid.NewGuid(); // Whether description is present in webpart bool isDescription = false; // Image url string wimgurl = GetItemImage(itemID, itemType); // Set description text string descriptionText = itemDescription; // Parent webpart info WebPartInfo pwpi = null; // If webpart look for parent's description and documentation if (wpi != null) { // Get parent description if webpart is inherited if (wpi.WebPartParentID > 0) { pwpi = WebPartInfoProvider.GetWebPartInfo(wpi.WebPartParentID); if (pwpi != null) { if ((descriptionText == null || descriptionText.Trim() == "")) { // Set description from parent descriptionText = pwpi.WebPartDescription; } // Set documentation text from parent if WebPart is inherited if ((wpi.WebPartDocumentation == null) || (wpi.WebPartDocumentation.Trim() == "")) { itemDocumentation = pwpi.WebPartDocumentation; if (!String.IsNullOrEmpty(itemDocumentation)) { documentation = 2; } } } } } // Set description as present if (descriptionText.Trim().Length > 0) { isDescription = true; } // Generate HTML for menu and content menu += " <a href=\"#_" + mguid.ToString() + "\">" + HTMLHelper.HTMLEncode(itemDisplayName) + "</a> "; // Generate webpart header content += "<table style=\"width:100%;\"><tr><td><h1><a name=\"_" + mguid.ToString() + "\">" + HTMLHelper.HTMLEncode(cdr[namePrefix + "CategoryDisplayName"].ToString()) + " > " + HTMLHelper.HTMLEncode(itemDisplayName) + "</a></h1></td><td style=\"text-align:right;\"> <a href=\"#top\" class=\"noprint\">top</a></td></tr></table>"; // Generate WebPart content content += @"<table style=""width: 100%; height: 200px; border: solid 1px #DDDDDD;""> <tr> <td style=""width: 50%; text-align:center; border-right: solid 1px #DDDDDD; vertical-align: middle;margin-left: auto; margin-right:auto; text-align:center;""> <img src=""" + wimgurl + @""" alt=""imageTeaser""> </td> <td style=""width: 50%; vertical-align: center;text-align:center;"">" + HTMLHelper.HTMLEncode(ResHelper.LocalizeString(descriptionText)) + @" </td> </tr> </table>"; // Properties content content += "<div class=\"DocumentationWebPartsProperties\">"; // Generate content if (wpi != null) { GenerateDocContent(CreateFormInfo(wpi)); } else if (wi != null) { GenerateDocContent(CreateFormInfo(wi)); } // Close content area content += "</div>"; // Generate documentation text content content += "<br /><div style=\"border: solid 1px #dddddd;width: 100%;\">" + DataHelper.GetNotEmpty(HTMLHelper.ResolveUrls(itemDocumentation, null), "<strong>Additional documentation text is not provided.</strong>") + "</div>"; // Set page break tag for print content += "<br /><p style=\"page-break-after: always;width:100%\"> </p><hr class=\"noprint\" />"; // If development is required - highlight missing description, images and doc. text if (development) { // Check image if (!isImagePresent) { menu += "<span style=\"color:Brown;\">image </span>"; } // Check properties if (undocumentedProperties > 0) { menu += "<span style=\"color:Red;\">properties(" + undocumentedProperties + ") </span>"; } // Check properties if (!isDescription) { menu += "<span style=\"color:#37627F;\">description </span>"; } // Check documentation text if (String.IsNullOrEmpty(itemDocumentation)) { documentation = 1; } switch (documentation) { // Display information about missing documentation case 1: menu += "<span style=\"color:Green;\">documentation </span>"; break; // Display information about inherited documentation case 2: menu += "<span style=\"color:Green;\">documentation (inherited) </span>"; break; } } menu += "<br />"; } } } } } ltlContent.Text = menu + "<br /><p style=\"page-break-after: always;width:100%\"> </p><hr class=\"noprint\" />" + content; }