-
Notifications
You must be signed in to change notification settings - Fork 577
Expand file tree
/
Copy pathCustomFilterRepository.cs
More file actions
93 lines (86 loc) · 3.36 KB
/
Copy pathCustomFilterRepository.cs
File metadata and controls
93 lines (86 loc) · 3.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using BlogEngine.Core.Data.Contracts;
using BlogEngine.Core.Data.Models;
using BlogEngine.Core.Web.Extensions;
using System;
using System.Collections.Generic;
using System.Data;
namespace BlogEngine.Core.Data
{
/// <summary>
/// Custom filter repo
/// </summary>
public class CustomFilterRepository : ICustomFilterRepository
{
/// <summary>
/// The custom filters.
/// </summary>
static protected ExtensionSettings CustomFilters;
/// <summary>
/// Get list of custom filters
/// </summary>
/// <returns>List of filters</returns>
public IEnumerable<CustomFilter> GetCustomFilters()
{
if (!Security.IsAuthorizedTo(Rights.AccessAdminPages))
throw new UnauthorizedAccessException();
var filterList = new List<CustomFilter>();
try
{
CustomFilters = ExtensionManager.GetSettings("MetaExtension", "BeCustomFilters");
DataTable dt = CustomFilters.GetDataTable();
foreach (DataRow row in dt.Rows)
{
var f = new CustomFilter
{
Name = row["Name"].ToString(),
FullName = row["FullName"].ToString(),
Checked = int.Parse(row["Checked"].ToString()),
Spam = int.Parse(row["Cought"].ToString()),
Mistakes = int.Parse(row["Reported"].ToString())
};
var ext = ExtensionManager.GetExtension(f.Name);
f.Enabled = ext == null ? true : ext.Enabled;
filterList.Add(f);
}
}
catch (Exception ex)
{
Utils.Log("CustomFilterRepository.GetCustomFilters(): " + ex.Message);
}
return filterList;
}
/// <summary>
/// Reset counters for custom filter
/// </summary>
/// <param name="filterName">Filter name</param>
/// <returns>Json response</returns>
public JsonResponse ResetCounters(string filterName)
{
if (!Security.IsAuthorizedTo(Rights.AccessAdminPages))
throw new UnauthorizedAccessException();
try
{
if (!string.IsNullOrEmpty(filterName))
{
// reset statistics for this filter
for (int i = 0; i < CustomFilters.Parameters[0].Values.Count; i++)
{
if (CustomFilters.Parameters[1].Values[i] == filterName)
{
CustomFilters.Parameters[2].Values[i] = "0";
CustomFilters.Parameters[3].Values[i] = "0";
CustomFilters.Parameters[4].Values[i] = "0";
}
}
ExtensionManager.SaveSettings("MetaExtension", CustomFilters);
}
return new JsonResponse() { Success = true, Message = $"Counters for {filterName} reset"};
}
catch (Exception ex)
{
Utils.Log($"CustomFilterRepository.ResetCounters: {ex.Message}");
return new JsonResponse() { Message = "Error resetting counters" };
}
}
}
}