12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- using System;
- using System.IO;
- using System.Reflection;
- using InABox.Core;
- using InABox.IPC;
- using InABox.Logging;
- using InABox.Rpc;
- 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, PortStatusResult>(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
- );
- }
- }
- }
|