Beispiel #1
0
        /// <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 />"));
        }