123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- using System;
- using System.IO;
- using System.Reflection;
- using InABox.Core;
- using InABox.IPC;
- using InABox.Logging;
- namespace PRSServer
- {
- public interface IEngine
- {
- string ServiceName { get; set; }
- string Version { get; set; }
- void Run();
- void Stop();
- void Configure(Server settings);
- PortStatus[] PortStatusList();
- }
- public abstract class Engine<TProperties> : IEngine where TProperties : ServerProperties
- {
-
- private RPCServerPipeTransport _enginemanager;
- public TProperties Properties { get; private set; }
- public abstract void Run();
- public abstract void Stop();
- public virtual PortStatus[] PortStatusList()
- {
- return new PortStatus[] { };
- }
- public string ServiceName { get; set; }
- public string Version { get; set; }
- protected string AppDataFolder { get; set; }
- public virtual void Configure(Server server)
- {
- Properties = server.Properties as TProperties;
- AppDataFolder = GetPath(server.Key);
- MainLogger.AddLogger(new LogFileLogger(AppDataFolder));
- MainLogger.AddLogger(new NamedPipeLogger(server.Key));
-
- _enginemanager = new RPCServerPipeTransport($"{ServiceName}$");
- _enginemanager.AddHandler<IEngine, PortStatusCommand, PortStatusParameters, PortStatus[]>(new PortStatusHandler(this));
- _enginemanager.AfterMessage += (transport, args) => MainLogger.Send(LogType.Information,"",$"Engine Manager Message: {args.Message?.Command}");
- _enginemanager.Start();
- }
- public static string GetPath(string key)
- {
- if (Assembly.GetEntryAssembly() != null)
- return Path.Combine(
- Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
- Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().Location),
- key
- );
- return Path.Combine(
- Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
- Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().Location),
- key
- );
- }
- }
- }
|