Use the IBackgroundCopyManager interface to create transfer jobs, retrieve an enumerator object that contains the jobs in the queue, and to retrieve individual jobs from the queue.
Inheritance: IDisposable
Beispiel #1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            _manager = new BitsManager();
            _manager.EnumJobs(JobOwner.CurrentUser);

            foreach (var job in _manager.Jobs.Values)
                listBox1.Items.Add(job.DisplayName);
        }
Beispiel #2
0
 internal BitsJob(BitsManager manager, IBackgroundCopyJob job)
 {
     this.manager = manager;
     this.job = job;
     this.job2 = this.job as IBackgroundCopyJob2;
     ///store existing notification handler and route message to this as well
     ///otherwisse it may break system download jobs
     if (this.NotificationInterface != null)
     {
         this.notificationTarget = this.NotificationInterface;   //pointer to the existing one;
     }
     this.NotificationInterface = manager.NotificationHandler;
 }
Beispiel #3
0
        internal BitsJob(BitsManager manager, IBackgroundCopyJob job)
        {
            this.manager = manager;
            this.job     = job;
            this.job2    = this.job as IBackgroundCopyJob2;
            this.job3    = this.job as IBackgroundCopyJob3;
            this.job4    = this.job as IBackgroundCopyJob4;

            ///store existing notification handler and route message to this as well
            ///otherwise it may break system download jobs
            if (this.NotificationInterface != null)
            {
                this.notificationTarget = this.NotificationInterface;   //pointer to the existing one;
            }
            this.NotificationInterface = manager.NotificationHandler;   //notification interface will be disabled when NotifyCmd is set
        }
Beispiel #4
0
        /// <summary>Initializes a new instance of the <see cref="BitsJob" /> class.</summary>
        /// <param name="manager">The manager for the BITS.</param>
        /// <param name="job">The current job.</param>
        internal BitsJob(BitsManager manager, IBackgroundCopyJob job)
        {
            this.manager = manager;
            this.Job = job;
            this.job2 = this.Job as IBackgroundCopyJob2;
            this.job3 = this.Job as IBackgroundCopyJob3;
            this.job4 = this.Job as IBackgroundCopyJob4;

            // store existing notification handler and route message to this as well otherwise it may break system
            // download jobs
            if (this.NotificationInterface != null)
            {
                this.NotificationTarget = this.NotificationInterface; // pointer to the existing one;
            }

            this.NotificationInterface = manager.NotificationHandler;

            // notification interface will be disabled when NotifyCmd is set
        }
        private bool DownloadMovies() {
            using (var bitsManager = new BitsManager()) {
                bitsManager.OnInterfaceError += (sender, args) => _logger.Error("BITS error: {0}\n{1}", args.Message, args.Description);

                if (CheckRunningJob(bitsManager)) {
                    return false;
                }

                var moviesToDownload = _movies
                    .Where(m => string.IsNullOrEmpty(m.LocalPath) || !File.Exists(m.LocalPath))
                    .Take(200)
                    .ToList();

                if (moviesToDownload.Any()) {
                    var job = bitsManager.CreateJob("AerialForWindows", JobType.Download);
                    job.Priority = JobPriority.Low;
                    job.MinimumRetryDelay = 5 * 60; // 5 minutes
                    job.NoProgressTimeout = 30 * 60; // 30 minutes

                    foreach (var movie in moviesToDownload) {
                        var localPath = GetLocalPathForMovie(movie);
                        movie.LocalPath = localPath;
                        job.AddFile(movie.DownloadUrl, localPath);
                    }

                    job.Resume();
                    Settings.Instance.BitsJobId = job.JobId;
                    Settings.Instance.Save();

                    _logger.Debug($"Startet download of {moviesToDownload.Count} files");

                    return true;
                }
                return false;
            }
        }
Beispiel #6
0
 public BitsUrlDownloader(string applicationName)
 {
     manager = new BitsManager();
     this.applicationName = applicationName;
 }
Beispiel #7
0
 internal BitsNotification(BitsManager manager)
 {
     this.manager = manager;
 }
 /// <summary>Initializes a new instance of the <see cref="BitsJobsDictionary" /> class.</summary>
 /// <param name="manager">The manager.</param>
 /// <param name="jobList">The job list.</param>
 internal BitsJobsDictionary(BitsManager manager, IEnumBackgroundCopyJobs jobList)
 {
     this.manager = manager;
     this.Jobs    = jobList;
     this.Update();
 }
        // only required for initialization

        /// <summary>Initializes a new instance of the <see cref="BitsJobsDictionary" /> class.</summary>
        /// <param name="manager">The manager.</param>
        internal BitsJobsDictionary(BitsManager manager)
        {
            this.manager = manager;
        }
Beispiel #10
0
 /// <summary>Initializes a new instance of the <see cref="BitsNotification" /> class.</summary>
 /// <param name="manager">The manager.</param>
 internal BitsNotification(BitsManager manager)
 {
     this.manager = manager;
 }
Beispiel #11
0
 internal BitsJobs(BitsManager manager, IEnumBackgroundCopyJobs jobList)
 {
     this.manager = manager;
     this.jobList = jobList;
     this.Update();
 }
Beispiel #12
0
 //only required for initialization
 internal BitsJobs(BitsManager manager)
 {
     this.manager = manager;
 }
Beispiel #13
0
        private void Form1_Load(object sender, EventArgs e)
        {
            if (!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\Downloads"))
                Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\Downloads");

            _downloadManager = new BitsManager();
            _downloadManager.OnJobModified += downloadManager_OnJobModified;
            _downloadManager.OnJobTransferred += downloadManager_OnJobTransferred;
            _downloadManager.EnumJobs(JobOwner.CurrentUser);

            foreach (var job in _downloadManager.Jobs.Values)
            {
                if (job.State == JobState.Transferred)
                    job.Complete();
                else
                    AddJobFlags(job);
            }

            _colIDs = new ColumnIDs(dataGridView1);

            dataGridView1.Rows.AddRange(GetDownloadJobsAsRows().ToArray());
        }
 private static bool CheckRunningJob(BitsManager bitsManager) {
     if (Settings.Instance.BitsJobId.HasValue) {
         BitsJob runningJob;
         if (bitsManager.EnumJobs().TryGetValue(Settings.Instance.BitsJobId.Value, out runningJob)) {
             if (runningJob.State == JobState.Transferred) {
                 _logger.Debug("Download completed");
                 Settings.Instance.BitsJobId = null;
                 Settings.Instance.Save();
                 runningJob.Complete();
             } else if (runningJob.State == JobState.Error) {
                 var error = runningJob.Error;
                 _logger.Error($"Download of {error.File.RemoteName} failed: {error.Description}\n{error.ContextDescription}");
                 Settings.Instance.BitsJobId = null;
                 Settings.Instance.Save();
                 runningJob.Cancel();
             } else if (runningJob.State == JobState.TransientError) {
                 var error = runningJob.Error;
                 _logger.Warn("Download of {0} is failing: {1}\n{2}", error.File.RemoteName, error.Description,
                     error.ContextDescription);
             } else if (runningJob.State == JobState.Transferring) {
                 var progress = runningJob.Progress;
                 _logger.Debug(
                     $"Download is in progress (files {progress.FilesTransferred} of {progress.FilesTotal}, bytes {progress.BytesTransferred} of {progress.BytesTotal})");
             }
             return true;
         } else {
             Settings.Instance.BitsJobId = null;
             Settings.Instance.Save();
         }
     }
     return false;
 }
 public static void CancelRunningJob() {
     if (Settings.Instance.BitsJobId.HasValue) {
         using (var bitsManager = new BitsManager()) {
             BitsJob runningJob;
             if (bitsManager.EnumJobs().TryGetValue(Settings.Instance.BitsJobId.Value, out runningJob)) {
                 runningJob.Cancel();
             }
         }
         Settings.Instance.BitsJobId = null;
         Settings.Instance.Save();
     }
 }