J'ai fait un webservice topshelf qui utilise le paramètre personnalisé:Topshelf - fils à partir en fonction des paramètres personnalisés
string department = null;
// *********************Below is a TopShelf code*****************************//
HostFactory.Run(hostConfigurator =>
{
hostConfigurator.AddCommandLineDefinition("department", f => { department = f; }); //Define new parameter
hostConfigurator.ApplyCommandLine(); //apply it
Helpers.LogFile("xxx", "Got department:"+department);
hostConfigurator.Service<MyService>(serviceConfigurator =>
{
serviceConfigurator.ConstructUsing(() => new MyService(department)); //what service we are using
serviceConfigurator.WhenStarted(myService => myService.Start()); //what to run on start
serviceConfigurator.WhenStopped(myService => myService.Stop()); // and on stop
}
);
hostConfigurator.RunAsLocalService();
//****************Change those names for other services*******************************************//
string d = "CallForwardService_" + department;
hostConfigurator.SetDisplayName(d);
hostConfigurator.SetDescription("CallForward using Topshelf");
hostConfigurator.SetServiceName(d);
});
...
public class MyService
string depTask;
public MyService(string d)
{
//***********************Three tasks for three different destinations***********************
depTask = d;
_taskL = new Task(Logistics);
_taskP = new Task(Planners);
_taskW = new Task(Workshop);
Helpers.LogFile(depTask, "started working on threads for "+d);
public void Start()
{
if (depTask == "logistics")
{
_taskL.Start();
Helpers.LogFile(depTask, "proper thread selected");
}
...
Où Helpers.logfile
écrit simplement un fichier texte. Aa vous pouvez voir à partir du code ci-dessus le paramètre department
est passé à MyService(string d)
. Tout fonctionne correctement lorsque je débogue en utilisant le "-partment: workshop" comme paramètre de débogage. Mais quand j'essaye d'installer le programme en tant que service utilisant callforward.exe install -department:logistics
je crée le service callforwardservice_logistics
bu quand je vérifie le journal le paramètre n'a pas été passé au MyService.
Qu'est-ce que je fais mal?
Ceci est une fonctionnalité très demandée si, et serait une demande de traction bienvenue. Je suis sûr que j'y arriverai finalement, c'est tout juste trop élevé sur mon radar à ce stade. –