Exemplo n.º 1
0
        private static void StartTask(SearchTask task)
        {
            task.Report("任务开始执行");
            task.Report("统计此任务完成程度...");

            var finished_instance = task.SearchImageInstances.Where(x => x.ResultInfos != null).ToArray();

            task.Report($"目前已完成 {finished_instance.Length} 个任务");
            task.Report(finished_instance);

            IEnumerable <SearchInstance> list;

            //RequestLimit limit = new RequestLimit();

            do
            {
                //limit.CheckLimit();

                list = task.SearchImageInstances.Where(x => x.ResultInfos == null);

                foreach (var instance in list)
                {
                    if (TrySearch(task.Options, instance))
                    {
                        task.Report(instance);
                    }
                    else
                    {
                        task.Report($"Search image infomation ({instance.ImagePath}) failed,it will try again later...");
                    }
                }
            } while (!list.Any());

            task.Report($"任务执行完成!");
        }
Exemplo n.º 2
0
        public static void SaveTask(SearchTask search_task)
        {
            if (string.IsNullOrWhiteSpace(search_task.FilePath))
            {
                return;
            }

            var content = JsonConvert.SerializeObject(search_task, Formatting.Indented);

            File.WriteAllText(search_task.FilePath, content);
        }
Exemplo n.º 3
0
        public static void BeginTask(SearchTask search_task)
        {
            Debug.Assert(SearchTask.CurrentSearchTask != search_task, "Not support multi tasks");
            if (search_task?.IsProcessing ?? true)
            {
                return;
            }

            search_task.IsProcessing = true;

            CancellationTokenSource source = new CancellationTokenSource();

            search_task.Report("等待任务执行...");

            var r = Task.Run(() => StartTask(search_task), source.Token);

            search_task.ProcessingTask   = (r, source);
            SearchTask.CurrentSearchTask = search_task;
        }
Exemplo n.º 4
0
        public static void StopTask(SearchTask search_task)
        {
            Debug.Assert(SearchTask.CurrentSearchTask != search_task, "Not support multi tasks");
            if (!(search_task?.IsProcessing ?? true))
            {
                return;
            }

            search_task.IsProcessing = true;

            if (!(search_task.ProcessingTask is (Task task, CancellationTokenSource source)))
            {
                return;
            }

            source.Cancel();
            SaveTask(search_task);

            SearchTask.CurrentSearchTask = null;
        }