コード例 #1
0
ファイル: InternetUtils.cs プロジェクト: muhliz25/cs-codebook
        /* Methode zum asynchronen Download einer Datei */
        public void DownloadAsync(string url, Stream destStream, int blockSize,
                                  DownloadProgress downloadProgress, DownloadEnd downloadEnd)
        {
            // Das Download-Status-Objekt, das über das Status-
            // Feld des asynchronen Aufrufs weitergegeben wird,
            // erzeugen und initialisieren
            DownloadStatus downloadStatus = new DownloadStatus();

            downloadStatus.BlockSize        = blockSize;
            downloadStatus.ReadBuffer       = new Byte[blockSize];
            downloadStatus.DownloadProgress = downloadProgress;
            downloadStatus.DownloadEnd      = downloadEnd;
            downloadStatus.DestStream       = destStream;
            downloadStatus.manualResetEvent = new ManualResetEvent(false);
            downloadStatus.manualResetEvent.Reset();

            // WebRequest-Instanz für den Download erzeugen
            downloadStatus.Request = WebRequest.Create(url);

            // Die Antwort asynchron abfragen
            IAsyncResult asyncResult = (IAsyncResult)downloadStatus.Request.BeginGetResponse(
                new AsyncCallback(ResponseCallback), downloadStatus);

            //downloadStatus.manualResetEvent.WaitOne();
        }
コード例 #2
0
ファイル: InternetUtils.cs プロジェクト: muhliz25/cs-codebook
 /* Konstruktor */
 public Download(string url, Stream destStream, int blockSize,
                 DownloadProgress downloadProgress, DownloadEnd downloadEnd,
                 DownloadError downloadError)
 {
     this.Url              = url;
     this.BlockSize        = blockSize;
     this.DownloadProgress = downloadProgress;
     this.DownloadEnd      = downloadEnd;
     this.DestStream       = destStream;
     this.DownloadError    = downloadError;
 }
コード例 #3
0
ファイル: InternetUtils.cs プロジェクト: muhliz25/cs-codebook
        /* Methode zum synchronen Download einer Datei */
        public void DownloadSync(string url, Stream destStream, int blockSize,
                                 DownloadProgress downloadProgress, DownloadEnd downloadEnd,
                                 DownloadError downloadError)
        {
            // Download-Objekt erzeugen und initialisieren
            Download download = new Download(url, destStream, blockSize,
                                             downloadProgress, downloadEnd, downloadError);

            // Download synchron starten
            download.PerformDownload();
        }
コード例 #4
0
 /* Konstruktor */
 public Download(string url, Stream destStream, int blockSize,
     DownloadProgress downloadProgress, DownloadEnd downloadEnd,
     DownloadError downloadError)
 {
     this.Url = url;
     this.BlockSize = blockSize;
     this.DownloadProgress = downloadProgress;
     this.DownloadEnd  = downloadEnd;
     this.DestStream = destStream;
     this.DownloadError = downloadError ;
 }
コード例 #5
0
        /* Methode zum synchronen Download einer Datei */
        public void DownloadSync(string url, Stream destStream, int blockSize,
            DownloadProgress downloadProgress, DownloadEnd downloadEnd,
            DownloadError downloadError)
        {
            // Download-Objekt erzeugen und initialisieren
            Download download = new Download(url, destStream, blockSize,
                downloadProgress, downloadEnd, downloadError);

            // Download synchron starten
            download.PerformDownload();
        }
コード例 #6
0
        /* Methode zum asynchronen Download einer Datei */
        public void DownloadAsync(string url, Stream destStream, int blockSize, 
            DownloadProgress downloadProgress, DownloadEnd downloadEnd,
            DownloadError downloadError)
        {
            // Download-Objekt erzeugen und initialisieren
            Download download = new Download(url, destStream, blockSize,
                downloadProgress, downloadEnd, downloadError);

            // Thread für den Download starten
            Thread downloadThread = new Thread(new ThreadStart(download.PerformDownload));
            downloadThread.Start();
        }
コード例 #7
0
ファイル: InternetUtils.cs プロジェクト: muhliz25/cs-codebook
        /* Methode zum asynchronen Download einer Datei */
        public void DownloadAsync(string url, Stream destStream, int blockSize,
                                  DownloadProgress downloadProgress, DownloadEnd downloadEnd,
                                  DownloadError downloadError)
        {
            // Download-Objekt erzeugen und initialisieren
            Download download = new Download(url, destStream, blockSize,
                                             downloadProgress, downloadEnd, downloadError);

            // Thread für den Download starten
            Thread downloadThread = new Thread(new ThreadStart(download.PerformDownload));

            downloadThread.Start();
        }
コード例 #8
0
        private void Completed(object sender, AsyncCompletedEventArgs e)
        {
            sw.Reset();

            if (e.Cancelled == true)
            {
                MessageBox.Show("Download has been canceled.");
            }
            else
            {
                Debug.WriteLine("Download completed!");
                DownloadEnd?.Invoke(this, EventArgs.Empty);
            }
        }
コード例 #9
0
ファイル: InternetUtils.cs プロジェクト: muhliz25/cs-codebook
        /* Methode zum synchronen Download einer Datei */
        public void DownloadSync(string url, Stream destStream, int blockSize,
                                 DownloadProgress downloadProgress, DownloadEnd downloadEnd)
        {
            // WebRequest-Instanz für den Download erzeugen
            WebRequest request = WebRequest.Create(url);

            // Die Antwort anfordern
            WebResponse response = request.GetResponse();
            long        fileSize = response.ContentLength;

            // Den Antwort-Stream ermitteln
            Stream responseStream = response.GetResponseStream();

            // Stream blockweise lesen und in den Zielstream schreiben
            int bytesRead      = 0;
            int totalBytesRead = 0;

            byte[] buffer = new byte[blockSize];
            do
            {
                bytesRead       = responseStream.Read(buffer, 0, blockSize);
                totalBytesRead += bytesRead;
                destStream.Write(buffer, 0, bytesRead);

                // Fortschritt melden
                if (downloadProgress != null)
                {
                    downloadProgress(DownloadState.ReadingData, totalBytesRead, fileSize);
                }
            } while (bytesRead > 0);

            // Den Response-Stream und das WebResponse-Objekt schließen
            responseStream.Close();
            response.Close();

            // Ende des Download melden
            if (downloadEnd != null)
            {
                downloadEnd(destStream);
            }
        }
コード例 #10
0
ファイル: Repository.cs プロジェクト: aegisarma3/chimera
        private Task <bool> RunSyncItem(Manifest.SyncItem f,
                                        bool verify, bool simulate,
                                        DownloadProgressChanged dpc, DownloadEnd de, DownloadMessage dm,
                                        CancellationTokenSource cts,
                                        string overrideDestination = null)
        {
            switch (f.type)
            {
            case "rsync":
                RSyncDownloader dd = new RSyncDownloader(this);
                dd.appPath         = AppPath;
                dd.tmpPath         = TmpPath;
                dd.VerifyChecksums = verify;
                dd.Simulate        = simulate;
                return(dd.Download(LatestManifest.rsyncUrl + "/" + f.name, f, RootPath,
                                   dpc, de, dm, cts, overrideDestination));

            case "delete":
                return(Task <bool> .Run(() =>
                {
                    if (f.name.EndsWith("/") && Directory.Exists(RootPath + "/" + f.name))
                    {
                        dm.Invoke("Deleting directory " + f.name);
                        Directory.Delete(RootPath + "/" + f.name, true);
                    }
                    else if (File.Exists(RootPath + "/" + f.name))
                    {
                        dm.Invoke("Deleting file " + f.name);
                        File.Delete(RootPath + "/" + f.name);
                    }
                    return true;
                }));

            default:
                return(null);
            }
        }
コード例 #11
0
ファイル: Repository.cs プロジェクト: aegisarma3/chimera
        private Task<bool> RunSyncItem(Manifest.SyncItem f,
            bool verify, bool simulate,
            DownloadProgressChanged dpc, DownloadEnd de, DownloadMessage dm,
            CancellationTokenSource cts,
            string overrideDestination = null)
        {
            switch (f.type)
            {
                case "rsync":
                    RSyncDownloader dd = new RSyncDownloader(this);
                    dd.appPath = AppPath;
                    dd.tmpPath = TmpPath;
                    dd.VerifyChecksums = verify;
                    dd.Simulate = simulate;
                    return dd.Download(LatestManifest.rsyncUrl + "/" + f.name, f, RootPath,
                        dpc, de, dm, cts, overrideDestination);

                case "delete":
                    return Task<bool>.Run(() =>
                    {
                        if (f.name.EndsWith("/") && Directory.Exists(RootPath + "/" + f.name)) {
                            dm.Invoke("Deleting directory " + f.name);
                            Directory.Delete(RootPath + "/" + f.name, true);
                        } else if (File.Exists(RootPath + "/" + f.name)) {
                            dm.Invoke("Deleting file " + f.name);
                            File.Delete(RootPath + "/" + f.name);
                        }
                        return true;
                    });

                default:
                    return null;
            }
        }
コード例 #12
0
 public static void OnDownloadEnd(object sender, DownloadEventArgs ev) => DownloadEnd?.Invoke(sender, ev);
コード例 #13
0
 private void OnDownloadEnd(DownloadEndEventArgs e)
 {
     try { DownloadEnd?.Invoke(this, e); } catch { }
 }