public async Task <string[]> Download(params string[] uris) { if (Downloading) { throw new NotSupportedException("This downloader is already downloading!"); } Downloading = true; var files = new List <string>(); try { DownloadStarted?.Invoke(this, EventArgs.Empty); foreach (var uri in uris) { files.Add(await DownloadFile(uri)); } DownloadCompleted?.Invoke(this, EventArgs.Empty); } catch { files.Clear(); DownloadFailed?.Invoke(this, EventArgs.Empty); } Downloading = false; return(files.ToArray()); }
public void CancelDownload(DownloadHandle download) { var client = download.Client; client.Abort(download); DownloadStarted?.Invoke(this, new DownloadEventArgs(download, DownloadNotificationType.Abort)); }
public static void RegisterDownload(MusixSongResult Download, CancellationTokenSource cancellationToken = null) { lock (Downloads) { Downloads.Add(new KeyValuePair <MusixSongResult, CancellationTokenSource>(Download, cancellationToken)); new Thread(x => { DownloadStarted?.Invoke(Download); DownloadsChanged?.Invoke(); }).Start(); } }
/// <summary> /// Download map of a region you mention. We get two points at top left and bottom right /// </summary> /// <param name="lat_bgn">Latitude of top left point region</param> /// <param name="lng_bgn">Longitude of top left point region</param> /// <param name="lat_end">Latitude of bottom right point region</param> /// <param name="lng_end">Longitude of bottom right point region</param> /// <param name="MaxZoomLevel">Maximum zoom level to download tiles. Default value is 17</param> public async void DownloadMap(double lat_bgn, double lng_bgn, double lat_end, double lng_end, int MaxZoomLevel = 17) { AllDownloads = 0; Downloaded = 0; FailedDownloads = 0; //Calculate Total downloads number for (int z = 1; z <= MaxZoomLevel; z++) { TileCoordinate c_bgn = new TileCoordinate(lat_bgn, lng_bgn, z); var c1 = c_bgn.locationCoord(); TileCoordinate c_end = new TileCoordinate(lat_end, lng_end, z); var c2 = c_end.locationCoord(); var x_min = (int)c_bgn.x; var x_max = (int)c_end.x; var y_min = (int)c_bgn.y; var y_max = (int)c_end.y; for (int x = x_min; x <= x_max; x++) { for (int y = y_min; y <= y_max; y++) { AllDownloads++; } } } DownloadStarted?.Invoke(this, AllDownloads); //Start Download for (int z = 1; z <= MaxZoomLevel; z++) { TileCoordinate c_bgn = new TileCoordinate(lat_bgn, lng_bgn, z); var c1 = c_bgn.locationCoord(); TileCoordinate c_end = new TileCoordinate(lat_end, lng_end, z); var c2 = c_end.locationCoord(); var x_min = (int)c_bgn.x; var x_max = (int)c_end.x; var y_min = (int)c_bgn.y; var y_max = (int)c_end.y; for (int x = x_min; x <= x_max; x++) { for (int y = y_min; y <= y_max; y++) { String mapparams = "x_" + x + "-y_" + y + "-z_" + z; //http://mt0.google.com/vt/lyrs=m@405000000&hl=x-local&src=app&sG&x=43614&y=25667&z=16 await Download("http://mt" + ((x + y) % 4) + ".google.com/vt/lyrs=m@405000000&hl=x-local&&src=app&sG&x=" + x + "&y=" + y + "&z=" + z, "mah_" + mapparams + ".jpeg"); Downloaded++; } } } //Download Completed DownloadCompleted?.Invoke(this, true); AllDownloads = 0; }
public void DownloadAllImages(List <string> urls) { DownloadStarted?.Invoke(urls.Count); new Thread(() => { foreach (var url in urls) { DownloadImage(url); } }).Start(); }
private async Task AddDownloadOperation(NicoVideoCacheRequest req, DownloadOperation op) { using (var releaser = await _DownloadOperationsLock.LockAsync()) { _DownloadOperations.Add(req, op); ++CurrentDownloadTaskCount; } // ダウンロード開始イベントをトリガー DownloadStarted?.Invoke(this, req, op); }
internal void OnDownloadStarted(CachedImageEvents.DownloadStartedEventArgs e) { DownloadStarted?.Invoke(this, e); var downloadStartedCommand = DownloadStartedCommand; if (downloadStartedCommand != null && downloadStartedCommand.CanExecute(e)) { downloadStartedCommand.Execute(e); } }
public DownloadHandle DownloadItem(DownloadType downloadType, string downloadUri) { var downloadClients = _provider.GetServices <IDownloadClient>(); var clients = downloadClients.Where(d => d.DownloadTypes.Contains(downloadType)).ToArray(); var client = clients[_random.Next(0, clients.Length)]; var correlationId = Guid.NewGuid().ToString("N"); var download = new DownloadHandle(client, downloadType, downloadUri, correlationId); client.Download(download); DownloadStarted?.Invoke(this, new DownloadEventArgs(download, DownloadNotificationType.Start)); return(download); }
public void Download(string url) { // declare current download DownloadStarted.Invoke((object)url, new EventArgs()); // create filename string fileName = (Files.Count + 1).ToString().PadLeft(5, '0') + Path.GetExtension(url); // add to dictionary Files.TryAdd(url, Path.Combine(Location, fileName)); // download (async so we can tap into the progress meter) DownloadFileAsync(new Uri(url), Path.Combine(Location, fileName)); }
private void RunTask(BeatmapDownloadTask task) { Log.Verbose("Detect {name} {id} downloading", task.IsBeatmapSet ? "beatmapset" : "beatmap", task.Id); IBeatmapInfo beatmapInfo = null; try { Task <IBeatmapInfo> infoTask = task.IsBeatmapSet ? _beatmapProvider.LookupBySetIdAsync(task.Id) : _beatmapProvider.LookupByIdAsync(task.Id); beatmapInfo = infoTask.Result ?? throw new BeatmapNotFoundException(task.Id); DownloadStarted?.Invoke(this, new BeatmapDownloadEventArgs(beatmapInfo)); var option = new BeatmapDownloadOption(); if (DownloadProgressChanged != null) { option.Progress = new PropagateHandler(this, beatmapInfo); } var result = _beatmapProvider.DownloadAsync(beatmapInfo, option).Result; if (result.Exception != null) { throw result.Exception; } if (File.Exists(_process.MainModule?.FileName)) { Process.Start(_process.MainModule !.FileName, result.FilePath); } DownloadCompleted?.Invoke(this, new BeatmapDownloadEventArgs(beatmapInfo)); } catch (Exception e) { DownloadFailed?.Invoke(this, new BeatmapDownloadFailedEventArgs(beatmapInfo, e)); var fallbackUrl = task.IsBeatmapSet ? $"https://osu.ppy.sh/beatmapsets/{task.Id}" : $"https://osu.ppy.sh/b/{task.Id}"; Process.Start(fallbackUrl); } }
public async Task <List <string> > Download() { DownloadStarted?.Invoke(this, EventArgs.Empty); var tasks = _map.Select(x => CreateTask(x.Key, x.Value)).ToList(); await Task.WhenAll(tasks.ToArray()); var result = tasks.Select(x => x.Result).ToList(); DownloadComplited?.Invoke(this, new FilesDownloadEventArgs(result.ToArray())); return(result); }
/// <summary> /// Handles ScanRMDEvent. Invokes FlashSessionStarted, DownloadStarted, BlockFinished, DownloadEnded, /// FlashSessionEnded, or FirmwareStatusOrErrorReceived. /// </summary> /// <param name="eventType"></param> /// <param name="prmdData"></param> private void OnScanRmdEvent(short eventType, ref string prmdData) { var xdoc = XDocument.Parse(prmdData); var status = (StatusCode)ParseStatus(xdoc); var scannerId = ParseScannerId(xdoc); switch ((RmdEventType)eventType) { case RmdEventType.SessionStarted: { FlashSessionStarted?.Invoke(this, new FlashStartEventArgs(scannerId, status, ParseTotalRecords(xdoc))); break; } case RmdEventType.DownloadStarted: { DownloadStarted?.Invoke(this, new DownloadEventArgs(scannerId, status, ParseComponent(xdoc))); break; } case RmdEventType.BlockFinished: { BlockFinished?.Invoke(this, new DownloadEventArgs(scannerId, status, ParseComponent(xdoc), ParseProgress(xdoc))); break; } case RmdEventType.DownloadEnded: { DownloadEnded?.Invoke(this, new DownloadEventArgs(scannerId, status, ParseComponent(xdoc))); break; } case RmdEventType.SessionEnded: { FlashSessionEnded?.Invoke(this, new FirmwareEventArgs(scannerId, status)); break; } case RmdEventType.ErrorOrStatus: { FirmwareStatusOrErrorReceived?.Invoke(this, new FirmwareEventArgs(scannerId, status)); break; } } }
public static void StartDownload(Download down) { var t = new Thread(() => { _downloads.Add(down); DownloadStarted?.Invoke(down); for (int i = 0; i < down.Bytes.Length; i += GetDownloadSpeed()) { Thread.Sleep(1000); _downloads[_downloads.IndexOf(down)].Progress = (int)((float)(i / down.Bytes.Length) * 100); ProgressUpdate?.Invoke(_downloads.IndexOf(down), (int)((float)(i / down.Bytes.Length) * 100)); } ShiftOS.Objects.ShiftFS.Utils.WriteAllBytes(down.Destination, down.Bytes); _downloads.Remove(down); DownloadCompleted?.Invoke(down.Destination); }); t.IsBackground = true; t.Start(); }
public CrawlingQueueItem ChangeStatus(CrawlingStatuses status) { if (Status != status) { Status = status; switch (status) { case CrawlingStatuses.InProxyQueue: QueuedInProxyQueue?.Invoke(); break; case CrawlingStatuses.InLocalQueue: QueuedInLocalQueue?.Invoke(); break; case CrawlingStatuses.Downloading: DownloadStarted?.Invoke(); break; case CrawlingStatuses.Downloaded: DownloadCompleted?.Invoke(); break; case CrawlingStatuses.Processing: ProcessingStarted?.Invoke(); break; case CrawlingStatuses.Processed: ProcessingCompleted?.Invoke(); break; default: throw new NotSupportedException(); } } return(this); }
private void OnDownloadStarted(DownloadStartedEventArgs e) { Package.IsSaving = true; DownloadStarted?.Invoke(this, e); }
private void OnDownloadStarted(DownloadStartedEventArgs e) { DownloadStarted?.Invoke(this, e); }
protected virtual void OnDownloadStarted(DownloadEventArgs e) { DownloadStarted?.Invoke(this, e); }
internal static void Start(ProgressJob job) { DownloadStarted?.Invoke(job); }
private bool OnDownloadStarted(CancelEventArgs e) { DownloadStarted?.Invoke(this, e); return(e.Cancel); }
} // PayloadReceived private void FireDownloadStarted() { DownloadStarted?.Invoke(this, EventArgs.Empty); } // FireDownloadStarted
protected void OnDownloadStarted() { DownloadStarted?.Invoke(this); DownloadsUpdated?.Invoke(this); }
private void OnDownloadStarted() { DownloadStarted?.Invoke(this, new DownloadStartArgs { Tag = TagName }); }
} // SegmentDownloadCompleted #endregion #region OnEvent() methods protected virtual void OnDownloadStarted(object sender, DownloadStartedEventArgs e) { DownloadStarted?.Invoke(sender, e); } // OnDownloadStarted