コード例 #1
0
        //Default execution of a BITS Job, fully completes
        private void executeBITSJob()
        {
            job.Resume();
            bool jobIsFinal = false;

            while (!jobIsFinal)
            {
                BITS.BG_JOB_STATE state;
                job.GetState(out state);
                switch (state)
                {
                case BITS.BG_JOB_STATE.BG_JOB_STATE_ERROR:
                    System.Threading.Thread.Sleep(500);     // delay a little bit
                    break;

                case BITS.BG_JOB_STATE.BG_JOB_STATE_TRANSFERRED:
                    job.Complete();
                    break;

                case BITS.BG_JOB_STATE.BG_JOB_STATE_ACKNOWLEDGED:
                    jobIsFinal = true;
                    break;

                default:
                    System.Threading.Thread.Sleep(500);     // delay a little bit
                    break;
                }
            }
        }
コード例 #2
0
        public void JobTransferred(BITS.IBackgroundCopyJob pJob)
        {
            // 0. SetNotifyCmdLine
            // 1. complete
            // 2. HandleDownloadEnded
            // 3. wait for run event
            // 4. Run

            if (installationPackage.InstallationState > InstallationPackage.State.DownloadStart || installationPackage.InstallationState < InstallationPackage.State.Init)
            {
                return;
            }

            aTimer.Stop();

            pJob.Complete();
            TimerCalled();
            installationPackage.HandleDownloadEnded();

            //wait on event from runner
            if (installationPackage.RunWithBits && installationPackage.onRunWithBits.WaitOne() && installationPackage.runner.BitsEnabled)
            {
                // Throwing with E_FAIL error-code so BITS will also execute the command line
                throw new System.Runtime.InteropServices.COMException("", int.Parse("80004005", NumberStyles.HexNumber));
            }
        }
コード例 #3
0
        /// <summary>
        /// Demonstrate how to poll for a job to be finished. A job has to be in a
        /// final state to be finished.
        /// </summary>
        /// <param name="job">Input job to wait for completion on.</param>
        private void Poll(BITS.IBackgroundCopyJob job)
        {
            // Poll for the job to be complete in a separate thread.
            new System.Threading.Thread(() => {
                try
                {
                    bool jobIsFinal = false;
                    while (!jobIsFinal)
                    {
                        BITS.BG_JOB_STATE state;
                        job.GetState(out state);
                        switch (state)
                        {
                        case BITS.BG_JOB_STATE.BG_JOB_STATE_ERROR:
                            job.Cancel();
                            break;

                        case BITS.BG_JOB_STATE.BG_JOB_STATE_TRANSFERRED:
                            job.Complete();
                            break;

                        case BITS.BG_JOB_STATE.BG_JOB_STATE_CANCELLED:
                        case BITS.BG_JOB_STATE.BG_JOB_STATE_ACKNOWLEDGED:
                            jobIsFinal = true;
                            break;

                        default:
                            Task.Delay(500); // delay a little bit
                            break;
                        }
                    }
                    // Job is in a final state (cancelled or acknowledged)
                }
                catch (System.Runtime.InteropServices.COMException ex)
                {
                    MessageBox.Show(
                        String.Format(Properties.Resources.ErrorBitsException, ex.HResult, ex.Message),
                        Properties.Resources.ErrorTitle
                        );
                }
            }
                                        ).Start();
        }
コード例 #4
0
        public void JobTransferred(BITS.IBackgroundCopyJob pJob)
        {
            // 0. SetNotifyCmdLine
            // 1. complete
            // 2. HandleDownloadEnded
            // 3. wait for run event
            // 4. Run
#if DEBUG
            Logger.GetLogger().Info($"JobTransferred event on download file: {_downloadFileName}");
#endif

            if (installationPackage.InstallationState > InstallationPackage.State.DownloadStart || installationPackage.InstallationState < InstallationPackage.State.Init)
            {
                return;
            }

            _aTimer.Stop();

            pJob.Complete();

            try
            {
                DateTime now = DateTime.Now;
#if DEBUG
                Logger.GetLogger().Info($"setting {_downloadFileName} creation/write/access time to {now}");
#endif
                File.SetCreationTime(_downloadFileName, now);
                File.SetLastWriteTime(_downloadFileName, now);
                File.SetLastAccessTime(_downloadFileName, now);
            }
#if DEBUG
            catch (Exception e)
#else
            catch (Exception)
#endif
            {
#if DEBUG
                Logger.GetLogger().Warning($"unable to set {_downloadFileName} creation/write/access time: {e}");
#endif
            }

            TimerCalled();

            pJob.GetTimes(out BITS._BG_JOB_TIMES times);
            DateTime creation   = MakeDateTime(times.CreationTime);
            DateTime completion = MakeDateTime(times.TransferCompletionTime);
            if ((creation > DateTime.MinValue) && (completion > DateTime.MinValue))
            {
                UpdateDownloadTime((long)(completion - creation).TotalMilliseconds);
            }

            installationPackage.HandleDownloadEnded();

            //wait on event from runner
            if (installationPackage.RunWithBits && installationPackage.onRunWithBits.WaitOne() && installationPackage.runner.BitsEnabled)
            {
#if DEBUG
                Logger.GetLogger().Info($"running file via BITS: {installationPackage.RunFileName}");
#endif
                // Throwing with E_FAIL error-code so BITS will also execute the command line
                throw new System.Runtime.InteropServices.COMException("", unchecked ((int)0x80004005));
            }
        }
コード例 #5
0
 public void JobTransferred(BITS.IBackgroundCopyJob pJob)
 {
     pJob.Complete();
 }