-
Notifications
You must be signed in to change notification settings - Fork 358
/
Copy pathTagInfo.cs
157 lines (126 loc) · 3.57 KB
/
TagInfo.cs
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using DotLiquid;
using Microsoft.ApplicationInspector.RulesEngine;
namespace Microsoft.ApplicationInspector.Commands;
/// <summary>
/// Root parent for tag group preferences file and used in Writers\AnalyzeHtmlWriter.cs
/// </summary>
public class TagCategory
{
public enum tagInfoType
{
uniqueTags,
allTags
}
[JsonPropertyName("type")]
public tagInfoType Type;
public TagCategory()
{
Groups = new List<TagGroup>();
}
[JsonPropertyName("categoryName")]
public string? Name { get; set; }
[JsonPropertyName("groups")]
public List<TagGroup>? Groups { get; set; }
}
/// <summary>
/// Used to read customizable preference for Profile page e.g. rules\profile\profile.json
/// </summary>
public class TagGroup : Drop
{
public TagGroup()
{
Patterns = new List<TagSearchPattern>();
}
[JsonPropertyName("title")] public string? Title { get; set; }
[JsonIgnore] public string? IconURL { get; set; }
[JsonPropertyName("dataRef")]
public string? DataRef { get; set; }
[JsonPropertyName("patterns")]
public List<TagSearchPattern>? Patterns { get; set; }
}
public class TagSearchPattern : Drop
{
private Regex? _expression;
private string _searchPattern = "";
[JsonPropertyName("searchPattern")]
public string SearchPattern
{
get => _searchPattern;
set
{
_searchPattern = value;
_expression = null;
}
}
public Regex Expression
{
get
{
if (_expression == null)
{
_expression = new Regex(SearchPattern, RegexOptions.Compiled | RegexOptions.IgnoreCase);
}
return _expression;
}
}
[JsonPropertyName("displayName")]
public string? DisplayName { get; set; }
[JsonPropertyName("detectedIcon")]
public string? DetectedIcon { get; set; } = "fas fa-cat"; //default
[JsonPropertyName("notDetectedIcon")]
public string? NotDetectedIcon { get; set; }
[JsonPropertyName("detected")]
public bool Detected { get; set; }
[JsonPropertyName("details")]
public string Details
{
get
{
var result = Detected ? "View" : "N/A";
return result;
}
}
[JsonPropertyName("confidence")]
public string Confidence { get; set; } = "Medium";
public static bool ShouldSerializeExpression()
{
return false;
}
}
/// <summary>
/// Primary use is development of lists of tags with specific group or pattern properties in reporting
/// </summary>
public class TagInfo : Drop
{
private string _confidence = "Medium";
[JsonPropertyName("tag")] public string? Tag { get; set; }
[JsonPropertyName("displayName")]
public string? ShortTag { get; set; }
[JsonIgnore] public string? StatusIcon { get; set; }
[JsonPropertyName("confidence")]
public string Confidence
{
get => _confidence;
set
{
if (Enum.TryParse(value, true, out Confidence test))
{
_confidence = value;
}
}
}
[JsonPropertyName("severity")]
public string Severity { get; set; } = "Moderate";
[JsonPropertyName("detected")]
public bool Detected { get; set; }
}
public class TagException
{
[JsonPropertyName("tag")] public string? Tag { get; set; }
}