/// <summary>
        /// Handle asyncCheckout
        /// </summary>
        private void HandleDownloadFileCompleted(object sender, DownloadFileCompletedEventArgs e)
        {
            // Exception was thrown during invokation, result is unavailable
            if (e.Error != null)
            {
                string szError = "DownloadFilesProgressChanged: " + e.Error.ToString() + "\r\n\r\n";
                textBoxResult.Text = szError;
                m_failed_count++;
                return;
            }

            string fileId = e.UserState.ToString();

            // Operation was cancelled, result is unavailable
            if (e.Cancelled)
            {
                return;
            }

            Item file = e.Result;

            if (file.isError())
            {
                string szError = "Fault: File '" + fileId + "'\r\n " + file.getErrorString() + "\r\n";
                textBoxResult.Text = szError;
                return;
            }

            string name = file.getProperty("filename");

            string resultText = textBoxResult.Text;

            resultText         = resultText + "Success: " + name + "\r\n";
            textBoxResult.Text = resultText;
        }
Exemplo n.º 2
0
        void HandlePlasmaServiceDownloadFileCompleted(object sender, DownloadFileCompletedEventArgs e)
        {
            var down = (TorrentDownload)e.UserState;

            if (e.Error != null || e.Cancelled)
            {
                Trace.TraceError("Error downloading {0}: {1}", down.Name, e.Error);
                down.Finish(false);
                return;
            }

            if (!e.Result || e.links == null || e.torrent == null || e.links.Count() == 0)
            {
                Trace.TraceWarning("Cannot download {0}, not registered or has no links", down.Name);
                down.Finish(false);
                return;
            }

            try
            {
                var tor = Torrent.Load(e.torrent);
                down.FileName = tor.Files[0].Path;
                //down.Length = (int)tor.Size;
                down.Length         = 1;//workaround for progress bars
                down.TypeOfResource = e.resourceType == ResourceType.Map ? DownloadType.MAP : DownloadType.MOD;


                // just 1 link, use normal webdownload
                if (e.links.Count() == 1 || e.links.Count(x => !x.Contains("springfiles.com")) == 1) // mirrors or mirros without jobjol = 1
                {
                    var wd = new WebFileDownload(e.links[0], GetDestPath(down.TypeOfResource, down.FileName), incomingFolder);
                    down.AddNeededDownload(wd);
                    down.Finish(true); // mark current torrent dl as complete - will wait for dependency
                    wd.Start();        // start dependent download
                }
                else
                {
                    var wd = new WebMultiDownload(e.links.Shuffle(), GetDestPath(down.TypeOfResource, down.FileName), incomingFolder, tor);
                    down.AddNeededDownload(wd);
                    down.Finish(true); // mark current torrent dl as complete - will wait for dependency
                    wd.Start();        // start dependent download
                }
                foreach (var dependency in e.dependencies)
                {
                    var dep = plasmaDownloader.GetResource(DownloadType.UNKNOWN, dependency);
                    if (dep != null)
                    {
                        down.AddNeededDownload(dep);
                    }
                }
            }
            catch (Exception ex)
            {
                Trace.TraceError("downloading torrent failed {0}", ex);
                down.Finish(false);
            }
        }
        private void OnDownloadCompleted(object sender, DownloadFileCompletedEventArgs e)
        {
            var downloadedPicture =
                DownloadablePictures.FirstOrDefault(elem => elem.PictureName == e.DownloadedFileName);

            if (downloadedPicture != null)
            {
                downloadedPicture.IsDownloaded = true;
            }
        }
        void ps_DownloadFileCompleted(object sender, DownloadFileCompletedEventArgs e)
        {
            if (e.Error != null || e.UserState == null)
            {
                return;
            }
            var ev = (TasSayEventArgs)e.UserState;

            foreach (string s in e.links)
            {
                ah.Respond(ev, s.Replace(" ", "%20"));
            }
        }
Exemplo n.º 5
0
        private void WhenCompleted(object?sender, DownloadFileCompletedEventArgs e)
        {
            TotalDownloaded++;
            InvokeDownloadProgressChangedEvent((double)TotalDownloaded / NeedToDownload, e.AverageSpeed);
            DownloadFileCompletedEvent?.Invoke(this, e);

            if (!(e.Success ?? false))
            {
                _retryFiles.Add(e.File);
                return;
            }

            if (!CheckFile)
            {
                return;
            }

            Check(e.File, ref _retryFiles);
        }
Exemplo n.º 6
0
        private void client_DownloadFileCompleted(object sender, DownloadFileCompletedEventArgs e)
        {
            if (e.Error == null)
            {
                lblStatus.Text = "Download completed.";

                // Get the SaveFileDialog that was passed in with the call.
                SaveFileDialog saveDialog = (SaveFileDialog)e.UserState;

                using (Stream stream = saveDialog.OpenFile())
                {
                    stream.Write(e.Result, 0, e.Result.Length);
                }
                lblStatus.Text = "File saved to " + saveDialog.SafeFileName;
            }
            else
            {
                lblStatus.Text = "Download failed.";
            }
        }
Exemplo n.º 7
0
        private void HandleDownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
        {
            if (e.Cancelled)
            {
                if (File.Exists(DestinationFilePath))
                {
                    try
                    {
                        File.Delete(DestinationFilePath);
                    }
                    catch
                    {
                        // ignored
                    }
                }

                DownloadFileCompletedEventArgs eva = new DownloadFileCompletedEventArgs(true);
                OnDownloadFileCompleted(eva);
            }
            else
            {
                DownloadFileCompletedEventArgs eva = new DownloadFileCompletedEventArgs();
                OnDownloadFileCompleted(eva);
            }
        }
Exemplo n.º 8
0
        private void BeginDownload(Uri downloadUri, string destinationFilePath)
        {
            try
            {
                OnDownloadFileStarting();

                sourceUri = downloadUri;
                DestinationFilePath = destinationFilePath;

                webClient.DownloadFileAsync(downloadUri, destinationFilePath);
            }
            catch (Exception ex)
            {
                DownloadFileCompletedEventArgs eva = new DownloadFileCompletedEventArgs(ex);
                OnDownloadFileCompleted(eva);
            }
        }
Exemplo n.º 9
0
        protected virtual void OnDownloadFileCompleted(DownloadFileCompletedEventArgs e)
        {
            EventHandler<DownloadFileCompletedEventArgs> handler = DownloadFileCompleted;

            if (handler != null)
                handler(this, e);
        }
Exemplo n.º 10
0
 private void HandleDownloadFileCompleted(object sender, DownloadFileCompletedEventArgs e)
 {
     ExecuteSafeInUi(() =>
     {
         if (e.Cancelled)
             ChangeStateToDownloadCanceled();
         else if (e.Error != null)
             ChangeStateToDownloadError(e.Error);
         else
             ChangeStateToDownloadSuccess();
     });
 }
Exemplo n.º 11
0
 protected void OnDownloadFileCompleted(object sender, DownloadFileCompletedEventArgs e)
 {
     DownloadFileCompleted?.Invoke(sender, e);
 }
        /// <summary>
        /// Handle asyncCheckout
        /// </summary>
        private void HandleDownloadFileCompleted(object sender, DownloadFileCompletedEventArgs e)
        {
            // Exception was thrown during invokation, result is unavailable
            if (e.Error != null)
            {
                string szError = "DownloadFilesProgressChanged: " + e.Error.ToString() + "\r\n\r\n";
                textBoxResult.Text = szError;
                m_failed_count++;
                return;
            }

            string fileId = e.UserState.ToString();

            // Operation was cancelled, result is unavailable
            if (e.Cancelled)
            {
                return;
            }

            Item file = e.Result;
            if (file.isError())
            {
                string szError = "Fault: File '" + fileId + "'\r\n " + file.getErrorString() + "\r\n";
                textBoxResult.Text = szError;
                return;
            }

            string name = file.getProperty("filename");

            string resultText = textBoxResult.Text;
            resultText = resultText + "Success: " + name + "\r\n";
            textBoxResult.Text = resultText;
        }