public void ProcessQueues(XLHelper xlHelper, Queue <XLTaskItem> taskItems) { int totalCount = taskItems.Count; int completeCount = 0; string lastProcessUrl = string.Empty; while (true) { if (taskItems.Count == 0) { break; } var xlTaskItem = taskItems.Dequeue(); if (lastProcessUrl == xlTaskItem.Url) { completeCount++; Console.WriteLine("Escape processed same task: {0} => {1} / {2}", xlTaskItem.FileName, completeCount, totalCount); continue; } var filePath = string.Format("{0}\\{1}", xlTaskItem.SaveTo, xlTaskItem.FileName); if (File.Exists(filePath)) { completeCount++; Console.WriteLine("Escape completed task: {0} => {1} / {2}", xlTaskItem.FileName, completeCount, totalCount); continue; } lastProcessUrl = xlTaskItem.Url; var startTask = xlHelper.StartTask(xlTaskItem); ConsoleHelper.NewLine(); ConsoleHelper.UpdateLine(string.Format("Processing: {0} => ", startTask.FileName)); int taskFailCount = 0; for (int i = 0; i < NextTaskWaitSeconds; i++) { var queryTask = xlHelper.QueryTask(startTask); if (queryTask.Result.Success) { completeCount++; //Console.WriteLine("Complete => {0} / {1}", completeCount, totalCount); ConsoleHelper.UpdateLine(string.Format("Processing: {0} => Complete {1} / {2}", startTask.FileName, completeCount, totalCount)); break; } var completePercent = (float)queryTask.Result.Data; if (Math.Abs(completePercent) < 0.01) { taskFailCount++; } if (taskFailCount > 10) { Console.WriteLine("fail: {0} {1} {2}", startTask.SaveTo, startTask.FileName, startTask.Url); taskFailCount = 0; continue; } //Console.Write("{0}%. ", (int)((float)(queryTask.Result.Data) * 100)); ConsoleHelper.UpdateLine(string.Format("Processing: {0} => {1}%", startTask.FileName, (int)(completePercent * 100))); Thread.Sleep(1000 * 2); } } }
private MessageResult ProcessTask(XLHelper xlHelper, XLTaskItem xlTaskItem) { var start = DateTime.Now; ConsoleHelper.NewLine(); var startTask = xlHelper.StartTask(xlTaskItem); var logFilePath = AppDomain.CurrentDomain.BaseDirectory.TrimEnd('\\') + "\\fail.txt"; TryFixFailFile(logFilePath); //·ÀÖ¹Á¬½ÓÌ«¿ì£¬×´Ì¬·µ»ØµÄ´íÎó Thread.Sleep(3000); var processSuccess = false; ConsoleHelper.UpdateLine(string.Format("Processing: {0} => ", startTask.FileName)); int tryConnectCount = 0; for (int i = 0; i < ProcessTaskMaxSeconds; i++) { var queryTask = xlHelper.QueryTask(startTask); if (queryTask.Result.Success) { processSuccess = true; ConsoleHelper.UpdateLine(string.Format("Processing: {0} => 100%", startTask.FileName)); break; } var completePercent = (float)queryTask.Result.Data; ConsoleHelper.UpdateLine(string.Format("Processing: {0} => {1}%", startTask.FileName, (int)(completePercent * 100))); if (Math.Abs(completePercent) < 0.0001) { tryConnectCount++; ConsoleHelper.UpdateLine(string.Format("Processing: {0} => {1}% => connect time: {2}", startTask.FileName, (int)(completePercent * 100), tryConnectCount)); } if (tryConnectCount > 30) { var filePath = string.Format("{0}\\{1}", startTask.SaveTo, startTask.FileName); var message = string.Format("{0}\n", filePath); if (File.Exists(filePath)) { processSuccess = true; } ConsoleHelper.NewLine(); Console.WriteLine(message); File.AppendAllText(logFilePath, message); break; } Thread.Sleep(1000); } var end = DateTime.Now; var processSeconds = (int)(end - start).TotalSeconds; Console.WriteLine("\n{0} Process Task Use Seconds: {1}", xlTaskItem.FileName, processSeconds); var mr = new MessageResult(); mr.Success = processSuccess; mr.Message = string.Format("Processing Complete: {0} => {1}({2})", startTask.FileName, processSuccess, processSeconds); mr.Data = processSeconds; return(mr); }