| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 | 
							- using H.Pipes;
 
- using InABox.Wpf.Console;
 
- using System;
 
- using System.Collections.Generic;
 
- using System.Linq;
 
- using System.Text;
 
- using System.Threading.Tasks;
 
- using System.Timers;
 
- using System.Windows;
 
- using System.Windows.Media;
 
- using System.Windows.Threading;
 
- using Console = InABox.Wpf.Console.Console;
 
- namespace PRSServer;
 
- public class ServerConsole : Console
 
- {
 
-     private PipeClient<string>? _client;
 
-     private PRSService? _service;
 
-     private readonly bool _monitoronly = true;
 
-     public string ServiceName { get; private set; }
 
-     private Timer? RefreshTimer;
 
-     public ServerConsole(string servicename, string description, bool monitoronly = true): base(description)
 
-     {
 
-         ServiceName = servicename;
 
-         _monitoronly = monitoronly;
 
-     }
 
-     protected override void OnLoaded()
 
-     {
 
-         base.OnLoaded();
 
-         _client = new PipeClient<string>(ServiceName, ".");
 
-         _client.MessageReceived += (o, args) =>
 
-         {
 
-             Dispatcher.BeginInvoke(() =>
 
-             {
 
-                 ConsoleControl.LoadLogEntry(args.Message ?? "");
 
-             });
 
-         };
 
-         _client.Connected += (o, args) =>
 
-         {
 
-             Dispatcher.BeginInvoke(() => ConsoleControl.Enabled = true);
 
-         };
 
-         _client.Disconnected += (o, args) =>
 
-         {
 
-             Dispatcher.BeginInvoke(() => ConsoleControl.Enabled = false);
 
-             if (RefreshTimer == null)
 
-             {
 
-                 RefreshTimer = new Timer(1000);
 
-                 RefreshTimer.Elapsed += RefreshTimer_Elapsed;
 
-             }
 
-             RefreshTimer.Start();
 
-         };
 
-         _client.ExceptionOccurred += (o, args) =>
 
-         {
 
-         };
 
-         if (!_client.IsConnecting)
 
-         {
 
-             _client.ConnectAsync();
 
-         }
 
-         if (!_monitoronly)
 
-         {
 
-             var timer = new DispatcherTimer { Interval = new TimeSpan(0, 0, 3) };
 
-             timer.Tick += (o, args) =>
 
-             {
 
-                 timer.IsEnabled = false;
 
-                 _service = new PRSService(ServiceName, null);
 
-                 _service.Run(ServiceName);
 
-             };
 
-             timer.IsEnabled = true;
 
-         }
 
-     }
 
-     private void RefreshTimer_Elapsed(object? sender, ElapsedEventArgs e)
 
-     {
 
-         if (_client is null) return;
 
-         if (!_client.IsConnected)
 
-         {
 
-             if (!_client.IsConnecting)
 
-             {
 
-                 _client.ConnectAsync();
 
-             }
 
-         }
 
-         else
 
-         {
 
-             RefreshTimer?.Stop();
 
-         }
 
-     }
 
-     protected override void OnClosing()
 
-     {
 
-         base.OnClosing();
 
-         if (_monitoronly)
 
-         {
 
-             _client?.DisposeAsync().AsTask().Wait();
 
-             RefreshTimer?.Stop();
 
-         }
 
-         else
 
-             _service?.Halt();
 
-     }
 
-     protected override string GetLogDirectory()
 
-     {
 
-         return DatabaseEngine.GetPath(ServiceName);
 
-     }
 
- }
 
 
  |