コード例 #1
0
 /// <summary>
 /// 追加待下载的图片至数据集中
 /// </summary>
 /// <param name="list">待下载的图片</param>
 protected void PushWaitImagesList(IEnumerable <string> list)
 {
     foreach (string url in list)
     {
         WaitImageUrlQueue.Enqueue(url);
     }
 }
コード例 #2
0
 /// <summary>
 /// 行动
 /// </summary>
 public override async Task Action()
 {
     while (!CancelTokenSource.IsCancellationRequested)
     {
         try
         {
             if (File.Exists(FilePath))
             {
                 string url;
                 using (FileStream fs = new FileStream(FilePath, FileMode.Open, FileAccess.Read))
                 {
                     using (StreamReader read = new StreamReader(fs, Encoding.Default))
                     {
                         Progress("[文件分析器]正在读取文件...");
                         int count = 1;
                         while (!string.IsNullOrWhiteSpace((url = await read.ReadLineAsync())))
                         {
                             while (true)
                             {
                                 if (WaitImageUrlQueue.Count <= 500)
                                 {
                                     Progress("[文件分析器]正在读取行[{0}]:{1}", count, url);
                                     if (UrlHelper.IsImg(url))
                                     {
                                         WaitImageUrlQueue.Enqueue(url);
                                     }
                                     else
                                     {
                                         Progress("[文件分析器]行({0}):{1}不是合法的图片链接!", count, url);
                                     }
                                     count++;
                                     break;
                                 }
                             }
                         }
                         Progress("[文件分析器]读取文件结束...");
                     }
                 }
             }
             else
             {
                 Progress("[文件分析器]文件({0})不存在!", FilePath);
             }
         }
         catch (Exception ex)
         {
             Progress("[文件分析器]发生异常:" + ex.ToString());
         }
     }
 }