/// <summary> /// This is the main entry point for the SHRD host service. /// </summary> /// <param name="args"></param> public static void Run(string[] args) { string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location; Globals.InitializeProgram(exePath, "Self Hosted Remote Desktop", true); PrivateAccessor.SetStaticFieldValue(typeof(Globals), "errorFilePath", Globals.WritableDirectoryBase + "SHRD_Log.txt"); FileInfo fiExe = new FileInfo(exePath); Environment.CurrentDirectory = fiExe.Directory.FullName; System.Windows.Forms.Application.ThreadException += Application_ThreadException; AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; //byte[] buf = new byte[4]; //ByteUtil.WriteFloat(5, buf, 0); //float f = ByteUtil.ReadFloat(buf, 0); //Logger.Info(f.ToString()); if (Environment.UserInteractive) { bool cmd = args.Length > 0 && args[0] == "cmd"; if (cmd || Debugger.IsAttached) { BPUtil.NativeWin.WinConsole.Initialize(); Logger.logType = LoggingMode.Console | LoggingMode.File; Logger.Info("Console environment detected. Logging to console is enabled."); ServiceWrapper.Initialize(); ServiceWrapper.Start(); do { Console.WriteLine("Type \"exit\" to close"); }while (Console.ReadLine().ToLower() != "exit"); ServiceWrapper.Stop(); return; } else { Logger.logType = LoggingMode.File; } string Title = "SelfHostedRemoteDesktop " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString() + " Service Manager"; string ServiceName = "SelfHostedRemoteDesktop"; ButtonDefinition btnStartCmdTest = new ButtonDefinition("Test w/console", btnStartCmdTest_Click); ButtonDefinition[] customButtons = new ButtonDefinition[] { btnStartCmdTest }; System.Windows.Forms.Application.Run(new ServiceManager(Title, ServiceName, customButtons)); } else { ServiceBase[] ServicesToRun; ServicesToRun = new ServiceBase[] { new SelfHostedRemoteDesktopSvc() }; ServiceBase.Run(ServicesToRun); } }
protected override void OnStart(string[] args) { ServiceWrapper.Initialize(); ServiceWrapper.Start(); }