Ejemplo n.º 1
0
        /// <summary>
        /// Called when the service is being started by the SCM.
        /// </summary>
        /// <param name="args">The arguments.</param>
        protected override void OnStart(string[] args)
        {
////#if DEBUG
////            System.Threading.Thread.Sleep(10000);
////#endif

            LogInfo("Starting service...");
            try
            {
                var options = TaskManagerOptions.Create("Start parameters: ", args);
                Initialize(options.EventLog);
                TaskSupervisor.Initialize(options.StatsStrategy);
                ModuleSupervisor.Initialize();

                LogInfo("Service successfully started...");

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

                File.WriteAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TaskManager.start.error.txt"), e.Message);
                throw;
            }
        }
Ejemplo n.º 2
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();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Called when the service is being stopped by the SCM.
        /// </summary>
        protected override void OnStop()
        {
            LogInfo("Stopping service...");
            try
            {
                ModuleSupervisor.Shutdown();
                TaskSupervisor.Shutdown();
                LogInfo("Service successfully stopped...");
            }
            catch (Exception e)
            {
                LogError("Unable to stop service.", e);
                throw;
            }

            lock (_eventLog)
            {
                _eventLog.Close();
                _eventLog = null;
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Called when the service is being started by the SCM.
        /// </summary>
        /// <param name="args">The arguments.</param>
        protected override void OnStart(string[] args)
        {
            ////#if DEBUG
            ////            System.Threading.Thread.Sleep(10000);
            ////#endif

            LogInfo("Starting service...");
            try
            {
                TaskSupervisor.Initialize();
                ModuleSupervisor.Initialize();
                LogInfo("Service successfully started...");

                ModuleSupervisor.Execute();
            }
            catch (Exception e)
            {
                LogError("Unable to start service.", e);
                throw;
            }
        }
Ejemplo n.º 5
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.");
        }