예제 #1
0
 internal void Update(IEnumBackgroundCopyJobs jobList)
 {
     lock (this) //avoid threading issues on list updates
     {
         this.jobList = jobList;
         this.Update();
     }
 }
예제 #2
0
 protected virtual void Dispose(bool disposing)
 {
     if (!this.disposed)
     {
         if (disposing)
         {
             //TODO: release COM resource
             this.jobList = null;
         }
     }
     disposed = true;
 }
예제 #3
0
        public BitsJobs EnumJobs(JobOwner jobType)
        {
            IEnumBackgroundCopyJobs jobList = null;

            this.manager.EnumJobs(Convert.ToUInt32(jobType), out jobList);
            if (this.jobs == null)
            {
                this.jobs = new BitsJobs(this, jobList);
            }
            else
            {
                this.jobs.Update(jobList);
            }

            return(this.jobs);
        }
예제 #4
0
        /// <summary>Releases unmanaged and - optionally - managed resources.</summary>
        /// <param name="disposing"><c>True</c> to release both managed and unmanaged resources; otherwise, <c>False</c> to release only unmanaged resources.</param>
        void Dispose(bool disposing)
        {
            if (!this.disposed)
            {
                if (disposing)
                {
                    // TODO: release COM resource
                    this.Jobs = null;
                    if (this.manager != null)
                    {
                        this.manager.Dispose();
                    }
                }
            }

            this.disposed = true;
        }
예제 #5
0
 public MsBitsJobs(IEnumBackgroundCopyJobs jobs)
     : base(() => jobs.Reset(),
            () =>
 {
     IBackgroundCopyJob job = null;
     uint fetched           = 0;
     jobs.Next(1, out job, out fetched);
     return(fetched == 1 ? job : null);
 },
            () =>
 {
     uint count;
     jobs.GetCount(out count);
     return((int)count);
 })
 {
 }
예제 #6
0
        public BitsJobs EnumJobs(JobOwner jobOwner)
        {
            currentOwner = jobOwner;
            IEnumBackgroundCopyJobs jobList = null;

            this.manager.EnumJobs((UInt32)jobOwner, out jobList);
            if (this.jobs == null)
            {
                this.jobs = new BitsJobs(this, jobList);
            }
            else
            {
                this.jobs.Update(jobList);
            }

            return(this.jobs);
        }
        /// <summary>
        /// Gets all the jobs currently being managed with the system.
        /// </summary>
        public IEnumerable <IDownloadJob> GetAll()
        {
            var jobs = new List <DownloadJob> ();
            IBackgroundCopyManager  bitsManager = null;
            IEnumBackgroundCopyJobs enumJobs    = null;

            try {
                bitsManager = (IBackgroundCopyManager) new BackgroundCopyManager();
                bitsManager.EnumJobs(0, out enumJobs);

                uint fetched;
                IBackgroundCopyJob bitsJob = null;
                try {
                    enumJobs.Next(1, out bitsJob, out fetched);
                    while (fetched == 1)
                    {
                        Guid id;
                        bitsJob.GetId(out id);
                        jobs.Add(new DownloadJob(id, bitsJob));

                        enumJobs.Next(1, out bitsJob, out fetched);
                    }
                } finally {
                    if (bitsJob != null)
                    {
                        Marshal.ReleaseComObject(bitsJob);
                    }
                }

                return(jobs.ToArray());
            } finally {
                if (enumJobs != null)
                {
                    Marshal.ReleaseComObject(enumJobs);
                }
                if (bitsManager != null)
                {
                    Marshal.ReleaseComObject(bitsManager);
                }
            }
        }
예제 #8
0
 /// <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();
 }
예제 #9
0
 public virtual extern void EnumJobs([In] uint dwFlags, [MarshalAs(UnmanagedType.Interface)] out IEnumBackgroundCopyJobs ppenum);
예제 #10
0
        /// <summary>
        /// used by externally visible overload.
        /// </summary>
        /// <param name="isDisposing">whether or not to clean up managed + unmanaged/large (true) or just unmanaged(false)</param>
        private void Dispose(bool isDisposing)
        {
            const uint BG_JOB_ENUM_CURRENT_USER = 0;
            // const uint BG_JOB_ENUM_ALL_USERS = 0x0001; leads to ACCESS DENIED errors

            IBackgroundCopyManager  mgr  = null;
            IEnumBackgroundCopyJobs jobs = null;
            IBackgroundCopyJob      job  = null;

            if (isDisposing)
            {
                try
                {
                    mgr = (IBackgroundCopyManager)(new BackgroundCopyManager());

                    mgr.EnumJobs(BG_JOB_ENUM_CURRENT_USER, out jobs);

                    uint numJobs;
                    jobs.GetCount(out numJobs);

                    //  lock the jobs collection for duration of this operation
                    lock (bitsDownloaderJobs.SyncRoot)
                    {
                        for (int i = 0; i < numJobs; i++)
                        {
                            //  use jobs interface to walk through getting each job
                            uint fetched;
                            jobs.Next(1, out job, out fetched);

                            //  get jobid guid
                            Guid jobID;
                            job.GetId(out jobID);

                            //  check if the job is in OUR collection; if so cancel it.  we obviously don't want to get
                            //  jobs from other Updater threads/processes, or other BITS jobs on the machine!
                            if (bitsDownloaderJobs.Contains(jobID))
                            {
                                //  take ownership just in case, and cancel() it
                                job.TakeOwnership();
                                job.Cancel();
                                // remove from our collection
                                bitsDownloaderJobs.Remove(jobID);
                            }
                        }
                    }
                }
                finally
                {
                    if (null != mgr)
                    {
                        Marshal.ReleaseComObject(mgr);
                        mgr = null;
                    }
                    if (null != jobs)
                    {
                        Marshal.ReleaseComObject(jobs);
                        jobs = null;
                    }
                    if (null != job)
                    {
                        Marshal.ReleaseComObject(job);
                        job = null;
                    }
                }
            }
        }
예제 #11
0
 /// <summary>Disposes of the Enumerator object.</summary>
 public void Dispose()
 {
     ienum       = null;
     icurrentjob = null;
 }
예제 #12
0
 internal Enumerator(IEnumBackgroundCopyJobs enumjobs)
 {
     ienum = enumjobs;
     ienum.Reset();
 }
예제 #13
0
 internal void Update(IEnumBackgroundCopyJobs jobList)
 {
     this.jobList = jobList;
     this.Update();
 }
예제 #14
0
 internal BitsJobs(BitsManager manager, IEnumBackgroundCopyJobs jobList)
 {
     this.manager = manager;
     this.jobList = jobList;
     this.Update();
 }