Example #1
0
        /// <summary>
        /// Runs the task manager from the console.
        /// </summary>
        private static void RunFromConsole()
        {
            Console.WriteLine("Press ENTER to locate task modules.");

            Console.ReadLine();

            TaskManagerService.LogInfo("Initializing service...");
            try
            {
                TaskSupervisor.Initialize();
                ModuleSupervisor.Initialize();
            }
            catch (Exception e)
            {
                TaskManagerService.LogError("Unable to initialize service.", e);
                return;
            }

            Console.WriteLine("Press ENTER to start.");

            Console.ReadLine();

            try
            {
                TaskManagerService.LogInfo("Service successfully started...");

                ModuleSupervisor.Execute();
            }
            catch (Exception e)
            {
                TaskManagerService.LogError("Unable to start service.", e);
                return;
            }

            Console.WriteLine("Press ENTER to stop.");

            // If you are debugging, you can freeze the main thread here.
            Console.ReadLine();

            TaskManagerService.LogInfo("Stopping service...");
            try
            {
                ModuleSupervisor.Shutdown();
                TaskSupervisor.Shutdown();
                TaskManagerService.LogInfo("Service successfully stopped...");
            }
            catch (Exception e)
            {
                TaskManagerService.LogError("Unable to stop service.", e);
                return;
            }

            Console.WriteLine("Press ENTER to finish.");
            Console.ReadLine();
        }
Example #2
0
 /// <summary>
 /// Logs an exception.
 /// </summary>
 /// <param name="text">The message.</param>
 /// <param name="ex">The exception.</param>
 public void Log(string text, Exception ex)
 {
     TaskManagerService.LogError(text, ex);
 }
Example #3
0
 /// <summary>
 /// Logs an exception.
 /// </summary>
 /// <param name="ex">The exception.</param>
 public void Log(Exception ex)
 {
     TaskManagerService.LogError("Exception caught", ex);
 }
Example #4
0
        private static void RunFromConsole(string[] args)
        {
            ShowHeader();
            TaskManagerOptions options;

            try
            {
                options = TaskManagerOptions.Create("TaskManager.exe", args);
            }
            catch (Exception ex)
            {
                Show("Argument parsing error: ");
                Show(ex.Message);
                Show("Try `TaskManager --help` for more information");
                Environment.Exit(3);
                return;
            }

            if (options.ShowHelp)
            {
                Show(options.HelpText);
                return;
            }

            WaitUserInteraction(options, "Press ENTER to locate task modules.");
            TaskManagerService.LogInfo("Initializing service...");

            try
            {
                Show("Event log: {0}", options.EventLog.GetType().Name);
                Show("Stats strategy: {0}", options.StatsStrategy.GetType().Name);

                TaskSupervisor.Initialize(options.StatsStrategy);
                TaskManagerService.Initialize(options.EventLog);
                ModuleSupervisor.Initialize();
            }
            catch (Exception e)
            {
                TaskManagerService.LogError("Unable to initialize service.", e);
                WaitUserInteraction(options);
                return;
            }

            WaitUserInteraction(options, "Press ENTER to start.");

            try
            {
                TaskManagerService.LogInfo("Service successfully started...");
                ModuleSupervisor.Execute();

                if (options.NonStop && options.NonStopWait > 0)
                {
                    Show("Waiting {0} milliseconds to tasks execution...", options.NonStopWait);
                    Thread.Sleep(options.NonStopWait);
                }
            }
            catch (Exception e)
            {
                TaskManagerService.LogError("Unable to start service.", e);
                WaitUserInteraction(options);

                return;
            }

            // If you are debugging, you can freeze the main thread here.
            WaitUserInteraction(options, "Press ENTER to stop.");

            TaskManagerService.LogInfo("Stopping service...");
            try
            {
                ModuleSupervisor.Shutdown();
                TaskSupervisor.Shutdown();
                TaskManagerService.LogInfo("Service successfully stopped...");
            }
            catch (Exception e)
            {
                TaskManagerService.LogError("Unable to stop service.", e);
                return;
            }

            WaitUserInteraction(options, "Press ENTER to finish.");
        }