CEL_Payroll/Ease.SvcHost/Program.cs
2024-09-17 14:30:13 +06:00

120 lines
3.9 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration.Install;
using System.ServiceProcess;
namespace Ease.SvcHost
{
class Program
{
private const string Help =
"Ease.SvcHost Usage:\n"
+ "------------------------------------------------------\n"
+ "Ease.SvcHost -r[un]\n"
+ "Ease.SvcHost -i[nstall] name [\"... description ...\"]\n"
+ "Ease.SvcHost -u[ninstall] name\n\n"
+ "Notes:\n"
+ "Use quotes around name if name contains spaces.\n"
+ "Use -r option to verify host configuration in interactive mode.";
/// <summary>
/// Entry Point
///
/// </summary>
/// <param name="args"></param>
static void Main(string[] args)
{
if (args.Length > 0)
{
switch (args[0].ToLower())
{
case "-i":
case "-install":
if (args.Length < 2 || args.Length > 3)
{
MessageWait("Wrong number of Arguments\n\n{0}", Help);
return;
}
string n = "-name=" + args[1];
string d = "-desc=" + (args.Length > 2 ? args[2] : "");
try
{
ManagedInstallerClass.InstallHelper(new string[] { n, d, "Ease.SvcHost.exe" });
}
catch (Exception ex)
{
MessageWait("Exception:\n{0}", ex.ToString());
return;
}
MessageWait("");
break;
case "-u":
case "-uninstall":
if (args.Length < 2)
{
MessageWait("Wrong number of Arguments\n\n{0}", Help);
return;
}
try
{
ManagedInstallerClass.InstallHelper(new string[] { "-u", "-name=" + args[1], "Ease.SvcHost.exe" });
}
catch (Exception ex)
{
MessageWait("Exception:\n{0}", ex.ToString());
return;
}
MessageWait("");
break;
case "-r":
case "-run":
RemotingHost host = new RemotingHost();
host.Start();
Console.WriteLine(host.Status);
MessageWait("");
host.Stop();
MessageWait(host.Status);
break;
case "-start":
if (args.Length >= 2)
{
ServiceBase.Run(new HostService(args[1]));
}
break;
case "-?":
case "-h":
MessageWait(Help);
break;
default:
MessageWait("Invalid Arguments\n\n{0}", Help);
break;
}
}
else
{
MessageWait(Help);
}
}
static void MessageWait(string msg, params object[] args)
{
Console.WriteLine("");
Console.WriteLine(string.Format(msg, args));
Console.WriteLine("");
Console.WriteLine("Press Enter to continue ...");
Console.ReadLine();
}
}
}