using System; using System.IO; using System.Reflection; using System.Threading; using InABox.Logging; namespace PRSServer { public interface IEngine { string ServiceName { get; set; } string Version { get; set; } void Run(); void Stop(); void Configure(Server settings); } public abstract class Engine : IEngine where TProperties : ServerProperties { public TProperties Properties { get; private set; } public abstract void Run(); public abstract void Stop(); 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)); } 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 ); } } }