Пример #1
0
 /// <summary>
 /// 工作线程执行方法
 /// </summary>
 private void ThreadWork()
 {
     // 绑定Invoker执行上下文
     this.BindContext();
     do
     {
         this._notify.WaitOne();
         try
         {
             if (this._needInit)
             {
                 // 初始化执行脚本
                 this._innerSE.Execute(FileUnity.ReadConfigFile(this.CurrSetting.ScriptFile));
                 this._needInit = false;
             }
             // 执行任务
             var execRest = this._innerSE.Invoke("parse", this.CurrSetting.Url);
             if (int.TryParse(execRest as string, out int rest) && rest == 1)
             {
                 this.Result.Success = true;
             }
         }
         catch (Exception ex)
         {
             // todo: 记录错误信息
         }
         finally
         {
             this.Status = TaskInvokerStatus.Stop;
             this._callBack?.Invoke(this);
         }
     }while (true);
 }
Пример #2
0
        /// <summary>
        /// 初始化脚本
        /// </summary>
        /// <param name="scriptFile"></param>
        private bool InitScript(string scriptFile)
        {
            try
            {
                if (this._needInit)
                {
                    // 初始化执行脚本
                    this._innerSE.Execute(FileUnity.ReadConfigFile(scriptFile));
                    this._innerSE.Execute(@"function ______tryRun(uri){ 
try{
    var result = run(uri);
    if(result == undefined || result == 1 || result == true){
        return 'OK';
    }
    else{
        return 'parse is not return 1 or true';
    }     
}catch(e){
    return e.message;
}}");
                    this._needInit = false;
                }
                return(true);
            }
            catch (Exception ex)
            {
                LoggerProxy.Error(LogSource, string.Format("call InitScript error,scriptFile:'{0}'.{1}.", scriptFile, ex.Message), ex);
            }
            return(false);
        }
Пример #3
0
        /// <summary>
        /// 执行初始化脚本
        /// </summary>
        private void ExecuteInitScript()
        {
            var script = FileUnity.ReadConfigFile(this.ConfigFile);

            this._mainSE.Execute(script);
            this._script = this._mainSE.Invoke("config");
            if (this._script == null)
            {
                throw new Exception("Task Init Error, the \"config\" method has no return value.");
            }
            var strSet = Serializer.JsonSerialize(this._script);

            if (string.IsNullOrWhiteSpace(strSet))
            {
                throw new Exception("Task Init Error, the \"config\" method return value is empty.");
            }
            this.TaskSetting = Serializer.JsonDeserialize <TaskSetting>(strSet);
            if (!TaskInvokerStorage.Instance.AddRoot(new TaskInvokerStorageEntity()
            {
                ParentId = 0,
                Script = this.TaskSetting.Script,
                TaskId = this.TaskId,
                Url = this.TaskSetting.Url
            }))
            {
                throw new Exception("Task Init Error, add rootTask failed.");
            }
        }
Пример #4
0
        /// <summary>
        /// 初始化任务生成工厂
        /// </summary>
        /// <param name="cfgFile">任务工厂配置文件</param>
        /// <param name="isTest">是否为测试任务</param>
        public Task(string cfgFile)
        {
            this.ExecutePath = FileUnity.GetDrectory(cfgFile);
            this._freeSE     = new Queue <TaskInvoker>();
            var script = FileUnity.ReadConfigFile(cfgFile);

            if (string.IsNullOrEmpty(script))
            {
                throw new Exception("task init error, the config file content is empty.");
            }
            this.TaskSetting = Serializer.JsonDeserialize <TaskSetting>(script);
            this.InitTaskStorage();
            this._lock = new Semaphore(this.TaskSetting.Parallel, this.TaskSetting.Parallel);
        }