//all of these should be ordered in columns in list view just like in the order here public Video(string playlistID, string Location)//playlist null object { ID = playlistID; Type = "playlist"; this.Location = Location; downloadThread = null; }
public Segment(uint aid, string url, SegmentType segmentType, long contentLength, int threads) { Aid = aid; FinishedThreadCount = 0; IsFinished = false; Url = url; Type = segmentType; Length = contentLength; string directory = Bili_dl.SettingPanel.settings.TempPath + "\\"; Directory.CreateDirectory(directory); Filepath = string.Format("{0}{1}", directory, Url.Substring(Url.LastIndexOf('/') + 1, Url.IndexOf('?') - Url.LastIndexOf('/') - 1)); Threads = threads; DownloadThreads = new List <DownloadThread>(); for (int i = 0; i < threads; i++) { DownloadThread downloadThread; if (i != threads - 1) { downloadThread = new DownloadThread(Aid, Filepath + "_" + (i + 1), Url, i * (Length / threads), (i + 1) * (Length / threads) - 1, Threads); } else { downloadThread = new DownloadThread(Aid, Filepath + "_" + threads, Url, (threads - 1) * (Length / threads), Length - 1, Threads); } downloadThread.Finished += DownloadThread_Finished; DownloadThreads.Add(downloadThread); } }
/// <summary> /// helps when image file was corrupted, arranges reload. /// </summary> /// <param name="tile"></param> /// <param name="baseName"></param> public static void resetBackdrop(Tile tile, string baseName) { string imageFileName = Path.Combine(m_mapsPath, baseName + imageExt); try { if (Project.serverAvailable) { string imageUrl = getFileUrl(tile, baseName, imageFileName); DownloadThread dt = new DownloadThread(); dt.DownloadUrl = imageUrl; dt.tile = tile; dt.baseName = baseName; dt.fileName = imageFileName; dt.CompleteCallback += new DownloadCompleteHandler(imageDownloadCompleteCallback); dt.ProgressCallback += new DownloadProgressHandler(imageDownloadProgressCallback); dt.addMonitoredMethod = new AddMonitoredMethod(ProgressMonitor.addMonitored); //add dt worker method to the thread pool / queue a task //Project.threadPool.PostRequest (new WorkRequestDelegate (dt.Download), baseName); ThreadPool2.QueueUserWorkItem(new WaitCallback(dt.Download), baseName); #if DEBUG LibSys.StatusBar.Trace("OK: TileCache:resetBackdrop() - tile '" + baseName + "' - loading remote from " + imageUrl); #endif } } catch (Exception e) { LibSys.StatusBar.Error("file '" + imageFileName + "' failed to load on reset: " + e.Message); } }
private void cancel_Click(object sender, EventArgs e) { if (Downloading) { try { if (DownloadThread != null && DownloadThread.IsAlive) { DownloadThread.Abort( ); } } catch (ThreadAbortException) { this.LogWarn("Abortting 'Download' Thread."); } } if (RunningThread != null && RunningThread.IsAlive) { try { RunningThread.Abort( ); } catch (ThreadAbortException) { this.LogWarn("Abortting 'Running' Thread."); } } this.DialogResult = DialogResult.Cancel; }
public Video(string ID, string Name, string Location, string Format, Trim trim, string AudioFromPlaylist) //audio from playlist download { downloadThread = new DownloadThread(ID, Name, Location, Format, trim, null); //start download this.ID = ID; this.Location = Location; this.Format = Format; this.trim = trim; Type = "Audio"; }
public Video(string ID, string Name, string Location, string Format, string VideoFromPlaylist) //video from playlist download { downloadThread = new DownloadThread(ID, Name, Location, Format); //start download this.ID = ID; this.Location = Location; this.Format = Format; this.trim = null; Type = "Video"; }
public Video(string ID, string Location, string Format, Trim trim) //audio download { downloadThread = new DownloadThread(ID, Location, Format, trim, null); //start download this.ID = ID; this.Location = Location; this.Format = Format; this.trim = trim; Type = "Audio"; }
public Video(string ID, string Location, string Format) //video download { downloadThread = new DownloadThread(ID, Location, Format); //start download this.ID = ID; this.Location = Location; this.Format = Format; this.trim = null; Type = "Video"; }
/// <summary> /// 开始下载 /// </summary> public void Start() { if (Url == null || Url.Length == 0 || ThreadNum < 1 || Info == null) { throw new NullReferenceException("参数错误"); } try { if (Info.Completed) { DownloadState = DownloadStateEnum.Completed; DownloadPercentage = 100F; DownloadSpeed = 0; return; } DownloadState = DownloadStateEnum.Downloading; var response = GetResponse(); if (response == null) { DownloadState = DownloadStateEnum.Faulted; return; } if (!File.Exists(DownloadPath)) { var stream = new FileStream(DownloadPath, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.ReadWrite, 1024 * 1024 * 5); stream.SetLength(response.ContentLength); stream.Close(); } _threads = new DownloadThread[Info.DownloadBlockList.Count]; new Thread(ReportDownloadProgress).Start(); var num = 0; for (var i = 0; i < Info.DownloadBlockList.Count; i++) { var block = Info.DownloadBlockList[i]; if (num == Url.Length) { num = 0; } _threads[i] = new DownloadThread() { ID = i, DownloadUrl = Url[num], Path = DownloadPath, Block = block, Info = Info }; _threads[i].ThreadCompletedEvent += HttpDownload_ThreadCompletedEvent; num++; } } catch { DownloadState = DownloadStateEnum.Faulted; } }
/// <summary> /// Clean up any resources being used. /// </summary> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> protected override void Dispose(bool disposing) { if (DownloadThread.IsAlive) { DownloadThread.Abort(); } if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); }
/// <summary> /// serves silent preload /// </summary> public static void downloadIfMissing(string baseName) { string imageFileName = tileImagePath(baseName); try { if (m_backdropCache.ContainsKey(baseName) || File.Exists(imageFileName) || !Project.serverAvailable) { return; } string imageUrl = getImageUrl(baseName); if (!m_backdropCache.ContainsKey(baseName)) { DownloadThread dt = new DownloadThread(); dt.DownloadUrl = imageUrl; dt.tile = null; dt.baseName = baseName; dt.fileName = imageFileName; dt.CompleteCallback += new DownloadCompleteHandler(imageDownloadCompleteCallback); dt.ProgressCallback += new DownloadProgressHandler(imageDownloadProgressCallback); dt.addMonitoredMethod = new AddMonitoredMethod(ProgressMonitor.addMonitored); // tilesBeingLoadedCount++; //add dt worker method to the thread pool / queue a task //Project.threadPool.PostRequest (new WorkRequestDelegate (dt.Download), baseName); ThreadPool2.QueueUserWorkItem(new WaitCallback(dt.Download), baseName); #if DEBUG LibSys.StatusBar.Trace("OK: TerraserverCache:getBackdrop() - tile '" + baseName + "' - loading remote from " + imageUrl); #endif } else { //LibSys.StatusBar.Trace("OK: TerraserverCache:getBackdrop() - tile '" + baseName + "' - already in cache"); } } catch (Exception e) { LibSys.StatusBar.Error("file '" + imageFileName + "' failed to load: " + e.Message); } }
public void Start() { if (!(DownLoadUrl != null && DownLoadPath != null && FileName != null && ThreadNum != 0)) { return; } try { HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(DownLoadUrl); HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse(); contentLength = httpWebResponse.ContentLength; threads = new DownloadThread[ThreadNum]; long q = contentLength / ThreadNum; new Thread(SpeedStatistics).Start(); for (int i = 0; i < ThreadNum; i++) { if (i == (ThreadNum - 1)) { threads[i] = new DownloadThread { Url = DownLoadUrl, FileName = DownLoadPath + "\\" + FileName + "._tmp" + i.ToString(), From = q * i, To = contentLength, download = this }; break; } threads[i] = new DownloadThread { Url = DownLoadUrl, FileName = DownLoadPath + "\\" + FileName + "._tmp" + i.ToString(), From = q * i, To = (q * (i + 1)) - 1, download = this }; } } catch (Exception ex) { MessageBox.Show("下载失败! 错误: " + ex.ToString()); } }
//ִ�����ذ�ť����¼� private void buttonX1_Click(object sender, EventArgs e) { if (!inputCheck()) { return; } else { //���������б� string[] dList = getDownloadList(); string folderPath = this.filePathTextbox.Text; setDownloadTab(dList, folderPath); //��ִ̨������ DownloadThread dt = new DownloadThread(dList, folderPath, getPicEventHandler, itemList); Thread thread = new Thread(dt.ThreadProc); thread.IsBackground = true; thread.Start(); //�л�tabҳ��status��� this.metroShell1.SelectedTab = this.metroTabItem2; } }
//执行下载按钮点击事件 private void buttonX1_Click(object sender, EventArgs e) { if (!inputCheck()) { return; } else { //生成下载列表 string[] dList = getDownloadList(); string folderPath = this.filePathTextbox.Text; setDownloadTab(dList, folderPath); //后台执行下载 DownloadThread dt = new DownloadThread(dList, folderPath, getPicEventHandler, itemList); Thread thread = new Thread(dt.ThreadProc); thread.IsBackground = true; thread.Start(); //切换tab页到status面板 this.metroShell1.SelectedTab = this.metroTabItem2; } }
public void StartDownLoadRes(int threadNum = 1) { if (Directory.Exists(mLocalTempDir)) { Directory.Delete(mLocalTempDir, true); } mFinishedSize = 0; StopAllDownload(); mDownloadThreads = new List <DownloadThread>(); mIsDownloading = true; for (int i = 0; i < threadNum; i++) { if (mUpdateItems.Count > 0) { var downloadThread = new DownloadThread(this); mDownloadThreads.Add(downloadThread); downloadThread.StartDownloadItem(mRemoteResPath, mLocalTempDir, mUpdateItems.Dequeue()); } } }
string DownloadFiles(CallType callType, string fileName = "file", int count = 1, int threads = 1) { InitConsole(); string name; string ext; if (callType == CallType.Console) { name = ConfigurationManager.AppSettings["SourcePath"] + Path.GetFileNameWithoutExtension(fileName);; ext = !string.IsNullOrEmpty(Path.GetExtension(fileName)) ? Path.GetExtension(fileName) : "docx"; } else { name = fileName; ext = ""; } var total = count; var offset = total / threads; var parameters = new DownloadParams { Offset = 0, Count = offset, Config = _config, FileName = name, FileType = ext }; //var download = new DownloadThread("THREAD " + 0 + ", View PDF of " + offset + " DOCX", parameters); for (int i = 0; i < threads; i++) { parameters.Offset = i * offset; var download = new DownloadThread("THREAD " + i + ", Download of " + offset + " DOCX", parameters); } return("Download success!"); }
public MainViewModel() { if (MainViewModel.instance == null) { Width = 525; Height = 350; Threads = new BindingList <DownloadThread>(); fetch = new DelegateCommand <object>((s) => { Threads.Clear(); DownloadThread.Clear(); Downloader.count = 0; new DownloadThread(RootURL); }, (s) => { return(!string.IsNullOrWhiteSpace(RootURL)); }); RootURL = "http://www.apple.com"; MainViewModel.Instance = this; } else { throw new Exception("There can only be one!!!!!"); } }
//private void Run(object state, DateTime requestEnqueueTime) private void Run(object state) { string emailText = importTextBox.Text; string lineToSearch = "http://www.geocaching.com/seek/cache_details.asp"; m_errorCount = 0; //ArrayList links = new ArrayList(); int nCaches; int gcCount = 0; int lineno = 0; string line; StringReader stream = new StringReader(emailText); // first, count the links to make sure there are some, and to set progress bar maximum: try { while ((line = stream.ReadLine()) != null) { lineno++; if (line.IndexOf(lineToSearch) != -1) { gcCount++; //links.Add(line.Trim()); } } } catch {} nCaches = gcCount; if (nCaches == 0) { statusLabel.Text = "Error: pasted text does not contain links to geocache pages."; } else { statusLabel.Text = "OK: email contains " + nCaches + " caches"; progressBar.Maximum = nCaches; progressBar.Minimum = 0; // bring up Progress monitor form, first sleep in the loop will give it some time to initialize: //Project.threadPool.PostRequest (new WorkRequestDelegate (RunPM), "import geocache"); ThreadPool2.QueueUserWorkItem(new WaitCallback(RunPM), "import geocache"); lineno = 0; gcCount = 0; try { stream = new StringReader(emailText); while ((line = stream.ReadLine()) != null && gcCount < m_maxLinks && !m_stop) { lineno++; try { if (line.IndexOf(lineToSearch) != -1) { // try not to overload the server: Thread.Sleep(gcCount == 0 ? 1000 : m_processingDelaySec * 1000); gcCount++; progressBar.Value = gcCount; string link = line.Trim(); statusLabel.Text = "IP: processing " + link + " - " + gcCount + " of " + nCaches; DownloadThread dt = new DownloadThread(); dt.DownloadUrl = link; dt.tile = null; int pos = link.IndexOf("ID="); dt.baseName = pos < 0 ? link : link.Substring(pos); dt.fileName = ""; dt.CompleteCallback += new DownloadCompleteHandler(gcDownloadCompleteCallback); dt.ProgressCallback += new DownloadProgressHandler(gcDownloadProgressCallback); dt.addMonitoredMethod = new AddMonitoredMethod(ProgressMonitor.addMonitored); //add dt worker method to the thread pool / queue a task //Project.threadPool.PostRequest (new WorkRequestDelegate (dt.Download), dt.baseName); ThreadPool2.QueueUserWorkItem(new WaitCallback(dt.Download), dt.baseName); } } catch (Exception ee) { LibSys.StatusBar.Error(" line=" + lineno + " " + ee.Message); } } } catch {} statusLabel.Text = "OK: finished processing, " + gcCount + " links processed, " + m_errorCount + " errors"; if (gcCount >= m_maxLinks) { statusLabel.Text += " [limit " + m_maxLinks + " reached]"; } WaypointsCache.RefreshWaypointsDisplayed(); m_pictureManager.Refresh(); } importButton.Enabled = true; }
void ThreadStartDownload(object sender, DoWorkEventArgs e) { DownloadThread th = new DownloadThread(); th.mre = (ManualResetEvent)e.Argument; th.parent = this.parent; lock (this.toDoFiles) { if (this.toDoFiles.Count == 0) { this.downloadDone = true; e.Result = th; return; } //Get a random mirror this.mirrorWalker = ++this.mirrorWalker % this.baseUrls.Count; th.remoteUrl = this.baseUrls[this.mirrorWalker] + this.toDoFiles[0].path; th.localUrl = this.toDoFiles[0].localUrl; th.filesize = this.toDoFiles[0].length; th.sha1sum = this.toDoFiles[0].sha1sum; th.parts = this.toDoFiles[0].parts; this.toDoFiles.RemoveAt(0); } th.StartDownload(); e.Result = th; }
public static Backdrop getBackdrop(Tile tile, string baseName) { string imageFileName = Path.Combine(m_mapsPath, baseName + imageExt); Backdrop ret = null; try { if (m_backdropCache.ContainsKey(baseName)) { ret = (Backdrop)m_backdropCache[baseName]; // may be IsEmpty, if proven that can't download ret.MarkUsed(); #if DEBUG LibSys.StatusBar.Trace("OK: TileCache:getBackdrop() - tile '" + baseName + "' - found in cache - " + ret); #endif return(ret); } bool loadedFromFile = false; if (!Project.reloadRefresh && File.Exists(imageFileName)) { try { ret = new Backdrop(imageFileName, baseName, true); #if DEBUG LibSys.StatusBar.Trace("OK: TileCache:getBackdrop() - tile '" + baseName + "' - loaded from file"); #endif AddBackdrop(baseName, ret); loadedFromFile = true; } catch {} } if (!loadedFromFile && m_mappingServers.Count > 0) { string imageUrl = getFileUrl(tile, baseName, imageFileName); if (imageUrl == null) { ret = new Backdrop(null, baseName, true); // doFill with null name makes it Empty AddBackdrop(baseName, ret); return(ret); } if (!m_backdropCache.ContainsKey(baseName)) { ret = new Backdrop(imageFileName, baseName, false); // fill later AddBackdrop(baseName, ret); DownloadThread dt = new DownloadThread(); dt.DownloadUrl = imageUrl; dt.tile = tile; dt.baseName = baseName; dt.fileName = imageFileName; dt.CompleteCallback += new DownloadCompleteHandler(imageDownloadCompleteCallback); dt.ProgressCallback += new DownloadProgressHandler(imageDownloadProgressCallback); dt.addMonitoredMethod = new AddMonitoredMethod(ProgressMonitor.addMonitored); //add dt worker method to the thread pool / queue a task //Project.threadPool.PostRequest (new WorkRequestDelegate (dt.Download)); ThreadPool2.QueueUserWorkItem(new WaitCallback(dt.Download), baseName); #if DEBUG LibSys.StatusBar.Trace("OK: TileCache:getBackdrop() - tile '" + baseName + "' - loading remote from " + imageUrl); #endif } #if DEBUG else { LibSys.StatusBar.Trace("OK: TileCache:getBackdrop() - tile '" + baseName + "' - already in cache"); } #endif } } catch (Exception e) { LibSys.StatusBar.Error("file '" + imageFileName + "' failed to load: " + e.Message); } // whatever happened before, returning null is not an option. if (ret == null) { ret = new Backdrop(null, baseName, true); // doFill with null name makes it Empty AddBackdrop(baseName, ret); } return(ret); }
public static Features getFeatures(Tile tile, string baseName) { string featuresFileName = Path.Combine(m_mapsPath, baseName + featuresExt); Features ret = null; try { if (m_featuresCache.ContainsKey(baseName)) { ret = (Features)m_featuresCache[baseName]; // may be still downloading if (ret != null) { ret.MarkUsed(); } #if DEBUG LibSys.StatusBar.Trace("OK: TileCache:getFeatures() - tile '" + baseName + "' - found in cache - " + ret); #endif return(ret); } bool loadedFromFile = false; if (!Project.reloadRefresh && File.Exists(featuresFileName)) { try { ret = new Features(featuresFileName, baseName, true); #if DEBUG LibSys.StatusBar.Trace("OK: TileCache:getFeatures() - tile '" + baseName + "' - loaded local"); #endif AddFeatures(baseName, ret); loadedFromFile = true; } catch {} } if (!loadedFromFile && m_mappingServers.Count > 0) { string featuresUrl = getFileUrl(tile, baseName, featuresFileName); if (featuresUrl == null) { ret = new Features(null, baseName, true); // doFill with null name makes it Empty AddFeatures(baseName, ret); return(ret); } if (!m_featuresCache.ContainsKey(baseName)) { ret = new Features(featuresFileName, baseName, false); // fill later AddFeatures(baseName, ret); DownloadThread dt = new DownloadThread(); dt.DownloadUrl = featuresUrl; dt.tile = tile; dt.baseName = baseName; dt.fileName = featuresFileName; dt.CompleteCallback += new DownloadCompleteHandler(featuresDownloadCompleteCallback); dt.ProgressCallback += new DownloadProgressHandler(featuresDownloadProgressCallback); dt.addMonitoredMethod = new AddMonitoredMethod(ProgressMonitor.addMonitored); //add this to the thread pool / queue a task //Project.threadPool.PostRequest (new WorkRequestDelegate (dt.Download)); ThreadPool2.QueueUserWorkItem(new WaitCallback(dt.Download), baseName); #if DEBUG LibSys.StatusBar.Trace("OK: TileCache:getFeatures() - tile '" + baseName + "' - loading remote from " + featuresUrl); #endif } } } catch (Exception e) { LibSys.StatusBar.Error("file '" + featuresFileName + "' failed to load: " + e.Message); } // whatever happened before, returning null is not an option. if (ret == null) { ret = new Features(null, baseName, true); // doFill with null name makes it Empty AddFeatures(baseName, ret); } return(ret); }
private void perform_Click(object sender, EventArgs e) { try { SetControlEnabled(this.perform, false); SetControlVisible(this.progress, true); SetControlVisible(stepImage, true); if (DownloadThread != null && DownloadThread.IsAlive) { try { DownloadThread.Abort( ); } catch (ThreadAbortException taex) { this.LogWarn("Aborted download thread."); } } DownloadThread = new Thread(new ThreadStart(delegate { FileInfo tfile = new FileInfo(ZipFile); if (tfile.Exists) { tfile.Delete( ); } if (!tfile.Directory.Exists) { tfile.Directory.Create( ); } this.LogInfo("Checking USB Driver Version..."); bool isCupcake = AndroidUsbDriverHelper.IsCupcakeDriver; this.LogInfo("Downloading {0} SDK Tools", isCupcake ? "1.5" : "1.6"); HttpWebRequest req = HttpWebRequest.Create(new Uri(isCupcake ? Properties.Resources.AndroidCupcakeSdkDownloadUrl : Properties.Resources.AndroidDonutSdkDownloadUrl)) as HttpWebRequest; if (Settings.Instance.Proxy.Enabled) { req.Proxy = Settings.Instance.Proxy.CreateProxy( ); } HttpWebResponse resp = req.GetResponse( ) as HttpWebResponse; using (Stream reader = resp.GetResponseStream( )) { Downloading = true; int bytesRead = 0; byte[] buffer = new byte[2048]; long totalBytes = resp.ContentLength; long totalBytesRead = 0; using (FileStream fs = new FileStream(ZipFile, FileMode.Create, FileAccess.Write, FileShare.Read)) { while ((bytesRead = reader.Read(buffer, 0, buffer.Length)) > 0) { fs.Write(buffer, 0, bytesRead); totalBytesRead += bytesRead; int percentage = ( int )((( double )totalBytesRead / ( double )totalBytes) * 100f); if (this.InvokeRequired) { this.Invoke(new UpdateProgressBarValueDelegate(this.UpdateProgressBarValue), 0, 100, percentage); this.Invoke(new UpdateLabelDelegate(this.UpdateStatusLabel), string.Format(new DroidExplorer.Core.IO.FileSizeFormatProvider( ), "Downloading Android Tools: {0:fs} of {1:fs} - {2}%", totalBytesRead, totalBytes, percentage)); } else { UpdateProgressBarValue(0, 100, percentage); UpdateStatusLabel(string.Format(new DroidExplorer.Core.IO.FileSizeFormatProvider( ), "Downloading Android Tools: {0:fs} of {1:fs} - {2}%", totalBytesRead, totalBytes, percentage)); } } if (this.InvokeRequired) { this.Invoke(new UpdateProgressBarValueDelegate(this.UpdateProgressBarValue), 0, 100, 0); this.Invoke(new UpdateLabelDelegate(this.UpdateStatusLabel), "Download Complete"); } else { UpdateProgressBarValue(0, 100, 0); UpdateStatusLabel("Download Complete"); } Downloading = false; } } if (RunningThread != null && RunningThread.IsAlive) { try { RunningThread.Abort( ); } catch { } } RunningThread = new Thread(new ThreadStart(delegate { Step2( ); })); RunningThread.Start( ); })); DownloadThread.Start( ); } catch (Exception ex) { this.LogError(ex.Message, ex); SetError(ex); FinializeSetup( ); } }