Beispiel #1
0
        public void Initialize()
        {
            BitsManager bitsManager = new BitsManager();

            bitsManager.OnInterfaceError += new EventHandler <BitsInterfaceNotificationEventArgs>(bitsManager_OnInterfaceError);
            BitsJobs jobs     = bitsManager.EnumJobs(Owner);
            bool     foundJob = false;

            foreach (BitsJob job in jobs.Values)
            {
                if (job.DisplayName == Name)
                {
                    // if not transferring, then it is dangling so remove it
#warning Fix behaviour here
                    if (true) //job.State != JobState.Transferring) {
                    {
                        job.Cancel();
                    }
                    else
                    {
                        UnderlyingJob = job;
                        foundJob      = true;
                    }
                }
            }
            if (!foundJob)
            {
                UnderlyingJob = bitsManager.CreateJob(Name, JobType);
                OnCreate(UnderlyingJob);
            }
            UnderlyingJob.OnJobErrorEvent       += new EventHandler <JobErrorNotificationEventArgs>(UnderlyingJob_OnJobErrorEvent);
            UnderlyingJob.OnJobTransferredEvent += new EventHandler <JobNotificationEventArgs>(UnderlyingJob_OnJobTransferredEvent);
        }
Beispiel #2
0
        private BitsJob GetDownloadManifestJob()
        {
            if (_downloadJob == null)
            {
                string jobName = string.Format(
                    "{0} Patch Manifest",
                    _productName
                    );

                // delete all relevant jobs
                foreach (BitsJob job in _bitsManager.EnumJobs(JobOwner.CurrentUser).Values)
                {
                    if (job.DisplayName == jobName)
                    {
                        job.Cancel();
                    }
                }

                // if job is still null then create the job
                _downloadJob = _bitsManager.CreateJob(
                    jobName,
                    JobType.Download
                    );
                _downloadJob.NotificationFlags =
                    NotificationFlags.JobTransferred |
                    NotificationFlags.JobErrorOccured |
                    NotificationFlags.JobModified;
                _downloadJob.ProxySettings.ProxyUsage = ProxyUsage.AutoDetect;
                if (File.Exists(LocalPatchFile))
                {
                    try {
                        File.Delete(LocalPatchFile);
                    } catch {
                    }
                }
                _downloadJob.AddFile(
                    _patchFile.ToString(),
                    LocalPatchFile
                    );
                _downloadJob.Resume();

                AddEventListenersToJob(_downloadJob);
            }
            return(_downloadJob);
        }