Пример #1
0
        public void Start()
        {
            if (serverSocket != null)
            {
                throw new Exception("Server already has been started.");
            }

            Stopwatch sw = new Stopwatch();

            sw.Start();
            Initialize();

            serverSocket.Bind(new IPEndPoint(IPAddress.Any, configuration.Port));
            serverSocket.Listen(0);
            serverSocket.BeginAccept(AcceptCallback, null);

            RunServerStartupTasks();
            sw.Stop();

            loggingService.WriteLog($"Server started in {sw.ElapsedMilliseconds}ms", "Server", "Start");
            loggingService.WriteLog($"Running at port {configuration.Port}");

            Console.WriteLine("Type 'exit' to stop; 'reboot' to send reboot request event...");
            string line = "";

            cliHost = serviceManager.GetService <ICLIHostService>();
            if (cliHost.RegisteredCommands().Count > 0)
            {
                Console.ForegroundColor = ConsoleColor.Cyan;
                Console.WriteLine($"\nCommands available on this CLI:");
                foreach (CLICommand command in cliHost.RegisteredCommands())
                {
                    Console.WriteLine($"=>  {command.CommandText}: {command.CommandDescription}");
                }
                Console.ForegroundColor = ConsoleColor.White;
            }

            if (configuration.IsConsoleApplication)
            {
                while (line != "exit")
                {
                    line = Console.ReadLine();

                    CLICommand command = cliHost.GetCommand(line);
                    if (command == null)
                    {
                        Console.WriteLine("No such command");
                    }
                    else
                    {
                        TryActivateCommand(command);
                    }

                    if (line == "reboot")
                    {
                        Reboot();
                    }
                }
            }
        }
Пример #2
0
        public void Load(IServiceManager manager)
        {
            ILoggingService logging = manager.GetService <ILoggingService>();

            logging.WriteLog("Hello! Im a file-based extension loaded dinamically from SocketAppServer! :)");


            ICLIHostService cliHost = manager.GetService <ICLIHostService>();

            cliHost.RegisterCLICommand("file-x", "Run a funny function inside this beautifull extension :)", new FunnyCommand());
        }
Пример #3
0
        public void Load(IServiceManager manager)
        {
            ICLIHostService cliHost = manager.GetService <ICLIHostService>();

            cliHost.RegisterCLICommand("client-maker", "Generate client layer classes for access each Controller/Action on this server", new GeneratorCommand());
        }
Пример #4
0
 public LoggingServiceImpl()
 {
     cliHost = ServiceManager.GetInstance().GetService <ICLIHostService>();
 }