public static void Process(int id) { Process(new List <FileTaskInfo>() { FileTask.GetFileTask(id) }); }
private static string getMd5FromResultUrl(string url) { var filePath = replaceFileUrl(url); var md5 = FileTask.GetMD5HashFromFile(filePath); return(md5); }
public static void Process(string md5) { Process(new List <FileTaskInfo>() { FileTask.GetFileTask(md5) }); }
private void Fw_Created(object sender, System.IO.FileSystemEventArgs e) { if (_fileExtIsOk(e.FullPath)) { //休眠的目的是为了让刚上传的文件不产生争用 System.Threading.Thread.Sleep(3000); //交文件处理模块转为任务 FileTask.CreateTaskAsync(e.FullPath); } }
static void ExecModule(string[] args) { string cmd = "all"; string[] cmdArr; if (args != null && args.Length > 0) { cmd = args[0].ToLower(); cmdArr = cmd.Split(new char[] { '|', ',', ';' }); } else { cmdArr = new string[] { }; } //启动新文件监视器,将监视文件的变化,新增,修改,删除等 if (cmd == "all" || cmdArr.Contains <string>("nf")) { Console.WriteLine("Load NewFileProcessor"); NewFileProcessor.GetInstance().Run(); } //启动任务监视器 if (cmd == "all" || cmdArr.Contains <string>("tm")) { Console.WriteLine("Load TaskMonitor"); TaskMonitor.GetInstance().Run(); } //将历史文件转化问处理任务 if (cmdArr.Contains <string>("hisdata")) { Console.WriteLine("Load HistoryFileProcessor"); HistoryFileProcessor.GetInstance().Run(); } //讲CorpId为空的数据更新为有数据 if (cmdArr.Contains <string>("upcorpid")) { FileTask.UpdateCorpId(); } //Console.WriteLine("Run..."); Console.ReadLine(); }
public static void CreateTaskAsync(string filePath) { if (String.IsNullOrEmpty(filePath)) { return; } Task.Factory.StartNew(() => { try { FileTask.CreateTask(filePath); } catch (Exception ex) { FaceHand.Common.Util.SystemLoger.Current.Write(ex); } }); }
private void RunThread() { //加载所有文件 var files = System.IO.Directory.EnumerateFiles(_currentDirName); var fileReplacePattern = !_currentDirName.EndsWith("\\") ? _currentDirName + "\\" : _currentDirName; foreach (var fileFullPath in files) { try { if (ValidateFileExtName(fileFullPath)) { var shortFileName = fileFullPath.Replace(fileReplacePattern, String.Empty); if (!_fi.Exist(shortFileName)) { //创建任务 FileTask.CreateTask(fileFullPath); Console.WriteLine("CHF " + fileFullPath); //Console.WriteLine("FileTask.CreateTask("+ fileFullPath + ")"); //添加到索引表示文件已处理过 _fi.AddFile(shortFileName); } else { Console.WriteLine("SHF " + fileFullPath); } } } catch (Exception ex) { FaceHand.Common.Util.SystemLoger.Current.Write(ex); } System.Threading.Thread.Sleep(100); } //是放当前对象内容的资源 this.Close(); //处理子目录 ProcessChildDir(); }
public void Run() { var str_MonitorInterval = System.Configuration.ConfigurationManager.AppSettings["MonitorInterval"]; var int_MonitorInterval = String.IsNullOrEmpty(str_MonitorInterval) ? 30 : Convert.ToInt32(str_MonitorInterval); ThreadPool.QueueUserWorkItem((object state) => { while (true) { try { //腾讯云限制最大只能20个 var tasks = FileTask.GetFileTaskWaitPorcessing(20); if (tasks != null && tasks.Count() > 0) { SexyFilter.Process(tasks); //更新任务状态,防止重复查询 var taskIds = from item in tasks select item.Id; FileTask.UpdateTaskProcessState(taskIds); //记录日志 if (LogState.Enabled) { string log = String.Format("{0} {1} {2}", DateTime.Now, tasks.Count(), String.Join(",", taskIds)); FaceHand.Common.Core.WxLogProvider.Write(log, "TaskMonitor_Run"); } } } catch (Exception ex) { FaceHand.Common.Util.SystemLoger.Current.Write(ex); } //定时检测频率 Thread.Sleep(int_MonitorInterval * 1000); } }); }
public static Task Process(IEnumerable <FileTaskInfo> tasks) { return(Task.Factory.StartNew(() => { if (tasks == null || tasks.Count() == 0) { return; } try { var urls = new List <string>(); var taskIds = new List <long>(); foreach (var task in tasks) { if (String.IsNullOrEmpty(task.FileFullPath) || task.IsProcessed) { continue; } if (!System.IO.File.Exists(task.FileFullPath)) { //文件已不存在,删除任务 FileTask.RemoveFileTask(task.Id); continue; } var url = replaceFileUrl(task.FileFullPath); TaskIdMaps.Set(url, task.Id);//将ID映射记录下来 urls.Add(url); taskIds.Add(task.Id); } //再次确认哪些URL要处理 if (urls.Count == 0) { return; } var reqdata = new RequestBody() { appid = CLOUD_appid, bucket = CLOUD_bucket, url_list = urls }; var str_reqdata = Newtonsoft.Json.JsonConvert.SerializeObject(reqdata); var byt_reqdata = Encoding.UTF8.GetBytes(str_reqdata); var sign_reqdata = GetSign(); var client = (HttpWebRequest)WebRequest.Create(CLOUD_url); client.Headers.Add("Authorization", sign_reqdata); client.ContentType = "application/json"; client.ContentLength = byt_reqdata.Length; client.Timeout = 20000;//20s client.Method = "POST"; //写数据到请求 using (var reqStream = client.GetRequestStream()) { reqStream.Write(byt_reqdata, 0, byt_reqdata.Length); } //发送请求前记录请求日志 if (LogState.Enabled) { string log = String.Format("{0} {1} {2}\n{3}", DateTime.Now, tasks.Count(), sign_reqdata, str_reqdata); FaceHand.Common.Core.WxLogProvider.Write(log, "SexyFilter_Process"); } //发送请求 try { HttpWebResponse resp = client.GetResponse() as HttpWebResponse; using (var respStream = resp.GetResponseStream()) { var sr = new System.IO.StreamReader(respStream, Encoding.UTF8); var resp_data = Newtonsoft.Json.JsonConvert.DeserializeObject <ResponseBody>(sr.ReadToEnd()); //处理结果 TaskResult.Process(resp_data.result_list); } } catch (WebException ex) { HttpWebResponse resp = ex.Response as HttpWebResponse; var buf = new StringBuilder(); buf.AppendLine("Service Interface Call Exception " + ((int)resp.StatusCode).ToString() + " " + resp.StatusDescription); buf.AppendLine("Url:" + CLOUD_url + " Sign:" + sign_reqdata); //在次检测文件的有效性,有问题的直接删除任务 foreach (var task in tasks) { if (!System.IO.File.Exists(task.FileFullPath)) { FileTask.RemoveFileTask(task.Id); } buf.AppendLine(String.Format("{0} {1}", task.Id, task.FileFullPath)); } //再次更新为可处理的状态 FileTaskDAL.GetInstance().UpdateTaskProcessState4(taskIds); if (LogState.Enabled) { FaceHand.Common.Core.WxLogProvider.Write(buf.ToString(), "SexyFilter_Process"); } } } catch (Exception ex) { FaceHand.Common.Util.SystemLoger.Current.Write(ex); } })); }