Beispiel #1
0
        public object Invoke(CollectInfo collectInfo, CollectTaskInfo taskInfo)
        {
            CallContextManager.SetCollectInfo(collectInfo);
            CallContextManager.SetCollectTaskInfo(taskInfo);

            var scriptPath = taskInfo != null ? taskInfo.ScriptFilePath : collectInfo.ScriptFilePath;

            if (this._scriptPath == null || this._scriptPath != scriptPath)
            {
                this._scriptPath = scriptPath;
                this.ScriptEngine.Execute(this.GetInvokeScript());
            }
            return(this.ScriptEngine.Invoke("___func___"));
        }
Beispiel #2
0
        /// <summary>
        /// 添加采集数据
        /// </summary>
        /// <param name="strContent"></param>
        public int content(string strContent)
        {
            if (string.IsNullOrEmpty(strContent))
            {
                return(-1);
            }
            var task = CallContextManager.GetCollectTaskInfo();

            if (task == null)
            {
                throw new Exception("未能从当前线程上下文中获取对象 CollectTaskInfo");
            }
            return(this._contentRepository.Insert(new CollectContentInfo()
            {
                CollectId = task.CollectId,
                CollectTaskId = task.Id,
                Content = strContent
            }));
        }
Beispiel #3
0
        /// <summary>
        /// 获取一个新的文件名,格式({collectId_collectTaskId_fileName})
        /// </summary>
        /// <param name="uri"></param>
        /// <returns></returns>
        public string newFileName(string uri)
        {
            if (string.IsNullOrEmpty(uri))
            {
                return("");
            }
            var idx = uri.LastIndexOf("/");

            if (idx >= 0)
            {
                uri = uri.Substring(idx + 1);
            }
            var collect = CallContextManager.GetCollectInfo();

            if (collect == null)
            {
                throw new Exception("未能从当前线程上下文中获取对象 ollectInfo");
            }
            var task = CallContextManager.GetCollectTaskInfo();

            return($"{collect.Id}_{(task == null ? 0 : task.Id)}_{uri}");
        }
Beispiel #4
0
        /// <summary>
        /// 创建新任务
        /// </summary>
        /// <param name="task">{ uri:xx,script:xx }</param>
        public int add(dynamic task)
        {
            var collect = CallContextManager.GetCollectInfo();

            if (collect == null)
            {
                throw new Exception("未能从当前线程上下文中获取对象 ollectInfo");
            }
            var parentTask = CallContextManager.GetCollectTaskInfo();
            var newTask    = new CollectTaskInfo();

            newTask.CollectId      = collect.Id;
            newTask.RetryCount     = 0;
            newTask.ScriptFilePath = task.script;
            newTask.Status         = CollectTaskStatus.None;
            newTask.Uri            = task.uri;
            if (parentTask != null)
            {
                newTask.ParentId = parentTask.Id;
                newTask.Uri      = new Uri(new Uri(parentTask.Uri), newTask.Uri).ToString();
            }
            return(this._taskRepository.Insert(newTask));
        }