예제 #1
0
 public TaskInvoker(string scriptFile)
 {
     this._innerSE = new V8ScriptEngine();
     this._innerSE.LoadSystemModules();
     this.Context             = new TaskInvokerContext();
     this.Context.ExecutePath = FileUnity.GetDrectory(scriptFile);
     this.Context.Engine      = this._innerSE;
     this.BindContext();
     this._needInit = true;
     this.InitScript(scriptFile);
 }
예제 #2
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);
        }
예제 #3
0
 /// <summary>
 /// 初始化任务生成工厂
 /// </summary>
 /// <param name="cfgFile">任务工厂配置文件</param>
 public Task(string cfgFile)
 {
     this.ExecutePath = FileUnity.GetDrectory(cfgFile);
     this.ConfigFile  = cfgFile;
     this._mainSE     = new V8ScriptEngine();
     this._mainSE.LoadSystemModules();
     this._freeSE = new Queue <TaskInvoker>();
     this._http   = new HttpModule();
     this._mainSE.AddHostObject("http", this._http);
     // 临时绑定上下文到当前线程中,该引用会被下一个初始化任务覆盖
     this.Context             = new TaskContext();
     this.Context.ExecutePath = this.ExecutePath;
     this.Context.HttpClient  = this._http;
     this.Context.Engine      = this._mainSE;
     this.Context.BindContext();
     this.ExecuteInitScript();
     this.Context.TaskId = this.TaskId;
     this._lock          = new Semaphore(this.TaskSetting.Parallel, this.TaskSetting.Parallel);
 }