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; using ln.types.odb.ng.storage.session; using ln.types.odb.ng.storage.fs; namespace ln.provider { public class ProviderApplication : Application { public String ServerString { get; private set; } public ProviderApplication() { ServerString = "ln.provider(0.1)"; DirectoryResource www = new DirectoryResource(new string[] { "../../www", "www" }); www.DefaultResource = www.GetResource("index.html"); www.FallBackResource = www.DefaultResource; RootResource = www; ServiceContainer.Add(ServiceDefinition.From(true)); ServiceContainer.Add(ServiceDefinition.From(true)); } public override void PrepareStart() { } } public class CoreService : ApplicationServiceBase { public ProviderApplication Application => (ProviderApplication)base.CurrentApplication; public IStorageContainer CoreStorageContainer { get; private set; } public SessionStorageContainer CoreStorageSession { get; private set; } public Mapper CoreStorageMapper { get; private set; } public CoreService() :base(nameof(CoreService)) { } public override void ServiceMain(Application application) { CoreStorageContainer = new FSStorageContainer("/var/cache/ln.provider"); CoreStorageContainer.Open(); CoreStorageSession = new SessionStorageContainer(CoreStorageContainer); CoreStorageMapper = new Mapper(CoreStorageSession); Application.RPCContainer.Add("core",new RPC(Application)); Ready(); 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()); } } } }