Exemplo n.º 1
0
        private void NewTaskCreated(string configPath)
        {
            TaskExecutionHost tmp = null;

            try
            {
                string folder = Path.GetDirectoryName(configPath).ToUpper();
                if (!m_TaskExecutionHostList.Exists(t => t.FolderPath == folder))
                {
                    lock (s_SyncObj)
                    {
                        if (!m_TaskExecutionHostList.Exists(t => t.FolderPath == folder))
                        {
                            tmp = new TaskExecutionHost(configPath);
                            tmp.UnhandledException += (s, e) => { OnUnhandledException(s, e); };
                            tmp.EachTaskStarted    += (s, e) => { OnEachTaskStarted(s, e); };
                            tmp.EachTaskStarting   += (s, e) => { OnEachTaskStarting(s, e); };
                            tmp.EachTaskStopped    += (s, e) => { OnEachTaskStopped(s, e); };
                            tmp.EachTaskStopping   += (s, e) => { OnEachTaskStopping(s, e); };
                            tmp.EachTaskRestarted  += (s, e) => { OnEachTaskRestarted(s, e); };
                            tmp.EachTaskRestarting += (s, e) => { OnEachTaskRestarting(s, e); };
                            m_TaskExecutionHostList.Add(tmp);
                        }
                    }
                }
                if (tmp != null)
                {
                    tmp.Open();
                }
            }
            catch (Exception ex)
            {
                if (tmp != null)
                {
                    tmp.Dispose();
                }
                var e = new ExceptionEventArgs(ex, Path.GetDirectoryName(configPath), "", "启动整个目录里的服务时出现异常,请确认任务配置文件是否正确!");
                Logger.Error(e);
                try
                {
                    OnUnhandledException(this, e);
                }
                catch (Exception ex1)
                {
                    Logger.Error(e.Folder, "", ex1, "执行TaskExecutionHostMain.OnUnhandledException时出错");
                }
            }
        }
Exemplo n.º 2
0
        public TaskExecutionHostMain()
        {
            string[]      arry       = Directory.GetDirectories(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, "*.*", SearchOption.TopDirectoryOnly);
            List <string> taskFolder = new List <string>(arry.Length);

            foreach (string folder in arry)
            {
                if (File.Exists(Path.Combine(folder, CONFIG_FILE_NAME)))
                {
                    taskFolder.Add(folder);
                }
            }
            m_TaskExecutionHostList = new List <TaskExecutionHost>(taskFolder.Count);
            foreach (string folder in taskFolder)
            {
                try
                {
                    TaskExecutionHost tmp = new TaskExecutionHost(Path.Combine(folder, CONFIG_FILE_NAME));
                    tmp.UnhandledException += (s, e) => { OnUnhandledException(s, e); };
                    tmp.ExecutedNotify     += (s, e) => { OnExecutedNotify(s, e); };
                    tmp.EachTaskStarted    += (s, e) => { OnEachTaskStarted(s, e); };
                    tmp.EachTaskStarting   += (s, e) => { OnEachTaskStarting(s, e); };
                    tmp.EachTaskStopped    += (s, e) => { OnEachTaskStopped(s, e); };
                    tmp.EachTaskStopping   += (s, e) => { OnEachTaskStopping(s, e); };
                    tmp.EachTaskRestarted  += (s, e) => { OnEachTaskRestarted(s, e); };
                    tmp.EachTaskRestarting += (s, e) => { OnEachTaskRestarting(s, e); };
                    m_TaskExecutionHostList.Add(tmp);
                }
                catch (Exception ex)
                {
                    var e = new ExceptionEventArgs(ex, folder, "", "启动整个目录里的服务时出现异常,请确认任务配置文件是否正确!");
                    Logger.Error(e);
                    try
                    {
                        OnUnhandledException(this, e);
                    }
                    catch (Exception ex1)
                    {
                        Logger.Error(folder, "", ex1, "执行TaskExecutionHostMain.OnUnhandledException时出错");
                    }
                }
            }
            m_Watcher = new TaskFolderWatcher(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, CONFIG_FILE_NAME, NewTaskCreated, TaskDeleted, TaskRenamed);
        }
Exemplo n.º 3
0
        private void TaskDeleted(string configPath)
        {
            TaskExecutionHost tmp    = null;
            string            folder = Path.GetDirectoryName(configPath).ToUpper();
            int index = m_TaskExecutionHostList.FindIndex(t => t.FolderPath == folder);

            if (index >= 0)
            {
                lock (s_SyncObj)
                {
                    index = m_TaskExecutionHostList.FindIndex(t => t.FolderPath == folder);
                    if (index >= 0)
                    {
                        tmp = m_TaskExecutionHostList[index];
                        m_TaskExecutionHostList.RemoveAt(index);
                    }
                }
            }
            if (tmp != null)
            {
                tmp.Close();
            }
        }