ln.provider/ProviderApplication.cs

102 lines
2.3 KiB
C#
Raw Permalink Normal View History

2019-09-02 07:22:55 +02:00
using System;
using ln.application;
using ln.application.service;
using System.Threading;
using ln.http.resources;
using ln.types.odb.ng;
using ln.types.odb.ng.storage;
2019-10-04 16:36:17 +02:00
using ln.types.odb.ng.storage.session;
using ln.types.odb.ng.storage.fs;
2019-09-02 07:22:55 +02:00
namespace ln.provider
{
public class ProviderApplication : Application
{
public String ServerString { get; private set; }
public ProviderApplication()
{
ServerString = "ln.provider(0.1)";
2020-01-07 08:53:53 +01:00
DirectoryResource www = new DirectoryResource(new string[] { "../../www", "www" });
www.DefaultResource = www.GetResource("index.html");
www.FallBackResource = www.DefaultResource;
2019-09-02 07:22:55 +02:00
2020-01-07 08:53:53 +01:00
RootResource = www;
ServiceContainer.Add(ServiceDefinition.From<CoreService>(true));
2019-10-04 16:36:17 +02:00
ServiceContainer.Add(ServiceDefinition.From<IPPoolService>(true));
2019-09-02 07:22:55 +02:00
}
public override void PrepareStart()
{
}
}
public class CoreService : ApplicationServiceBase
{
2020-01-07 08:53:53 +01:00
public ProviderApplication Application => (ProviderApplication)base.CurrentApplication;
2019-09-02 07:22:55 +02:00
public IStorageContainer CoreStorageContainer { get; private set; }
2019-10-04 16:36:17 +02:00
public SessionStorageContainer CoreStorageSession { get; private set; }
2019-09-02 07:22:55 +02:00
public Mapper CoreStorageMapper { get; private set; }
public CoreService()
:base(nameof(CoreService))
{
}
2020-01-07 08:53:53 +01:00
public override void ServiceMain(Application application)
2019-09-02 07:22:55 +02:00
{
CoreStorageContainer = new FSStorageContainer("/var/cache/ln.provider");
CoreStorageContainer.Open();
2019-10-04 16:36:17 +02:00
CoreStorageSession = new SessionStorageContainer(CoreStorageContainer);
2019-09-02 07:22:55 +02:00
CoreStorageMapper = new Mapper(CoreStorageSession);
Application.RPCContainer.Add("core",new RPC(Application));
2019-10-04 16:36:17 +02:00
Ready();
2019-09-02 07:22:55 +02:00
while (!StopRequested)
{
lock (this)
{
Monitor.Wait(this);
}
}
CoreStorageMapper = null;
CoreStorageSession.Dispose();
CoreStorageSession = null;
CoreStorageContainer.Dispose();
CoreStorageContainer = null;
}
class RPC
{
ProviderApplication providerApplication;
public RPC(ProviderApplication providerApplication)
{
this.providerApplication = providerApplication;
}
public String GetServerString()
{
return providerApplication.ServerString;
}
public void Shutdown()
{
ThreadPool.QueueUserWorkItem((state) => providerApplication.Stop());
}
}
}
}