|
@@ -48,6 +48,8 @@ namespace PRSServer
|
|
|
|
|
|
private Button _statusButton;
|
|
private Button _statusButton;
|
|
|
|
|
|
|
|
+ private CancellationTokenSource cancel = new CancellationTokenSource();
|
|
|
|
+
|
|
public ServerGrid()
|
|
public ServerGrid()
|
|
{
|
|
{
|
|
Options.AddRange(DynamicGridOption.AddRows, DynamicGridOption.EditRows, DynamicGridOption.DeleteRows, DynamicGridOption.ShowHelp);
|
|
Options.AddRange(DynamicGridOption.AddRows, DynamicGridOption.EditRows, DynamicGridOption.DeleteRows, DynamicGridOption.ShowHelp);
|
|
@@ -85,7 +87,7 @@ namespace PRSServer
|
|
else
|
|
else
|
|
{
|
|
{
|
|
var key = row.Get<Server, string>(x => x.Key);
|
|
var key = row.Get<Server, string>(x => x.Key);
|
|
- if(SecureConnections.TryGetValue(key, out var secure))
|
|
|
|
|
|
+ if(_secureConnections.TryGetValue(key, out var secure))
|
|
{
|
|
{
|
|
return secure
|
|
return secure
|
|
? secureImage
|
|
? secureImage
|
|
@@ -107,7 +109,7 @@ namespace PRSServer
|
|
else
|
|
else
|
|
{
|
|
{
|
|
var key = row.Get<Server, string>(x => x.Key);
|
|
var key = row.Get<Server, string>(x => x.Key);
|
|
- if (SecureConnections.TryGetValue(key, out var secure))
|
|
|
|
|
|
+ if (_secureConnections.TryGetValue(key, out var secure))
|
|
{
|
|
{
|
|
return secure
|
|
return secure
|
|
? column.TextToolTip("Secure (HTTPS) Connection")
|
|
? column.TextToolTip("Secure (HTTPS) Connection")
|
|
@@ -281,8 +283,10 @@ namespace PRSServer
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
- private Dictionary<string, bool> SecureConnections { get; set; } = new Dictionary<string, bool>();
|
|
|
|
- private HashSet<string> LoadingInfos = new HashSet<string>();
|
|
|
|
|
|
+ private Dictionary<String, ServiceControllerStatus> _serviceStatuses = new Dictionary<string, ServiceControllerStatus>();
|
|
|
|
+ private Dictionary<string, bool> _secureConnections { get; set; } = new Dictionary<string, bool>();
|
|
|
|
+ private Dictionary<String,RpcClientPipeTransport> _pipemonitors = new Dictionary<string, RpcClientPipeTransport>();
|
|
|
|
+ private Dictionary<String,HttpClient> _webmonitors = new Dictionary<string, HttpClient>();
|
|
|
|
|
|
protected override void Reload(Filters<Server> criteria, Columns<Server> columns, ref SortOrder<Server>? sort,
|
|
protected override void Reload(Filters<Server> criteria, Columns<Server> columns, ref SortOrder<Server>? sort,
|
|
Action<CoreTable?, Exception?> action)
|
|
Action<CoreTable?, Exception?> action)
|
|
@@ -312,153 +316,102 @@ namespace PRSServer
|
|
table.LoadRow(row, server);
|
|
table.LoadRow(row, server);
|
|
table.Rows.Add(row);
|
|
table.Rows.Add(row);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ action(table, null);
|
|
|
|
|
|
- if (table.Rows.Any(x => x.Get<Server, ServerType>(x => x.Type) == ServerType.Certificate))
|
|
|
|
- {
|
|
|
|
-
|
|
|
|
- foreach (var row in table.Rows.Where(x => x.Get<Server, ServerType>(x => x.Type) == ServerType.Web))
|
|
|
|
|
|
+ _monitor ??= Task.Run(
|
|
|
|
+ () =>
|
|
{
|
|
{
|
|
- var key = row.Get<Server, string>(x => x.Key);
|
|
|
|
- var props = row.ToObject<Server>().Properties as WebServerProperties;
|
|
|
|
- if (props != null)
|
|
|
|
|
|
+ while (!cancel.Token.IsCancellationRequested)
|
|
{
|
|
{
|
|
-
|
|
|
|
- Task.Run(() =>
|
|
|
|
|
|
+ bool testcertificates = false;
|
|
|
|
+ var certrow = table.Rows.FirstOrDefault(x => x.Get<Server, ServerType>(x => x.Type) == ServerType.Certificate);
|
|
|
|
+ if (certrow != null)
|
|
{
|
|
{
|
|
- bool IsHTTPs = false;
|
|
|
|
- var client = new HttpClient { BaseAddress = new Uri($"https://127.0.0.1:{props.ListenPort}") };
|
|
|
|
- try
|
|
|
|
- {
|
|
|
|
- client.GetAsync("/").Wait();
|
|
|
|
- SecureConnections[key] = true;
|
|
|
|
- }
|
|
|
|
- catch (Exception e)
|
|
|
|
- {
|
|
|
|
- System.Console.WriteLine(e);
|
|
|
|
- throw;
|
|
|
|
- }
|
|
|
|
- // try
|
|
|
|
- // {
|
|
|
|
- // client.GetAsync("operations").Wait();
|
|
|
|
- // URL = $"https://{url}";
|
|
|
|
- // isHTTPS = true;
|
|
|
|
- // }
|
|
|
|
- // catch (Exception)
|
|
|
|
- // {
|
|
|
|
- // URL = $"http://{url}";
|
|
|
|
- // isHTTPS = false;
|
|
|
|
- // }
|
|
|
|
- // }
|
|
|
|
- // return URL;
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- foreach (var row in table.Rows.Where(x => x.Get<Server, ServerType>(x => x.Type) == ServerType.Database))
|
|
|
|
- {
|
|
|
|
- var key = row.Get<Server, string>(x => x.Key);
|
|
|
|
|
|
+ var key = certrow.Get<Server, string>(x => x.Key);
|
|
|
|
+ var certservice = GetService(key);
|
|
|
|
+ certservice.Refresh();
|
|
|
|
+ if (certservice.Status == ServiceControllerStatus.Running)
|
|
|
|
+ testcertificates = true;
|
|
|
|
+ }
|
|
|
|
|
|
- var service = GetService(key);
|
|
|
|
- if (service is not null && service.Status == ServiceControllerStatus.Running)
|
|
|
|
- {
|
|
|
|
- if (!LoadingInfos.Contains(key))
|
|
|
|
|
|
+ foreach (var row in table.Rows)
|
|
{
|
|
{
|
|
- LoadingInfos.Add(key);
|
|
|
|
- Task.Run(() =>
|
|
|
|
|
|
+ bool bRefresh = false;
|
|
|
|
+ var key = row.Get<Server, string>(x => x.Key);
|
|
|
|
+
|
|
|
|
+ var service = GetService(key);
|
|
|
|
+ _serviceStatuses.TryGetValue(key, out var oldstatus);
|
|
|
|
+ service.Refresh();
|
|
|
|
+ _serviceStatuses[key] = service.Status;
|
|
|
|
+ if (_serviceStatuses[key] != oldstatus)
|
|
|
|
+ bRefresh = true;
|
|
|
|
+
|
|
|
|
+ if (testcertificates && (_serviceStatuses[key] == ServiceControllerStatus.Running))
|
|
{
|
|
{
|
|
- while (true)
|
|
|
|
|
|
+ var type = row.Get<Server, ServerType>(x => x.Type);
|
|
|
|
+ if (type == ServerType.Database)
|
|
|
|
+ {
|
|
|
|
+ _secureConnections.TryGetValue(key, out bool oldsecure);
|
|
|
|
+ if (!_pipemonitors.TryGetValue(key, out RpcClientPipeTransport client))
|
|
|
|
+ {
|
|
|
|
+ client = new RpcClientPipeTransport(DatabaseServerProperties.GetPipeName(key));
|
|
|
|
+ client.Connect();
|
|
|
|
+ _pipemonitors[key] = client;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ var info = client.IsConnected()
|
|
|
|
+ ? client.Send<RpcInfoCommand, RpcInfoParameters, RpcInfoResult>(new RpcInfoParameters()).Info
|
|
|
|
+ : null;
|
|
|
|
+ _secureConnections[key] = info?.IsHTTPS ?? false;
|
|
|
|
+
|
|
|
|
+ bRefresh = bRefresh || (_secureConnections[key] != oldsecure);
|
|
|
|
+ }
|
|
|
|
+ else if (type == ServerType.Web)
|
|
{
|
|
{
|
|
- var client = new RpcClientPipeTransport(DatabaseServerProperties.GetPipeName(key));
|
|
|
|
- //var client = IPCClientFactory.GetClient(DatabaseServerProperties.GetPipeName(key));
|
|
|
|
- var response = client.Info();
|
|
|
|
- //var response = client.Send(IPCMessage.Info(new InfoRequest()), 10_000).GetResponse<InfoResponse>();
|
|
|
|
- if (response != null)
|
|
|
|
|
|
+ var props = row.ToObject<Server>().Properties as WebServerProperties;
|
|
|
|
+ _secureConnections.TryGetValue(key, out bool oldsecure);
|
|
|
|
+ if (!_webmonitors.TryGetValue(key, out HttpClient client))
|
|
{
|
|
{
|
|
- SecureConnections[key] = response.IsHTTPS;
|
|
|
|
- break;
|
|
|
|
|
|
+ client = new HttpClient { BaseAddress = new Uri($"https://127.0.0.1:{props.ListenPort}") };
|
|
|
|
+ _webmonitors[key] = client;
|
|
}
|
|
}
|
|
- else
|
|
|
|
|
|
+ try
|
|
{
|
|
{
|
|
- SecureConnections.Remove(key);
|
|
|
|
- var service = GetService(key);
|
|
|
|
- if (service is null || service.Status != ServiceControllerStatus.Running)
|
|
|
|
- break;
|
|
|
|
|
|
+ client.GetAsync("/").Wait();
|
|
|
|
+ _secureConnections[key] = true;
|
|
}
|
|
}
|
|
|
|
+ catch (Exception e)
|
|
|
|
+ {
|
|
|
|
+ _secureConnections[key] = false;
|
|
|
|
+ }
|
|
|
|
+ bRefresh = bRefresh || (_secureConnections[key] != oldsecure);
|
|
}
|
|
}
|
|
- Dispatcher.Invoke(() =>
|
|
|
|
- {
|
|
|
|
- InvalidateRow(row);
|
|
|
|
- });
|
|
|
|
- LoadingInfos.Remove(key);
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- if(SecureConnections.TryGetValue(key, out var info))
|
|
|
|
- {
|
|
|
|
- SecureConnections.Remove(key);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- action(table, null);
|
|
|
|
-
|
|
|
|
- _monitor ??= Task.Run(() =>
|
|
|
|
- {
|
|
|
|
- while (true)
|
|
|
|
- {
|
|
|
|
- try
|
|
|
|
- {
|
|
|
|
- var bRefresh = false;
|
|
|
|
- foreach (var service in _services)
|
|
|
|
|
|
+ }
|
|
|
|
+ else
|
|
{
|
|
{
|
|
- var oldstatus = service.Status;
|
|
|
|
- service.Refresh();
|
|
|
|
- bRefresh = bRefresh || service.Status != oldstatus;
|
|
|
|
- /*if ((oldstatus != ServiceControllerStatus.Stopped) && (service.Status == ServiceControllerStatus.Stopped))
|
|
|
|
- Dispatcher.Invoke(() => StopConsole(service.ServiceName));*/
|
|
|
|
|
|
+ bRefresh = bRefresh || _secureConnections.ContainsKey(key);
|
|
|
|
+ _secureConnections.Remove(key);
|
|
}
|
|
}
|
|
-
|
|
|
|
if (bRefresh)
|
|
if (bRefresh)
|
|
- Dispatcher.Invoke(() => { Refresh(false, true); });
|
|
|
|
- }
|
|
|
|
- catch (Exception e)
|
|
|
|
- {
|
|
|
|
|
|
+ Dispatcher.Invoke(() =>
|
|
|
|
+ {
|
|
|
|
+ if (testcertificates && (ActionColumns[1].Position != DynamicActionColumnPosition.Start))
|
|
|
|
+ ActionColumns[1].Position = DynamicActionColumnPosition.Start;
|
|
|
|
+ else if (!testcertificates && (ActionColumns[1].Position != DynamicActionColumnPosition.Hidden))
|
|
|
|
+ ActionColumns[1].Position = DynamicActionColumnPosition.Hidden;
|
|
|
|
+ Refresh(true, false);
|
|
|
|
+ InvalidateRow(row);
|
|
|
|
+ });
|
|
}
|
|
}
|
|
-
|
|
|
|
- Task.Delay(500).Wait();
|
|
|
|
|
|
+
|
|
|
|
+ Task.Delay(TimeSpan.FromSeconds(1)).Wait();
|
|
}
|
|
}
|
|
- });
|
|
|
|
|
|
+ },
|
|
|
|
+ cancel.Token
|
|
|
|
+ );
|
|
}
|
|
}
|
|
-
|
|
|
|
- // protected override void SelectItems(CoreRow[] rows)
|
|
|
|
- // {
|
|
|
|
- // base.SelectItems(rows);
|
|
|
|
- // if (rows != null && rows.Length == 1)
|
|
|
|
- // {
|
|
|
|
- // var type = rows.First().Get<Server, ServerType>(x => x.Type);
|
|
|
|
- // DatabaseLicense.Visibility = Equals(type, ServerType.Database) ? Visibility.Visible : Visibility.Collapsed;
|
|
|
|
- // DatabaseCustomFields.Visibility = Equals(type, ServerType.Database) ? Visibility.Visible : Visibility.Collapsed;
|
|
|
|
- // DatabaseScripts.Visibility = Equals(type, ServerType.Database) ? Visibility.Visible : Visibility.Collapsed;
|
|
|
|
- //
|
|
|
|
- // EditWebSettings.Visibility = Equals(type, ServerType.Web) ? Visibility.Visible : Visibility.Collapsed;
|
|
|
|
- //
|
|
|
|
- // ScheduledScripts.Visibility = type == ServerType.Schedule ? Visibility.Visible : Visibility.Collapsed;
|
|
|
|
- // }
|
|
|
|
- // else
|
|
|
|
- // {
|
|
|
|
- // EditWebSettings.Visibility = Visibility.Collapsed;
|
|
|
|
- // DatabaseLicense.Visibility = Visibility.Collapsed;
|
|
|
|
- // DatabaseCustomFields.Visibility = Visibility.Collapsed;
|
|
|
|
- // DatabaseScripts.Visibility = Visibility.Collapsed;
|
|
|
|
- // ScheduledScripts.Visibility = Visibility.Collapsed;
|
|
|
|
- // }
|
|
|
|
- // }
|
|
|
|
-
|
|
|
|
|
|
+
|
|
protected override Server LoadItem(CoreRow row)
|
|
protected override Server LoadItem(CoreRow row)
|
|
{
|
|
{
|
|
var key = row.Get<Server, string>(x => x.Key);
|
|
var key = row.Get<Server, string>(x => x.Key);
|
|
@@ -766,8 +719,9 @@ namespace PRSServer
|
|
{
|
|
{
|
|
if (arg == null)
|
|
if (arg == null)
|
|
return Properties.Resources.tick.AsBitmapImage();
|
|
return Properties.Resources.tick.AsBitmapImage();
|
|
- var service = GetService(arg.Get<Server, string>(c => c.Key));
|
|
|
|
- var state = service != null ? (int)service.Status : 0;
|
|
|
|
|
|
+ var key = arg.Get<Server, string>(c => c.Key);
|
|
|
|
+ var service = GetService(key);
|
|
|
|
+ int state = service != null ? (int)service.Status : 0;
|
|
return _stateimages[state];
|
|
return _stateimages[state];
|
|
}
|
|
}
|
|
|
|
|