Skip to content

Commit e1fa4d2

Browse files
committed
Allow to configure service
1 parent 65e2a55 commit e1fa4d2

4 files changed

Lines changed: 16 additions & 9 deletions

File tree

Tools/Psdz/PsdzRpcClient/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ static async Task<int> Main(string[] args)
355355
}
356356

357357
PsdzRpcServerStarter serverStarter = new(Console.Out);
358-
bool connected = await serverStarter.ConnectClient(serverExe, ProcessWindowStyle.Minimized, client, cts, userName, password).ConfigureAwait(false);
358+
bool connected = await serverStarter.ConnectClient(serverExe, null, ProcessWindowStyle.Minimized, client, cts, userName, password).ConfigureAwait(false);
359359
if (!connected)
360360
{
361361
if (_verbosity >= Options.VerbosityOption.Error)

Tools/Psdz/PsdzRpcClientLibrary/PsdzRpcServerStarter.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ public PsdzRpcServerStarter(TextWriter output = null)
2222
_output = output;
2323
}
2424

25-
public async Task<bool> ConnectClient(string serverExe, ProcessWindowStyle windowStyle, PsdzRpcClient client, CancellationTokenSource cts,
25+
public async Task<bool> ConnectClient(string serverExe, string serviceName, ProcessWindowStyle windowStyle, PsdzRpcClient client, CancellationTokenSource cts,
2626
string userName = null, string password = null)
2727
{
28-
if (!StartServerIfNeeded(serverExe, windowStyle, userName, password))
28+
if (!StartServerIfNeeded(serverExe, serviceName, windowStyle, userName, password))
2929
{
3030
_output?.WriteLine("No server available. Exiting.");
3131
return false;
@@ -44,7 +44,7 @@ public async Task<bool> ConnectClient(string serverExe, ProcessWindowStyle windo
4444
}
4545

4646
_output?.WriteLine("Try to restart server...");
47-
if (!StartServerIfNeeded(serverExe, windowStyle, userName, password))
47+
if (!StartServerIfNeeded(serverExe, serviceName, windowStyle, userName, password))
4848
{
4949
_output?.WriteLine("No server available. Exiting.");
5050
return false;
@@ -72,7 +72,7 @@ public bool IsPipeAvailable()
7272
/// Startet den Server-Prozess, falls ein Pfad angegeben ist.
7373
/// Wartet nur bis der Prozess gestartet ist, nicht bis die Pipe verfügbar ist.
7474
/// </summary>
75-
public bool StartServerIfNeeded(string serverExe, ProcessWindowStyle windowStyle, string userName, string password)
75+
public bool StartServerIfNeeded(string serverExe, string serviceName, ProcessWindowStyle windowStyle, string userName, string password)
7676
{
7777
if (IsPipeAvailable())
7878
{
@@ -81,7 +81,7 @@ public bool StartServerIfNeeded(string serverExe, ProcessWindowStyle windowStyle
8181
}
8282

8383
// Zuerst versuchen den Windows-Dienst zu starten
84-
if (TryStartWindowsService("PsdzRpcServer"))
84+
if (TryStartWindowsService(serviceName))
8585
{
8686
return true;
8787
}
@@ -94,6 +94,11 @@ private bool TryStartWindowsService(string serviceName)
9494
{
9595
try
9696
{
97+
if (String.IsNullOrEmpty(serviceName))
98+
{
99+
return false;
100+
}
101+
97102
using ServiceController sc = new ServiceController(serviceName);
98103
ServiceControllerStatus status = sc.Status;
99104

Tools/Psdz/WebPsdzClient/App_Data/SessionContainer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ public SessionContainer(string sessionId, string dealerId)
648648
try
649649
{
650650
Cts = new CancellationTokenSource();
651-
bool connected = Task.Run(() => serverStarter.ConnectClient(Global.RpcServer, ProcessWindowStyle.Hidden, RpcClient, Cts)).GetAwaiter().GetResult();
651+
bool connected = Task.Run(() => serverStarter.ConnectClient(Global.RpcServer, Global.RpcServiceName, ProcessWindowStyle.Hidden, RpcClient, Cts)).GetAwaiter().GetResult();
652652
log.InfoFormat("ConnectClient result: {0}", connected);
653653

654654
if (!connected)

Tools/Psdz/WebPsdzClient/Global.asax.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public class Global : HttpApplication
2929
public static string IstaFolder { get; private set; }
3030
#if USE_RPC_CLIENT
3131
public static string RpcServer { get; private set; }
32+
public static string RpcServiceName { get; private set; }
3233
#endif
3334
public static string SqlServer { get; private set; }
3435
public static string TestLicenses { get; private set; }
@@ -44,6 +45,7 @@ protected void Application_Start(object sender, EventArgs e)
4445
IstaFolder = ConfigurationManager.AppSettings["IstaFolder"];
4546
#if USE_RPC_CLIENT
4647
RpcServer = ConfigurationManager.AppSettings["RpcServer"];
48+
RpcServiceName = ConfigurationManager.AppSettings["RpcServiceName"];
4749
#endif
4850
SqlServer = ConfigurationManager.AppSettings["SqlServer"];
4951
TestLicenses = ConfigurationManager.AppSettings["TestLicenses"];
@@ -56,9 +58,9 @@ protected void Application_Start(object sender, EventArgs e)
5658

5759
#if USE_RPC_CLIENT
5860
#if !DEBUG
59-
if (string.IsNullOrEmpty(RpcServer) || !File.Exists(RpcServer))
61+
if (string.IsNullOrEmpty(RpcServiceName))
6062
{
61-
RpcServer = PsdzRpcClient.PsdzRpcServerStarter.GetProgramsServerLocation();
63+
RpcServiceName = "PsdzRpcServer";
6264
}
6365
#endif
6466
if (string.IsNullOrEmpty(RpcServer) || !File.Exists(RpcServer))

0 commit comments

Comments
 (0)