示例#1
0
        /// <summary>
        /// Main entry for the application
        /// </summary>
        public static void Main()
        {
            // Initialize the connection string
            InitConnection();

            try {
                // Get the server version from the external text file
                UpdateServerVersion();
            } catch {
                // If could not get the version, default it to 0.0
                Console.WriteLine("Could not get version.");
                return;
            }

            var TM = new ThreadManager();

            // Start the monitors for the Directions Handler
            DirectionsFinder.EnqueueMonitors(TM);

            // Start the expiration checker for admin logins
            TM.Enqueue(AdminHandler.DeleteExpiredLogins(TM), ThreadPriority.Low);

            // Start the listener for console commands
            TM.Enqueue(HandleConsoleRequests(TM), ThreadPriority.Low);

            // Start the listener for HTTP requests
            TM.Enqueue(WebController.HandleClients(TM));

            // Start the ThreadManager
            TM.Start(1);
        }
示例#2
0
        /// <summary>
        /// Handles console commands
        /// </summary>
        /// <param name="TM">Thread Manager</param>
        /// <returns>No return</returns>
        public static IEnumerable <ThreadInfo> HandleConsoleRequests(ThreadManager TM)
        {
            var currentThread = TM.CurrentThread;

            while (true)
            {
                yield return(TM.WaitForConsole(currentThread));

                string request = TM.GetResult <string>(currentThread);
                try {
                    switch (request)
                    {
                    case "help":
                        Console.WriteLine("update\nstatus\nexecutions\nqueues\nthreads\ndirections\nexit");
                        break;

                    case "update":
                        UpdateServerVersion();
                        break;

                    case "status":
                        TM.WriteExecutionStatus();
                        TM.WriteQueueStatus();
                        TM.WriteThreadStatus();
                        DirectionsFinder.WriteStatus();
                        break;

                    case "executions":
                        TM.WriteExecutionStatus();
                        break;

                    case "queues":
                        TM.WriteQueueStatus();
                        break;

                    case "threads":
                        TM.WriteThreadStatus();
                        break;

                    case "directions":
                        DirectionsFinder.WriteStatus();
                        break;

                    case "exit":
                        System.Environment.Exit(0);
                        break;

                    default:
                        Console.WriteLine("Invalid request.");
                        break;
                    }
                } catch (Exception ex) {
                    Console.WriteLine("An exception occurred: {0}\nStack trace:\n{1}", ex.Message, ex.StackTrace);
                }
                Console.WriteLine();
            }
        }
示例#3
0
        protected override IEnumerable <ThreadInfo> HandleIntPath(ThreadManager TM, int value, object state)
        {
            var currentThread = TM.CurrentThread;

            IntRedirect = DirectionsFinder.GetFinder(value);
            if (IntRedirect == null)
            {
                yield return(TM.Return(currentThread, new JsonResponse(HttpStatusCode.BadRequest)));
            }
            yield return(TM.Return(currentThread, -1));
        }