Пример #1
0
        private void SetJobProperties(BITS.IBackgroundCopyJob job)
        {
            //TODO  - BITS_JOB_TRANSFER_POLICY = BITS_JOB_TRANSFER_POLICY_ALWAYS

            if (job is BITS5.IBackgroundCopyJob5 job5)
            {
                var value = new BITS5.BITS_JOB_PROPERTY_VALUE
                {
                    Enable = 1
                };
                job5.SetProperty(BITS5.BITS_JOB_PROPERTY_ID.BITS_JOB_PROPERTY_DYNAMIC_CONTENT, value);

                var value_high_perf = new BITS5.BITS_JOB_PROPERTY_VALUE
                {
                    Enable = 0
                };
                job5.SetProperty(BITS5.BITS_JOB_PROPERTY_ID.BITS_JOB_PROPERTY_HIGH_PERFORMANCE, value_high_perf);
            }

            job.SetPriority(BITS.BG_JOB_PRIORITY.BG_JOB_PRIORITY_FOREGROUND);
            job.SetMinimumRetryDelay(RETRY_DELAY_SECONDS);
        }
Пример #2
0
        public void SetJobProperties(BITS.IBackgroundCopyJob job)
        {
            var job2           = (BITS.IBackgroundCopyJob2)job;    // Job2 exists on all supported version of Windows.
            var job5           = job as BITS5.IBackgroundCopyJob5; // Job5 will be null on, e.g., Windows 7 and earlier.
            var jobHttpOptions = job as BITS4.IBackgroundCopyJobHttpOptions;

            if (job5 != null)
            {
                // Set the job properties.
                var costs = _jobCosts;
                if (costs.HasValue)
                {
                    var value = new BITS5.BITS_JOB_PROPERTY_VALUE();
                    value.Dword = (UInt32)costs.Value;
                    job5.SetProperty(BITS5.BITS_JOB_PROPERTY_ID.BITS_JOB_PROPERTY_ID_COST_FLAGS, value);
                }

                var isDynamic = _jobIsDynamic;
                if (isDynamic.HasValue)
                {
                    var value = new BITS5.BITS_JOB_PROPERTY_VALUE();
                    value.Enable = isDynamic.Value ? 1 : 0;
                    job5.SetProperty(BITS5.BITS_JOB_PROPERTY_ID.BITS_JOB_PROPERTY_DYNAMIC_CONTENT, value);
                }

                var isHighPerformance = _jobIsHighPerformance;
                if (isHighPerformance.HasValue)
                {
                    var value = new BITS5.BITS_JOB_PROPERTY_VALUE();
                    value.Enable = isHighPerformance.Value ? 1 : 0;
                    job5.SetProperty(BITS5.BITS_JOB_PROPERTY_ID.BITS_JOB_PROPERTY_HIGH_PERFORMANCE, value);
                }
            }

            if (jobHttpOptions != null)
            {
                var text = _uiCustomHeadersAll.Text;
                if (!String.IsNullOrWhiteSpace(text))
                {
                    jobHttpOptions.SetCustomHeaders(text);
                }
            }

            var priority = _jobPriority;

            if (priority.HasValue)
            {
                job.SetPriority(priority.Value);
            }

            var authScheme = _authScheme;

            if (authScheme.HasValue)
            {
                var serverCredentials = new BITS.BG_AUTH_CREDENTIALS();
                serverCredentials.Scheme = (BITS.BG_AUTH_SCHEME)authScheme.Value;
                serverCredentials.Target = BITS.BG_AUTH_TARGET.BG_AUTH_TARGET_SERVER;
                serverCredentials.Credentials.Password = _uiPassword.Text;
                serverCredentials.Credentials.UserName = _uiUserName.Text;
                job2.SetCredentials(serverCredentials);
            }

            // Some enterprises have a proxy that requires implicit credentials. For
            // those places, allow the user to add the NEGOTIAGE and NTLM schemes.
            // NEGOTIATE is newer and is more common.
            if (_jobIsAuthProxyImplicit.HasValue && _jobIsAuthProxyImplicit.Value)
            {
                var proxyCredentials = new BITS.BG_AUTH_CREDENTIALS();
                proxyCredentials.Target = BITS.BG_AUTH_TARGET.BG_AUTH_TARGET_PROXY;
                proxyCredentials.Scheme = BITS.BG_AUTH_SCHEME.BG_AUTH_SCHEME_NEGOTIATE;
                proxyCredentials.Credentials.Password = null;
                proxyCredentials.Credentials.UserName = null;
                job2.SetCredentials(proxyCredentials);

                // Some enterprises won't have Nego set up; for them, also allow
                // plain NTLM without the possibility of Kerberos.
                proxyCredentials.Scheme = BITS.BG_AUTH_SCHEME.BG_AUTH_SCHEME_NTLM;
                job2.SetCredentials(proxyCredentials);
            }
        }