/// <summary> /// 开始运行 /// </summary> public void Start() { TaskApplication.Instance().ExecuteTaskStartupEvents(); foreach (TaskThread thread in this.taskThreads) { thread.InitializeTimer(); } }
/// <summary> /// 结束 /// </summary> public void Stop() { foreach (TaskThread thread in this.taskThreads) { thread.Dispose(); } this.taskThreads.Clear(); TaskApplication.Instance().ExecuteTaskShutdownEvents(); }
/// <summary> /// LoadModule /// </summary> /// <param name="modulesNode"></param> private void LoadModules(XmlNode modulesNode) { TaskApplication taskApplication = TaskApplication.Instance(); XmlAttribute attribute; string value; foreach (XmlNode node in modulesNode.ChildNodes) { if (node.NodeType == XmlNodeType.Comment) { continue; } string name = node.Name; if (name != null) { if (name != "clear") { if (name == "remove") { attribute = node.Attributes["name"]; value = (attribute == null) ? null : attribute.Value; if (!string.IsNullOrEmpty(value) && taskApplication.Modules.ContainsKey(value)) { taskApplication.Modules.Remove(value); } } if (name == "add") { attribute = node.Attributes["enabled"]; if ((attribute == null) || (attribute.Value != "false")) { XmlAttribute attName = node.Attributes["name"]; XmlAttribute attType = node.Attributes["type"]; string strAttName = (attName == null) ? null : attName.Value; string strAttType = (attType == null) ? null : attType.Value; if (!string.IsNullOrEmpty(strAttName) && !string.IsNullOrEmpty(strAttType)) { Type type = Type.GetType(strAttType); if (type != null) { ITaskModule module = Activator.CreateInstance(type) as ITaskModule; if (module != null) { module.Init(taskApplication, node); taskApplication.Modules[strAttName] = module; } } } } } continue; } taskApplication.Modules.Clear(); } } }
internal void ExecuteTasks() { this.started = DateTime.Now; this.isRunning = true; foreach (Task task in this.tasks.Values) { if (task.Enabled) { TaskApplication.Instance().ExecutePreTaskRunEvents(task); task.ExecuteTask(); TaskApplication.Instance().ExecutePostTaskRunEvents(task); } } this.isRunning = false; this.completed = DateTime.Now; }
internal void ExecuteTask() { this._isRunning = true; ITask task = this.CreateTaskInstance(); if (task != null) { this._lastStart = DateTime.Now; try { task.Execute(this._node); this._lastEnd = this._lastSucess = DateTime.Now; } catch (Exception exception) { this._enabled = !this.EnableShutDown; this._lastEnd = DateTime.Now; TaskApplication.Instance().ExecuteTaskExceptionEvents(this, exception); } } this._isRunning = false; }