forked from boldreports/demo-services
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Global.asax.cs
89 lines (83 loc) · 3.47 KB
/
Global.asax.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.Routing;
using System.Net;
using System.Text;
using System.IO;
using Bold.Licensing;
using BoldReports.Base.Logger;
using BoldReports.Web;
using Newtonsoft.Json;
using System.Reflection;
namespace ReportServices
{
public class WebApiApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
// Register Bold Reports license
string License = File.ReadAllText(Server.MapPath("BoldLicense.txt"), Encoding.UTF8);
log4net.GlobalContext.Properties["LogPath"] = this.GetAppDataFolderPath();
BoldReports.Base.Logger.LogExtension.RegisterLog4NetConfig();
BoldLicenseProvider.RegisterLicense(License, bool.Parse(System.Configuration.ConfigurationManager.AppSettings["IsOfflineLicense"]));
ReportConfig.DefaultSettings = new ReportSettings()
{
MapSetting = this.GetMapSettings()
}.RegisterExtensions(this.GetDataExtension());
//Establish a TLS connection for image downloading.
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
System.Web.Http.GlobalConfiguration.Configuration.EnableCors();
System.Web.Http.GlobalConfiguration.Configuration.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional });
}
public string GetAppDataFolderPath()
{
try
{
return System.IO.Path.GetFullPath(AppDomain.CurrentDomain.BaseDirectory);
}
catch
{
return null;
}
}
private BoldReports.Web.MapSetting GetMapSettings()
{
try
{
string basePath = HttpContext.Current.Server.MapPath("~/Scripts");
return new MapSetting()
{
ShapePath = basePath + "\\ShapeData\\",
MapShapes = JsonConvert.DeserializeObject<List<MapShape>>(System.IO.File.ReadAllText(basePath + "\\ShapeData\\mapshapes.txt"))
};
}
catch (Exception ex)
{
LogExtension.LogError("Failed to Load Map Settings", ex, MethodBase.GetCurrentMethod());
}
return null;
}
private List<string> GetDataExtension()
{
var extensions = !string.IsNullOrEmpty(System.Configuration.ConfigurationManager.AppSettings["ExtAssemblies"]) ? System.Configuration.ConfigurationManager.AppSettings["ExtAssemblies"] : string.Empty;
try
{
var ExtNames = new List<string>(extensions.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries));
List<string> ExtCollections = new List<string>();
ExtNames.ForEach(Extension => ExtCollections.Add(System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "bin", Extension + ".dll")));
return ExtCollections;
}
catch (Exception ex)
{
LogExtension.LogError("Failed to Load Data Extension", ex, MethodBase.GetCurrentMethod());
}
return null;
}
}
}