Inheritance: System.MarshalByRefObject, INotifyPropertyChanged
 public Exception Download(DownloadInfo downloadInfo)
 {
     _downloadThread = System.Threading.Thread.CurrentThread;
     _downloadInfo = downloadInfo;
     try
     {
         MMSDownload(downloadInfo.Url, downloadInfo.LocalFile);
     }
     catch (Exception ex)
     {
         if (!_connectionEstablished && !Cancelled)
         {
             try
             {
                 HTTPMMSDownload(downloadInfo.Url, downloadInfo.LocalFile);
             }
             catch (Exception ex2)
             {
                 return ex2;
             }
         }
         else
         {
             return ex;
         }
     }
     return null;
 }
        public Exception Download(DownloadInfo downloadInfo)
        {
            IDownload sourceFilter = null;

            try
            {
                downloadThread = System.Threading.Thread.CurrentThread;
                this.downloadResult = 0;
                this.downloadFinished = false;
                this.cancelled = false;

                sourceFilter = (IDownload)new MPUrlSourceSplitter();
                String url = UrlBuilder.GetFilterUrl(downloadInfo.Util, downloadInfo.Url);

                IDownload downloadFilter = (IDownload)sourceFilter;
                int result = downloadFilter.DownloadAsync(url, downloadInfo.LocalFile, this);
                // throw exception if error occured while initializing download
                Marshal.ThrowExceptionForHR(result);

                while (!this.downloadFinished)
                {
                    long total = 0;
                    long current = 0;
                    if (downloadFilter.QueryProgress(out total, out current) >= 0)
                    {
                        // succeeded or estimated value
                        downloadInfo.DownloadProgressCallback(total, current);
                    }

                    // sleep some time
                    System.Threading.Thread.Sleep(100);

                    if (this.cancelled)
                    {
                        downloadFilter.AbortOperation();
                        this.downloadFinished = true;
                        this.downloadResult = 0;
                    }
                }

                // throw exception if error occured while downloading
                Marshal.ThrowExceptionForHR(this.downloadResult);

                return null;
            }
            catch (Exception ex)
            {
                return ex;
            }
            finally
            {
                if (sourceFilter != null)
                {
                    Marshal.ReleaseComObject(sourceFilter);
                }
            }
        }
        public Exception Download(DownloadInfo downloadInfo)
        {
            HttpWebResponse response = null;
            try
            {
				downloadThread = System.Threading.Thread.CurrentThread;
                using (FileStream fs = new FileStream(downloadInfo.LocalFile, FileMode.Create, FileAccess.Write, FileShare.None))
                {
                    HttpWebRequest request = (HttpWebRequest)System.Net.WebRequest.Create(downloadInfo.Url);
                    request.Timeout = 15000;
                    request.UserAgent = OnlineVideoSettings.Instance.UserAgent;
                    request.Accept = "*/*";
                    request.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate");
                    response = (HttpWebResponse)request.GetResponse();
                                        
                    Stream responseStream;
                    if (response.ContentEncoding.ToLower().Contains("gzip"))
                        responseStream = new System.IO.Compression.GZipStream(response.GetResponseStream(), System.IO.Compression.CompressionMode.Decompress);
                    else if (response.ContentEncoding.ToLower().Contains("deflate"))
                        responseStream = new System.IO.Compression.DeflateStream(response.GetResponseStream(), System.IO.Compression.CompressionMode.Decompress);
                    else
                        responseStream = response.GetResponseStream();

                    long size = response.ContentLength;
                    int buffSize = 4096;
                    byte[] buffer = new byte[buffSize];
                    long totalRead = 0;
                    long readSize;
                    do
                    {
                        readSize = responseStream.Read(buffer, 0, buffSize);
                        totalRead += readSize;
                        fs.Write(buffer, 0, (int)readSize);
                        downloadInfo.DownloadProgressCallback(size, totalRead);
                    }
                    while (readSize > 0 && !Cancelled);

                    fs.Flush();
                    fs.Close();

                    return null;
                }
            }
            catch (Exception ex)
            {
                return ex;
            }
            finally
            {
                if (response != null) response.Close();
            }
        }
Beispiel #4
0
 public bool Contains(DownloadInfo dlInfo)
 {
     lock (_locker)
     {
         bool result = _currentDownloadsParallel.Any(c =>
                                                     (c.CurrentItem != null && c.CurrentItem.VideoInfo != null && c.CurrentItem.VideoInfo.VideoUrl == dlInfo.VideoInfo.VideoUrl) ||
                                                     (c.DownloadItems != null && c.DownloadItems.Any(i => i.VideoInfo.VideoUrl == dlInfo.VideoInfo.VideoUrl)));
         if (!result)
         {
             result = _currentDownloadsQueuedPerSite.Any(c => c.Value.Any(l =>
                                                                          (l.CurrentItem != null && l.CurrentItem.VideoInfo != null && l.CurrentItem.VideoInfo.VideoUrl == dlInfo.VideoInfo.VideoUrl) ||
                                                                          (l.DownloadItems != null && l.DownloadItems.Any(i => i.VideoInfo.VideoUrl == dlInfo.VideoInfo.VideoUrl))));
         }
         return(result);
     }
 }
 public static DownloadList Create(DownloadInfo currentItem)
 {
     DownloadList di = (DownloadList)CrossDomain.OnlineVideosAppDomain.Domain.CreateInstanceAndUnwrap(typeof(DownloadList).Assembly.FullName, typeof(DownloadList).FullName, false, System.Reflection.BindingFlags.CreateInstance | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic, null, null, null, null);
     di.CurrentItem = currentItem;
     return di;
 }
Beispiel #6
0
        public Exception Download(DownloadInfo downloadInfo)
        {
            HttpWebResponse response = null;

            try
            {
                _downloadThread = System.Threading.Thread.CurrentThread;
                using (FileStream fs = new FileStream(downloadInfo.LocalFile, FileMode.Create, FileAccess.Write, FileShare.None))
                {
                    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(downloadInfo.Url);
                    request.Timeout   = 15000;
                    request.UserAgent = OnlineVideoSettings.Instance.UserAgent;
                    request.Accept    = "*/*";
                    request.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate");
                    response = (HttpWebResponse)request.GetResponse();

                    Stream responseStream;
                    if (response.ContentEncoding.ToLower().Contains("gzip"))
                    {
                        responseStream = new System.IO.Compression.GZipStream(response.GetResponseStream(), System.IO.Compression.CompressionMode.Decompress);
                    }
                    else if (response.ContentEncoding.ToLower().Contains("deflate"))
                    {
                        responseStream = new System.IO.Compression.DeflateStream(response.GetResponseStream(), System.IO.Compression.CompressionMode.Decompress);
                    }
                    else
                    {
                        responseStream = response.GetResponseStream();
                    }

                    long   size      = response.ContentLength;
                    int    buffSize  = 4096;
                    byte[] buffer    = new byte[buffSize];
                    long   totalRead = 0;
                    long   readSize;
                    do
                    {
                        readSize   = responseStream.Read(buffer, 0, buffSize);
                        totalRead += readSize;
                        fs.Write(buffer, 0, (int)readSize);
                        downloadInfo.DownloadProgressCallback(size, totalRead);
                    }while (readSize > 0 && !Cancelled);

                    fs.Flush();
                    fs.Close();

                    return(null);
                }
            }
            catch (Exception ex)
            {
                return(ex);
            }
            finally
            {
                if (response != null)
                {
                    response.Close();
                }
            }
        }