/// <summary> /// Used to manually flush the attribute cache. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> protected void btnClearCache_Click(object sender, EventArgs e) { var msgs = new List <string>(); // Clear the static object that contains all auth rules (so that it will be refreshed) Rock.Security.Authorization.Flush(); msgs.Add("Authorizations have been cleared"); // Flush the static entity attributes cache Rock.Web.Cache.AttributeCache.FlushEntityAttributes(); msgs.Add("EntityAttributes have been cleared"); // Clear all cached items Rock.Web.Cache.RockMemoryCache.Clear(); msgs.Add("RockMemoryCache has been cleared"); // Flush Site Domains Rock.Web.Cache.SiteCache.Flush(); // Flush today's Check-in Codes Rock.Model.AttendanceCodeService.FlushTodaysCodes(); string webAppPath = Server.MapPath("~"); // Check for any unregistered entity types, field types, and block types EntityTypeService.RegisterEntityTypes(webAppPath); FieldTypeService.RegisterFieldTypes(webAppPath); BlockTypeService.RegisterBlockTypes(webAppPath, Page, false); msgs.Add("EntityTypes, FieldTypes, BlockTypes have been re-registered"); // Clear workflow trigger cache Rock.Workflow.TriggerCache.Refresh(); // Delete all cached files try { var dirInfo = new DirectoryInfo(Path.Combine(webAppPath, "App_Data/Cache")); foreach (var childDir in dirInfo.GetDirectories()) { childDir.Delete(true); } foreach (var file in dirInfo.GetFiles().Where(f => f.Name != ".gitignore")) { file.Delete(); } msgs.Add("Cached files have been deleted"); } catch (Exception ex) { nbMessage.NotificationBoxType = Rock.Web.UI.Controls.NotificationBoxType.Warning; nbMessage.Visible = true; nbMessage.Text = "The following error occurred when attempting to delete cached files: " + ex.Message; return; } nbMessage.NotificationBoxType = Rock.Web.UI.Controls.NotificationBoxType.Success; nbMessage.Visible = true; nbMessage.Title = "Clear Cache"; nbMessage.Text = string.Format("<p>{0}</p>", msgs.AsDelimited("<br />")); }
/// <summary> /// Loads the block types. /// </summary> private void LoadBlockTypes(bool registerBlockTypes) { if (registerBlockTypes) { // Add any unregistered blocks try { BlockTypeService.RegisterBlockTypes(Request.MapPath("~"), Page); } catch (Exception ex) { nbMessage.Text = "Error registering one or more block types"; nbMessage.Details = ex.Message + "<code>" + HttpUtility.HtmlEncode(ex.StackTrace) + "</code>"; nbMessage.Visible = true; } } // Get a list of BlockTypes that does not include Mobile block types. var allExceptMobileBlockTypes = BlockTypeCache.All(); foreach (var cachedBlockType in BlockTypeCache.All().Where(b => string.IsNullOrEmpty(b.Path))) { try { var blockCompiledType = cachedBlockType.GetCompiledType(); if (typeof(Rock.Blocks.IRockMobileBlockType).IsAssignableFrom(blockCompiledType)) { allExceptMobileBlockTypes.Remove(cachedBlockType); } } catch (Exception) { // Intentionally ignored } } var blockTypes = allExceptMobileBlockTypes.Select(b => new { b.Id, b.Name, b.Category, b.Description }).ToList(); ddlBlockType.Items.Clear(); // Add the categorized block types foreach (var blockType in blockTypes.Where(b => b.Category != "").OrderBy(b => b.Category).ThenBy(b => b.Name)) { var li = new ListItem(blockType.Name, blockType.Id.ToString()); li.Attributes.Add("optiongroup", blockType.Category); li.Attributes.Add("title", blockType.Description); ddlBlockType.Items.Add(li); } // Add the uncategorized block types foreach (var blockType in blockTypes.Where(b => b.Category == null || b.Category == "").OrderBy(b => b.Name)) { var li = new ListItem(blockType.Name, blockType.Id.ToString()); li.Attributes.Add("optiongroup", "Other (not categorized)"); li.Attributes.Add("title", blockType.Description); ddlBlockType.Items.Add(li); } }
/// <summary> /// Loads the block types. /// </summary> private void LoadBlockTypes(bool registerBlockTypes) { if (registerBlockTypes) { // Add any unregistered blocks try { BlockTypeService.RegisterBlockTypes(Request.MapPath("~"), Page); } catch (Exception ex) { nbMessage.Text = "Error registering one or more block types"; nbMessage.Details = ex.Message + "<code>" + HttpUtility.HtmlEncode(ex.StackTrace) + "</code>"; nbMessage.Visible = true; } } // Load the block types using (var rockContext = new RockContext()) { Rock.Model.BlockTypeService blockTypeService = new Rock.Model.BlockTypeService(rockContext); var blockTypes = blockTypeService.Queryable().AsNoTracking() .Select(b => new { b.Id, b.Name, b.Category, b.Description }) .ToList(); ddlBlockType.Items.Clear(); // Add the categorized block types foreach (var blockType in blockTypes .Where(b => b.Category != "") .OrderBy(b => b.Category) .ThenBy(b => b.Name)) { var li = new ListItem(blockType.Name, blockType.Id.ToString()); li.Attributes.Add("optiongroup", blockType.Category); li.Attributes.Add("title", blockType.Description); ddlBlockType.Items.Add(li); } // Add the uncategorized block types foreach (var blockType in blockTypes .Where(b => b.Category == null || b.Category == "") .OrderBy(b => b.Name)) { var li = new ListItem(blockType.Name, blockType.Id.ToString()); li.Attributes.Add("optiongroup", "Other (not categorized)"); li.Attributes.Add("title", blockType.Description); ddlBlockType.Items.Add(li); } } }
/// <summary> /// Raises the <see cref="E:System.Web.UI.Control.Load" /> event. /// </summary> /// <param name="e">The <see cref="T:System.EventArgs" /> object that contains the event data.</param> protected override void OnLoad(EventArgs e) { if (!Page.IsPostBack) { tbNameFilter.Text = gfSettings.GetUserPreference("Name"); tbPathFilter.Text = gfSettings.GetUserPreference("Path"); ddlCategoryFilter.SetValue(gfSettings.GetUserPreference("Category")); cbExcludeSystem.Checked = !string.IsNullOrWhiteSpace(gfSettings.GetUserPreference("Exclude System")); BlockTypeService.RegisterBlockTypes(Request.MapPath("~"), Page); BindGrid(); } base.OnLoad(e); }
public IActionResult btnClearCache_Click() { var msgs = RockCache.ClearAllCachedItems(); // Flush today's Check-in Codes Rock.Model.AttendanceCodeService.FlushTodaysCodes(); #if false string webAppPath = Server.MapPath( "~" ); // Check for any unregistered entity types, field types, and block types EntityTypeService.RegisterEntityTypes( webAppPath ); FieldTypeService.RegisterFieldTypes( webAppPath ); BlockTypeService.RegisterBlockTypes( webAppPath, Page, false ); msgs.Add( "EntityTypes, FieldTypes, BlockTypes have been re-registered" ); // Delete all cached files try { var dirInfo = new DirectoryInfo( Path.Combine( webAppPath, "App_Data/Cache" ) ); foreach ( var childDir in dirInfo.GetDirectories() ) { childDir.Delete( true ); } foreach ( var file in dirInfo.GetFiles().Where( f => f.Name != ".gitignore" ) ) { file.Delete(); } msgs.Add( "Cached files have been deleted" ); } catch ( Exception ex ) { return new OkObjectResult( new { Error = true, Messages = new [] { $"The following error occurred when attempting to delete cahced files: {ex.Message}" } ); } #endif return new OkObjectResult( new { Error = false, Messages = msgs } ); } #endregion }
/// <summary> /// Used to manually flush the attribute cache. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> protected void btnClearCache_Click(object sender, EventArgs e) { var msgs = RockCache.ClearAllCachedItems(); // Flush today's Check-in Codes Rock.Model.AttendanceCodeService.FlushTodaysCodes(); string webAppPath = Server.MapPath("~"); // Check for any unregistered entity types, field types, and block types EntityTypeService.RegisterEntityTypes(); FieldTypeService.RegisterFieldTypes(); BlockTypeService.FlushRegistrationCache(); BlockTypeService.RegisterBlockTypes(webAppPath, Page, false); msgs.Add("EntityTypes, FieldTypes, BlockTypes have been re-registered"); // Delete all cached files try { var dirInfo = new DirectoryInfo(Path.Combine(webAppPath, "App_Data/Cache")); foreach (var childDir in dirInfo.GetDirectories()) { childDir.Delete(true); } foreach (var file in dirInfo.GetFiles().Where(f => f.Name != ".gitignore")) { file.Delete(); } msgs.Add("Cached files have been deleted"); } catch (Exception ex) { nbMessage.NotificationBoxType = Rock.Web.UI.Controls.NotificationBoxType.Warning; nbMessage.Visible = true; nbMessage.Text = "The following error occurred when attempting to delete cached files: " + ex.Message; return; } nbMessage.NotificationBoxType = Rock.Web.UI.Controls.NotificationBoxType.Success; nbMessage.Visible = true; nbMessage.Title = "Clear Cache"; nbMessage.Text = string.Format("<p>{0}</p>", msgs.AsDelimited("<br />")); }
/// <summary> /// Used to manually flush the attribute cache. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> protected void btnClearCache_Click(object sender, EventArgs e) { // Clear all cached items Rock.Web.Cache.RockMemoryCache.Clear(); // Clear the static object that contains all auth rules (so that it will be refreshed) Rock.Security.Authorization.Flush(); // Flush the static entity attributes cache Rock.Web.Cache.AttributeCache.FlushEntityAttributes(); // Check for any unregistered entity types, field types, and block types string webAppPath = Server.MapPath("~"); EntityTypeService.RegisterEntityTypes(webAppPath); FieldTypeService.RegisterFieldTypes(webAppPath); BlockTypeService.RegisterBlockTypes(webAppPath, Page, false); // Delete all cached files try { var dirInfo = new DirectoryInfo(Path.Combine(webAppPath, "App_Data/Cache")); foreach (var childDir in dirInfo.GetDirectories()) { childDir.Delete(true); } foreach (var file in dirInfo.GetFiles().Where(f => f.Name != ".gitignore")) { file.Delete(); } } catch (Exception ex) { nbMessage.NotificationBoxType = Rock.Web.UI.Controls.NotificationBoxType.Warning; nbMessage.Visible = true; nbMessage.Text = "Cache has been cleared, but following error occurred when attempting to delete cached files: " + ex.Message; return; } nbMessage.NotificationBoxType = Rock.Web.UI.Controls.NotificationBoxType.Success; nbMessage.Visible = true; nbMessage.Text = "The cache has been cleared."; }
/// <summary> /// Raises the <see cref="E:System.Web.UI.Control.Load" /> event. /// </summary> /// <param name="e">The <see cref="T:System.EventArgs" /> object that contains the event data.</param> protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (!IsPostBack) { int pageId = PageParameter("Page").AsInteger(); int siteId = PageParameter("SiteId").AsInteger(); BlockTypeService.RegisterBlockTypes(Request.MapPath("~"), Page); // Load page picker if (siteId != 0) { LoadPagePicker(siteId); } if (pageId != 0) { ShowDetail(pageId); } else { ShowPageEdit(pageId); } } else { if (pnlBlocks.Visible == true) { // // Rebind zones so postback events work correctly. // BindZones(); } if (Request["__EVENTTARGET"].ToStringSafe() == lbDragCommand.ClientID) { ProcessDragEvents(); } } }
/// <summary> /// Loads the block types. /// </summary> private void LoadBlockTypes() { // Add any unregistered blocks BlockTypeService.RegisterBlockTypes(Request.MapPath("~"), Page); // Load the block types Rock.Model.BlockTypeService blockTypeService = new Rock.Model.BlockTypeService(new RockContext()); var blockTypes = blockTypeService.Queryable() .Select(b => new { b.Id, b.Name, b.Category, b.Description }) .ToList(); ddlBlockType.Items.Clear(); // Add the categorized block types foreach (var blockType in blockTypes .Where(b => b.Category != "") .OrderBy(b => b.Category) .ThenBy(b => b.Name)) { var li = new ListItem(blockType.Name, blockType.Id.ToString()); li.Attributes.Add("optiongroup", blockType.Category); li.Attributes.Add("title", blockType.Description); ddlBlockType.Items.Add(li); } // Add the uncategorized block types foreach (var blockType in blockTypes .Where(b => b.Category == null || b.Category == "") .OrderBy(b => b.Name)) { var li = new ListItem(blockType.Name, blockType.Id.ToString()); li.Attributes.Add("optiongroup", "Other (not categorized)"); li.Attributes.Add("title", blockType.Description); ddlBlockType.Items.Add(li); } }
/// <summary> /// Handles the Click event of the btnAddBlock control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> protected void btnAddBlock_Click(object sender, EventArgs e) { tbNewBlockName.Text = string.Empty; // Load the block types using (var rockContext = new RockContext()) { try { BlockTypeService.RegisterBlockTypes(Request.MapPath("~"), Page); } catch { // ignore } Rock.Model.BlockTypeService blockTypeService = new Rock.Model.BlockTypeService(rockContext); var blockTypes = blockTypeService.Queryable().AsNoTracking() .Select(b => new { b.Id, b.Name, b.Category, b.Description }) .ToList(); ddlBlockType.Items.Clear(); // Add the categorized block types foreach (var blockType in blockTypes .Where(b => b.Category != string.Empty) .OrderBy(b => b.Category) .ThenBy(b => b.Name)) { var li = new ListItem(blockType.Name, blockType.Id.ToString()); li.Attributes.Add("optiongroup", blockType.Category); li.Attributes.Add("title", blockType.Description); ddlBlockType.Items.Add(li); } // Add the uncategorized block types foreach (var blockType in blockTypes .Where(b => b.Category == null || b.Category == string.Empty) .OrderBy(b => b.Name)) { var li = new ListItem(blockType.Name, blockType.Id.ToString()); li.Attributes.Add("optiongroup", "Other (not categorized)"); li.Attributes.Add("title", blockType.Description); ddlBlockType.Items.Add(li); } } var htmlContentBlockType = BlockTypeCache.Read(Rock.SystemGuid.BlockType.HTML_CONTENT.AsGuid()); ddlBlockType.SetValue(htmlContentBlockType.Id); rblAddBlockLocation.Items.Clear(); var page = PageCache.Read(hfPageId.Value.AsInteger()); var listItemPage = new ListItem(); listItemPage.Text = string.Format("Page ({0})", page.ToString()); listItemPage.Value = "Page"; listItemPage.Selected = true; var listItemLayout = new ListItem(); listItemLayout.Text = string.Format("Layout ({0})", page.Layout); listItemLayout.Value = "Layout"; listItemLayout.Selected = false; var listItemSite = new ListItem(); listItemSite.Text = string.Format("Site ({0})", page.Layout.Site); listItemSite.Value = "Site"; listItemSite.Selected = false; rblAddBlockLocation.Items.Add(listItemPage); rblAddBlockLocation.Items.Add(listItemLayout); rblAddBlockLocation.Items.Add(listItemSite); mdAddBlock.Title = "Add Block to " + ddlZones.SelectedValue + " Zone"; mdAddBlock.Show(); }
/// <summary> /// Handles the Click event of the btnRefreshAll control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> protected void btnRefreshAll_Click(object sender, EventArgs e) { BlockTypeService.RegisterBlockTypes(Request.MapPath("~"), Page, true); BindGrid(); }
/// <summary> /// Handles the Click event of the btnAddBlock control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> protected void btnAddBlock_Click(object sender, EventArgs e) { tbNewBlockName.Text = string.Empty; // Load the block types using (var rockContext = new RockContext()) { try { BlockTypeService.RegisterBlockTypes(Request.MapPath("~"), Page); } catch { // ignore } // Get a list of BlockTypes that does not include Mobile block types. List <BlockTypeCache> allExceptMobileBlockTypes = new List <BlockTypeCache>(); foreach (var cachedBlockType in BlockTypeCache.All()) { try { var blockCompiledType = cachedBlockType.GetCompiledType(); if (!typeof(Rock.Blocks.IRockMobileBlockType).IsAssignableFrom(blockCompiledType)) { allExceptMobileBlockTypes.Add(cachedBlockType); } } catch (Exception) { // Intentionally ignored } } var blockTypes = allExceptMobileBlockTypes.Select(b => new { b.Id, b.Name, b.Category, b.Description }).ToList(); ddlBlockType.Items.Clear(); // Add the categorized block types foreach (var blockType in blockTypes.Where(b => b.Category != string.Empty).OrderBy(b => b.Category).ThenBy(b => b.Name)) { var li = new ListItem(blockType.Name, blockType.Id.ToString()); li.Attributes.Add("optiongroup", blockType.Category); li.Attributes.Add("title", blockType.Description); ddlBlockType.Items.Add(li); } // Add the uncategorized block types foreach (var blockType in blockTypes.Where(b => b.Category == null || b.Category == string.Empty).OrderBy(b => b.Name)) { var li = new ListItem(blockType.Name, blockType.Id.ToString()); li.Attributes.Add("optiongroup", "Other (not categorized)"); li.Attributes.Add("title", blockType.Description); ddlBlockType.Items.Add(li); } } // Set the initial selection to the HTMLContent block. ddlBlockType.SetValue(BlockTypeCache.Get(Rock.SystemGuid.BlockType.HTML_CONTENT.AsGuid()).Id); rblAddBlockLocation.Items.Clear(); var page = PageCache.Get(hfPageId.Value.AsInteger()); var listItemPage = new ListItem(); listItemPage.Text = string.Format("Page ({0})", page.ToString()); listItemPage.Value = "Page"; listItemPage.Selected = true; var listItemLayout = new ListItem(); listItemLayout.Text = string.Format("Layout ({0})", page.Layout); listItemLayout.Value = "Layout"; listItemLayout.Selected = false; var listItemSite = new ListItem(); listItemSite.Text = string.Format("Site ({0})", page.Layout.Site); listItemSite.Value = "Site"; listItemSite.Selected = false; rblAddBlockLocation.Items.Add(listItemPage); rblAddBlockLocation.Items.Add(listItemLayout); rblAddBlockLocation.Items.Add(listItemSite); mdAddBlock.Title = "Add Block to " + ddlZones.SelectedValue + " Zone"; mdAddBlock.Show(); }