/// <summary> /// Add item /// </summary> /// <param name="item"></param> /// <returns>New item</returns> public CommentFilterItem Add(CommentFilterItem item) { if (!Security.IsAuthorizedTo(BlogEngine.Core.Rights.AccessAdminPages)) throw new System.UnauthorizedAccessException(); try { Filters = ExtensionManager.GetSettings("MetaExtension", "BeCommentFilters"); string id = Guid.NewGuid().ToString(); int parLen = Filters.Parameters[0].Values.Count; for (int i = 0; i < parLen; i++) { bool exists = Filters.Parameters[1].Values[i] == item.Action && Filters.Parameters[2].Values[i] == item.Subject && Filters.Parameters[3].Values[i] == item.Operation && Filters.Parameters[4].Values[i] == item.Filter; if (exists) { throw new System.ApplicationException("Item already exists"); } } string[] f = new string[] { id, item.Action, item.Subject, item.Operation, item.Filter }; Filters.AddValues(f); ExtensionManager.SaveSettings("MetaExtension", Filters); return new CommentFilterItem { Id = Guid.Parse(id), Action = item.Action, Subject = item.Subject, Operation = item.Operation, Filter = item.Filter }; } catch (Exception ex) { Utils.Log("Error adding new comment filter", ex); throw; } }
/// <summary> /// The init custom filters. /// </summary> private static void InitCustomFilters() { var settings = new ExtensionSettings("BeCustomFilters"); settings.AddParameter("FullName", "Name", 100, true, true); settings.AddParameter("Name"); settings.AddParameter("Checked"); settings.AddParameter("Cought"); settings.AddParameter("Reported"); settings.AddParameter("Priority"); customFilters = ExtensionManager.InitSettings("MetaExtension", settings); if (customFilters == null) { return; } var dt = customFilters.GetDataTable(); var codeAssemblies = Utils.CodeAssemblies(); foreach (var type in codeAssemblies.Cast<Assembly>().Select(a => a.GetTypes()).SelectMany( types => (from type in types where type.GetInterface("BlogEngine.Core.ICustomFilter") != null let found = dt.Rows.Cast<DataRow>().Any(row => row[0].ToString() == type.Name) where !found select type))) { // if new filter found in the assembly, add it to settings if (!customFilters.IsKeyValueExists(type.FullName)) { customFilters.AddValues(new[] { type.FullName, type.Name, "0", "0", "0", "0" }); ExtensionManager.SaveSettings("MetaExtension", customFilters); } } }