Example #1
0
 public bool Stop(long taskid)
 {
     NodeTaskRuntimeInfo nodetask = TaskPool.Instance().Get(taskid.ToString());
     if (nodetask == null)
     {
         LogHelper.WriteInfo("" + taskid + "任务没有在运行");
         return false;
     }
     if (Dispose(taskid, nodetask))
     {
         try
         {
             TaskDal taskdal = new TaskDal();
             TaskModel model = taskdal.GetById(GlobalConfig.TaskDataBaseConnectString, taskid.ToString());
             model.TaskState = 0;
             model.TaskStopTime = DateTime.Now;
             taskdal.EditTask(GlobalConfig.TaskDataBaseConnectString, model);
             return true;
         }
         catch (Exception ex)
         {
             LogHelper.WriteError(ex);
             return false;
         }
     }
     return false;
 }
Example #2
0
        /// <summary>
        /// 任务开启
        /// </summary>
        /// <param name="taskid"></param>
        /// <returns></returns>
        public bool Start(long taskid)
        {
            LogHelper.WriteInfo("启动" + taskid + "任务");
            try
            {
                NodeTaskRuntimeInfo nodetask = TaskPool.Instance().Get(taskid.ToString());
                if (nodetask != null)
                {
                    LogHelper.WriteInfo("" + taskid + "任务已经开启");
                    return false;
                }
                TaskDal taskdal = new TaskDal();
                nodetask = new NodeTaskRuntimeInfo();
                nodetask.Tasklock = new TaskLock();
                nodetask.TaskModel = taskdal.GetById(GlobalConfig.TaskDataBaseConnectString, taskid.ToString());
                string filepath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, GlobalConfig.TaskDLL, nodetask.TaskModel.Id.ToString());  //任务dll在节点service存放地址
                string srcpath = Path.Combine(nodetask.TaskModel.TaskClassPath, nodetask.TaskModel.TaskFileName);
                DeCompressionHelper.UnCompress(srcpath, filepath);

                AppDomainSetup setup = new AppDomainSetup();
                setup.ShadowCopyFiles = "true";
                setup.ApplicationBase = System.IO.Path.GetDirectoryName(filepath);

                var appdomain = AppDomain.CreateDomain(Path.Combine(filepath, nodetask.TaskModel.TaskClassNamespace), null, setup);
                BaseTaskDLL taskdll = (BaseTaskDLL)appdomain.CreateInstanceFromAndUnwrap(Path.Combine(filepath, nodetask.TaskModel.TaskFileName), nodetask.TaskModel.TaskClassNamespace);
                
                nodetask.TaskDLL = taskdll;

                TaskPool.Instance().Add(taskid.ToString(), nodetask);

                LogHelper.WriteInfo("节点开启成功");
                return true;
            }
            catch (Exception ex)
            {
                LogHelper.WriteError(ex);
                return false;
            }
        }