private void DownloadComplete() { DownloadCompleted?.Invoke(this, new EventArgs()); var lzma = WorkingPath + "\\javatemp.lzma"; var zip = WorkingPath + "\\javatemp.zip"; SevenZipWrapper.DecompressFileLZMA(lzma, zip); using (var extractor = ZipFile.Read(zip)) { extractor.ExtractAll(RuntimeDirectory, ExtractExistingFileAction.OverwriteSilently); } if (!File.Exists(RuntimeDirectory + "\\bin\\javaw.exe")) { try { DeleteDirectory(RuntimeDirectory); } catch { } throw new Exception("Failed Download"); } UnzipCompleted?.Invoke(this, new EventArgs()); }
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 OnDownloadCompleted(DeploymentFile file) { DownloadCompleted?.Invoke(new DownloadEventArgs { File = file, }); }
internal async Task <bool> _AddCacheRequest_Internal(NicoVideoCacheRequest req) { var nicoVideo = await MediaManager.GetNicoVideoAsync(req.RawVideoId); var div = nicoVideo.GetDividedQualityNicoVideo(req.Quality); if (div.IsCached) { if (req.IsRequireForceUpdate) { Debug.WriteLine($"{req.RawVideoId}<{req.Quality}> is already cached, but enable force update .(re-download)"); await RemoveCacheRequest(req.RawVideoId, req.Quality); } else { Debug.WriteLine($"{req.RawVideoId}<{req.Quality}> is already cached. (skip download)"); Requested?.Invoke(this, req); DownloadCompleted?.Invoke(this, req, div.CacheFilePath); return(false); } } using (var pendingVideoLockReleaser = await _CacheDownloadPendingVideosLock.LockAsync()) { _CacheDownloadPendingVideos.Add(req); } Requested?.Invoke(this, req); return(true); }
public void Download(Version version) { if (!m_blnIsDownloading) { m_blnIsDownloading = true; string strVersionString = version.ToString(3); //Required for SSL connections ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls; using (m_webClient = new WebClient()) { m_webClient.DownloadProgressChanged += (s, e) => DownloadProgressChanged?.Invoke(this, e); m_webClient.DownloadDataCompleted += (s, e) => { if (!e.Cancelled) { DownloadCompleted?.Invoke(this, e); s_logger.Trace("Download completed"); } else { s_logger.Trace("User canceled download"); } m_blnIsDownloading = false; }; m_webClient.DownloadDataAsync(GetDownloadUri(version)); } } }
void client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e) { m_webClient.Dispose(); m_webClient = null; DownloadCompleted?.Invoke(this, e); }
protected virtual async void OnDownloadCompleted(Download e) { await PodcastManager.Current.AddDownloadedEpisode(e.Source.GetMetadata()); DownloadCompleted?.Invoke(this, e); ExecutePendingDownload(); }
public override void OnReceive(Context context, Intent intent) { long id = intent.GetLongExtra(DownloadManager.ExtraDownloadId, -1); System.Console.WriteLine(string.Format("Received intent for {0}:\n", id)); if (DownloadManager.ActionDownloadComplete.Equals(intent.Action)) { if (downloadId == id) { var manager = DownloadManager.FromContext(context); var query = new DownloadManager.Query(); query.SetFilterById(id); ICursor cursor = manager.InvokeQuery(query); if (cursor.MoveToFirst()) { // get the status var columnIndex = cursor.GetColumnIndex(DownloadManager.ColumnStatus); var status = (DownloadStatus)cursor.GetInt(columnIndex); System.Console.WriteLine(string.Format(" Received status {0}\n", status)); if (status == Android.App.DownloadStatus.Successful) { DownloadCompleted?.Invoke(); } } } } }
private void WebClient_DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e) { if (e.Error != null) { Error = e.Error; } else { try { if (File.Exists(Paths[CurrentIndex])) { File.Delete(Paths[CurrentIndex]); } File.Move(Paths[CurrentIndex] + ".incomplete", Paths[CurrentIndex]); } catch (Exception ex) { Error = ex; return; } if (CurrentIndex + 1 >= Links.Length) { DownloadCompleted?.Invoke(this, EventArgs.Empty); Done = true; } else { CurrentIndex++; ProcessNext(); } } }
private void Download_StateChanged(object sender, DownloadStateChangedEventArgs e) { Download download = sender as Download ?? throw new ArgumentException(nameof(sender)); _log.Info($"Download {download.Id} state changed from {e.OldState} to {e.NewState}"); switch (e.NewState) { case DownloadState.Pending: _log.Info($"Download {download.Id} pending"); break; case DownloadState.Cancelled: _log.Info($"Download {download.Id} cancelled"); break; case DownloadState.Downloading: _log.Info($"Download {download.Id} downloading"); break; case DownloadState.Completed: DownloadCompleted?.Invoke(this, download); _log.Info($"Download {download.Id} completed"); break; case DownloadState.Error: _log.Info($"Download {download.Id} failed"); break; default: throw new ArgumentOutOfRangeException(); } }
private void OnDownloadCompleted() { // update flag m_IsUpdateReady = true; DownloadCompleted?.Invoke(this, EventArgs.Empty); }
public static void Download(Version version) { string strVersionString = version.ToString(3); if (version < NewVersionFormat) { strVersionString = version.ToString(2); } else { } using (m_webClient = new WebClient()) { m_webClient.DownloadProgressChanged += (s, e) => DownloadProgressChanged?.Invoke(s, e); m_webClient.DownloadDataCompleted += (s, e) => { if (!e.Cancelled) { DownloadCompleted?.Invoke(s, e); } else { Log.WriteLine("Download canceled", LogType.Debug); } }; m_webClient.DownloadDataAsync(new Uri($"{BaseUrl}/download/{strVersionString}/Spawn.HDT.DustUtility.zip")); } }
public string CheckJava(string binaryName) { var javapath = Path.Combine(RuntimeDirectory, "bin", binaryName); if (!File.Exists(javapath)) { string json = ""; var javaUrl = ""; using (var wc = new WebClient()) { //this line was added if (MRule.OSName == MRule.Linux) { return("java"); } json = wc.DownloadString(MojangServer.LauncherMeta); var job = JObject.Parse(json)[MRule.OSName]; javaUrl = job[MRule.Arch]?["jre"]?["url"]?.ToString(); if (string.IsNullOrEmpty(javaUrl)) { throw new PlatformNotSupportedException("Downloading JRE on current OS is not supported. Set JavaPath manually."); } Directory.CreateDirectory(RuntimeDirectory); } var lzmapath = Path.Combine(Path.GetTempPath(), "jre.lzma"); var zippath = Path.Combine(Path.GetTempPath(), "jre.zip"); var webdownloader = new WebDownload(); webdownloader.DownloadProgressChangedEvent += Downloader_DownloadProgressChangedEvent; webdownloader.DownloadFile(javaUrl, lzmapath); DownloadCompleted?.Invoke(this, new EventArgs()); SevenZipWrapper.DecompressFileLZMA(lzmapath, zippath); var z = new SharpZip(zippath); z.ProgressEvent += Z_ProgressEvent; z.Unzip(RuntimeDirectory); if (!File.Exists(javapath)) { throw new Exception("Failed Download"); } if (MRule.OSName != MRule.Windows) { IOUtil.Chmod(javapath, IOUtil.Chmod755); } } return(javapath); }
private void WebClient_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e) { if (!stopped) { DownloadCompleted?.Invoke(this); } }
public string CheckJava(string binaryName) { var javapath = Path.Combine(RuntimeDirectory, "bin", binaryName); if (!File.Exists(javapath)) { string json = ""; var WorkingPath = Path.Combine(Path.GetTempPath(), "temp_download_runtime"); if (Directory.Exists(WorkingPath)) { IOUtil.DeleteDirectory(WorkingPath); } Directory.CreateDirectory(WorkingPath); var javaUrl = ""; using (var wc = new WebClient()) { json = wc.DownloadString(MojangServer.LauncherMeta); var job = JObject.Parse(json)[MRule.OSName]; javaUrl = job[MRule.Arch]?["jre"]?["url"]?.ToString(); if (string.IsNullOrEmpty(javaUrl)) { throw new Exception("unsupport os"); } Directory.CreateDirectory(RuntimeDirectory); } var downloader = new WebDownload(); downloader.DownloadProgressChangedEvent += Downloader_DownloadProgressChangedEvent; downloader.DownloadFile(javaUrl, Path.Combine(WorkingPath, "javatemp.lzma")); var lzma = Path.Combine(WorkingPath, "javatemp.lzma"); var zip = Path.Combine(WorkingPath, "javatemp.zip"); SevenZipWrapper.DecompressFileLZMA(lzma, zip); var z = new SharpZip(zip); z.Unzip(RuntimeDirectory); if (!File.Exists(javapath)) { IOUtil.DeleteDirectory(WorkingPath); throw new Exception("Failed Download"); } if (MRule.OSName != "windows") { IOUtil.Chmod(javapath, IOUtil.Chmod755); } DownloadCompleted?.Invoke(this, new EventArgs()); } return(javapath); }
private void Process() { try { if (Info == null) { State = Status.GettingHeaders; GetHeaders(); aop.Post(delegate { DownloadInfoReceived.Raise(this, EventArgs.Empty); }, null); } var append = RemainingRangeStart > 0; var bytesRead = 0; var buffer = new byte[2 * 1024]; State = Status.SendingRequest; using (var response = RequestHelper.CreateRequestGetResponse(Info, RemainingRangeStart, BeforeSendingRequest, AfterGettingResponse)) { State = Status.GettingResponse; using (var responseStream = response.GetResponseStream()) using (var file = FileHelper.CheckFile(FullFileName, append)) { while (allowDownload && (bytesRead = responseStream.Read(buffer, 0, buffer.Length)) > 0) { State = Status.Downloading; file.Write(buffer, 0, bytesRead); TotalBytesReceived += bytesRead; speedBytesTotal += bytesRead; aop.Post(delegate { ProgressChanged.Raise(this, new ProgressChangedEventArgs(SpeedInBytes, this.Progress, TotalBytesReceived)); }, Progress); } } } if (RemainingRangeStart > Info.Length) { throw new Exception("Total bytes received overflows content length"); } if (TotalBytesReceived == Info.Length) { State = Status.Completed; DownloadCompleted.Raise(this, EventArgs.Empty); } else if (!allowDownload) { State = Status.Paused; } } catch (Exception ex) { State = Status.ErrorOccured; aop.Post(delegate { ErrorOccured.Raise(this, new ErrorEventArgs(ex)); }, null); } }
private void OnWebClientOnDownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e) { var webClient = (WebClient)sender; webClient.DownloadProgressChanged -= OnWebClientOnDownloadProgressChanged; webClient.DownloadDataCompleted -= OnWebClientOnDownloadDataCompleted; DownloadCompleted.SafeInvoke(this); }
/// <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; }
/// <summary> /// The method will be called by the OnStatusChanged method. /// </summary> /// <param name="e"></param> protected virtual void OnDownloadCompleted(DownloadCompletedEventArgs e) { if (e.Error != null && this.status != DownloadStatus.Canceled) { this.Status = DownloadStatus.Completed; } DownloadCompleted?.Invoke(this, e); }
private void Worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { if (image != null) { Status = "Download Completed"; } DownloadCompleted?.Invoke(null, EventArgs.Empty); }
public static void DownloadString(Uri location, Action <string> callback) { var data = context.DownloadString(location.AbsoluteUri); if (!string.IsNullOrEmpty(data)) { callback?.Invoke(data); DownloadCompleted?.Invoke(context, null); } }
public bool CheckStartNext() { if (clients.Count == 0) { DownloadCompleted.Invoke(this); File.Delete(Path.Combine(chapter.GetChapterRoot().Parent.FullName, "dl" + chapter.GetID())); return(true); } return(false); }
void OnDownloadCompleted(bool haserror) { if (DownloadCompleted != null) { DownloadCompleted.BeginInvoke(this, new DownloadEventArgs { HasError = haserror }, null, null); } }
private static void Wc_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e) { lock (QueueLocker) { IdleDownloaderQueue.Enqueue(sender as WebClient); } DownloadCompleted?.Invoke(sender, new DownloadCompletedEventArgs { Key = e.UserState as string, Result = e.Result }); }
public Download(Image image) { Status = "Download Completed"; this.Link = "Raw Image"; this.image = image; Thumbnail = ImageLoad.GetThumbnailImage(image, 100); Vault.Controller.AddImageToDownloadFolder(this.image); this.image = null; SD.Garbage.ClearRAM.Clear(); DownloadCompleted?.Invoke(null, EventArgs.Empty); }
public void PieceCompleted(Piece piece) { blockRequests.ClearBlocksForPiece(piece); foreach (var peer in peers) { peer.SendMessage(new HaveMessage(piece)); } if (!DataHandler.IncompletePieces().Any()) { DownloadCompleted?.Invoke(this, new EventArgs()); } }
public void OnDownloadUpdated(IBrowser browser, DownloadItem downloadItem, IDownloadItemCallback callback) { DownloadUpdated?.Invoke(this, new DownloadEventArgs(downloadItem)); if (downloadItem.IsComplete) { //System.Windows.MessageBox.Show("Download Completed"); DownloadCompleted?.Invoke(this, new DownloadEventArgs(downloadItem)); } }
private void Download() { Uri uri = new Uri(string.Format(uriFormat, version)); using (var client = new WebClient()) { client.DownloadProgressChanged += (sender, args) => DownloadProgressChanged?.Invoke(sender, args); client.DownloadFileCompleted += Unzip; client.DownloadFileCompleted += (sender, args) => DownloadCompleted?.Invoke(sender, args); client.DownloadFileAsync(uri, ZipFilePath); } }
private async Task Start(long range) { var request = (HttpWebRequest)WebRequest.Create(_source); request.Method = "GET"; request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:53.0) Gecko/20100101 Firefox/53.0"; request.Referer = @"http://reseton.pl/static/player/v612/jwplayer.flash.swf"; request.AddRange(range); try { using (var response = await request.GetResponseAsync()) { CurrentResponse = response; ContentLength = response.ContentLength; using (var responseStream = response.GetResponseStream()) { bool isDone = false; using (var fs = new FileStream(_destination, FileMode.Append, FileAccess.Write, FileShare.ReadWrite)) { while (_allowedToRun) { var buffer = new byte[_chunkSize]; var bytesRead = await responseStream.ReadAsync(buffer, 0, buffer.Length); if (bytesRead == 0) { isDone = true; break; } await fs.WriteAsync(buffer, 0, bytesRead); BytesWritten += bytesRead; DownloadProgressChanged?.Invoke(this, null); } await fs.FlushAsync(); } if (isDone) { DownloadCompleted?.Invoke(this, null); } } } } catch (Exception e) { Debug.Write("Download file exceptions: " + e.ToString()); ContentLength = -1; } }
private void DownloadComplete(object sender, DownloadDataCompletedEventArgs args) { try { DownloadCompleted?.Invoke(args.Result); } catch (Exception ex) { var token = Client.Headers[HttpRequestHeader.Authorization]; var im = ex.InnerException.Message; var x = ex; } }