Esempio n. 1
0
 public void Synchronize()
 {
     _data = new byte[0];
     _download = new HttpDownload(_parent, Channel.Link, Channel.Link);
     _download.DownloadProgress += new ProgressChangedEventHandler(DownloadProgress);
     _download.DownloadComplete += new RunWorkerCompletedEventHandler(DownloadComplete);
     _download.Start();
 }
Esempio n. 2
0
        public void Start(ChannelItem channelItem)
        {
            HttpDownload download = new HttpDownload(_parent, channelItem.Guid, channelItem.Enclosure.Url);
            download.ResponseReceived += new ProgressChangedEventHandler(ResponseReceived);
            download.DownloadProgress += new ProgressChangedEventHandler(this.DownloadProgress);
            download.DownloadComplete += new RunWorkerCompletedEventHandler(this.DownloadComplete);

            if (_downloads.Contains(download.Guid) == false)
            {
                string filename = Path.Combine(channelItem.Channel.GetDirectory(), channelItem.Enclosure.GetFilename());
                OdeoApplication.TraceMessage("Downloading file {0}...", channelItem.Enclosure.Url);

                _downloads.Add(download.Guid, download);
                download.Start(filename);
            }
        }
Esempio n. 3
0
        private void DownloadComplete(object sender, RunWorkerCompletedEventArgs e)
        {
            MemoryStream stream = null;
            RunWorkerCompletedEventArgs eventArgs = e;

            try
            {
                if (e.Cancelled == false && e.Error == null)
                {
                    if (_data != null)
                    {
                        stream = new MemoryStream(_data);
                        Channel.Process(stream);
                        Channel.Save();
                    }
                }
            }
            catch (Exception ex)
            {
                eventArgs = new RunWorkerCompletedEventArgs(e.Result, e.Cancelled, ex);
            }
            finally
            {
                this.OnSynchronized(this, eventArgs);

                // Dispose of the download helper and close the memory stream.
                if (_download != null)
                    _download = null;

                if (stream != null)
                    stream.Close();
            }
        }