Ejemplo n.º 1
0
        private bool CreateJob(int type, out BITS4.GUID jobGuid, out BITS4.IBackgroundCopyJob job)
        {
            var    mgr         = new BITS4.BackgroundCopyManager4_0();
            string randJobName = RandomString(15);

            switch (type)
            {
            case 0:
                mgr.CreateJob(randJobName, BITS4.BG_JOB_TYPE.BG_JOB_TYPE_DOWNLOAD, out jobGuid, out job);
                break;

            case 1:
                mgr.CreateJob(randJobName, BITS4.BG_JOB_TYPE.BG_JOB_TYPE_UPLOAD, out jobGuid, out job);
                break;

            case 2:
                mgr.CreateJob(randJobName, BITS4.BG_JOB_TYPE.BG_JOB_TYPE_UPLOAD_REPLY, out jobGuid, out job);
                break;

            default:
                jobGuid = new BITS4.GUID();
                job     = null;
                break;
            }

            return(job != null ? true : false);
        }
Ejemplo n.º 2
0
        private static bool ExecuteJob(BITS4.IBackgroundCopyJob job)
        {
            var jobIsFinal   = false;
            var jobCompleted = false;

            while (!jobIsFinal)
            {
                job.GetState(out var state);
                switch (state)
                {
                case BITS4.BG_JOB_STATE.BG_JOB_STATE_ERROR:
                    job.Cancel();
                    break;

                case BITS4.BG_JOB_STATE.BG_JOB_STATE_TRANSFERRED:
                    job.Complete();
                    jobCompleted = true;
                    break;

                case BITS4.BG_JOB_STATE.BG_JOB_STATE_CANCELLED:
                    jobIsFinal = true;
                    break;

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

                default:
                    break;
                }
            }

            return(jobCompleted ? true : false);
        }