123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- using Comal.Classes;
- using Comal.Stores;
- using InABox.Clients;
- using InABox.Configuration;
- using InABox.Core;
- using InABox.Rpc;
- using InABox.Wpf.Reports;
- using PRS.Shared;
- using PRSServer;
- using PRSServices;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- namespace PRSLicensing;
- public class LicensingEngine : Engine<LicensingEngineProperties>
- {
- public override void Run()
- {
- Logger.Send(LogType.Information, "", "Starting..");
- if (string.IsNullOrWhiteSpace(Properties.Server))
- {
- Logger.Send(LogType.Error, "", "Server is blank!");
- return;
- }
- var transport = new RpcClientPipeTransport(DatabaseServerProperties.GetPipeName(Properties.Server, true));
- ClientFactory.SetClientType(typeof(RpcClient<>), Platform.WebEngine, Version, transport);
- CheckConnection();
-
- Logger.Send(LogType.Information, "", "Registering Classes");
- StoreUtils.RegisterClasses();
- CoreUtils.RegisterClasses();
- ComalUtils.RegisterClasses();
- PRSSharedUtils.RegisterClasses();
- ReportUtils.RegisterClasses();
- ConfigurationUtils.RegisterClasses();
- Logger.Send(LogType.Information, "", "Starting Listener on port " + Properties.ListenPort);
- }
- private void CheckConnection()
- {
- // Wait for server connection
- while (!Client.Ping())
- {
- Logger.Send(LogType.Error, "", "Database server unavailable. Trying again in 30 seconds...");
- Task.Delay(30_000).Wait();
- Logger.Send(LogType.Information, "", "Retrying connection...");
- }
- ClientFactory.SetBypass();
- }
- public override void Stop()
- {
- Logger.Send(LogType.Information, "", "Stopping");
- }
- }
- public class LicensingEngineProperties : ServerProperties
- {
- [ComboLookupEditor(typeof(LicensingDatabaseServerLookupGenerator))]
- [EditorSequence(1)]
- public string Server { get; set; }
- [IntegerEditor]
- [EditorSequence(2)]
- public int ListenPort { get; set; }
- public override ServerType Type()
- {
- return ServerType.Other;
- }
- }
- public class LicensingDatabaseServerLookupGenerator : LookupGenerator<LicensingEngineProperties>
- {
- public LicensingDatabaseServerLookupGenerator(LicensingEngineProperties[] items) : base(items)
- {
- }
- protected override void DoGenerateLookups()
- {
- var config = new LocalConfiguration<ServerSettings>(CoreUtils.GetCommonAppData("PRSServer"), "");
- var servers = config.LoadAll();
- foreach (var server in servers.Select(x => x.Value.CreateServer(x.Key)))
- {
- if (server.Type == ServerType.Database)
- {
- AddValue(server.Key, server.Name);
- }
- }
- }
- }
|