ServerGrid.cs 48 KB

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