ServerGrid.cs 47 KB

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