예제 #1
0
        public static void Main(string[] args)
        {
            AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit;

            Portable.Initialise();

            if (!Portable.IsProcessIsolationEnabled())
            {
                Console.WriteLine("Worker is disabled in portable.ini");
                Console.WriteLine("Press 'Enter' to exit");
                Console.Read();
                return;
            }

            int    port = 8037; // Default Port;
            string token;

            if (args.Length != 0)
            {
                foreach (string argument in args)
                {
                    if (argument.StartsWith("--port"))
                    {
                        string value = argument.TrimStart("--port=".ToCharArray());
                        if (int.TryParse(value, out var parsedPort))
                        {
                            port = parsedPort;
                        }
                    }

                    if (argument.StartsWith("--token"))
                    {
                        token = argument.TrimStart("--token=".ToCharArray());
                        TokenService.RegisterToken(token);
                    }
                }
            }

            Console.WriteLine("Worker: Starting HandBrake Engine ...");
            router = new ApiRouter();
            router.TerminationEvent += Router_TerminationEvent;

            Console.WriteLine("Worker: Starting Web Server on port {0} ...", port);
            Dictionary <string, Func <HttpListenerRequest, string> > apiHandlers = RegisterApiHandlers();
            HttpServer webServer = new HttpServer(apiHandlers, port, TokenService);

            if (webServer.Run())
            {
                Console.WriteLine("Worker: Server Started");
                manualResetEvent.WaitOne();
                webServer.Stop();
            }
            else
            {
                Console.WriteLine("Worker: Failed to start. Exiting ...");
            }
        }
예제 #2
0
        public static void Main(string[] args)
        {
            int port      = 8037; // Default Port;
            int verbosity = 1;

            if (args.Length != 0)
            {
                foreach (string argument in args)
                {
                    if (argument.StartsWith("--port"))
                    {
                        string value = argument.TrimStart("--port=".ToCharArray());
                        if (int.TryParse(value, out var parsedPort))
                        {
                            port = parsedPort;
                        }
                    }

                    if (argument.StartsWith("--verbosity"))
                    {
                        string value = argument.TrimStart("--port=".ToCharArray());
                        if (int.TryParse(value, out var verbosityVal))
                        {
                            verbosity = verbosityVal;
                        }
                    }
                }
            }

            Console.WriteLine("Starting HandBrake Engine ...");
            router = new ApiRouter();
            router.Initialise(verbosity);

            Console.WriteLine("Starting Web Server ...");
            Console.WriteLine("Using Port: {0}", port);
            Dictionary <string, Func <HttpListenerRequest, string> > apiHandlers = RegisterApiHandlers();
            HttpServer webServer = new HttpServer(apiHandlers, port);

            webServer.Run();

            Console.WriteLine("Web Server Started");

            manualResetEvent.WaitOne();

            webServer.Stop();
        }
예제 #3
0
        public static void Main(string[] args)
        {
            int    port  = 8037; // Default Port;
            string token = null;

            if (args.Length != 0)
            {
                foreach (string argument in args)
                {
                    if (argument.StartsWith("--port"))
                    {
                        string value = argument.TrimStart("--port=".ToCharArray());
                        if (int.TryParse(value, out var parsedPort))
                        {
                            port = parsedPort;
                        }
                    }

                    if (argument.StartsWith("--token"))
                    {
                        token = argument.TrimStart("--token=".ToCharArray());
                    }
                }
            }

            Console.WriteLine("Worker: Starting HandBrake Engine ...");
            router = new ApiRouter();
            router.TerminationEvent += Router_TerminationEvent;

            Console.WriteLine("Worker: Starting Web Server on port {0} ...", port);
            Dictionary <string, Func <HttpListenerRequest, string> > apiHandlers = RegisterApiHandlers();
            HttpServer webServer = new HttpServer(apiHandlers, port, token);

            if (webServer.Run())
            {
                Console.WriteLine("Worker: Server Started");
                manualResetEvent.WaitOne(); webServer.Stop();
                webServer.Stop();
            }
            else
            {
                Console.WriteLine("Worker: Failed to start. Exiting ...");
            }
        }
예제 #4
0
파일: Program.cs 프로젝트: zoyag/HandBrake
        public static void Main(string[] args)
        {
            Console.WriteLine("Starting Web Server ...");
            router = new ApiRouter();

            Dictionary <string, Func <HttpListenerRequest, string> > apiHandlers = RegisterApiHandlers();

            int port = 8080; // Default Port;

            if (args.Length != 0)
            {
                foreach (string argument in args)
                {
                    if (argument.StartsWith("--port"))
                    {
                        string portStr = argument.TrimStart("--port=".ToCharArray());
                        if (int.TryParse(portStr, out var parsedPort))
                        {
                            port = parsedPort;
                        }
                    }
                }
            }

            Console.WriteLine("Using Port: {0}", port);

            HttpServer webServer = new HttpServer(apiHandlers, port);

            webServer.Run();

            Console.WriteLine("Webserver Started");
            Console.WriteLine("Press any key to exit");

            Console.ReadKey(); // Block from closing.

            webServer.Stop();
        }
예제 #5
0
        public static void Main(string[] args)
        {
            AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit;

            Portable.Initialise();

            if (!Portable.IsProcessIsolationEnabled())
            {
                Console.WriteLine("Worker is disabled in portable.ini");
                Console.WriteLine("Press 'Enter' to exit");
                Console.Read();
                return;
            }

            int    port = 8037; // Default Port;
            string token;

            if (args.Length != 0)
            {
                foreach (string argument in args)
                {
                    if (argument.StartsWith("--port"))
                    {
                        string value = argument.TrimStart("--port=".ToCharArray());
                        if (int.TryParse(value, out var parsedPort))
                        {
                            port = parsedPort;
                        }
                    }

                    if (argument.StartsWith("--token"))
                    {
                        token = argument.TrimStart("--token=".ToCharArray());
                        TokenService.RegisterToken(token);
                    }
                }
            }

            if (!TokenService.IsTokenSet())
            {
                ConsoleOutput.WriteLine("# HandBrake Worker", ConsoleColor.DarkYellow);
                ConsoleOutput.WriteLine("*** Please note, this application should not be run standalone. To run the GUI, please use 'HandBrake.exe' *** ", ConsoleColor.Red);
                Console.WriteLine();
            }

            ConsoleOutput.WriteLine("Worker: Starting HandBrake Engine ...", ConsoleColor.White, true);
            router = new ApiRouter();
            router.TerminationEvent += Router_TerminationEvent;

            ConsoleOutput.WriteLine(string.Format("Worker: Starting Web Server on port {0} ...", port), ConsoleColor.White, true);

            Dictionary <string, Func <HttpListenerRequest, string> > apiHandlers = RegisterApiHandlers();
            HttpServer webServer = new HttpServer(apiHandlers, port, TokenService);

            if (webServer.Run().Result)
            {
                ConsoleOutput.WriteLine("Worker: Server Started", ConsoleColor.White, true);
                manualResetEvent.WaitOne();
                webServer.Stop();
            }
            else
            {
                ConsoleOutput.WriteLine("Worker is exiting ...");
            }
        }