forked from kipusoep/UrlTracker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UrlTrackerSettings.cs
290 lines (281 loc) · 11.7 KB
/
UrlTrackerSettings.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;
using umbraco;
namespace InfoCaster.Umbraco.UrlTracker
{
public static class UrlTrackerSettings
{
public const string TableName = "icUrlTracker";
public const string OldTableName = "infocaster301";
public const string HttpModuleCheck = "890B748D-E226-49FA-A0D7-9AFD3A359F88";
public static bool SEOMetadataInstalled
{
get
{
if (!_seoMetadataInstalled.HasValue)
{
_seoMetadataInstalled = AppDomain.CurrentDomain.GetAssemblies().Any(x => x.FullName.Contains("Epiphany.SeoMetadata"));
}
return _seoMetadataInstalled.Value;
}
}
public static string SEOMetadataPropertyName
{
get
{
return !string.IsNullOrEmpty(ConfigurationManager.AppSettings["SeoMetadata.PropertyName"]) ? ConfigurationManager.AppSettings["SeoMetadata.PropertyName"] : "metadata";
}
}
static bool? _seoMetadataInstalled;
/// <summary>
/// Returns wether or not the UrlTracker is disabled
/// </summary>
/// <remarks>
/// appSetting: 'urlTracker:disabled'
/// </remarks>
public static bool IsDisabled
{
get
{
if (!_isDisabled.HasValue)
{
bool isDisabled = false;
if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["urlTracker:disabled"]))
{
bool parsedAppSetting;
if (bool.TryParse(ConfigurationManager.AppSettings["urlTracker:disabled"], out parsedAppSetting))
isDisabled = parsedAppSetting;
}
_isDisabled = isDisabled;
}
return _isDisabled.Value;
}
}
/// <summary>
/// Returns wether or not logging for the UrlTracker is enabled
/// </summary>
/// <remarks>
/// appSettings: 'urlTracker:enableLogging' & 'umbracoDebugMode'
/// </remarks>
public static bool EnableLogging
{
get
{
if (!_enableLogging.HasValue)
{
bool enableLogging = false;
if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["urlTracker:enableLogging"]))
{
bool parsedAppSetting;
if (bool.TryParse(ConfigurationManager.AppSettings["urlTracker:enableLogging"], out parsedAppSetting))
enableLogging = parsedAppSetting;
}
_enableLogging = enableLogging;
}
return _enableLogging.Value && GlobalSettings.DebugMode;
}
}
/// <summary>
/// Returns the URLs to ignore for 404 Not Found logging
/// </summary>
/// <remarks>
/// appSetting: 'urlTracker:404UrlsToIgnore'
/// </remarks>
public static string[] NotFoundUrlsToIgnore
{
get
{
if (_notFoundUrlsToIgnore == null)
{
_notFoundUrlsToIgnore = new string[] { "favicon.ico" };
if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["urlTracker:404UrlsToIgnore"]))
_notFoundUrlsToIgnore = _notFoundUrlsToIgnore.Union(ConfigurationManager.AppSettings["urlTracker:404UrlsToIgnore"].Split(',')).ToArray();
}
return _notFoundUrlsToIgnore;
}
}
/// <summary>
/// Returns the regex patterns for NotFound urls to ignore
/// </summary>
public static Regex[] RegexNotFoundUrlsToIgnore
{
get
{
return new Regex[] { new Regex("__browserLink/requestData/.*", RegexOptions.Compiled), new Regex("[^/]/arterySignalR/ping", RegexOptions.Compiled) };
}
}
/// <summary>
/// Returns the UrlTracker UI URL to ignore as referrer
/// </summary>
public static string ReferrerToIgnore
{
get { return "Umbraco/UrlTracker/InfoCaster.Umbraco.UrlTracker.UI"; }
}
/// <summary>
/// Returns wether or not tracking URL changes is disabled
/// </summary>
/// <remarks>
/// appSetting: 'urlTracker:trackingDisabled'
/// </remarks>
public static bool IsTrackingDisabled
{
get
{
if (!_isTrackingDisabled.HasValue)
{
bool isTrackingDisabled = false;
if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["urlTracker:trackingDisabled"]))
{
bool parsedAppSetting;
if (bool.TryParse(ConfigurationManager.AppSettings["urlTracker:trackingDisabled"], out parsedAppSetting))
isTrackingDisabled = parsedAppSetting;
}
_isTrackingDisabled = isTrackingDisabled;
}
return _isTrackingDisabled.Value;
}
}
/// <summary>
/// Returns wether or not not found (404) tracking is disabled
/// </summary>
/// <remarks>
/// appSetting: 'urlTracker:notFoundTrackingDisabled'
/// </remarks>
public static bool IsNotFoundTrackingDisabled
{
get
{
if (!_isNotFoundTrackingDisabled.HasValue)
{
bool isNotFoundTrackingDisabled = false;
if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["urlTracker:notFoundTrackingDisabled"]))
{
bool parsedAppSetting;
if (bool.TryParse(ConfigurationManager.AppSettings["urlTracker:notFoundTrackingDisabled"], out parsedAppSetting))
isNotFoundTrackingDisabled = parsedAppSetting;
}
_isNotFoundTrackingDisabled = isNotFoundTrackingDisabled;
}
return _isNotFoundTrackingDisabled.Value;
}
}
/// <summary>
/// Gets a value indicating whether or not to append port numbers to URLs. Default is true.
/// </summary>
/// <value>
/// <c>true</c> if we are to append the port number; otherwise, <c>false</c>.
/// </value>
public static bool AppendPortNumber
{
get
{
if (!_appendPortNumber.HasValue)
{
bool appendPortNumber = true;
if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["urlTracker:appendPortNumber"]))
{
bool parsedAppSetting;
if (bool.TryParse(ConfigurationManager.AppSettings["urlTracker:appendPortNumber"], out parsedAppSetting))
appendPortNumber = parsedAppSetting;
}
_appendPortNumber = appendPortNumber;
}
return _appendPortNumber.Value;
}
}
/// <summary>
/// Returns wether or not a child node has a domain configured
/// </summary>
/// <remarks>
/// appSetting: 'urlTracker:hasDomainOnChildNode'
/// </remarks>
public static bool HasDomainOnChildNode
{
get
{
if (!_hasDomainOnChildNode.HasValue)
{
var hasDomainOnChildNode = false;
if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["urlTracker:hasDomainOnChildNode"]))
{
bool parsedAppSetting;
if (bool.TryParse(ConfigurationManager.AppSettings["urlTracker:hasDomainOnChildNode"], out parsedAppSetting))
hasDomainOnChildNode = parsedAppSetting;
}
_hasDomainOnChildNode = hasDomainOnChildNode;
}
return _hasDomainOnChildNode.Value;
}
}
/// <summary>
/// Gets a value indicating whether or not forced redirects should be cached for a period of time. Default is false.
/// Setting this to true will enabled forced redirect updates and additions to propagate to all servers in a multi-server environment
/// </summary>
/// <value>
/// <c>true</c> if we are to cache forced redirects for a period of time; otherwise, <c>false</c>.
/// </value>
/// <remarks>
/// appSetting: 'urlTracker:forcedRedirectCacheTimeoutEnabled'
/// </remarks>
public static bool ForcedRedirectCacheTimeoutEnabled
{
get
{
if (!_forcedRedirectCacheTimeoutEnabled.HasValue)
{
bool forcedRedirectCacheTimeoutEnabled = false;
if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["urlTracker:forcedRedirectCacheTimeoutEnabled"]))
{
bool parsedAppSetting;
if (bool.TryParse(ConfigurationManager.AppSettings["urlTracker:forcedRedirectCacheTimeoutEnabled"], out parsedAppSetting))
forcedRedirectCacheTimeoutEnabled = parsedAppSetting;
}
_forcedRedirectCacheTimeoutEnabled = forcedRedirectCacheTimeoutEnabled;
}
return _forcedRedirectCacheTimeoutEnabled.Value;
}
}
/// <summary>
/// Amount of time, in seconds, that the forced redirects will be cached for. Default is 14400 (4 hours).
/// The default value will be used when the app setting is less than 1.
/// This setting does nothing unless urlTracker:forcedRedirectCacheTimeoutEnabled is true
/// </summary>
/// <remarks>
/// appSetting: 'urlTracker:forcedRedirectCacheTimeoutSeconds'
/// </remarks>
public static int ForcedRedirectCacheTimeoutSeconds
{
get
{
if (!_forcedRedirectCacheTimeoutSeconds.HasValue)
{
int forcedRedirectCacheTimeoutSeconds = 14400; // 4 hours
if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["urlTracker:forcedRedirectCacheTimeoutSeconds"]))
{
int parsedAppSetting;
if (int.TryParse(ConfigurationManager.AppSettings["urlTracker:forcedRedirectCacheTimeoutSeconds"], out parsedAppSetting)
&& parsedAppSetting > 0)
{
forcedRedirectCacheTimeoutSeconds = parsedAppSetting;
}
}
_forcedRedirectCacheTimeoutSeconds = forcedRedirectCacheTimeoutSeconds;
}
return _forcedRedirectCacheTimeoutSeconds.Value;
}
}
static bool? _isDisabled;
static bool? _enableLogging;
static string[] _notFoundUrlsToIgnore;
static bool? _isTrackingDisabled;
static bool? _isNotFoundTrackingDisabled;
static bool? _appendPortNumber;
static bool? _hasDomainOnChildNode;
static bool? _forcedRedirectCacheTimeoutEnabled;
static int? _forcedRedirectCacheTimeoutSeconds;
}
}