Пример #1
0
        public void RemoveDownload(HttpFileDownloadTask task)
        {
            if (task == null)
            {
                throw new ArgumentNullException("task");
            }

            lock (SyncRoot) {
                if (disposed)
                {
                    return;
                }

                tasks.Remove(task);
            }
        }
Пример #2
0
        public HttpFileDownloadTask CreateDownloadTask(string url, object userState)
        {
            Uri uri;

            if (String.IsNullOrEmpty(url))
            {
                throw new ArgumentException("Cannot be null or empty", "url");
            }
            else if (!Uri.TryCreate(url, UriKind.Absolute, out uri))
            {
                throw new UriFormatException("url:  Is not a well formed Uri.");
            }

            string[] segments = uri.Segments;
            string   fileName = System.Web.HttpUtility.UrlDecode(segments[segments.Length - 1].Trim('/'));

            MD5 hasher = MD5.Create();

            byte[] hash = hasher.ComputeHash(
                Encoding.UTF8.GetBytes(url)
                );

            string urlHash = BitConverter.ToString(hash)
                             .Replace("-", String.Empty)
                             .ToLower();

            string remoteUri = url;
            string localPath = tmpDir + urlHash + Path.DirectorySeparatorChar + Hyena.StringUtil.EscapeFilename(fileName);

            HttpFileDownloadTask task = null;

            string [] parts = fileName.Split('.');
            if (parts.Length > 0 && downloader_types.ContainsKey(parts[parts.Length - 1]))
            {
                task = (HttpFileDownloadTask)Activator.CreateInstance(downloader_types[parts[parts.Length - 1]], remoteUri, localPath, userState);
            }
            else
            {
                task = new HttpFileDownloadTask(url, localPath, userState);
            }

            return(task);
        }
Пример #3
0
        public void RemoveDownload(HttpFileDownloadTask task)
        {
            if (task == null) {
                throw new ArgumentNullException ("task");
            }

            lock (SyncRoot) {
                if (disposed) {
                    return;
                }

                tasks.Remove (task);
            }
        }
Пример #4
0
        public HttpFileDownloadTask CreateDownloadTask(string url, object userState)
        {
            Uri uri;

            if (String.IsNullOrEmpty (url)) {
                throw new ArgumentException ("Cannot be null or empty", "url");
            } else if (!Uri.TryCreate (url, UriKind.Absolute, out uri)) {
                throw new UriFormatException ("url:  Is not a well formed Uri.");
            }

            string[] segments = uri.Segments;
            string fileName = System.Web.HttpUtility.UrlDecode (segments[segments.Length-1].Trim ('/'));

            MD5 hasher = MD5.Create ();

            byte[] hash = hasher.ComputeHash (
                Encoding.UTF8.GetBytes (url)
            );

            string urlHash = BitConverter.ToString (hash)
                                         .Replace ("-", String.Empty)
                                         .ToLower ();

            string remoteUri = url;
            string localPath = tmpDir + urlHash + Path.DirectorySeparatorChar + Hyena.StringUtil.EscapeFilename (fileName);

            HttpFileDownloadTask task = null;
            string [] parts = fileName.Split ('.');
            if (parts.Length > 0 && downloader_types.ContainsKey (parts[parts.Length - 1])) {
                task = (HttpFileDownloadTask) Activator.CreateInstance (downloader_types[parts[parts.Length - 1]], remoteUri, localPath, userState);
            } else {
                task = new HttpFileDownloadTask (url , localPath, userState );
            }

            return task;
        }
Пример #5
0
        private void TaskAddedAction(HttpFileDownloadTask task)
        {
            Feed parentFeed = null;
            FeedEnclosure enc = task.UserState as FeedEnclosure;

            if (enc != null) {
                lock (sync) {
                    parentFeed = enc.Item.Feed;

                    if (parentFeed != null && queued_downloads.ContainsKey (enc)) {
                        if (queued_downloads.Count == 0) {
                            download_handle.Reset ();
                        }

                        enc.DownloadStatus = FeedDownloadStatus.Pending;
                        //parentFeed.IncrementQueuedDownloadCount ();
                    }
                }
            }
        }
Пример #6
0
        private void DownloadTaskRemoved(FeedEnclosure enc, HttpFileDownloadTask task, bool decQueuedCount)
        {
            if (queued_downloads.ContainsKey (enc)) {
                queued_downloads.Remove (enc);
                task.Completed -= OnDownloadTaskCompletedHandler;

                if (decQueuedCount) {
                    //enc.Item.Feed.DecrementQueuedDownloadCount ();
                }

                if (queued_downloads.Count == 0) {
                    if (download_handle != null) {
                        download_handle.Set ();
                    }
                }
            }
        }