Exemple #1
0
        private void EmitCompletionEvents(FeedDownloadError err)
        {
            switch (err)
            {
            case FeedDownloadError.None:
                SetStatus(TaskStatus.Succeeded);
                feed.DownloadStatus = FeedDownloadStatus.Downloaded;
                break;

            case FeedDownloadError.Canceled:
                SetStatus(TaskStatus.Cancelled);
                feed.DownloadStatus = FeedDownloadStatus.None;
                break;

            default:
                SetStatus(TaskStatus.Failed);
                feed.DownloadStatus = FeedDownloadStatus.DownloadFailed;
                break;
            }

            OnTaskCompleted(null, (Status == TaskStatus.Cancelled));

            if (mre != null)
            {
                mre.Set();
            }
        }
        public FeedDownloadCompletedEventArgs(Feed feed,
                                              FeedDownloadError error) : base(feed)
        {
            if (error < FeedDownloadError.None ||
                error > FeedDownloadError.DownloadSizeLimitExceeded)
            {
                throw new ArgumentException("error:  Value out of range");
            }

            this.error = error;
        }
        public FeedDownloadCompletedEventArgs(Feed feed,
                                               FeedDownloadError error)
            : base(feed)
        {
            if (error < FeedDownloadError.None ||
                error > FeedDownloadError.DownloadSizeLimitExceeded) {
                throw new ArgumentException ("error:  Value out of range");
            }

            this.error = error;
        }
Exemple #4
0
        // Deletes file associated with enclosure.
        // Does not cancel an active download like the WRP.
        public void DeleteFile()
        {
            lock (sync) {
                if (!String.IsNullOrEmpty(local_path) && File.Exists(local_path))
                {
                    try {
                        File.SetAttributes(local_path, FileAttributes.Normal);
                        File.Delete(local_path);
                        Directory.Delete(Path.GetDirectoryName(local_path));
                    } catch {}
                }

                LocalPath         = null;
                DownloadStatus    = FeedDownloadStatus.None;
                LastDownloadError = FeedDownloadError.None;
                Save();
            }
        }
Exemple #5
0
        public void SetFileImpl(string url, string path, string mimeType, string filename)
        {
            if (filename.EndsWith(".torrent", StringComparison.OrdinalIgnoreCase))
            {
                filename = filename.Substring(0, filename.Length - 8);
            }
            string local_enclosure_path = Item.Feed.LocalEnclosurePath;

            string full_path      = Path.Combine(path, filename);
            string new_local_path = Path.Combine(local_enclosure_path, filename);

            try {
                if (!Directory.Exists(path))
                {
                    throw new InvalidOperationException("Directory specified by path does not exist");
                }
                else if (!File.Exists(full_path))
                {
                    throw new InvalidOperationException(String.Format("File: {0}, does not exist", full_path));
                }

                if (!Directory.Exists(local_enclosure_path))
                {
                    Directory.CreateDirectory(local_enclosure_path);
                }

                if (File.Exists(new_local_path))
                {
                    int last_dot = new_local_path.LastIndexOf(".");

                    if (last_dot == -1)
                    {
                        last_dot = new_local_path.Length - 1;
                    }

                    string rep = String.Format("-{0}",
                                               Guid.NewGuid().ToString()
                                               .Replace("-", String.Empty)
                                               .ToLower()
                                               );

                    new_local_path = new_local_path.Insert(last_dot, rep);
                }

                File.Move(full_path, new_local_path);
                File.SetAttributes(new_local_path, FileAttributes.ReadOnly);

                try {
                    Directory.Delete(path);
                } catch {}
            } catch {
                LastDownloadError = FeedDownloadError.DownloadFailed;
                DownloadStatus    = FeedDownloadStatus.DownloadFailed;
                Save();
                throw;
            }

            LocalPath = new_local_path;
            Url       = url;
            MimeType  = mimeType;

            DownloadStatus    = FeedDownloadStatus.Downloaded;
            LastDownloadError = FeedDownloadError.None;
            Save();
        }
Exemple #6
0
        private void EmitCompletionEvents(FeedDownloadError err)
        {
            switch (err) {
                case FeedDownloadError.None:
                    SetStatus (TaskStatus.Succeeded);
                    feed.DownloadStatus = FeedDownloadStatus.Downloaded;
                    break;
                case FeedDownloadError.Canceled:
                    SetStatus (TaskStatus.Cancelled);
                    feed.DownloadStatus = FeedDownloadStatus.None;
                    break;
                default:
                    SetStatus (TaskStatus.Failed);
                    feed.DownloadStatus = FeedDownloadStatus.DownloadFailed;
                    break;
            }

            OnTaskCompleted (null, (Status == TaskStatus.Cancelled));

            if (mre != null) {
                mre.Set ();
            }
        }