예제 #1
0
 internal TaskAgent(ITask task, Guid assemblyId, TaskRunParam taskConfig)
 {
     this.task       = task;
     taskStatus      = TaskStatus.Stop;
     id              = Guid.NewGuid();
     this.assemblyId = assemblyId;
     this.taskConfig = taskConfig;
 }
예제 #2
0
파일: TaskAgent.cs 프로젝트: cy101/NetTask
        internal TaskAgent(ITask task, Guid assemblyId, TaskRunParam taskConfig)
        {
            this.task = task;
            Logger logger = new Logger(task.GetType().FullName, assemblyId.ToString());

            task.logger.onInfo  += logger.Info;
            task.logger.onError += logger.Error;
            taskStatus           = TaskStatus.Stop;
            id = Guid.NewGuid();
            this.assemblyId = assemblyId;
            this.taskConfig = taskConfig;
        }
예제 #3
0
        public void LoadAssembly(Guid assemblyId)
        {
            var    rootDir = Path.Join(AssemblyPath, assemblyId.ToString());
            string xmlPath = Path.Join(rootDir, "main.xml");

            if (!File.Exists(xmlPath))
            {
                throw new FileNotFoundException("入口文件main.xml未找到!");
            }
            var configuration = new Configuration(xmlPath);
            var dllPath       = Path.Join(rootDir, configuration.EntryPoint);

            if (!File.Exists(dllPath))
            {
                throw new FileNotFoundException(string.Format("程序集{0}文件未找到!", configuration.EntryPoint));
            }
            byte[] assemblyInfo = File.ReadAllBytes(dllPath);
            var    assembly     = Assembly.Load(assemblyInfo);

            assemblies.Add(assembly, assemblyId.ToString());
            var  configs    = LoadTaskRunParam(assemblyId);
            bool saveConfig = configs == null;
            List <TaskRunParam> saveConfigs = new List <TaskRunParam>();
            var taskTypes = assembly.GetExportedTypes().Where(t => t.IsClass && !t.IsAbstract && typeof(NetTaskInterface.ITask).IsAssignableFrom(t)).ToArray();

            foreach (var t in taskTypes)
            {
                ITask        task     = (ITask)Activator.CreateInstance(t);
                var          typeName = task.GetType().FullName;
                TaskRunParam config   = null;
                if (configs != null && configs.ContainsKey(typeName))
                {
                    config = configs[typeName];
                }
                else
                {
                    config = TaskRunParam.CreateDefaultConfig(typeName);
                }
                TaskAgent ta = new TaskAgent(task, assemblyId, config);
                ta.configuration = configuration;
                AddTask(ta);
                if (saveConfig)
                {
                    saveConfigs.Add(config);
                }
            }
            if (saveConfig)
            {
                SaveTaskRunParam(assemblyId, saveConfigs);
            }
        }
예제 #4
0
        internal TaskAgent(ITask task, Guid assemblyId, TaskRunParam taskConfig, TaskManager taskManager)
        {
            this.task        = task;
            this.taskManager = taskManager;
            Logger logger = new Logger(task.GetType().FullName, assemblyId.ToString());

            task.logger.onInfo  += logger.Info;
            task.logger.onError += (message, ex, sendEmail) => { logger.Error(message, ex); if (sendEmail)
                                                                 {
                                                                     taskManager.TriggerTaskError(this, ex);
                                                                 }
            };                                                                                                                                         // logger.Error;
            task.logger.onMail += (receiver, message) => taskManager.TriggerTaskMail(this, message, receiver);
            taskStatus          = TaskStatus.Stop;
            id = Guid.NewGuid();
            this.assemblyId = assemblyId;
            this.taskConfig = taskConfig;
        }