Created
December 8, 2014 09:29
-
-
Save aruss/7abac55e14d4a62b0771 to your computer and use it in GitHub Desktop.
Wrapped service in a console
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static class Program | |
{ | |
/// <summary> | |
/// The main entry point for the application. | |
/// </summary> | |
static void Main(string[] args) | |
{ | |
var service = new Service(); | |
var arguments = string.Concat(args); | |
switch (arguments) | |
{ | |
case "--console": | |
RunInteractive(service, args); | |
break; | |
case "--install": | |
ManagedInstallerClass.InstallHelper(new[] { Assembly.GetExecutingAssembly().Location }); | |
break; | |
case "--uninstall": | |
ManagedInstallerClass.InstallHelper(new[] { "/u", Assembly.GetExecutingAssembly().Location }); | |
break; | |
default: | |
ServiceBase.Run(service); | |
break; | |
} | |
} | |
private static void RunInteractive(Service service, string[] args) | |
{ | |
service.InteractiveStart(args); | |
Console.WriteLine("Self-host server running..."); | |
Console.WriteLine("Press any key to stop."); | |
Console.ReadLine(); | |
service.InteractiveStop(); | |
} | |
} | |
public partial class Service : ServiceBase | |
{ | |
public Service() | |
{ | |
this.InitializeComponent(); | |
} | |
protected override void OnStart(string[] args) | |
{ | |
TeamFoundationHub.Core.Startup.Run(); | |
} | |
protected override void OnStop() | |
{ | |
} | |
public void InteractiveStart(string[] args) | |
{ | |
this.OnStart(args); | |
} | |
public void InteractiveStop() | |
{ | |
this.OnStop(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment