init
This commit is contained in:
60
Kreta.WebApi/Naplo/Kreta.Naplo.WebApi/Global.asax.cs
Normal file
60
Kreta.WebApi/Naplo/Kreta.Naplo.WebApi/Global.asax.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
using System;
|
||||
using System.Configuration;
|
||||
using System.Web;
|
||||
using System.Xml;
|
||||
|
||||
namespace Kreta.Naplo.WebApi
|
||||
{
|
||||
public class WebApiApplication : HttpApplication
|
||||
{
|
||||
private static KretaServer.KretaServer s_kretaServer;
|
||||
|
||||
protected void Application_Start()
|
||||
{
|
||||
ServerStarter();
|
||||
}
|
||||
|
||||
protected void Application_End(object sender, EventArgs e)
|
||||
{
|
||||
if (s_kretaServer != null)
|
||||
{
|
||||
if (s_kretaServer.IsRunning)
|
||||
{
|
||||
s_kretaServer.Stop();
|
||||
}
|
||||
else
|
||||
{
|
||||
#pragma warning disable S2696 // Instance members should not write to "static" fields
|
||||
s_kretaServer = null;
|
||||
#pragma warning restore S2696 // Instance members should not write to "static" fields
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")]
|
||||
private static void ServerStarter()
|
||||
{
|
||||
if (s_kretaServer == null || !s_kretaServer.IsRunning)
|
||||
{
|
||||
XmlNode fullnode = (XmlNode)ConfigurationManager.GetSection("ServerConfig");
|
||||
XmlDocument doc = new XmlDocument();
|
||||
doc.LoadXml(fullnode.SelectSingleNode("/ServerConfig/config").OuterXml);
|
||||
|
||||
s_kretaServer = s_kretaServer ?? new KretaServer.KretaServer(doc.DocumentElement);
|
||||
|
||||
try
|
||||
{
|
||||
s_kretaServer.Start();
|
||||
}
|
||||
#pragma warning disable S2221 // "Exception" should not be caught when not required by called methods
|
||||
catch
|
||||
#pragma warning restore S2221 // "Exception" should not be caught when not required by called methods
|
||||
{
|
||||
#pragma warning disable S3626 // Jump statements should not be redundant
|
||||
return;
|
||||
#pragma warning restore S3626 // Jump statements should not be redundant
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user