public bool OnBeforeDownload(DownloadItem downloadItem, out string downloadPath, out bool showDialog) { downloadPath = downloadItem.SuggestedFileName; showDialog = true; return true; }
public DownloadItem Add(EpisodeWithDownloadSettings ep, string template, string downloadpath,DownloadStatus status=DownloadStatus.Queue) { DownloadItem dinfo = null; lock (_downloadslock) { dinfo = new DownloadItem(ep, template, downloadpath, this, status); dinfo.Index = cnt++; dinfo.OnProgress += ((a) => { if (OnProgress != null) OnProgress(a); }); dinfo.OnFinish += ((a) => { Save(); CheckForDownload(); }); lock (_downloadslock) { _downloads.Add(dinfo); } } CheckForDownload(); return dinfo; }
public DownloadHandler(DownloadItem item) { strFilePath = item.SavePath; downloadID = item.DownloadID; stream = File.Create(strFilePath); }
public void OnDownloadUpdated(IBrowser browser, DownloadItem downloadItem, IDownloadItemCallback callback) { var handler = OnDownloadUpdatedFired; if (handler != null) { handler(this, downloadItem); } }
public void OnBeforeDownload(IBrowser browser, DownloadItem downloadItem, IBeforeDownloadCallback callback) { if (!callback.IsDisposed) { callback.Continue(downloadItem.SuggestedFileName, showDialog: true); callback.Dispose(); } }
public void AddDownload(string url, string filepath, string filename) { Dispatcher.BeginInvoke((Action) (() => { Item = new DownloadItem(filepath, url, filename); Item.Width = Content.ActualWidth; Item.Height = ItemHeight; canvas.Children.Add(Item); Canvas.SetTop(Item, Item.Height * ItemsCount); Items.Add(Item); this.Height = MarginTop + Items.Count * ItemHeight; ItemsCount += 1; })); }
public void OnBeforeDownload(IBrowser browser, DownloadItem downloadItem, IBeforeDownloadCallback callback) { var handler = OnBeforeDownloadFired; if (handler != null) { handler(this, downloadItem); } if (!callback.IsDisposed) { using (callback) { callback.Continue(downloadItem.SuggestedFileName, showDialog: true); } } }
public bool GetDownloadHandler(IWebBrowser browser, string mimeType, string fileName, long contentLength, ref IDownloadHandler handler) { SaveFileDialog dialog = new SaveFileDialog(); dialog.FileName = fileName; string strExt = Path.GetExtension(fileName); dialog.Filter = string.Format("{0} 文件(*{0})|*{0}", strExt); dialog.RestoreDirectory = true; dialog.OverwritePrompt = true; dialog.CheckFileExists = false; dialog.CheckPathExists = true; dialog.AutoUpgradeEnabled = true; if (dialog.ShowDialog() == DialogResult.OK) { string strFilePath = dialog.FileName; if (!string.IsNullOrEmpty(strFilePath)) { //string strFilePath = Path.Combine(strFolderPath, fileName); var downloadItem = new DownloadItem() { DownloadID = Guid.NewGuid(), SourceFileName = fileName, ContentLength = contentLength, MineType = mimeType, SavePath = strFilePath, SaveFileName = Path.GetFileName(strFilePath), StartTime = DateTime.Now }; downloadManager.Add(downloadItem); DownloadHandler downloadHandler = new DownloadHandler(downloadItem); downloadHandler.OnDownloadComplete += downloadHandler_OnDownloadComplete; downloadHandler.OnDownloadNotify += downloadHandler_OnDownloadNotify; handler = downloadHandler; (downloadManager as FormDownloadManger).Show(); (downloadManager as FormDownloadManger).BringToFront(); return true; } } return false; }
public void RemoveDownload(DownloadItem di) { Items.Remove(di); canvas.Children.Remove(di); ItemsCount = 0; Dispatcher.BeginInvoke((Action) (() => { foreach (DownloadItem Item in Items) { Item.Width = Content.ActualWidth; Item.Height = ItemHeight; Canvas.SetTop(Item, Item.Height * ItemsCount); this.Height = MarginTop + Items.Count * ItemHeight; ItemsCount += 1; } })); }
/// <summary> /// Queues file for download /// </summary> public void DownloadFile(string url, string fileName, FileType fileType) { DownloadItem d = new DownloadItem(); d.url = new Uri(url); d.fileType = fileType; if (fileType == FileType.Map) d.targetPath = spring.Path + "maps/"; else if (fileType == FileType.Mod) d.targetPath = spring.Path + "mods/"; d.fileName = fileName; downloadQueue.Enqueue(d); if (downloadQueue.Count == 1 && (downloadThread == null || downloadThread.IsAlive == false)) { downloadThread = new Thread(delegate() { wc = new WebClient(); GetNext(); }); downloadThread.Start(); } }
private static void LoadPersistedObjects(DownloadItem[] downloads) { for (int i = 0; i < downloads.Length; i++) { List<Segment> segments = new List<Segment>(); for (int j = 0; j < downloads[i].Segments.Length; j++) { Segment seg = new Segment(); seg.Index = downloads[i].Segments[j].Index; seg.InitialStartPosition = downloads[i].Segments[j].InitialStartPositon; seg.StartPosition = downloads[i].Segments[j].StartPositon; seg.EndPosition = downloads[i].Segments[j].EndPosition; segments.Add(seg); } Downloader d = DownloadManager.Instance.Add( downloads[i].rl, downloads[i].mirrors, downloads[i].LocalFile, segments, downloads[i].remoteInfo, downloads[i].requestedSegments, false, downloads[i].createdDateTime); if (downloads[i].extendedProperties != null) { SerializableDictionary<string, object>.Enumerator e = downloads[i].extendedProperties.GetEnumerator(); while (e.MoveNext()) { d.ExtendedProperties.Add(e.Current.Key, e.Current.Value); } } } }
public override void DownloadAll(IEnumerable<Uri> uris, DirectoryInfo output) { var poolName = string.Format("downloads to {0}", output.Name); var pool = new CustomThreadPool(poolName) { MinThreads = 1, MaxThreads = 4 }; pool.AfterWorkItem += ItemCompleted; foreach (Uri uri in uris) { var workItem = new DownloadItem(DownloadOne, uri, output); pool.AddWorkItem(workItem); } while(pool.WorkingThreads > 0) {} InvokeFinished(); }
public void OnBeforeDownload(IWebBrowser chromiumWebBrowser, IBrowser browser, DownloadItem downloadItem, IBeforeDownloadCallback callback) { new WebBrowser().Navigate(downloadItem.Url); }
public static bool TryHandleDownload(DcBot connection, DownloadItem item, Source source) { if (item != null && source != null) { string fileType = item.ContentInfo.Get(ContentInfo.FILELIST); string func = item.ContentInfo.Get("FUNC"); string path = item.ContentInfo.Get(ContentInfo.STORAGEPATH); string usrId = item.ContentInfo.Get("USR"); byte[] data = null; BaseFilelist filelist = null; int i = 0; while (i < 10) { try { data = File.ReadAllBytes(path); break; } catch (Exception) { System.Threading.Thread.Sleep(100); } finally { i++; } } if (data == null) return false; switch (fileType) { case BaseFilelist.XMLBZ: filelist = new FilelistXmlBz2(data, true); break; case BaseFilelist.XML: filelist = new FilelistXmlBz2(data, false); break; case BaseFilelist.BZ: filelist = new FilelistMyList(data, true); break; default: connection.SendMessage(Actions.PrivateMessage, usrId, "Unrecognized filelist."); return false; } LogMsg("CreateShare"); filelist.CreateShare(); LogMsg("/CreateShare"); Share share = filelist.Share as Share; File.Delete(path); if (share != null) { switch (func) { case "new": FuncListShare(connection, share, usrId, FunctionTypes.ListNewEpisodes); break; case "list": FuncListShare(connection, share, usrId, FunctionTypes.ListAllEpisodes); break; case "debug": FuncListShare(connection, share, usrId, FunctionTypes.ListDebugInfoOnEpisodes); break; case "countdown": case "cd": FuncCountDownShare(connection, share, usrId); break; } } } return false; }
private DownloadItemViewModel ToDownloadItemViewModel(DownloadItem downloadItem) { return(new DownloadItemViewModel(downloadItem.Id, downloadItem.FileName, downloadItem.Status, GetDownloadProgressText(downloadItem), GetDownloadProgressValue(downloadItem), downloadItem.DownloadDirectory, downloadItem.Logs.Select(downloadItemLogLine => ToDownloadItemLogLineViewModel(downloadItemLogLine)))); }
public DownloadEventArgs(DownloadItem item, Status status, string message) { DownloadItem = item; Status = status; Message = message; }
private void PersistList(object state) { List<DownloadItem> downloadsToSave = new List<DownloadItem>(); using (DownloadManager.Instance.LockDownloadList(false)) { //IList<Downloader> downloads = DownloadManager.Instance.Downloads; //for (int i = 0; i < downloads.Count; i++) foreach (Downloader downloader in DownloadManager.Instance.OrderedDownloads) { //if (downloads[i].State == DownloaderState.Ended) if (downloader.State == DownloaderState.Ended) { continue; } //Downloader downloader = downloads[i]; DownloadItem di = new DownloadItem(); di.id = downloader.Id; di.LocalFile = downloader.LocalFile; di.rl = downloader.ResourceLocation; di.mirrors = downloader.Mirrors.ToArray(); di.remoteInfo = downloader.RemoteFileInfo; di.requestedSegments = downloader.RequestedSegments; di.createdDateTime = downloader.CreatedDateTime; di.extendedProperties = new SerializableDictionary<string,object>(downloader.ExtendedProperties); using (downloader.LockSegments()) { di.Segments = new SegmentItem[downloader.Segments.Count]; for (int j = 0; j < downloader.Segments.Count; j++) { SegmentItem si = new SegmentItem(); Segment seg = downloader.Segments[j]; si.Index = seg.Index; si.InitialStartPositon = seg.InitialStartPosition; si.StartPositon = seg.StartPosition; si.EndPosition = seg.EndPosition; di.Segments[j] = si; } } downloadsToSave.Add(di); } } DownloadParameters downloadParameters = new DownloadParameters(); downloadParameters.defaultDownloadDirectory = DownloadManager.Instance.DefaultDownloadDirectorySource; downloadParameters.lastDownloadId = DownloadManager.Instance.LastDownloadId; downloadParameters.downloadItems = downloadsToSave.ToArray(); //SaveObjects(downloadsToSave); SaveObjects(downloadParameters); }
/// <summary> /// If source is related to a downloaditem in downloadmanager. /// First match will be returned. /// </summary> /// <param name="s">Source to find related downloaditems for</param> /// <param name="d">DownloadItem found for Source</param> /// <returns>Returns true if downloaditem was found for source</returns> public virtual bool TryGetDownload(Source s, out DownloadItem d) { FlowSortedList<DownloadItem> items = null; lock (this) { if (srcItems.TryGetValue(s, out items) && items.Count > 0) { d = items[0]; return true; } } d = null; return false; }
/// <summary> /// Adds downloaditem related to Source /// Source can be null /// </summary> /// <param name="d">DownloadItem to be added</param> /// <param name="sources">Sources to be related to downloaditem</param> public void AddDownload(DownloadItem d, Source[] sources) { // Downloads FlowSortedList<Source> tmpDwn = null; if (!dwnItems.ContainsKey(d)) { lock (this) { tmpDwn = new FlowSortedList<Source>(); d.DownloadCompleted += new FmdcEventHandler(d_DownloadCompleted); d.SegmentCanceled += new FmdcEventHandler(d_SegmentCanceled); d.SegmentCompleted += new FmdcEventHandler(d_SegmentCompleted); d.SegmentStarted += new FmdcEventHandler(d_SegmentStarted); dwnItems.Add(d, tmpDwn); } DownloadAdded(this, new FmdcEventArgs(0, d)); } else { lock (this) { // This is if we have a fake downloaditem (that we probably have) d = dwnItems.Keys[dwnItems.IndexOfKey(d)]; tmpDwn = dwnItems[d]; } } foreach (Source s in sources) { if (s != null) { lock (this) { tmpDwn.Add(s); // Sources FlowSortedList<DownloadItem> tmpSrc = null; if (!srcItems.ContainsKey(s)) { tmpSrc = new FlowSortedList<DownloadItem>(); srcItems.Add(s, tmpSrc); SourceAdded(this, new FmdcEventArgs(0, s)); } else { tmpSrc = srcItems[s]; } tmpSrc.Add(d); } } } }
public async Task SendIDExtract(DownloadItem item, string perc = "0") { await SendUpdate("{ \"type\": \"extract\", \"id\": \"" + item.ID + "\", \"perc\": \"" + perc + "\", \"group\": \"" + item.GroupID + "\" }", item.ID, item.DownloadGroupID, "downinfo"); }
protected override bool CollectAllItems() { item = AddDownload(_config); return(true); }
public void OnDownloadUpdated(IWebBrowser chromiumWebBrowser, CefSharp.IBrowser browser, DownloadItem downloadItem, IDownloadItemCallback callback) { if (_lastProgress != downloadItem.PercentComplete) { _lastProgress = downloadItem.PercentComplete; Console.WriteLine($"Download progress: {downloadItem.PercentComplete}%"); } if (downloadItem.IsComplete) { _taskCompletionSource.SetResult(downloadItem.FullPath); } }
public void OnBeforeDownload(IWebBrowser chromiumWebBrowser, CefSharp.IBrowser browser, DownloadItem downloadItem, IBeforeDownloadCallback callback) { if (!string.IsNullOrWhiteSpace(downloadItem.SuggestedFileName)) { var path = Path.Combine(Directory.GetCurrentDirectory(), downloadItem.SuggestedFileName); callback.Continue(path, false); return; } var match = _nameRegex.Match(downloadItem.ContentDisposition); if (match.Success) { var name = match.Groups[1].ToString(); var path = Path.Combine(Directory.GetCurrentDirectory(), name); callback.Continue(path, false); } }
/* public void OnDownloadUpdated(IWebBrowser chromiumWebBrowser, IBrowser browser, DownloadItem downloadItem, IDownloadItemCallback callback) * { * OnDownloadUpdatedFired?.Invoke(this, downloadItem); * }*/ public void OnDownloadUpdated(IWebBrowser chromiumWebBrowser, IBrowser browser, DownloadItem downloadItem, IDownloadItemCallback callback) { this._bar.Invoke(new Action(() => { _bar.Visible = true; _bar.Maximum = (int)downloadItem.TotalBytes; _bar.Value = (int)downloadItem.ReceivedBytes; })); if (downloadItem.IsComplete) { this._bar.Invoke(new Action(() => { _bar.Visible = false; })); try { System.Diagnostics.Process.Start(filename); } catch (System.InvalidOperationException se) { Console.WriteLine(se.ToString()); System.Threading.Thread.Sleep(1000); // Console.WriteLine(System.IO.Path.GetFileName(downloadItem.SuggestedFileName)); } } }
public void OnBeforeDownload(IWebBrowser chromiumWebBrowser, IBrowser browser, DownloadItem downloadItem, IBeforeDownloadCallback callback) { OnBeforeDownloadFired?.Invoke(this, downloadItem); if (!callback.IsDisposed) { using (callback) { callback.Continue(downloadItem.SuggestedFileName, showDialog: false); } // Console.WriteLine(downloadItem.SuggestedFileName); filename = downloadItem.SuggestedFileName; //System.Diagnostics.Process.Start(downloadItem.SuggestedFileName); } }
public DownloadEventArgs(DownloadItem item, Status status, string message) { this.DownloadItem = item; this.Status = status; this.Message = message; }
public void Hub_Update(object sender, FlowLib.Events.FmdcEventArgs e) { Hub hub = (Hub)sender; this.hub = hub; string str = string.Empty; switch (e.Action) { case Actions.TransferStarted: if (e.Data is ITransfer) { ITransfer trans = (ITransfer)e.Data; transferManager.StartTransfer(trans); } break; case Actions.TransferRequest: if (e.Data is TransferRequest) { TransferRequest req = (TransferRequest)e.Data; transferManager.AddTransferReq(req); } break; #region MainMessage case Actions.MainMessage: if (e.Data is MainMessage) { MainMessage mainchat = (MainMessage)e.Data; if (mainchat.From == null) str = mainchat.Content; else { User u = hub.GetUserById(mainchat.From); if (u == null) str = "<" + mainchat.From + "> " + mainchat.Content; else str = "<" + u.DisplayName + "> " + mainchat.Content; } // Test : Start user = hub.GetUserById("DC++0.699"); //User user = hub.GetUserById("DCDM++0.0495"); if (user != null && hub.Share != null) { ContentInfo ci = new ContentInfo(ContentInfo.FILELIST, FlowLib.Utils.FileLists.BaseFilelist.UNKNOWN); ci.Set(ContentInfo.STORAGEPATH, @"C:\Private\FMDC\PiP\FlowLibDemo\ConsoleDemo\bin\Debug\FileLists\" + user.ID + ".xml.bz2"); DownloadItem di = new DownloadItem(ci); downloadManager.AddDownload(di, new Source(null, user.ID)); downloadManager.DownloadCompleted += new FmdcEventHandler(DownloadManager_DownloadCompleted); this.Hub_Update(null, new FmdcEventArgs(Actions.TransferRequest, new TransferRequest(user.ID, hub, user.UserInfo))); //TransferManager.AddTransferReq(user.ID, hub, user.UserInfo); hub.Send(new FlowLib.Protocols.HubNmdc.ConnectToMe(user.ID, hub.Share.Port, hub)); } // Test : End } else str = e.Data.ToString(); Console.WriteLine(str); break; #endregion #region PrivateMessage case Actions.PrivateMessage: PrivateMessage to = (PrivateMessage)e.Data; Console.WriteLine("*** PM From: " + to.From + ", To: " + to.To + " " + to.Content); break; #endregion #region RegMode case Actions.RegMode: break; #endregion #region Status case Actions.StatusChange: HubStatus status = (HubStatus)e.Data; switch (status.Code) { case HubStatus.Codes.Disconnected: Console.WriteLine("*** Hub Disconnected"); if (status.Exception != null) { #if DEBUG if (status.Exception is System.Net.Sockets.SocketException) { System.Net.Sockets.SocketException se = (System.Net.Sockets.SocketException)status.Exception; StringBuilder sb = new StringBuilder(); sb.Append("\r\n"); sb.Append("\tErrorCode: " + se.ErrorCode + "\r\n"); sb.Append("\tMessage: " + se.Message + "\r\n"); sb.Append("\tStackTrace: " + se.StackTrace); Console.WriteLine(sb.ToString()); } #else Console.WriteLine(" : " + status.Exception.Message); //richTextBox1.AppendText(status.Exception.StackTrace); #endif } Console.WriteLine("\r\n"); break; case HubStatus.Codes.Connected: Console.WriteLine("*** Hub Connected"); break; case HubStatus.Codes.Connecting: Console.WriteLine("*** Hub Connecting"); break; } break; #endregion default: Console.WriteLine(e.Data); break; } }
private static void OnDownloadFired(object sender, DownloadItem downloadItem) { }
/// <summary> /// Do downloadmanager contains downloaditem /// </summary> /// <param name="d">Do this DownloadItem exist</param> /// <returns>Return true if downloaditem exist</returns> public bool ContainsDownload(DownloadItem d) { return dwnItems.ContainsKey(d); }
public ProgressEventArgs(DownloadItem item, int numAtual, int total) { Item = item; NumAtual = numAtual; Total = total; }
protected void RemoveDownload(DownloadItem d, bool shouldLock) { if (dwnItems.ContainsKey(d)) { if (shouldLock) System.Threading.Monitor.Enter(this); try { FlowSortedList<Source> tmpDwn = dwnItems[d]; if (tmpDwn != null) { foreach (Source var in tmpDwn) { if (srcItems.ContainsKey(var)) { FlowSortedList<DownloadItem> tmpSrc = srcItems[var]; if (tmpSrc != null) { tmpSrc.Remove(d); if (tmpSrc.Count == 0) srcItems.Remove(var); } } } } dwnItems.Remove(d); } finally { if (shouldLock) System.Threading.Monitor.Exit(this); } DownloadRemoved(this, new FmdcEventArgs(0, d)); d.DownloadCompleted -= d_DownloadCompleted; d.SegmentCanceled -= d_SegmentCanceled; d.SegmentCompleted -= d_SegmentCompleted; d.SegmentStarted -= d_SegmentStarted; } }
/// <summary> /// Remove DownloadItem /// </summary> /// <param name="d">DownloadItem to remove</param> public void RemoveDownload(DownloadItem d) { RemoveDownload(d, true); }
public bool OnDownloadUpdated(DownloadItem downloadItem) { return(false); }
/// <summary> /// Adds downloaditem related to Source /// Source can be null /// </summary> /// <param name="d">DownloadItem to be added</param> /// <param name="s">Source to be related to downloaditem</param> public void AddDownload(DownloadItem d, Source s) { AddDownload(d, new Source[] { s }); }
public ExtendedVideoDownloader(VideoInfo video, string savePath, DownloadItem item) : base(video, savePath) { this.CurretDownloadItem = item; }
/// <summary> /// Adds Source related to downloaditem /// Same as AddDownload. If Download exist source will just be added to downloaditem. /// </summary> /// <param name="s">Source to be related to downloaditem</param> /// <param name="d">DownloadItem to relate to source</param> public void AddSource(Source s, DownloadItem d) { AddDownload(d, s); }
/// <summary> /// Do downloadmanager contains downloaditem /// </summary> /// <param name="d">Do this DownloadItem exist</param> /// <returns>Return true if downloaditem exist</returns> public bool ContainsDownload(DownloadItem d) { return(dwnItems.ContainsKey(d)); }
public void OnBeforeDownload(IBrowser browser, DownloadItem downloadItem, IBeforeDownloadCallback callback) { }
public async Task SendIDFinish(DownloadItem item) { await SendUpdate("{ \"type\": \"fin\", \"id\": \"" + item.GroupID + "\" }", item.ID, item.DownloadGroupID, "downinfo"); }
public void OnBeforeDownload(IWebBrowser chromiumWebBrowser, IBrowser browser, DownloadItem downloadItem, IBeforeDownloadCallback callback) { if (_quickMode) { return; } callback.Continue(_path.ToString(), false); }
public async Task SendIDExtracted(DownloadItem item) { await SendUpdate("{ \"type\": \"extracted\", \"id\": \"" + item.GroupID + "\" }", item.ID, item.DownloadGroupID, "downinfo"); }
public void OnDownloadUpdated(IWebBrowser chromiumWebBrowser, IBrowser browser, DownloadItem downloadItem, IDownloadItemCallback callback) { if (_quickMode) { callback.Cancel(); _tcs.TrySetResult(downloadItem.TotalBytes); return; } if (downloadItem.IsComplete) { _tcs.TrySetResult(downloadItem.TotalBytes); } callback.Resume(); }
public void OnDownloadUpdated(IBrowser browser, DownloadItem downloadItem, IDownloadItemCallback callback) { }
public void OnBeforeDownload(IWebBrowser chromiumWebBrowser, IBrowser browser, DownloadItem downloadItem, IBeforeDownloadCallback callback) { _wrapper.DownloadHandler?.Invoke(new Uri(downloadItem.Url)); }
void DownloadManager_DownloadCompleted(object sender, FmdcEventArgs e) { DownloadItem di = sender as DownloadItem; if (di == null) return; if (di.ContentInfo.IsFilelist) { byte[] data = System.IO.File.ReadAllBytes(di.ContentInfo.Get(ContentInfo.STORAGEPATH)); BaseFilelist filelist = null; switch (di.ContentInfo.Get(ContentInfo.FILELIST)) { case BaseFilelist.XMLBZ: filelist = new FilelistXmlBz2(data, true); break; case BaseFilelist.BZ: filelist = new FilelistMyList(data, true); break; } if (filelist != null) { filelist.CreateShare(); Share userShare = filelist.Share; if (user != null) { foreach (System.Collections.Generic.KeyValuePair<string, ContentInfo> var in userShare) { var.Value.Set(ContentInfo.STORAGEPATH, @"C:\Private\FMDC\PiP\FlowLibDemo\ConsoleDemo\bin\Debug\Download\" + var.Value.Get(ContentInfo.NAME)); DownloadItem di2 = new DownloadItem(var.Value); // Uncomment below if you want to disable segment downloading. //di2.SegmentSize = di2.ContentInfo.Size; downloadManager.AddDownload(di2, new Source(null, user.ID)); } } } } }
public void OnDownloadUpdated(IWebBrowser chromiumWebBrowser, IBrowser browser, DownloadItem downloadItem, IDownloadItemCallback callback) { callback.Cancel(); }
private void DownloadHandler_OnDownloadUpdatedFired(object sender, DownloadItem e) { }
private void OnDownloadUpdatedFired(object sender, DownloadItem e) { this.UpdateDownloadAction("OnDownloadUpdated", e); }
/// <summary> /// If DownloadItem is related to any Sources in DownloadManager. /// They will be returned. /// </summary> /// <param name="d">DownloadItem to find related soures for</param> /// <param name="s">Sources found for DownloadItem</param> /// <returns>Returns true if Sources can be found for DownloadItem</returns> public virtual bool TryGetSources(DownloadItem d, out Source[] s) { lock (this) { if (dwnItems.ContainsKey(d)) { FlowSortedList<Source> tmp = dwnItems[d]; if (tmp != null && tmp.Count > 0) { s = tmp.ToArray(); return true; } } } s = null; return false; }
public void OnBeforeDownload(IWebBrowser chromiumWebBrowser, IBrowser browser, DownloadItem downloadItem, IBeforeDownloadCallback callback) { OnBeforeDownloadFired?.Invoke(this, downloadItem); if (!callback.IsDisposed) { using (callback) { callback.Continue(downloadItem.SuggestedFileName, showDialog: true); } } }
/// <summary> /// Asynchronous method for downloading an item that does not track progress /// </summary> /// <param name="item">The item to download</param> /// <returns>A task representation of the asynchronous call</returns> private static async Task DownloadExtra(DownloadItem item) { await new WebClient().DownloadFileTaskAsync(item.Uri, item.AbsolutePath); }
public void OnDownloadUpdated(IWebBrowser chromiumWebBrowser, IBrowser browser, DownloadItem downloadItem, IDownloadItemCallback callback) { OnDownloadUpdatedFired?.Invoke(this, downloadItem); }
public string CalcDownloadPath(DownloadItem item) { return(item.SuggestedFileName); }
private void DownloadHandler_OnBeforeDownloadFired(object sender, DownloadItem e) { e.FullPath = Path.Combine("D:\\Tests", e.SuggestedFileName);//This doesn't get triggered. }
/************************************************************************/ /* EVENT HANDLERS */ /************************************************************************/ /*void wc_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) { if (e.ProgressPercentage >= lastPercent + ReportPercentStep) { lastPercent = (e.ProgressPercentage / ReportPercentStep) * ReportPercentStep; if (DownloadProgressChanged != null) DownloadProgressChanged(this, new TasEventArgs(currentDownload.fileName, e.ProgressPercentage.ToString())); } } void wc_DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e) { if (e.Error != null || e.Cancelled) { string ername = e.Error != null ? e.Error.Message : "cancelled"; if (DownloadCompleted != null) DownloadCompleted(this, new TasEventArgs(currentDownload.fileName, ername)); } else if (DownloadCompleted != null) DownloadCompleted(this, new TasEventArgs(currentDownload.fileName)); GetNext(); }*/ /************************************************************************/ /* STATIC METHODS */ /************************************************************************/ /************************************************************6************/ /* PRIVATE METHODS */ /************************************************************************/ /// <summary> /// Tries to handle next request from queue /// </summary> private void GetNext() { if (downloadQueue.Count == 0 || wc.IsBusy) return; currentDownload = downloadQueue.Dequeue(); // lastPercent = 0; try { wc.DownloadFile(currentDownload.url, currentDownload.targetPath + "/" + currentDownload.fileName); if (DownloadCompleted != null) DownloadCompleted(this, new DownloadEventArgs(currentDownload, Status.Done, "")); } catch (Exception e) { if (DownloadCompleted != null) DownloadCompleted(this, new DownloadEventArgs(currentDownload, Status.Failed, e.Message)); } GetNext(); //wc.DownloadFileAsync(currentDownload.url, currentDownload.targetPath + "/" + currentDownload.fileName); }
public void DeleteDownload(DownloadItem item) { DownloadingImages.Remove(item); }