public static List <PeakList <T> > GetPeakListFromDtaDirectory <T>(string dtaDirectory, IProgressCallback progress) where T : IPeak, new() { var result = new List <PeakList <T> >(); var ddi = new DtaDirectoryIterator <T>(dtaDirectory); progress.SetMessage("Reading peak list from dta files of directory " + new DirectoryInfo(dtaDirectory).Name + ", total " + ddi.Count + " files ..."); progress.SetRange(0, ddi.Count); progress.SetPosition(0); while (ddi.HasNext()) { progress.Increment(1); if (progress.IsCancellationPending()) { throw new UserTerminatedException(); } result.Add(ddi.Next()); } return(result); }
private static bool DoDownloadFileAsync(string uri, string targetFile, IProgressCallback callback = null) { if (!File.Exists(targetFile)) { var tempFile = new FileInfo(targetFile).DirectoryName + "/" + Path.GetFileName(Path.GetTempFileName()); var webClient = new WebClient() { Proxy = null, }; Console.WriteLine(" " + Path.GetFileName(uri) + " ..."); webClient.DownloadFileAsync(new Uri(uri), tempFile); while (webClient.IsBusy) { if (callback != null && callback.IsCancellationPending()) { webClient.CancelAsync(); return(false); } Thread.Sleep(100); } if (File.Exists(tempFile)) { Console.WriteLine(" " + Path.GetFileName(uri) + " ... done."); File.Move(tempFile, targetFile); } else { Console.WriteLine(" " + Path.GetFileName(uri) + " ... failed."); } } return(File.Exists(targetFile)); }
private static bool DoDownloadFileAsync(string uri, string targetFile, IProgressCallback callback = null) { if (!File.Exists(targetFile)) { var tempFile = new FileInfo(targetFile).DirectoryName + "/" + Path.GetFileName(Path.GetTempFileName()); var webClient = new WebClient() { Proxy = null, }; Console.WriteLine(" " + Path.GetFileName(uri) + " ..."); webClient.DownloadFileAsync(new Uri(uri), tempFile); while(webClient.IsBusy) { if (callback != null && callback.IsCancellationPending()) { webClient.CancelAsync(); return false; } Thread.Sleep(100); } if (File.Exists(tempFile)) { Console.WriteLine(" " + Path.GetFileName(uri) + " ... done."); File.Move(tempFile, targetFile); } else { Console.WriteLine(" " + Path.GetFileName(uri) + " ... failed."); } } return File.Exists(targetFile); }