-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathActivator.cs
98 lines (92 loc) · 4.3 KB
/
Activator.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
/* *********************************************************************
* This Source Code Form is copyright of 51Degrees Mobile Experts Limited.
* Copyright © 2017 51Degrees Mobile Experts Limited, 5 Charlotte Close,
* Caversham, Reading, Berkshire, United Kingdom RG4 7BY
*
* This Source Code Form is the subject of the following patents and patent
* applications, owned by 51Degrees Mobile Experts Limited of 5 Charlotte
* Close, Caversham, Reading, Berkshire, United Kingdom RG4 7BY:
* European Patent No. 2871816;
* European Patent Application No. 17184134.9;
* United States Patent Nos. 9,332,086 and 9,350,823; and
* United States Patent Application No. 15/686,066.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0.
*
* If a copy of the MPL was not distributed with this file, You can obtain
* one at http://mozilla.org/MPL/2.0/.
*
* This Source Code Form is “Incompatible With Secondary Licenses”, as
* defined by the Mozilla Public License, v. 2.0.
* ********************************************************************* */
using System.Web;
using System.Web.Configuration;
using System;
// The following assembly attribute make the static method run on app start.
[assembly: PreApplicationStartMethod(typeof(FiftyOne.Foundation.PreApplicationStart), "Start")]
namespace FiftyOne.Foundation
{
/// <summary>
/// Classed used by ASP.NET v4 to activate 51Degrees.mobi Foundation removing
/// the need to activate from the web.config file.
/// </summary>
public static class PreApplicationStart
{
/// <summary>
/// Flag to indicate if the method has already been called.
/// </summary>
private static bool _initialised = false;
/// <summary>
/// Method called with the worker process starts to activate the
/// mobile capabilities of the DLL without requiring web.config
/// entries.
/// </summary>
public static void Start()
{
if (_initialised == false &&
FiftyOne.Foundation.Mobile.Detection.Configuration.Manager.Enabled)
{
// Replace the browser capabilities provider with one that is 51Degrees
// enabled if not done so already and detection is enabled.
if (HttpCapabilitiesBase.BrowserCapabilitiesProvider is
FiftyOne.Foundation.Mobile.Detection.MobileCapabilitiesProvider == false &&
FiftyOne.Foundation.Mobile.Detection.Configuration.Manager.Enabled)
{
HttpCapabilitiesBase.BrowserCapabilitiesProvider =
new FiftyOne.Foundation.Mobile.Detection.MobileCapabilitiesProvider();
}
// Include the detection module if the Microsoft.Web.Infrastructure assembly is
// available. This is needed to perform background actions such as automatic
// updates.
try
{
RegisterModule();
}
catch (Exception ex)
{
EventLog.Warn("Detection module could not automatically be registered. " +
"Some detection and redirection services will not be available unless the " +
"HttpModule is included explicitly in the web.config file or " +
"Microsoft.Web.Infrastructure is installed.");
if (EventLog.IsDebug)
EventLog.Debug(ex);
}
_initialised = true;
}
}
/// <summary>
/// Registers the HttpModule for detection and redirection.
/// </summary>
/// <remarks>
/// The detection module inherits from the redirection module due to maintaining
/// compaitability with legacy code. The functionality of the modules is controlled
/// via the 51Degrees.config file.
/// </remarks>
private static void RegisterModule()
{
Microsoft.Web.Infrastructure.DynamicModuleHelper.DynamicModuleUtility.RegisterModule(
typeof(FiftyOne.Foundation.Mobile.Detection.DetectorModule));
}
}
}