ServerGrid.cs 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365
  1. using System;
  2. using System.Collections.Concurrent;
  3. using System.Collections.Generic;
  4. using System.Diagnostics;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Net;
  8. using System.Net.Http;
  9. using System.ServiceProcess;
  10. using System.Threading;
  11. using System.Threading.Tasks;
  12. using System.Windows;
  13. using System.Windows.Controls;
  14. using System.Windows.Media.Imaging;
  15. using Comal.Classes;
  16. using Comal.Stores;
  17. using InABox.Client.IPC;
  18. using InABox.Clients;
  19. using InABox.Configuration;
  20. using InABox.Core;
  21. using InABox.Database;
  22. using InABox.Database.SQLite;
  23. using InABox.DynamicGrid;
  24. using InABox.IPC;
  25. using InABox.Rpc;
  26. using InABox.Wpf.Editors;
  27. using InABox.Wpf.Console;
  28. using InABox.WPF;
  29. using PRSClasses;
  30. using PRSServer.Forms;
  31. using PRSServer.Forms.DatabaseLicense;
  32. using RestSharp;
  33. using Method = RestSharp.Method;
  34. using Console = InABox.Wpf.Console.Console;
  35. using PRSServices;
  36. namespace PRSServer;
  37. class ServerStartupSettings : BaseObject, ILocalConfigurationSettings
  38. {
  39. public List<string> StartServers { get; set; } = new();
  40. }
  41. public class ServerGrid : DynamicGrid<Server>
  42. {
  43. private Task? _monitor;
  44. private ConcurrentBag<ServiceController> _services = new();
  45. private Button _channelButton;
  46. private Button _statusButton;
  47. private CancellationTokenSource cancel = new CancellationTokenSource();
  48. public ServerGrid()
  49. {
  50. ActionColumns.Add(new DynamicImageColumn(TypeImage)
  51. { Position = DynamicActionColumnPosition.Start, ToolTip = TypeToolTip });
  52. ActionColumns.Add(new DynamicImageColumn(SecureImage)
  53. { Position = DynamicActionColumnPosition.Start, ToolTip = SecureToolTip });
  54. ActionColumns.Add(new DynamicImageColumn(StateImage, StateAction)
  55. { Position = DynamicActionColumnPosition.End, ToolTip = StateToolTip });
  56. ActionColumns.Add(new DynamicMenuColumn(CreateServerMenu,ServerMenuStatus)
  57. { Position = DynamicActionColumnPosition.End, ToolTip = MenuToolTip });
  58. RowHeight = 40;
  59. FontSize = 14;
  60. _channelButton = AddButton("", Properties.Resources.autoupdate.AsBitmapImage(), "Change Update Channel", EditUpdateChannel_Click);
  61. _statusButton = AddButton("", Properties.Resources.secure.AsBitmapImage(), "Check Service Status", ShowServiceStatus);
  62. }
  63. protected override void DoReconfigure(DynamicGridOptions options)
  64. {
  65. base.DoReconfigure(options);
  66. options.AddRows = true;
  67. options.EditRows = true;
  68. options.DeleteRows = true;
  69. options.ShowHelp = true;
  70. }
  71. private BitmapImage secureImage = Properties.Resources.secure.AsBitmapImage();
  72. private BitmapImage insecureImage = Properties.Resources.insecure.AsBitmapImage();
  73. private BitmapImage? SecureImage(CoreRow? row)
  74. {
  75. if(row is null)
  76. {
  77. return secureImage;
  78. }
  79. else
  80. {
  81. var key = row.Get<Server, string>(x => x.Key);
  82. if(_secureConnections.TryGetValue(key, out var secure))
  83. {
  84. return secure
  85. ? secureImage
  86. : insecureImage;
  87. }
  88. else
  89. {
  90. return null;
  91. }
  92. }
  93. }
  94. private FrameworkElement? SecureToolTip(DynamicActionColumn column, CoreRow? row)
  95. {
  96. if(row is null)
  97. {
  98. return column.TextToolTip("Connection Security");
  99. }
  100. else
  101. {
  102. var key = row.Get<Server, string>(x => x.Key);
  103. if (_secureConnections.TryGetValue(key, out var secure))
  104. {
  105. return secure
  106. ? column.TextToolTip("Secure (HTTPS) Connection")
  107. : column.TextToolTip("Insecure (HTTP) Connection");
  108. }
  109. else
  110. {
  111. return null;
  112. }
  113. }
  114. }
  115. private DynamicMenuStatus ServerMenuStatus(CoreRow arg)
  116. {
  117. if (arg == null)
  118. return DynamicMenuStatus.Hidden;
  119. return DynamicMenuStatus.Enabled;
  120. var type = arg.Get<Server, ServerType>(x => x.Type);
  121. var service = GetService(arg.Get<Server, string>(c => c.Key));
  122. var running = service?.Status == ServiceControllerStatus.Running;
  123. if ((type == ServerType.Database) || (type == ServerType.Web) || (type == ServerType.Schedule))
  124. {
  125. return running
  126. ? DynamicMenuStatus.Enabled
  127. : DynamicMenuStatus.Disabled;
  128. }
  129. return running
  130. ? DynamicMenuStatus.Enabled
  131. : DynamicMenuStatus.Hidden;
  132. }
  133. private void CreateServerMenu(DynamicMenuColumn column, CoreRow? row)
  134. {
  135. if (row is null)
  136. return;
  137. var status = ServerMenuStatus(row);
  138. if (status == DynamicMenuStatus.Hidden)
  139. return;
  140. var type = row.Get<Server, ServerType>(x => x.Type);
  141. var key = row.Get<Server, String>(x => x.Key);
  142. column.AddItem(
  143. "View Console",
  144. Properties.Resources.target,
  145. (row) => StartConsole(row!, key),
  146. null,
  147. status == DynamicMenuStatus.Enabled && !_consoles.ContainsKey(key)
  148. );
  149. column.AddItem(
  150. "Search Log Files",
  151. Properties.Resources.service,
  152. (row) => SearchLogFiles(row!),
  153. null,
  154. status == DynamicMenuStatus.Enabled
  155. );
  156. if (type.Equals(ServerType.Database))
  157. {
  158. column.AddSeparator();
  159. column.AddItem(
  160. "Custom Fields",
  161. Properties.Resources.service,
  162. (row) => EditCustomFields(row!),
  163. null,
  164. status == DynamicMenuStatus.Enabled
  165. );
  166. column.AddItem(
  167. "Database Scripts",
  168. Properties.Resources.script,
  169. (row) => EditDatabaseScripts(row!),
  170. null,
  171. status == DynamicMenuStatus.Enabled
  172. );
  173. column.AddSeparator();
  174. column.AddItem(
  175. "Update License",
  176. Properties.Resources.key,
  177. (row) => UpdateDatabaseLicense(row!),
  178. null,
  179. status == DynamicMenuStatus.Enabled
  180. );
  181. column.AddSeparator();
  182. column.AddItem(
  183. "Manage Deletions",
  184. Properties.Resources.delete,
  185. (row) => ManageDeletions(row!),
  186. null,
  187. status == DynamicMenuStatus.Enabled
  188. );
  189. }
  190. else if (type.Equals(ServerType.Web))
  191. {
  192. column.AddSeparator();
  193. column.AddItem(
  194. "Edit Templates",
  195. Properties.Resources.script,
  196. (row) => EditWebTemplates(row!),
  197. null,
  198. status == DynamicMenuStatus.Enabled
  199. );
  200. column.AddItem(
  201. "Edit Styles",
  202. Properties.Resources.css,
  203. (row) => EditWebStyles(row!),
  204. null,
  205. status == DynamicMenuStatus.Enabled
  206. );
  207. column.AddItem(
  208. "Edit Documents",
  209. Properties.Resources.pdf,
  210. (row) => EditWebDocuments(row!),
  211. null,
  212. status == DynamicMenuStatus.Enabled
  213. );
  214. column.AddSeparator();
  215. column.AddItem(
  216. "PRS Mobile Settings",
  217. Properties.Resources.web,
  218. (row) => PRSMobileSettings(row!),
  219. null,
  220. status == DynamicMenuStatus.Enabled
  221. );
  222. }
  223. else if (type.Equals(ServerType.Schedule))
  224. {
  225. column.AddSeparator();
  226. column.AddItem(
  227. "Scheduled Scripts",
  228. Properties.Resources.script,
  229. (row) => EditScheduledScripts(row!),
  230. null,
  231. status == DynamicMenuStatus.Enabled
  232. );
  233. }
  234. }
  235. private ServiceController? GetService(string key)
  236. {
  237. return _services.FirstOrDefault(x => string.Equals(x.ServiceName, key));
  238. }
  239. protected override void ShowHelp(string slug)
  240. {
  241. base.ShowHelp("Server_Configuration");
  242. }
  243. public void BeforeUpdate()
  244. {
  245. var sections = PRSService.GetConfiguration().LoadAll();
  246. RefreshServices(sections);
  247. var closed = new List<string>();
  248. foreach (var service in _services)
  249. {
  250. if(service.Status == ServiceControllerStatus.Running)
  251. {
  252. service.Stop();
  253. closed.Add(service.ServiceName);
  254. }
  255. }
  256. var config = PRSService.GetConfiguration<ServerStartupSettings>();
  257. var startupSettings = config.Load();
  258. startupSettings.StartServers = closed;
  259. config.Save(startupSettings);
  260. }
  261. #region Grid Handling
  262. private void RefreshServices(Dictionary<string, ServerSettings> sections)
  263. {
  264. Interlocked.Exchange(
  265. ref _services,
  266. new ConcurrentBag<ServiceController>(
  267. ServiceController.GetServices().Where(x => sections.ContainsKey(x.ServiceName))
  268. )
  269. );
  270. }
  271. private Dictionary<String, ServiceControllerStatus> _serviceStatuses = new Dictionary<string, ServiceControllerStatus>();
  272. private Dictionary<string, bool> _secureConnections = new Dictionary<string, bool>();
  273. private Dictionary<String,RpcClientPipeTransport> _pipemonitors = new Dictionary<string, RpcClientPipeTransport>();
  274. private Dictionary<String,HttpClient> _webmonitors = new Dictionary<string, HttpClient>();
  275. protected override void Reload(
  276. Filters<Server> criteria, Columns<Server> columns, ref SortOrder<Server>? sort,
  277. CancellationToken token, Action<CoreTable?, Exception?> action)
  278. {
  279. var table = new CoreTable();
  280. table.LoadColumns(typeof(Server));
  281. var sections = PRSService.GetConfiguration().LoadAll();
  282. RefreshServices(sections);
  283. var startupConfig = PRSService.GetConfiguration<ServerStartupSettings>();
  284. var startupSettings = startupConfig.Load();
  285. foreach (var startup in startupSettings.StartServers)
  286. {
  287. try
  288. {
  289. _services.FirstOrDefault(x => x.ServiceName == startup)?.Start();
  290. }
  291. catch(Exception e)
  292. {
  293. Logger.Send(LogType.Error, "", $"Could not start {startup}: {CoreUtils.FormatException(e)}");
  294. }
  295. }
  296. startupSettings.StartServers.Clear();
  297. startupConfig.Save(startupSettings);
  298. foreach (var section in sections.OrderBy(x => x.Value.Type))
  299. {
  300. var server = section.Value.CreateServer(section.Key);
  301. var service = _services.FirstOrDefault(x => string.Equals(x.ServiceName, section.Key));
  302. table.LoadRow(server);
  303. }
  304. action(table, null);
  305. _monitor ??= Task.Run(
  306. () =>
  307. {
  308. while (!cancel.Token.IsCancellationRequested)
  309. {
  310. bool testcertificates = false;
  311. var certrow = table.Rows.FirstOrDefault(x => x.Get<Server, ServerType>(x => x.Type) == ServerType.Certificate);
  312. if (certrow != null)
  313. {
  314. var key = certrow.Get<Server, string>(x => x.Key);
  315. var certservice = GetService(key);
  316. if(certservice is not null)
  317. {
  318. certservice.Refresh();
  319. if (certservice.Status == ServiceControllerStatus.Running)
  320. testcertificates = true;
  321. }
  322. }
  323. foreach (var row in table.Rows)
  324. {
  325. bool bRefresh = false;
  326. var key = row.Get<Server, string>(x => x.Key);
  327. var service = GetService(key);
  328. if(service is null)
  329. {
  330. continue;
  331. }
  332. _serviceStatuses.TryGetValue(key, out var oldstatus);
  333. service.Refresh();
  334. _serviceStatuses[key] = service.Status;
  335. if (_serviceStatuses[key] != oldstatus)
  336. bRefresh = true;
  337. if (testcertificates && (_serviceStatuses[key] == ServiceControllerStatus.Running))
  338. {
  339. var type = row.Get<Server, ServerType>(x => x.Type);
  340. if (type == ServerType.Database)
  341. {
  342. _secureConnections.TryGetValue(key, out var oldsecure);
  343. if (!_pipemonitors.TryGetValue(key, out var client))
  344. {
  345. client = new RpcClientPipeTransport(DatabaseServerProperties.GetPipeName(key, true));
  346. client.Connect();
  347. _pipemonitors[key] = client;
  348. }
  349. var info = client.IsConnected()
  350. ? client.Send<RpcInfoCommand, RpcInfoParameters, RpcInfoResult>(new RpcInfoParameters()).Info
  351. : null;
  352. _secureConnections[key] = info?.IsHTTPS ?? false;
  353. bRefresh = bRefresh || (_secureConnections[key] != oldsecure);
  354. }
  355. else if (type == ServerType.Web)
  356. {
  357. var props = row.ToObject<Server>().Properties as WebServerProperties;
  358. _secureConnections.TryGetValue(key, out var oldsecure);
  359. if (!_webmonitors.TryGetValue(key, out var client))
  360. {
  361. client = new HttpClient { BaseAddress = new Uri($"https://127.0.0.1:{props.ListenPort}") };
  362. _webmonitors[key] = client;
  363. }
  364. try
  365. {
  366. client.GetAsync("/").Wait();
  367. _secureConnections[key] = true;
  368. }
  369. catch (Exception e)
  370. {
  371. _secureConnections[key] = false;
  372. }
  373. bRefresh = bRefresh || (_secureConnections[key] != oldsecure);
  374. }
  375. }
  376. else
  377. {
  378. bRefresh = bRefresh || _secureConnections.ContainsKey(key);
  379. _secureConnections.Remove(key);
  380. }
  381. if (bRefresh)
  382. Dispatcher.Invoke(() =>
  383. {
  384. if (testcertificates && (ActionColumns[1].Position != DynamicActionColumnPosition.Start))
  385. ActionColumns[1].Position = DynamicActionColumnPosition.Start;
  386. else if (!testcertificates && (ActionColumns[1].Position != DynamicActionColumnPosition.Hidden))
  387. ActionColumns[1].Position = DynamicActionColumnPosition.Hidden;
  388. Refresh(true, false);
  389. InvalidateRow(row);
  390. });
  391. }
  392. Task.Delay(TimeSpan.FromSeconds(1)).Wait();
  393. }
  394. },
  395. cancel.Token
  396. );
  397. }
  398. public override Server LoadItem(CoreRow row)
  399. {
  400. var key = row.Get<Server, string>(x => x.Key);
  401. var settings = PRSService.GetConfiguration(key).Load();
  402. return settings.CreateServer(key);
  403. }
  404. private string CreateKey(ServerType type)
  405. {
  406. var services = ServiceController.GetServices();
  407. var key = string.Format("PRS{0}", type.ToString());
  408. var i = 1;
  409. while (services.Any(x => string.Equals(key, x.ServiceName)))
  410. key = string.Format("PRS{0}_{1}", type.ToString(), i++);
  411. return key;
  412. }
  413. private void CreateMenu(ContextMenu parent, string header, ServerType server, Type properties)
  414. {
  415. var menu = new MenuItem();
  416. menu.Header = header;
  417. menu.Tag = properties;
  418. menu.Icon = new Image() { Source = _typeimages[server] };
  419. menu.IsCheckable = false;
  420. menu.Click += (o, e) =>
  421. {
  422. var itemtype = ((o as MenuItem)?.Tag as Type)!;
  423. var props = (Activator.CreateInstance(itemtype) as ServerProperties)!;
  424. if (EditProperties(properties, props, true))
  425. {
  426. var server = CreateItem();
  427. server.Key = CreateKey(props.Type());
  428. server.Type = props.Type();
  429. server.Properties = props;
  430. SaveItem(server);
  431. Refresh(false, true);
  432. }
  433. };
  434. parent.Items.Add(menu);
  435. }
  436. protected override void DoAdd(bool openEditorOnDirectEdit = false)
  437. {
  438. var menu = new ContextMenu();
  439. CreateMenu(menu, "Database", ServerType.Database, typeof(DatabaseServerProperties));
  440. CreateMenu(menu, "GPS Connector", ServerType.GPS, typeof(GPSServerProperties));
  441. if (!Data.Rows.Any(r => r.Get<Server, ServerType>(c => c.Type) == ServerType.AutoDiscovery))
  442. CreateMenu(menu, "Auto Discovery", ServerType.AutoDiscovery, typeof(AutoDiscoveryServerProperties));
  443. CreateMenu(menu, "Scheduler", ServerType.Schedule, typeof(ScheduleServerProperties));
  444. CreateMenu(menu, "Web Service", ServerType.Web, typeof(WebServerProperties));
  445. if (!Data.Rows.Any(r => r.Get<Server, ServerType>(c => c.Type) == ServerType.Certificate))
  446. CreateMenu(menu, "HTTPS Certificate Engine", ServerType.Certificate, typeof(CertificateEngineProperties));
  447. menu.IsOpen = true;
  448. }
  449. protected override void DoEdit()
  450. {
  451. if (!SelectedRows.Any())
  452. return;
  453. var server = LoadItem(SelectedRows.First());
  454. var service = GetService(server.Key);
  455. var enabled = service == null || service.Status == ServiceControllerStatus.Stopped;
  456. if (EditProperties(server.Properties.GetType(), server.Properties, enabled))
  457. {
  458. server.Name = server.Properties.Name;
  459. SaveItem(server);
  460. Refresh(false, true);
  461. }
  462. }
  463. public override void SaveItem(Server item)
  464. {
  465. var settings = new ServerSettings();
  466. settings.Type = item.Type;
  467. settings.Properties = Serialization.Serialize(item.Properties, false);
  468. PRSService.GetConfiguration(item.Key).Save(settings);
  469. ReconfigureService(item);
  470. }
  471. private bool isServiceChanged(Server server, ServiceController? service, string newDisplayName)
  472. {
  473. return newDisplayName != service?.DisplayName || (server.Properties.HasOriginalValue(x => x.Username) && server.Properties.GetOriginalValue(x => x.Username) != server.Properties.Username);
  474. }
  475. protected override bool CanDeleteItems(params CoreRow[] rows)
  476. {
  477. var bOK = true;
  478. foreach (var row in rows)
  479. {
  480. var service = GetService(row.Get<Server, string>(x => x.Key));
  481. if (service != null && service.Status != ServiceControllerStatus.Stopped)
  482. bOK = false;
  483. }
  484. return bOK;
  485. }
  486. public override void DeleteItems(params CoreRow[] rows)
  487. {
  488. foreach (var row in rows)
  489. {
  490. var key = row.Get<Server, string>(x => x.Key);
  491. Interlocked.Exchange(
  492. ref _services,
  493. new ConcurrentBag<ServiceController>(
  494. _services.Where(x => !string.Equals(x.ServiceName, key))
  495. )
  496. );
  497. PRSService.GetConfiguration(key).Delete();
  498. var serverType = row.Get<Server, ServerType>(x => x.Type);
  499. if (serverType == ServerType.Certificate)
  500. {
  501. if (File.Exists(CertificateEngine.CertificateFile))
  502. {
  503. File.Delete(CertificateEngine.CertificateFile);
  504. }
  505. }
  506. PRSServiceInstaller.UninstallService(key);
  507. }
  508. }
  509. protected override void DefineLookups(ILookupEditorControl sender, Server[] items, bool async = true)
  510. {
  511. if(sender.EditorDefinition is ComboLookupEditor lookup && lookup.Type == typeof(DatabaseServerLookupGenerator))
  512. {
  513. base.DefineLookups(sender, Data.Rows.Select(x => x.ToObject<Server>()).ToArray());
  514. }
  515. else
  516. {
  517. base.DefineLookups(sender, items, async);
  518. }
  519. }
  520. #endregion
  521. #region Server Configuration
  522. private bool EditUpdateChannel_Click(Button arg1, CoreRow[] arg2)
  523. {
  524. var settings = new LocalConfiguration<AutoUpdateSettings>().Load();
  525. var editable = settings.ToEditable();
  526. var buttons = new DynamicEditorButtons()
  527. {
  528. new DynamicEditorButton(
  529. "",
  530. Properties.Resources.help.AsBitmapImage(),
  531. null,
  532. (o, e) => base.ShowHelp("Automatic_Updates"))
  533. };
  534. var propertyEditor = new DynamicEditorForm(typeof(EditableAutoUpdateSettings), null, buttons);
  535. propertyEditor.OnDefineEditor += PropertyEditor_OnDefineEditor;
  536. propertyEditor.OnDefineLookups += sender => DefineLookups(sender, new Server[] { });
  537. propertyEditor.Items = new BaseObject[] { editable };
  538. if (propertyEditor.ShowDialog() == true)
  539. {
  540. settings.FromEditable(editable);
  541. new LocalConfiguration<AutoUpdateSettings>().Save(settings);
  542. }
  543. return false;
  544. }
  545. private BaseEditor? PropertyEditor_OnDefineEditor(object item, DynamicGridColumn column)
  546. {
  547. if (string.Equals(column.ColumnName, "Elevated"))
  548. return new NullEditor();
  549. var result = GetEditor(item, column);
  550. if (result != null)
  551. result = result.CloneEditor();
  552. return result;
  553. }
  554. private void ReconfigureService(Server item)
  555. {
  556. var service = GetService(item.Key);
  557. var newDisplayName = "PRS - " + item.Properties.Name;
  558. string? username = item.Properties.Username;
  559. if (!isServiceChanged(item, service, newDisplayName)) return;
  560. string? password = null;
  561. if (!string.IsNullOrWhiteSpace(username))
  562. {
  563. var passwordEditor = new PasswordDialog(string.Format("Enter password for {0}", username));
  564. if(passwordEditor.ShowDialog() == true)
  565. {
  566. password = passwordEditor.Password;
  567. }
  568. else
  569. {
  570. password = null;
  571. }
  572. }
  573. else
  574. {
  575. username = null;
  576. }
  577. if (service == null)
  578. try
  579. {
  580. using (new WaitCursor())
  581. {
  582. PRSServiceInstaller.InstallService(
  583. item.Key,
  584. item.Properties.Name,
  585. newDisplayName,
  586. username,
  587. password
  588. );
  589. }
  590. }
  591. catch (Exception e)
  592. {
  593. MessageBox.Show(string.Format("Error Installing {0}: {1}", item.Key, e.Message));
  594. }
  595. else
  596. try
  597. {
  598. using (new WaitCursor())
  599. {
  600. PRSServiceInstaller.ChangeService(
  601. item.Key,
  602. item.Properties.Name,
  603. newDisplayName,
  604. username,
  605. password
  606. );
  607. }
  608. }
  609. catch (Exception e)
  610. {
  611. MessageBox.Show(string.Format("Error Configuring {0}: {1}", item.Key, e.Message));
  612. }
  613. }
  614. public bool EditProperties(Type type, ServerProperties item, bool enabled)
  615. {
  616. var pages = new DynamicEditorPages();
  617. if (type == typeof(DatabaseServerProperties))
  618. {
  619. pages.Add(new SMSProviderGrid());
  620. }
  621. var buttons = new DynamicEditorButtons();
  622. buttons.Add(
  623. "",
  624. Properties.Resources.help.AsBitmapImage(),
  625. item,
  626. (f, i) =>
  627. {
  628. Process.Start(new ProcessStartInfo("https://prsdigital.com.au/wiki/index.php/" + type.Name.SplitCamelCase().Replace(" ", "_"))
  629. { UseShellExecute = true });
  630. }
  631. );
  632. var propertyEditor = new DynamicEditorForm(type, pages, buttons);
  633. if(type == typeof(DatabaseServerProperties))
  634. {
  635. propertyEditor.OnSaveItem += (o, e) =>
  636. {
  637. propertyEditor.UnloadEditorPages(false);
  638. propertyEditor.UnloadEditorPages(true);
  639. };
  640. }
  641. propertyEditor.OnFormCustomiseEditor += PropertyEditor_OnFormCustomiseEditor;
  642. propertyEditor.ReadOnly = !enabled;
  643. propertyEditor.OnDefineLookups += sender => DefineLookups(sender, new Server[] { });
  644. propertyEditor.Items = new BaseObject[] { item };
  645. return propertyEditor.ShowDialog() == true;
  646. }
  647. private void PropertyEditor_OnFormCustomiseEditor(IDynamicEditorForm sender, object[] items, DynamicGridColumn column, BaseEditor editor)
  648. {
  649. var type = items[0].GetType();
  650. if(type == typeof(DatabaseServerProperties) && column.ColumnName == nameof(DatabaseServerProperties.EmailType) && editor is EnumLookupEditor lookup)
  651. {
  652. var button = new EditorButton(items[0] as DatabaseServerProperties, "Edit", 50, (o, item) =>
  653. {
  654. if (item is not DatabaseServerProperties properties) return;
  655. var props = properties.GetEmailProperties();
  656. var grid = DynamicGridUtils.CreateDynamicGrid(typeof(DynamicItemsListGrid<>), props.GetType());
  657. if (grid.EditItems([props]))
  658. {
  659. properties.SetEmailProperties(props);
  660. sender.SetEditorValue(column.ColumnName, properties.EmailType);
  661. }
  662. }, false);
  663. lookup.Buttons = [button];
  664. }
  665. }
  666. #endregion
  667. #region Service Start / Stop Actions
  668. private readonly Dictionary<int, BitmapImage> _stateimages = new()
  669. {
  670. { 0, Properties.Resources.warning.AsBitmapImage() },
  671. { (int)ServiceControllerStatus.Stopped, Properties.Resources.pause.AsBitmapImage() },
  672. { (int)ServiceControllerStatus.StartPending, Properties.Resources.working.AsBitmapImage() },
  673. { (int)ServiceControllerStatus.StopPending, Properties.Resources.working.AsBitmapImage() },
  674. { (int)ServiceControllerStatus.Running, Properties.Resources.tick.AsBitmapImage() },
  675. { (int)ServiceControllerStatus.ContinuePending, Properties.Resources.working.AsBitmapImage() },
  676. { (int)ServiceControllerStatus.PausePending, Properties.Resources.working.AsBitmapImage() },
  677. { (int)ServiceControllerStatus.Paused, Properties.Resources.pause.AsBitmapImage() }
  678. };
  679. private BitmapImage StateImage(CoreRow? arg)
  680. {
  681. if (arg == null)
  682. return Properties.Resources.tick.AsBitmapImage();
  683. var key = arg.Get<Server, string>(c => c.Key);
  684. var service = GetService(key);
  685. int state = service != null ? (int)service.Status : 0;
  686. return _stateimages[state];
  687. }
  688. private FrameworkElement? StateToolTip(DynamicActionColumn arg1, CoreRow? arg2)
  689. {
  690. if (arg2 == null)
  691. return null;
  692. var service = GetService(arg2.Get<Server, string>(c => c.Key));
  693. return arg1.TextToolTip(service != null ? "Current State: " + service.Status : "Not Installed");
  694. }
  695. private FrameworkElement? MenuToolTip(DynamicActionColumn arg1, CoreRow? arg2)
  696. {
  697. return arg2 != null ? arg1.TextToolTip("Server Options") : null;
  698. }
  699. private bool StateAction(CoreRow? arg)
  700. {
  701. if (arg == null)
  702. return false;
  703. var key = arg.Get<Server, string>(c => c.Key);
  704. var service = GetService(arg.Get<Server, string>(c => c.Key));
  705. if (service != null)
  706. {
  707. Task? task;
  708. if (service.Status == ServiceControllerStatus.Running)
  709. {
  710. task = Task.Run(
  711. () =>
  712. {
  713. service.Stop();
  714. Dispatcher.Invoke(()=> Refresh(false, false));
  715. });
  716. //StopConsole(key);
  717. }
  718. else if (service.Status == ServiceControllerStatus.Stopped)
  719. {
  720. task = Task.Run(
  721. () =>
  722. {
  723. service.Start();
  724. Dispatcher.Invoke(()=> Refresh(false, false));
  725. });
  726. StartConsole(arg,key);
  727. }
  728. else if (service.Status == ServiceControllerStatus.Paused)
  729. {
  730. task = Task.Run(() =>
  731. {
  732. service.Continue();
  733. Dispatcher.Invoke(()=> Refresh(false, false));
  734. });
  735. }
  736. else
  737. {
  738. MessageBox.Show(string.Format("Invalid Service State ({0})", service.Status.ToString()));
  739. return false;
  740. }
  741. task?.ContinueWith((e) =>
  742. {
  743. if (e.Exception?.InnerException is { } inner)
  744. {
  745. if(inner.InnerException != null)
  746. {
  747. MessageBox.Show(String.Format("Error while running service:\n{0}", inner.InnerException.Message));
  748. }
  749. else
  750. {
  751. MessageBox.Show(String.Format("Error while running service:\n{0}", inner.Message));
  752. }
  753. PRSServiceInstaller.UninstallService(arg.Get<Server, string>(x => x.Key));
  754. Refresh(false, true);
  755. }
  756. }, TaskScheduler.FromCurrentSynchronizationContext());
  757. return true;
  758. }
  759. MessageBox.Show("Cannot find Service - is it installed?");
  760. return false;
  761. }
  762. public void StopAll()
  763. {
  764. foreach (var service in _services.ToArray())
  765. if (service.Status == ServiceControllerStatus.Running)
  766. Task.Run(() => { service.Stop(); });
  767. }
  768. #endregion
  769. #region Server Type Images
  770. private readonly Dictionary<ServerType, BitmapImage> _typeimages = new()
  771. {
  772. { ServerType.Database, Properties.Resources.database.AsBitmapImage() },
  773. { ServerType.GPS, Properties.Resources.gps.AsBitmapImage() },
  774. { ServerType.AutoDiscovery, Properties.Resources.autodiscover.AsBitmapImage() },
  775. { ServerType.Schedule, Properties.Resources.schedule.AsBitmapImage() },
  776. { ServerType.Web, Properties.Resources.web.AsBitmapImage() },
  777. { ServerType.Certificate, Properties.Resources.certificate.AsBitmapImage() }
  778. };
  779. private BitmapImage TypeImage(CoreRow? arg)
  780. {
  781. if (arg == null)
  782. return Properties.Resources.help.AsBitmapImage();
  783. var type = arg.Get<Server, ServerType>(c => c.Type);
  784. return _typeimages[type];
  785. }
  786. private FrameworkElement? TypeToolTip(DynamicActionColumn arg1, CoreRow? arg2)
  787. {
  788. if (arg2 == null)
  789. return null;
  790. return arg1.TextToolTip(string.Format("{0} Service\nName: {1}",
  791. arg2.Get<Server, ServerType>(c => c.Type).ToString(),
  792. arg2.Get<Server, string>(c => c.Key)
  793. ));
  794. }
  795. #endregion
  796. #region Console Functions
  797. private BitmapImage? ConsoleImage(CoreRow? arg)
  798. {
  799. if (arg == null)
  800. return Properties.Resources.target.AsBitmapImage();
  801. var service = GetService(arg.Get<Server, string>(c => c.Key));
  802. var state = service != null ? (int)service.Status : 0;
  803. if (state == (int)ServiceControllerStatus.StartPending || state == (int)ServiceControllerStatus.Running)
  804. return Properties.Resources.target.AsBitmapImage();
  805. return null;
  806. }
  807. private bool ConsoleAction(CoreRow? arg)
  808. {
  809. if (arg == null)
  810. return false;
  811. var key = arg.Get<Server, string>(c => c.Key);
  812. var service = GetService(key);
  813. var state = service != null ? (int)service.Status : 0;
  814. if (state == (int)ServiceControllerStatus.StartPending || state == (int)ServiceControllerStatus.Running)
  815. StartConsole(arg, key);
  816. return false;
  817. }
  818. private Dictionary<String, Tuple<ServerConsole, int>> _consoles = new Dictionary<string, Tuple<ServerConsole, int>>();
  819. private void StartConsole(CoreRow arg, string key)
  820. {
  821. if (_consoles.ContainsKey(key))
  822. return;
  823. var name = arg.Get<Server, string>(c => c.Name);
  824. var console = new ServerConsole(key, $"{key} - {name}");
  825. var window = Window.GetWindow(this);
  826. int i = 0;
  827. while (_consoles.Any(x => x.Value.Item2 == i))
  828. i++;
  829. _consoles[key] = new Tuple<ServerConsole, int>(console, i);
  830. console.Top = window.Top + (i * 50);
  831. console.Left = window.Left + window.Width + 2 + (i*50);
  832. console.Height = window.Height;
  833. console.Closing += (o, e) =>
  834. {
  835. var c = o as ServerConsole;
  836. if (_consoles.ContainsKey(c.ServiceName))
  837. _consoles.Remove(c.ServiceName);
  838. };
  839. console.Show();
  840. }
  841. private void StopConsole(String key)
  842. {
  843. if (!_consoles.ContainsKey(key))
  844. return;
  845. var console = _consoles[key].Item1;
  846. console.Close();
  847. }
  848. #endregion
  849. #region Individual Server Buttons
  850. // Check if a database server is running at the given url and port
  851. private bool IsDatabaseServerRunning(string url, int port)
  852. {
  853. var uri = new Uri(string.Format("{0}:{1}", url, port));
  854. var cli = new RestClient(uri);
  855. var req = new RestRequest("/classes", Method.Get) { Timeout = TimeSpan.FromSeconds(20) };
  856. try
  857. {
  858. var res = cli.Execute(req);
  859. if (res.StatusCode != HttpStatusCode.OK || res.ErrorException != null)
  860. return false;
  861. return true;
  862. }
  863. catch (Exception e)
  864. {
  865. }
  866. return false;
  867. }
  868. // The following variables keep track of whether a database is currently being used, since if two people try to access two different databases,
  869. // terrible things will ensue.
  870. private int currentServerUsers;
  871. private string? currentServerURL;
  872. private int? currentServerPort;
  873. /// <summary>
  874. /// Configures a server for the duration of an action
  875. /// </summary>
  876. /// <typeparam name="TProperties"></typeparam>
  877. /// <param name="row"></param>
  878. /// <param name="hostaddress"></param>
  879. /// <param name="portnumber"></param>
  880. /// <param name="action"></param>
  881. /// <param name="blocking">
  882. /// If blocking is set to false, then currentServerUsers must be decreased by one manually once the
  883. /// task finishes
  884. /// </param>
  885. private void ConfigureServer<TProperties>(
  886. CoreRow row,
  887. Func<TProperties, string> hostaddress,
  888. Func<TProperties, int> portnumber,
  889. Action action,
  890. bool blocking = true
  891. ) where TProperties : ServerProperties
  892. {
  893. try
  894. {
  895. if (row == null)
  896. throw new Exception("No Row Selected!");
  897. var server = LoadItem(row);
  898. if (server == null)
  899. throw new Exception("Unable to load Server!");
  900. var props = server.Properties as TProperties;
  901. if (props == null)
  902. throw new Exception("Unable to Load Properties!");
  903. var url = hostaddress(props);
  904. var port = portnumber(props);
  905. using (new WaitCursor())
  906. {
  907. if (!IsDatabaseServerRunning(url, port))
  908. throw new Exception("Database Server is not available!");
  909. }
  910. if (action != null)
  911. {
  912. if (currentServerUsers == 0)
  913. {
  914. if (currentServerURL != url || currentServerPort != port)
  915. {
  916. ConfigurationCache.ClearAll(ConfigurationCacheType.Global);
  917. ConfigurationCache.ClearAll(ConfigurationCacheType.User);
  918. }
  919. currentServerURL = url;
  920. currentServerPort = port;
  921. currentServerName = null;
  922. ClientFactory.SetClientType(typeof(RestClient<>), Platform.Server, CoreUtils.GetVersion(), url, port, true);
  923. // override the need to provide credentials when configuring the database
  924. ClientFactory.SetBypass();
  925. }
  926. else
  927. {
  928. if (url != currentServerURL || port != currentServerPort)
  929. throw new Exception(string.Format("A different Database Server ({0}:{1}) is currently in use!", currentServerURL,
  930. currentServerPort));
  931. }
  932. currentServerUsers++;
  933. action();
  934. if (blocking) currentServerUsers--;
  935. }
  936. }
  937. catch (Exception e)
  938. {
  939. Logger.Send(LogType.Error, "", CoreUtils.FormatException(e));
  940. MessageBox.Show(e.Message);
  941. }
  942. }
  943. private string? currentServerName;
  944. private void ConfigureIPCServer<TProperties>(
  945. CoreRow row,
  946. Func<TProperties, string> hostPipeName,
  947. Action action,
  948. bool blocking = true
  949. ) where TProperties : ServerProperties
  950. {
  951. try
  952. {
  953. if (row == null)
  954. throw new Exception("No Row Selected!");
  955. var server = LoadItem(row);
  956. if (server == null)
  957. throw new Exception("Unable to load Server!");
  958. var props = server.Properties as TProperties;
  959. if (props == null)
  960. throw new Exception("Unable to Load Properties!");
  961. var pipeName = DatabaseServerProperties.GetPipeName(hostPipeName(props), false);
  962. if (action != null)
  963. {
  964. if (currentServerUsers == 0)
  965. {
  966. if (currentServerName != pipeName)
  967. {
  968. ConfigurationCache.ClearAll(ConfigurationCacheType.Global);
  969. ConfigurationCache.ClearAll(ConfigurationCacheType.User);
  970. }
  971. currentServerPort = null;
  972. currentServerURL = null;
  973. currentServerName = pipeName;
  974. ClientFactory.SetClientType(typeof(IPCClient<>), Platform.Server, CoreUtils.GetVersion(), pipeName);
  975. using (new WaitCursor())
  976. {
  977. if (!Client.Ping())
  978. {
  979. ClientFactory.ClearClientType();
  980. throw new Exception("Database Server is not available!");
  981. }
  982. }
  983. // override the need to provide credentials when configuring the database
  984. ClientFactory.SetBypass();
  985. }
  986. else
  987. {
  988. if (pipeName != currentServerName)
  989. throw new Exception(string.Format("A different Database Server ({0}) is currently in use!", currentServerName));
  990. }
  991. currentServerUsers++;
  992. try
  993. {
  994. action();
  995. }
  996. finally
  997. {
  998. if (blocking) currentServerUsers--;
  999. }
  1000. }
  1001. }
  1002. catch (Exception e)
  1003. {
  1004. Logger.Send(LogType.Error, "", CoreUtils.FormatException(e));
  1005. MessageBox.Show(e.Message);
  1006. }
  1007. }
  1008. private void ConfigureLocalDatabase(
  1009. CoreRow row,
  1010. Action action
  1011. )
  1012. {
  1013. try
  1014. {
  1015. if (row == null)
  1016. throw new Exception("No Row Selected!");
  1017. var server = LoadItem(row) ?? throw new Exception("Unable to load Server!");
  1018. if (server.Properties is not DatabaseServerProperties properties)
  1019. throw new Exception("Unable to Load Properties!");
  1020. if (!DbFactory.IsProviderSet || DbFactory.ProviderFactory is not SQLiteProviderFactory sql || sql.URL != properties.FileName)
  1021. {
  1022. ClientFactory.SetClientType(typeof(LocalClient<>), Platform.Server, CoreUtils.GetVersion());
  1023. Progress.ShowModal("Configuring database", (progress) =>
  1024. {
  1025. DbFactory.Stores = CoreUtils.TypeList(
  1026. AppDomain.CurrentDomain.GetAssemblies(),
  1027. myType =>
  1028. myType.IsClass
  1029. && !myType.IsAbstract
  1030. && !myType.IsGenericType
  1031. && myType.GetInterfaces().Contains(typeof(IStore))
  1032. ).ToArray();
  1033. DbFactory.DefaultStore = typeof(BaseStore<>);
  1034. DbFactory.ProviderFactory = new SQLiteProviderFactory(properties.FileName);
  1035. DbFactory.Start();
  1036. CoreUtils.GoogleAPIKey = properties.GoogleAPIKey;
  1037. PurchaseOrder.PONumberPrefix = properties.PurchaseOrderPrefix;
  1038. Job.JobNumberPrefix = properties.JobPrefix;
  1039. });
  1040. }
  1041. action();
  1042. }
  1043. catch(Exception e)
  1044. {
  1045. Logger.Send(LogType.Error, "", CoreUtils.FormatException(e));
  1046. MessageBox.Show(e.Message);
  1047. }
  1048. }
  1049. private bool UpdateDatabaseLicense(CoreRow selectedrow)
  1050. {
  1051. ConfigureIPCServer<DatabaseServerProperties>(
  1052. selectedrow,
  1053. //x => "http://127.0.0.1",
  1054. //x => x.Port,
  1055. x => selectedrow.Get<Server, string>(x => x.Key),
  1056. () =>
  1057. {
  1058. new LicenseRenewalForm().ShowDialog();
  1059. }
  1060. );
  1061. return false;
  1062. }
  1063. private bool SearchLogFiles(CoreRow selectedrow)
  1064. {
  1065. string Folder = "";
  1066. if (selectedrow != null)
  1067. {
  1068. var Key = selectedrow.Get<Server, string>(x => x.Key);
  1069. var manager = new RpcClientPipeTransport($"{Key}M");
  1070. var result = manager.Send<LogFolderCommand, LogFolderParameters, LogFolderResult>(new LogFolderParameters());
  1071. Folder = result.Folder;
  1072. }
  1073. var window = new LogSearcher();
  1074. logsearcherViewModel.Folder = Folder;
  1075. window.ShowDialog();
  1076. return false;
  1077. }
  1078. private bool ManageDeletions(CoreRow row)
  1079. {
  1080. ConfigureLocalDatabase(row, () =>
  1081. {
  1082. new DeletionsWindow().ShowDialog();
  1083. });
  1084. return false;
  1085. }
  1086. private bool EditCustomFields(CoreRow selectedrow)
  1087. {
  1088. ConfigureIPCServer<DatabaseServerProperties>(
  1089. selectedrow,
  1090. //x => "http://127.0.0.1",
  1091. //x => x.Port,
  1092. x => selectedrow.Get<Server, string>(x => x.Key),
  1093. () => { new MasterList(typeof(CustomProperty), "Class", null, true).ShowDialog(); }
  1094. );
  1095. return false;
  1096. }
  1097. private bool EditDatabaseScripts(CoreRow selectedrow)
  1098. {
  1099. ConfigureIPCServer<DatabaseServerProperties>(
  1100. selectedrow,
  1101. //x => "http://127.0.0.1",
  1102. //x => x.Port,
  1103. x => selectedrow.Get<Server, string>(x => x.Key),
  1104. () => { new MasterList(typeof(Script), "Section", null, true).ShowDialog(); }
  1105. );
  1106. return false;
  1107. }
  1108. private bool EditScheduledScripts(CoreRow selectedrow)
  1109. {
  1110. ConfigureIPCServer<ScheduleServerProperties>(
  1111. selectedrow,
  1112. x => x.Server,
  1113. () => { new MasterList(typeof(ScheduledScript), "", null, true, typeof(ScheduledScriptsGrid)).ShowDialog(); }
  1114. );
  1115. return false;
  1116. }
  1117. private bool EditWebTemplates(CoreRow selectedRow)
  1118. {
  1119. ConfigureIPCServer<WebServerProperties>(
  1120. selectedRow,
  1121. x => x.Server,
  1122. () =>
  1123. {
  1124. var window = new MasterList(typeof(WebTemplate), "DataModel", "", true);
  1125. window.Closed += (e, args) => { currentServerUsers--; };
  1126. window.Show();
  1127. },
  1128. false
  1129. );
  1130. return false;
  1131. }
  1132. private bool EditWebStyles(CoreRow selectedRow)
  1133. {
  1134. ConfigureIPCServer<WebServerProperties>(
  1135. selectedRow,
  1136. x => x.Server,
  1137. () =>
  1138. {
  1139. var window = new MasterList(typeof(WebStyle), "Code", "", true);
  1140. window.Closed += (e, args) => { currentServerUsers--; };
  1141. window.Show();
  1142. },
  1143. false
  1144. );
  1145. return false;
  1146. }
  1147. private bool EditWebDocuments(CoreRow selectedRow)
  1148. {
  1149. ConfigureIPCServer<WebServerProperties>(
  1150. selectedRow,
  1151. x => x.Server,
  1152. () =>
  1153. {
  1154. var window = new MasterList(typeof(WebDocument), "Code", "", true);
  1155. window.Closed += (e, args) => { currentServerUsers--; };
  1156. window.Show();
  1157. },
  1158. false
  1159. );
  1160. return false;
  1161. }
  1162. private bool PRSMobileSettings(CoreRow selectedrow)
  1163. {
  1164. ConfigureIPCServer<WebServerProperties>(
  1165. selectedrow,
  1166. x => x.Server,
  1167. () =>
  1168. {
  1169. var editor = new DynamicEditorForm(typeof(WebSettings));
  1170. var settings = new GlobalConfiguration<WebSettings>().Load();
  1171. editor.Items = new[] { settings };
  1172. if (editor.ShowDialog() == true) new GlobalConfiguration<WebSettings>().Save(settings);
  1173. }
  1174. );
  1175. return false;
  1176. }
  1177. private bool ShowServiceStatus(Button arg1, CoreRow[] arg2)
  1178. {
  1179. List<String> domains = new List<String>();
  1180. var certservers = Data.Rows.Where(row => row.Get<Server,ServerType>(c=>c.Type) == ServerType.Certificate)
  1181. .Select(row => LoadItem(row));
  1182. foreach (var certserver in certservers)
  1183. {
  1184. var certprops = certserver.Properties as CertificateEngineProperties;
  1185. if (certprops != null)
  1186. domains.AddRange(certprops.ParseDomainNames());
  1187. }
  1188. if (!domains.Any())
  1189. domains.Add("localhost");
  1190. var servers = Data.Rows.Where(row => row.Get<Server,ServerType>(c=>c.Type) != ServerType.Certificate)
  1191. .Select(row => LoadItem(row));
  1192. var statusgrid = new ServiceStatus(domains, servers);
  1193. statusgrid.ShowDialog();
  1194. return false;
  1195. }
  1196. #endregion
  1197. }