static void Main(string[] args) { #region Detect processes conflicts // Check does this instance a new single app, or same app already runned. if (!ServerAppConfigurator.IsProccessisUnique()) { // Log error. Console.WriteLine("\"THB Data Server\" already started. Application not allow multiple instances at single moment."); // Wait a time until exit. Thread.Sleep(2000); return; } #endregion #region Set default data \load DLLs \appling arguments // Check direcroties UniformDataOperator.AssembliesManagement.AssembliesHandler.LoadAssemblies( AppDomain.CurrentDomain.BaseDirectory + "libs\\"); // Looking for replaced types that could be used by handlers. UniformDataOperator.AssembliesManagement.Modifiers.TypeReplacer.RescanAssemblies(); // React on uniform arguments. ServerAppConfigurator.ArgsReactor(args); // react on args specified to that server. CustomArgsReactor(args); #endregion #region Initialize authority controller // Subscribe to events. //AuthorityController.Session.InformateRelatedServers += InformateRelatedServers; // Load users. AuthorityController.API.LocalUsers.DirectoryLoadingFinished += Users_DirectoryLoadingUnlocked; AuthorityController.API.LocalUsers.LoadProfilesAsync(Config.Active.UsersStorageDirectory); #endregion #region Loaded query handler processors. // Draw line ConsoleDraw.Primitives.DrawSpacedLine(); // Initialize Queue monitor. try { _ = UniformQueries.API.QueryHandlers; } catch (Exception ex) { Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US"); Console.WriteLine("QUERY HANDLER PROCESSORS LOADINT TERMINATED:\n{0}", ex.Message); } ConsoleDraw.Primitives.DrawSpacedLine(); Console.WriteLine(); #endregion #region Start queries monitor threads for (int i = 0; i < Environment.ProcessorCount; i++) { // Instiniate server. Server serverBufer = new Server { // Set fields. pipeName = "dnfAUTH" }; // Starting server loop. serverBufer.StartServerThread( "Queries monitor #" + i, serverBufer, ThreadingServerLoop_PP_Input); // Change thread culture. serverBufer.ServerThread.CurrentUICulture = new System.Globalization.CultureInfo("en-us"); // Skip line Console.WriteLine(); } // Draw line ConsoleDraw.Primitives.DrawLine(); Console.WriteLine(); #endregion #region Guest tokens broadcasting // Start broadcasting server that would share guest tokens. UniformServer.Standard.BroadcastServer.StartBroadcastingViaPP( "guests", PipesProvider.Security.SecurityLevel.Anonymous, AuthorityController.API.Tokens.AuthorizeNewGuestToken, 1); #endregion // Show help. CustomComands("help"); #region Main loop // Main loop that will provide server services until application close. while (!UniformServer.ServerAppConfigurator.AppTerminated) { // Check input if (Console.KeyAvailable) { // Log responce. Console.Write("\nEnter command: "); // Read command. string command = Console.ReadLine(); // Processing of entered command. if (!CustomComands(command)) { UniformServer.Commands.BaseCommands(command); } } Thread.Sleep(UniformServer.ServerAppConfigurator.PreferedThreadsSleepTime); } #endregion #region Finalize Console.WriteLine(); // Stop started servers. ServerAPI.StopAllServers(); // Unsubscribe from events //AuthorityController.Session.InformateRelatedServers -= InformateRelatedServers; AuthorityController.API.LocalUsers.DirectoryLoadingFinished -= Users_DirectoryLoadingUnlocked; // Whait until close. Console.WriteLine("Press any key to exit..."); Console.ReadKey(); #endregion }
static void Main(string[] args) { #region Detect processes conflicts // Check does this instance a new single app, or same app already runned. if (!ServerAppConfigurator.IsProccessisUnique()) { // Log error. Console.WriteLine("\"THB Data Server\" already started. Application not allow multiple instances at single moment."); // Wait a time until exit. Thread.Sleep(2000); return; } #endregion #region Set default data \load DLLs \appling arguments // Set default thread count. Can be changed via args or command. //threadsCount = Environment.ProcessorCount; //longTermServerThreads = new UniformServer.BaseServer[threadsCount]; // React on uniform arguments. ServerAppConfigurator.ArgsReactor(args); // Check direcroties UniformDataOperator.AssembliesManagement.AssembliesHandler.LoadAssemblies( AppDomain.CurrentDomain.BaseDirectory + "libs\\"); // Looking for replaced types that could be used by handlers. UniformDataOperator.AssembliesManagement.Modifiers.TypeReplacer.RescanAssemblies(); #endregion // Request anonymous configuration for system. General.SetLocalSecurityAuthority(SecurityLevel.Anonymous); #region Load routing tables. // Try to load tables. UniformClient.BaseClient.LoadRoutingTables(AppDomain.CurrentDomain.BaseDirectory + "plugins\\"); // Init new if not found. if (UniformClient.BaseClient.routingTable.intructions.Count == 0) { SetDefaultRoutingTable(); } #endregion #region Loaded query handler processors // Draw line ConsoleDraw.Primitives.DrawSpacedLine(); // Initialize Queue monitor. try { _ = UniformQueries.API.QueryHandlers; } catch (Exception ex) { Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US"); Console.WriteLine("QUERY HANDLER PROCESSORS LOADING TERMINATED:\n{0}", ex.Message); } ConsoleDraw.Primitives.DrawSpacedLine(); Console.WriteLine(); #endregion #region Start queries monitor threads for (int i = 0; i < Environment.ProcessorCount; i++) { // Configuring the routing instruction. RelayInstruction relayInstruction = new RelayInstruction() { entryPipeName = OPEN_CHANEL }; // Instiniating server. var serverBufer = UniformServer.Standard.RelayServer.EstablishDuplexRelayServer(relayInstruction); // Changing thread culture. serverBufer.ServerThread.CurrentCulture = new System.Globalization.CultureInfo("en-US"); // Skip line Console.WriteLine(); } #endregion #region Start broadcast relaying chanels. foreach (Instruction instruction in UniformClient.BaseClient.routingTable.intructions) { // Looking for broadcasting relays. if (instruction is RelayInstruction relayInstruction && relayInstruction.behavior == RelayInstruction.RelayBehavior.Broadcasting) { // Start relay server. UniformServer.Standard.RelayServer.EstablishBroadcastingRelayServer(relayInstruction); } } #endregion // Show help. UniformServer.Commands.BaseCommands("help"); #region Main loop // Main loop that will provide server services until application close. while (!UniformServer.ServerAppConfigurator.AppTerminated) { // Check input if (Console.KeyAvailable) { // Log responce. Console.Write("\nEnter command: "); // Read command. string command = Console.ReadLine(); // Processing of entered command. UniformServer.Commands.BaseCommands(command); } Thread.Sleep(UniformServer.ServerAppConfigurator.PreferedThreadsSleepTime); } #endregion #region Finalize Console.WriteLine(); // Stop started servers. ServerAPI.StopAllServers(); // Whait until close. Console.WriteLine("Press any key to exit..."); Console.ReadKey(); #endregion }