/// <summary> 获取下好的文件 返回null则需要等待 </summary> public string GetWaitCurrent(string file, Action <bool, int, int> action) { // Message:如果没下载完,则等待15s数据都下载完为止 flag = false; var result = this._fileCollection.Find(l => l.FilePath == file); int last = this._fileCollection.FindIndex(l => l.FilePath == _current.FilePath); int now = this._fileCollection.FindIndex(l => l.FilePath == file); _current = result; // Message:如果时间相差较多,重新分配下载区间 if (now - last > 5 * 15) { this.RefreshPosition(_current.FilePath); } if (last - now > 0) { this.RefreshPosition(_current.FilePath); } if (result.IsLoaded == 2) { return(result.LocalPath); } else { Thread.Sleep(1000); flag = true; var waitCache = _fileCollection.Skip(now).Take(this.Capacity).ToList(); while (!waitCache.TrueForAll(l => l.IsLoaded == 2)) { if (!flag) { Debug.WriteLine("取消等待"); return(null); } Thread.Sleep(500); action(false, waitCache.FindAll(l => l.IsLoaded == 2).Count, waitCache.Count); } action(true, waitCache.FindAll(l => l.IsLoaded == 2).Count, waitCache.Count); return(result.LocalPath); } }
public ImageCacheEngine(List <string> filePath, string localFolder, string startFile, string user, string password, string ip = "") { this.ID = Guid.NewGuid().ToString(); this.LocalFolder = Path.Combine(localFolder, this.ID); if (!Directory.Exists(this.LocalFolder)) { Directory.CreateDirectory(this.LocalFolder); } foreach (var item in filePath) { string localPath = Path.Combine(localFolder, this.ID, Path.GetFileName(item)); ImageCacheEntity entity = new ImageCacheEntity(item, localPath, user, password, ip); _fileCollection.Add(entity); } _current = _fileCollection.Find(l => l.FilePath == startFile);; }